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