blob: c226a02259d2ea04853fdc74dbd6ac88bc42b828 [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{
108 uint32_t gpu_index;
Courtney Goeltzenleuchter5c55b352015-06-10 17:52:04 -0600109 /* TODO: need another way to find the icd, display is not a gpu object */
Jon Ashburncedc15f2015-05-21 18:13:33 -0600110 struct loader_icd *icd = loader_get_icd((const VkBaseLayerObject *) display, &gpu_index);
111 VkResult res = VK_ERROR_INITIALIZATION_FAILED;
112
113 if (icd->GetDisplayInfoWSI)
114 res = icd->GetDisplayInfoWSI(display, infoType, pDataSize, pData);
115
116 return res;
117}
118
119
120/************ extension enablement ***************/
121static bool wsi_enabled = false;
122
123struct ext_props {
124 uint32_t version;
125 const char * const name;
126};
127
128#define WSI_LUNARG_EXT_ARRAY_SIZE 1
129static const struct ext_props wsi_lunarg_exts[WSI_LUNARG_EXT_ARRAY_SIZE] = {
130 {VK_WSI_LUNARG_REVISION, VK_WSI_LUNARG_EXTENSION_NAME},
131};
132
133void wsi_lunarg_register_extensions(
134 const VkInstanceCreateInfo* pCreateInfo)
135{
136 uint32_t i, ext_idx;
137
138 for (i = 0; i < pCreateInfo->extensionCount; i++) {
139 for (ext_idx = 0; ext_idx < WSI_LUNARG_EXT_ARRAY_SIZE; ext_idx++) {
140 /* TODO: Should we include version number as well as extension name? */
141 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], wsi_lunarg_exts[ext_idx].name) == 0) {
142 /* Found a matching extension name, mark it enabled */
143 wsi_enabled = true;
144 }
145
146 }
147 }
148
149}
150
151void *wsi_lunarg_GetInstanceProcAddr(
152 VkInstance instance,
153 const char* pName)
154{
155 if (instance == VK_NULL_HANDLE)
156 return NULL;
157
158 if (wsi_enabled == false)
159 return NULL;
160
161 /* since two of these entrypoints must be loader handled will report all */
162 if (!strcmp(pName, "vkGetDisplayInfoWSI"))
163 return (void*) wsi_lunarg_GetDisplayInfoWSI;
164 if (!strcmp(pName, "vkCreateSwapChainWSI"))
165 return (void*) wsi_lunarg_CreateSwapChainWSI;
166 if (!strcmp(pName, "vkDestroySwapChainWSI"))
167 return (void*) wsi_lunarg_DestroySwapChainWSI;
168 if (!strcmp(pName, "vkGetSwapChainInfoWSI"))
169 return (void*) wsi_lunarg_GetSwapChainInfoWSI;
170 if (!strcmp(pName, "vkQueuePresentWSI"))
171 return (void*) wsi_lunarg_QueuePresentWSI;
172
173 return NULL;
174}
175
176void *wsi_lunarg_GetDeviceProcAddr(
177 VkDevice device,
178 const char* name)
179{
180 if (device == VK_NULL_HANDLE)
181 return NULL;
182
183 if (wsi_enabled == false)
184 return NULL;
185
186 /* 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}