blob: 91be81241f18932c09d6f9111face4075c973664 [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;
43
44 disp = loader_get_instance_dispatch(display);
45
46 return disp->GetDisplayInfoWSI(display, infoType, pDataSize, pData);
47}
48
49VkResult wsi_lunarg_CreateSwapChainWSI(
50 VkDevice device,
51 const VkSwapChainCreateInfoWSI* pCreateInfo,
52 VkSwapChainWSI* pSwapChain)
53{
54 const VkLayerDispatchTable *disp;
55 VkResult res;
56
57 disp = loader_get_dispatch(device);
58
59 res = disp->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
60 if (res == VK_SUCCESS) {
61 loader_init_dispatch(*pSwapChain, disp);
62 }
63
64 return res;
65}
66
67VkResult wsi_lunarg_DestroySwapChainWSI(
68 VkSwapChainWSI swapChain)
69{
70 const VkLayerDispatchTable *disp;
71
72 disp = loader_get_dispatch(swapChain);
73
74 return disp->DestroySwapChainWSI(swapChain);
75}
76
77static VkResult wsi_lunarg_GetSwapChainInfoWSI(
78 VkSwapChainWSI swapChain,
79 VkSwapChainInfoTypeWSI infoType,
80 size_t* pDataSize,
81 void* pData)
82{
83 const VkLayerDispatchTable *disp;
84
85 disp = loader_get_dispatch(swapChain);
86
87 return disp->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
88}
89
90static VkResult wsi_lunarg_QueuePresentWSI(
91 VkQueue queue,
92 const VkPresentInfoWSI* pPresentInfo)
93{
94 const VkLayerDispatchTable *disp;
95
96 disp = loader_get_dispatch(queue);
97
98 return disp->QueuePresentWSI(queue, pPresentInfo);
99}
100
101/************ loader instance chain termination entrypoints ***************/
102VkResult loader_GetDisplayInfoWSI(
103 VkDisplayWSI display,
104 VkDisplayInfoTypeWSI infoType,
105 size_t* pDataSize,
106 void* pData)
107{
Courtney Goeltzenleuchter5c55b352015-06-10 17:52:04 -0600108 /* TODO: need another way to find the icd, display is not a gpu object */
Courtney Goeltzenleuchterac13c6f2015-06-10 20:39:06 -0600109// uint32_t gpu_index;
110// struct loader_icd *icd = loader_get_icd((VkPhysicalDevice) display, &gpu_index); //TODO fix dispaly -> PhysDev
Jon Ashburncedc15f2015-05-21 18:13:33 -0600111 VkResult res = VK_ERROR_INITIALIZATION_FAILED;
112
Courtney Goeltzenleuchterac13c6f2015-06-10 20:39:06 -0600113 for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) {
114 for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) {
115 for (uint32_t i = 0; i < icd->gpu_count; i++) {
116 if (icd->GetDisplayInfoWSI)
117 res = icd->GetDisplayInfoWSI(display, infoType, pDataSize, pData);
118 }
119 }
120 }
Jon Ashburncedc15f2015-05-21 18:13:33 -0600121
122 return res;
123}
124
125
126/************ extension enablement ***************/
Jon Ashburncedc15f2015-05-21 18:13:33 -0600127#define WSI_LUNARG_EXT_ARRAY_SIZE 1
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600128static const struct loader_extension_property wsi_lunarg_extension_info = {
129 .info = {
130 .sType = VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
131 .name = VK_WSI_LUNARG_EXTENSION_NAME,
132 .version = VK_WSI_LUNARG_REVISION,
133 .description = "loader: LunarG WSI extension",
134// .dependencyCount = 0,
135// .pDependencyList = NULL,
136 },
137 .origin = VK_EXTENSION_ORIGIN_LOADER,
138 .hosted = true,
Jon Ashburncedc15f2015-05-21 18:13:33 -0600139};
140
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600141void wsi_lunarg_create_instance(
142 struct loader_instance *ptr_instance)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600143{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600144 ptr_instance->wsi_lunarg_enabled = has_vk_extension_property(
145 &wsi_lunarg_extension_info.info,
146 &ptr_instance->enabled_instance_extensions);
Jon Ashburncedc15f2015-05-21 18:13:33 -0600147}
148
149void *wsi_lunarg_GetInstanceProcAddr(
150 VkInstance instance,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600151 const char* pName)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600152{
153 if (instance == VK_NULL_HANDLE)
154 return NULL;
155
Jon Ashburncedc15f2015-05-21 18:13:33 -0600156 /* since two of these entrypoints must be loader handled will report all */
157 if (!strcmp(pName, "vkGetDisplayInfoWSI"))
158 return (void*) wsi_lunarg_GetDisplayInfoWSI;
159 if (!strcmp(pName, "vkCreateSwapChainWSI"))
160 return (void*) wsi_lunarg_CreateSwapChainWSI;
161 if (!strcmp(pName, "vkDestroySwapChainWSI"))
162 return (void*) wsi_lunarg_DestroySwapChainWSI;
163 if (!strcmp(pName, "vkGetSwapChainInfoWSI"))
164 return (void*) wsi_lunarg_GetSwapChainInfoWSI;
165 if (!strcmp(pName, "vkQueuePresentWSI"))
166 return (void*) wsi_lunarg_QueuePresentWSI;
167
168 return NULL;
169}
170
171void *wsi_lunarg_GetDeviceProcAddr(
172 VkDevice device,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600173 const char* name)
Jon Ashburncedc15f2015-05-21 18:13:33 -0600174{
175 if (device == VK_NULL_HANDLE)
176 return NULL;
177
Jon Ashburncedc15f2015-05-21 18:13:33 -0600178 /* only handle device entrypoints that are loader special cases */
179 if (!strcmp(name, "vkCreateSwapChainWSI"))
180 return (void*) wsi_lunarg_CreateSwapChainWSI;
181
182 return NULL;
183}