blob: f4b62da7c70f40168dc0e1181c204979be3d2fd7 [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,
Jon Ashburncedc15f2015-05-21 18:13:33 -0600140};
141
Jon Ashburna445e092015-05-26 13:57:35 -0600142void wsi_lunarg_add_instance_extensions(
143 struct loader_extension_list *ext_list)
144{
145 loader_add_to_ext_list(ext_list, 1, &wsi_lunarg_extension_info);
146}
147
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600148void wsi_lunarg_create_instance(
149 struct loader_instance *ptr_instance)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600150{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600151 ptr_instance->wsi_lunarg_enabled = has_vk_extension_property(
152 &wsi_lunarg_extension_info.info,
153 &ptr_instance->enabled_instance_extensions);
Jon Ashburncedc15f2015-05-21 18:13:33 -0600154}
155
156void *wsi_lunarg_GetInstanceProcAddr(
157 VkInstance instance,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600158 const char* pName)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600159{
160 if (instance == VK_NULL_HANDLE)
161 return NULL;
162
Jon Ashburncedc15f2015-05-21 18:13:33 -0600163 /* since two of these entrypoints must be loader handled will report all */
164 if (!strcmp(pName, "vkGetDisplayInfoWSI"))
165 return (void*) wsi_lunarg_GetDisplayInfoWSI;
166 if (!strcmp(pName, "vkCreateSwapChainWSI"))
167 return (void*) wsi_lunarg_CreateSwapChainWSI;
168 if (!strcmp(pName, "vkDestroySwapChainWSI"))
169 return (void*) wsi_lunarg_DestroySwapChainWSI;
170 if (!strcmp(pName, "vkGetSwapChainInfoWSI"))
171 return (void*) wsi_lunarg_GetSwapChainInfoWSI;
172 if (!strcmp(pName, "vkQueuePresentWSI"))
173 return (void*) wsi_lunarg_QueuePresentWSI;
174
175 return NULL;
176}
177
178void *wsi_lunarg_GetDeviceProcAddr(
179 VkDevice device,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600180 const char* name)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600181{
182 if (device == VK_NULL_HANDLE)
183 return NULL;
184
Jon Ashburncedc15f2015-05-21 18:13:33 -0600185 /* only handle device entrypoints that are loader special cases */
186 if (!strcmp(name, "vkCreateSwapChainWSI"))
187 return (void*) wsi_lunarg_CreateSwapChainWSI;
188
189 return NULL;
190}