blob: 0269f272debd7ef81821c46bef27c8265f2c3d37 [file] [log] [blame]
Jon Ashburncedc15f2015-05-21 18:13:33 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Jon Ashburn <jon@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
27 */
28
29#include <string.h>
30#include "loader_platform.h"
31#include "loader.h"
32#include "wsi_lunarg.h"
33
34/************ Trampoline entrypoints *******************/
35/* since one entrypoint is instance level will make available all entrypoints */
Jon Ashburnba4a1952015-06-16 12:44:51 -060036/* TODO make this a device extension with NO trampoline code */
Jon Ashburncedc15f2015-05-21 18:13:33 -060037
38VkResult wsi_lunarg_CreateSwapChainWSI(
39 VkDevice device,
40 const VkSwapChainCreateInfoWSI* pCreateInfo,
41 VkSwapChainWSI* pSwapChain)
42{
43 const VkLayerDispatchTable *disp;
44 VkResult res;
45
46 disp = loader_get_dispatch(device);
47
48 res = disp->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
49 if (res == VK_SUCCESS) {
50 loader_init_dispatch(*pSwapChain, disp);
51 }
52
53 return res;
54}
55
56VkResult wsi_lunarg_DestroySwapChainWSI(
57 VkSwapChainWSI swapChain)
58{
59 const VkLayerDispatchTable *disp;
60
61 disp = loader_get_dispatch(swapChain);
62
63 return disp->DestroySwapChainWSI(swapChain);
64}
65
66static VkResult wsi_lunarg_GetSwapChainInfoWSI(
67 VkSwapChainWSI swapChain,
68 VkSwapChainInfoTypeWSI infoType,
69 size_t* pDataSize,
70 void* pData)
71{
72 const VkLayerDispatchTable *disp;
73
74 disp = loader_get_dispatch(swapChain);
75
76 return disp->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
77}
78
79static VkResult wsi_lunarg_QueuePresentWSI(
80 VkQueue queue,
81 const VkPresentInfoWSI* pPresentInfo)
82{
83 const VkLayerDispatchTable *disp;
84
85 disp = loader_get_dispatch(queue);
86
87 return disp->QueuePresentWSI(queue, pPresentInfo);
88}
89
Jon Ashburncedc15f2015-05-21 18:13:33 -060090/************ extension enablement ***************/
Jon Ashburncedc15f2015-05-21 18:13:33 -060091#define WSI_LUNARG_EXT_ARRAY_SIZE 1
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060092static const struct loader_extension_property wsi_lunarg_extension_info = {
93 .info = {
94 .sType = VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
95 .name = VK_WSI_LUNARG_EXTENSION_NAME,
96 .version = VK_WSI_LUNARG_REVISION,
97 .description = "loader: LunarG WSI extension",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060098 },
99 .origin = VK_EXTENSION_ORIGIN_LOADER,
Jon Ashburncedc15f2015-05-21 18:13:33 -0600100};
101
Jon Ashburna445e092015-05-26 13:57:35 -0600102void wsi_lunarg_add_instance_extensions(
103 struct loader_extension_list *ext_list)
104{
105 loader_add_to_ext_list(ext_list, 1, &wsi_lunarg_extension_info);
106}
107
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600108void wsi_lunarg_create_instance(
109 struct loader_instance *ptr_instance)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600110{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600111 ptr_instance->wsi_lunarg_enabled = has_vk_extension_property(
112 &wsi_lunarg_extension_info.info,
113 &ptr_instance->enabled_instance_extensions);
Jon Ashburncedc15f2015-05-21 18:13:33 -0600114}
115
116void *wsi_lunarg_GetInstanceProcAddr(
117 VkInstance instance,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600118 const char* pName)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600119{
120 if (instance == VK_NULL_HANDLE)
121 return NULL;
122
Jon Ashburnba4a1952015-06-16 12:44:51 -0600123 /* since one of these entrypoints must be loader handled will report all */
Jon Ashburncedc15f2015-05-21 18:13:33 -0600124 if (!strcmp(pName, "vkCreateSwapChainWSI"))
125 return (void*) wsi_lunarg_CreateSwapChainWSI;
126 if (!strcmp(pName, "vkDestroySwapChainWSI"))
127 return (void*) wsi_lunarg_DestroySwapChainWSI;
128 if (!strcmp(pName, "vkGetSwapChainInfoWSI"))
129 return (void*) wsi_lunarg_GetSwapChainInfoWSI;
130 if (!strcmp(pName, "vkQueuePresentWSI"))
131 return (void*) wsi_lunarg_QueuePresentWSI;
132
133 return NULL;
134}
135
136void *wsi_lunarg_GetDeviceProcAddr(
137 VkDevice device,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600138 const char* name)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600139{
140 if (device == VK_NULL_HANDLE)
141 return NULL;
142
Jon Ashburncedc15f2015-05-21 18:13:33 -0600143 /* only handle device entrypoints that are loader special cases */
144 if (!strcmp(name, "vkCreateSwapChainWSI"))
145 return (void*) wsi_lunarg_CreateSwapChainWSI;
146
147 return NULL;
148}