blob: e5d1513ee8e249319a0c4cb242016ca8124deaf7 [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 */
36VkResult VKAPI wsi_lunarg_GetDisplayInfoWSI(
37 VkDisplayWSI display,
38 VkDisplayInfoTypeWSI infoType,
39 size_t* pDataSize,
40 void* pData)
41{
42 const VkLayerInstanceDispatchTable *disp;
Jon Ashburnb40f2562015-05-29 13:15:39 -060043 VkResult res;
Jon Ashburncedc15f2015-05-21 18:13:33 -060044
45 disp = loader_get_instance_dispatch(display);
46
Jon Ashburnb40f2562015-05-29 13:15:39 -060047 loader_platform_thread_lock_mutex(&loader_lock);
48 res = disp->GetDisplayInfoWSI(display, infoType, pDataSize, pData);
49 loader_platform_thread_unlock_mutex(&loader_lock);
50 return res;
Jon Ashburncedc15f2015-05-21 18:13:33 -060051}
52
53VkResult wsi_lunarg_CreateSwapChainWSI(
54 VkDevice device,
55 const VkSwapChainCreateInfoWSI* pCreateInfo,
56 VkSwapChainWSI* pSwapChain)
57{
58 const VkLayerDispatchTable *disp;
59 VkResult res;
60
61 disp = loader_get_dispatch(device);
62
63 res = disp->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
64 if (res == VK_SUCCESS) {
65 loader_init_dispatch(*pSwapChain, disp);
66 }
67
68 return res;
69}
70
71VkResult wsi_lunarg_DestroySwapChainWSI(
72 VkSwapChainWSI swapChain)
73{
74 const VkLayerDispatchTable *disp;
75
76 disp = loader_get_dispatch(swapChain);
77
78 return disp->DestroySwapChainWSI(swapChain);
79}
80
81static VkResult wsi_lunarg_GetSwapChainInfoWSI(
82 VkSwapChainWSI swapChain,
83 VkSwapChainInfoTypeWSI infoType,
84 size_t* pDataSize,
85 void* pData)
86{
87 const VkLayerDispatchTable *disp;
88
89 disp = loader_get_dispatch(swapChain);
90
91 return disp->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
92}
93
94static VkResult wsi_lunarg_QueuePresentWSI(
95 VkQueue queue,
96 const VkPresentInfoWSI* pPresentInfo)
97{
98 const VkLayerDispatchTable *disp;
99
100 disp = loader_get_dispatch(queue);
101
102 return disp->QueuePresentWSI(queue, pPresentInfo);
103}
104
105/************ loader instance chain termination entrypoints ***************/
106VkResult loader_GetDisplayInfoWSI(
107 VkDisplayWSI display,
108 VkDisplayInfoTypeWSI infoType,
109 size_t* pDataSize,
110 void* pData)
111{
Courtney Goeltzenleuchter5c55b352015-06-10 17:52:04 -0600112 /* TODO: need another way to find the icd, display is not a gpu object */
Courtney Goeltzenleuchterac13c6f2015-06-10 20:39:06 -0600113// uint32_t gpu_index;
114// struct loader_icd *icd = loader_get_icd((VkPhysicalDevice) display, &gpu_index); //TODO fix dispaly -> PhysDev
Jon Ashburncedc15f2015-05-21 18:13:33 -0600115 VkResult res = VK_ERROR_INITIALIZATION_FAILED;
116
Courtney Goeltzenleuchterac13c6f2015-06-10 20:39:06 -0600117 for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) {
118 for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) {
119 for (uint32_t i = 0; i < icd->gpu_count; i++) {
120 if (icd->GetDisplayInfoWSI)
121 res = icd->GetDisplayInfoWSI(display, infoType, pDataSize, pData);
122 }
123 }
124 }
Jon Ashburncedc15f2015-05-21 18:13:33 -0600125
126 return res;
127}
128
129
130/************ extension enablement ***************/
Jon Ashburncedc15f2015-05-21 18:13:33 -0600131#define WSI_LUNARG_EXT_ARRAY_SIZE 1
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600132static const struct loader_extension_property wsi_lunarg_extension_info = {
133 .info = {
134 .sType = VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
135 .name = VK_WSI_LUNARG_EXTENSION_NAME,
136 .version = VK_WSI_LUNARG_REVISION,
137 .description = "loader: LunarG WSI extension",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600138 },
139 .origin = VK_EXTENSION_ORIGIN_LOADER,
140 .hosted = true,
Jon Ashburncedc15f2015-05-21 18:13:33 -0600141};
142
Jon Ashburna445e092015-05-26 13:57:35 -0600143void wsi_lunarg_add_instance_extensions(
144 struct loader_extension_list *ext_list)
145{
146 loader_add_to_ext_list(ext_list, 1, &wsi_lunarg_extension_info);
147}
148
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600149void wsi_lunarg_create_instance(
150 struct loader_instance *ptr_instance)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600151{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600152 ptr_instance->wsi_lunarg_enabled = has_vk_extension_property(
153 &wsi_lunarg_extension_info.info,
154 &ptr_instance->enabled_instance_extensions);
Jon Ashburncedc15f2015-05-21 18:13:33 -0600155}
156
157void *wsi_lunarg_GetInstanceProcAddr(
158 VkInstance instance,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600159 const char* pName)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600160{
161 if (instance == VK_NULL_HANDLE)
162 return NULL;
163
Jon Ashburncedc15f2015-05-21 18:13:33 -0600164 /* since two of these entrypoints must be loader handled will report all */
165 if (!strcmp(pName, "vkGetDisplayInfoWSI"))
166 return (void*) wsi_lunarg_GetDisplayInfoWSI;
167 if (!strcmp(pName, "vkCreateSwapChainWSI"))
168 return (void*) wsi_lunarg_CreateSwapChainWSI;
169 if (!strcmp(pName, "vkDestroySwapChainWSI"))
170 return (void*) wsi_lunarg_DestroySwapChainWSI;
171 if (!strcmp(pName, "vkGetSwapChainInfoWSI"))
172 return (void*) wsi_lunarg_GetSwapChainInfoWSI;
173 if (!strcmp(pName, "vkQueuePresentWSI"))
174 return (void*) wsi_lunarg_QueuePresentWSI;
175
176 return NULL;
177}
178
179void *wsi_lunarg_GetDeviceProcAddr(
180 VkDevice device,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600181 const char* name)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600182{
183 if (device == VK_NULL_HANDLE)
184 return NULL;
185
Jon Ashburncedc15f2015-05-21 18:13:33 -0600186 /* only handle device entrypoints that are loader special cases */
187 if (!strcmp(name, "vkCreateSwapChainWSI"))
188 return (void*) wsi_lunarg_CreateSwapChainWSI;
189
190 return NULL;
191}