1 /*
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Author: Jon Ashburn <jon@lunarg.com>
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <ctype.h>
23 #include <string>
24 #include <algorithm>
25 #include <assert.h>
26 #include <unordered_map>
27 #include <memory>
28
29 #include "vulkan/vk_layer.h"
30 #include "loader/generated/vk_dispatch_table_helper.h"
31 #include "loader/vk_loader_layer.h"
32
33 // Export full support of instance extension VK_EXT_direct_mode_display extension
34 #ifndef TEST_LAYER_EXPORT_DIRECT_DISP
35 #define TEST_LAYER_EXPORT_DIRECT_DISP 0
36 #endif
37
38 // Export full support of instance extension VK_EXT_display_surface_counter extension
39 #ifndef TEST_LAYER_EXPORT_DISP_SURF_COUNT
40 #define TEST_LAYER_EXPORT_DISP_SURF_COUNT 0
41 #endif
42
43 // Export full support of device extension VK_KHR_maintenance1 extension
44 #ifndef TEST_LAYER_EXPORT_MAINT_1
45 #define TEST_LAYER_EXPORT_MAINT_1 0
46 #endif
47
48 // Export full support of device extension VK_KHR_shared_presentable_image extension
49 #ifndef TEST_LAYER_EXPORT_PRESENT_IMAGE
50 #define TEST_LAYER_EXPORT_PRESENT_IMAGE 0
51 #endif
52
53 #if !defined(VK_LAYER_EXPORT)
54 #if defined(__GNUC__) && __GNUC__ >= 4
55 #define VK_LAYER_EXPORT __attribute__((visibility("default")))
56 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
57 #define VK_LAYER_EXPORT __attribute__((visibility("default")))
58 #else
59 #define VK_LAYER_EXPORT
60 #endif
61 #endif
62
63 struct wrapped_phys_dev_obj {
64 VkLayerInstanceDispatchTable *loader_disp;
65 struct wrapped_inst_obj *inst; // parent instance object
66 void *obj;
67 };
68
69 struct wrapped_inst_obj {
70 VkLayerInstanceDispatchTable *loader_disp;
71 VkLayerInstanceDispatchTable layer_disp; // this layer's dispatch table
72 PFN_vkSetInstanceLoaderData pfn_inst_init;
73 struct wrapped_phys_dev_obj *ptr_phys_devs; // any enumerated phys devs
74 VkInstance obj;
75 bool layer_is_implicit;
76 bool direct_display_enabled;
77 bool display_surf_counter_enabled;
78 };
79
80 struct wrapped_dev_obj {
81 VkLayerDispatchTable *loader_disp;
82 VkLayerDispatchTable disp;
83 PFN_vkSetDeviceLoaderData pfn_dev_init;
84 PFN_vkGetDeviceProcAddr pfn_get_dev_proc_addr;
85 VkDevice obj;
86 bool maintanence_1_enabled;
87 bool present_image_enabled;
88 };
89
90 struct wrapped_debutil_mess_obj {
91 VkInstance inst;
92 VkDebugUtilsMessengerEXT obj;
93 };
94
unwrap_instance(const VkInstance instance,wrapped_inst_obj ** inst)95 VkInstance unwrap_instance(const VkInstance instance, wrapped_inst_obj **inst) {
96 *inst = reinterpret_cast<wrapped_inst_obj *>(instance);
97 return (*inst)->obj;
98 }
99
unwrap_phys_dev(const VkPhysicalDevice physical_device,wrapped_phys_dev_obj ** phys_dev)100 VkPhysicalDevice unwrap_phys_dev(const VkPhysicalDevice physical_device, wrapped_phys_dev_obj **phys_dev) {
101 *phys_dev = reinterpret_cast<wrapped_phys_dev_obj *>(physical_device);
102 return reinterpret_cast<VkPhysicalDevice>((*phys_dev)->obj);
103 }
104
unwrap_device(const VkDevice device,wrapped_dev_obj ** dev)105 VkDevice unwrap_device(const VkDevice device, wrapped_dev_obj **dev) {
106 *dev = reinterpret_cast<wrapped_dev_obj *>(device);
107 return (*dev)->obj;
108 }
109
unwrap_debutil_messenger(const VkDebugUtilsMessengerEXT messenger,wrapped_debutil_mess_obj ** mess)110 VkDebugUtilsMessengerEXT unwrap_debutil_messenger(const VkDebugUtilsMessengerEXT messenger, wrapped_debutil_mess_obj **mess) {
111 *mess = reinterpret_cast<wrapped_debutil_mess_obj *>(messenger);
112 return (*mess)->obj;
113 }
114
get_chain_info(const VkInstanceCreateInfo * pCreateInfo,VkLayerFunction func)115 VkLayerInstanceCreateInfo *get_chain_info(const VkInstanceCreateInfo *pCreateInfo, VkLayerFunction func) {
116 VkLayerInstanceCreateInfo *chain_info = (VkLayerInstanceCreateInfo *)pCreateInfo->pNext;
117 while (chain_info && !(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && chain_info->function == func)) {
118 chain_info = (VkLayerInstanceCreateInfo *)chain_info->pNext;
119 }
120 assert(chain_info != NULL);
121 return chain_info;
122 }
123
get_chain_info(const VkDeviceCreateInfo * pCreateInfo,VkLayerFunction func)124 VkLayerDeviceCreateInfo *get_chain_info(const VkDeviceCreateInfo *pCreateInfo, VkLayerFunction func) {
125 VkLayerDeviceCreateInfo *chain_info = (VkLayerDeviceCreateInfo *)pCreateInfo->pNext;
126 while (chain_info && !(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && chain_info->function == func)) {
127 chain_info = (VkLayerDeviceCreateInfo *)chain_info->pNext;
128 }
129 assert(chain_info != NULL);
130 return chain_info;
131 }
132
133 namespace wrap_objects {
134
135 static const VkLayerProperties global_layer = {
136 "VK_LAYER_LUNARG_wrap_objects",
137 VK_HEADER_VERSION_COMPLETE,
138 1,
139 "LunarG Test Layer",
140 };
141
142 uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
143
wrap_vkCreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance)144 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
145 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) {
146 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
147 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
148 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
149 if (fpCreateInstance == NULL) {
150 return VK_ERROR_INITIALIZATION_FAILED;
151 }
152 // Advance the link info for the next element on the chain
153 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
154 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
155 if (result != VK_SUCCESS) {
156 return result;
157 }
158 auto inst = new wrapped_inst_obj;
159 if (!inst) return VK_ERROR_OUT_OF_HOST_MEMORY;
160 memset(inst, 0, sizeof(*inst));
161 inst->obj = (*pInstance);
162 *pInstance = reinterpret_cast<VkInstance>(inst);
163 // store the loader callback for initializing created dispatchable objects
164 chain_info = get_chain_info(pCreateInfo, VK_LOADER_DATA_CALLBACK);
165 if (chain_info) {
166 inst->pfn_inst_init = chain_info->u.pfnSetInstanceLoaderData;
167 result = inst->pfn_inst_init(inst->obj, reinterpret_cast<void *>(inst));
168 if (VK_SUCCESS != result) return result;
169 } else {
170 inst->pfn_inst_init = NULL;
171 inst->loader_disp = *(reinterpret_cast<VkLayerInstanceDispatchTable **>(inst->obj));
172 }
173 layer_init_instance_dispatch_table(*pInstance, &inst->layer_disp, fpGetInstanceProcAddr);
174 bool found = false;
175 for (uint32_t layer = 0; layer < pCreateInfo->enabledLayerCount; ++layer) {
176 std::string layer_name = pCreateInfo->ppEnabledLayerNames[layer];
177 std::transform(layer_name.begin(), layer_name.end(), layer_name.begin(),
178 [](char c) { return static_cast<char>(::tolower(static_cast<char>(c))); });
179 if (layer_name.find("wrap") != std::string::npos && layer_name.find("obj") != std::string::npos) {
180 found = true;
181 break;
182 }
183 }
184 if (!found) {
185 inst->layer_is_implicit = true;
186 }
187
188 for (uint32_t ext = 0; ext < pCreateInfo->enabledExtensionCount; ++ext) {
189 if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME)) {
190 #if TEST_LAYER_EXPORT_DIRECT_DISP
191 inst->direct_display_enabled = true;
192 #endif
193 }
194 if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME)) {
195 #if TEST_LAYER_EXPORT_DISP_SURF_COUNT
196 inst->display_surf_counter_enabled = true;
197 #endif
198 }
199 }
200
201 return result;
202 }
203
wrap_vkDestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)204 VKAPI_ATTR void VKAPI_CALL wrap_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
205 wrapped_inst_obj *inst;
206 auto vk_inst = unwrap_instance(instance, &inst);
207 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
208 pDisp->DestroyInstance(vk_inst, pAllocator);
209 if (inst->ptr_phys_devs) delete[] inst->ptr_phys_devs;
210 delete inst;
211 }
212
wrap_vkCreateDebugUtilsMessengerEXT(VkInstance instance,const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDebugUtilsMessengerEXT * pMessenger)213 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateDebugUtilsMessengerEXT(VkInstance instance,
214 const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
215 const VkAllocationCallbacks *pAllocator,
216 VkDebugUtilsMessengerEXT *pMessenger) {
217 wrapped_inst_obj *inst;
218 auto vk_inst = unwrap_instance(instance, &inst);
219 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
220 VkResult result = pDisp->CreateDebugUtilsMessengerEXT(vk_inst, pCreateInfo, pAllocator, pMessenger);
221 auto mess = new wrapped_debutil_mess_obj;
222 if (!mess) return VK_ERROR_OUT_OF_HOST_MEMORY;
223 memset(mess, 0, sizeof(*mess));
224 mess->obj = (*pMessenger);
225 *pMessenger = reinterpret_cast<VkDebugUtilsMessengerEXT>(mess);
226 return result;
227 }
228
wrap_vkDestroyDebugUtilsMessengerEXT(VkInstance instance,VkDebugUtilsMessengerEXT messenger,const VkAllocationCallbacks * pAllocator)229 VKAPI_ATTR void VKAPI_CALL wrap_vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
230 const VkAllocationCallbacks *pAllocator) {
231 wrapped_inst_obj *inst;
232 auto vk_inst = unwrap_instance(instance, &inst);
233 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
234 wrapped_debutil_mess_obj *mess;
235 auto vk_mess = unwrap_debutil_messenger(messenger, &mess);
236 pDisp->DestroyDebugUtilsMessengerEXT(vk_inst, vk_mess, pAllocator);
237 delete mess;
238 }
239
wrap_vkDestroySurfaceKHR(VkInstance instance,VkSurfaceKHR surface,const VkAllocationCallbacks * pAllocator)240 VKAPI_ATTR void VKAPI_CALL wrap_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
241 const VkAllocationCallbacks *pAllocator) {
242 wrapped_inst_obj *inst;
243 auto vk_inst = unwrap_instance(instance, &inst);
244 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
245 pDisp->DestroySurfaceKHR(vk_inst, surface, pAllocator);
246 }
247 #ifdef VK_USE_PLATFORM_ANDROID_KHR
wrap_vkCreateAndroidSurfaceKHR(VkInstance instance,const VkAndroidSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)248 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
249 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
250 wrapped_inst_obj *inst;
251 auto vk_inst = unwrap_instance(instance, &inst);
252 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
253 return pDisp->CreateAndroidSurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface);
254 }
255 #endif
256
257 #ifdef VK_USE_PLATFORM_WIN32_KHR
wrap_vkCreateWin32SurfaceKHR(VkInstance instance,const VkWin32SurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)258 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
259 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
260 wrapped_inst_obj *inst;
261 auto vk_inst = unwrap_instance(instance, &inst);
262 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
263 return pDisp->CreateWin32SurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface);
264 }
265 #endif // VK_USE_PLATFORM_WIN32_KHR
266
267 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
wrap_vkCreateWaylandSurfaceKHR(VkInstance instance,const VkWaylandSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)268 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
269 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
270 wrapped_inst_obj *inst;
271 auto vk_inst = unwrap_instance(instance, &inst);
272 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
273 return pDisp->CreateWaylandSurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface);
274 }
275 #endif // VK_USE_PLATFORM_WAYLAND_KHR
276
277 #ifdef VK_USE_PLATFORM_XCB_KHR
wrap_vkCreateXcbSurfaceKHR(VkInstance instance,const VkXcbSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)278 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
279 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
280 wrapped_inst_obj *inst;
281 auto vk_inst = unwrap_instance(instance, &inst);
282 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
283 return pDisp->CreateXcbSurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface);
284 }
285 #endif // VK_USE_PLATFORM_XCB_KHR
286
287 #ifdef VK_USE_PLATFORM_XLIB_KHR
wrap_vkCreateXlibSurfaceKHR(VkInstance instance,const VkXlibSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)288 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
289 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
290 wrapped_inst_obj *inst;
291 auto vk_inst = unwrap_instance(instance, &inst);
292 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
293 return pDisp->CreateXlibSurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface);
294 }
295 #endif // VK_USE_PLATFORM_XLIB_KHR
296
297 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
wrap_vkCreateDirectFBSurfaceEXT(VkInstance instance,const VkDirectFBSurfaceCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)298 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateDirectFBSurfaceEXT(VkInstance instance,
299 const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo,
300 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
301 wrapped_inst_obj *inst;
302 auto vk_inst = unwrap_instance(instance, &inst);
303 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
304 return pDisp->CreateDirectFBSurfaceEXT(vk_inst, pCreateInfo, pAllocator, pSurface);
305 }
306 #endif // VK_USE_PLATFORM_DIRECTFB_EXT
307
308 #ifdef VK_USE_PLATFORM_MACOS_MVK
wrap_vkCreateMacOSSurfaceMVK(VkInstance instance,const VkMacOSSurfaceCreateInfoMVK * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)309 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
310 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
311 wrapped_inst_obj *inst;
312 auto vk_inst = unwrap_instance(instance, &inst);
313 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
314 return pDisp->CreateMacOSSurfaceMVK(vk_inst, pCreateInfo, pAllocator, pSurface);
315 }
316 #endif // VK_USE_PLATFORM_MACOS_MVK
317
318 #ifdef VK_USE_PLATFORM_IOS_MVK
wrap_vkCreateIOSSurfaceMVK(VkInstance instance,const VkIOSSurfaceCreateInfoMVK * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)319 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
320 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
321 wrapped_inst_obj *inst;
322 auto vk_inst = unwrap_instance(instance, &inst);
323 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
324 return pDisp->CreateIOSSurfaceMVK(vk_inst, pCreateInfo, pAllocator, pSurface);
325 }
326 #endif // VK_USE_PLATFORM_IOS_MVK
327
328 #ifdef VK_USE_PLATFORM_GGP
wrap_vkCreateStreamDescriptorSurfaceGGP(VkInstance instance,const VkStreamDescriptorSurfaceCreateInfoGGP * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)329 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateStreamDescriptorSurfaceGGP(VkInstance instance,
330 const VkStreamDescriptorSurfaceCreateInfoGGP *pCreateInfo,
331 const VkAllocationCallbacks *pAllocator,
332 VkSurfaceKHR *pSurface) {
333 wrapped_inst_obj *inst;
334 auto vk_inst = unwrap_instance(instance, &inst);
335 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
336 return pDisp->CreateStreamDescriptorSurfaceGGP(vk_inst, pCreateInfo, pAllocator, pSurface);
337 }
338 #endif // VK_USE_PLATFORM_GGP
339
340 #if defined(VK_USE_PLATFORM_METAL_EXT)
wrap_vkCreateMetalSurfaceEXT(VkInstance instance,const VkMetalSurfaceCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)341 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateMetalSurfaceEXT(VkInstance instance, const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
342 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
343 wrapped_inst_obj *inst;
344 auto vk_inst = unwrap_instance(instance, &inst);
345 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
346 return pDisp->CreateMetalSurfaceEXT(vk_inst, pCreateInfo, pAllocator, pSurface);
347 }
348 #endif // VK_USE_PLATFORM_METAL_EXT
349
350 #ifdef VK_USE_PLATFORM_SCREEN_QNX
wrap_vkCreateScreenSurfaceQNX(VkInstance instance,const VkScreenSurfaceCreateInfoQNX * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)351 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateScreenSurfaceQNX(VkInstance instance, const VkScreenSurfaceCreateInfoQNX *pCreateInfo,
352 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
353 wrapped_inst_obj *inst;
354 auto vk_inst = unwrap_instance(instance, &inst);
355 VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp;
356 return pDisp->CreateScreenSurfaceQNX(vk_inst, pCreateInfo, pAllocator, pSurface);
357 }
358 #endif // VK_USE_PLATFORM_SCREEN_QNX
359
wrap_vkEnumeratePhysicalDevices(VkInstance instance,uint32_t * pPhysicalDeviceCount,VkPhysicalDevice * pPhysicalDevices)360 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
361 VkPhysicalDevice *pPhysicalDevices) {
362 wrapped_inst_obj *inst;
363 auto vk_inst = unwrap_instance(instance, &inst);
364 VkResult result = inst->layer_disp.EnumeratePhysicalDevices(vk_inst, pPhysicalDeviceCount, pPhysicalDevices);
365
366 if (VK_SUCCESS != result) return result;
367
368 if (pPhysicalDevices != NULL) {
369 assert(pPhysicalDeviceCount);
370 auto phys_devs = new wrapped_phys_dev_obj[*pPhysicalDeviceCount];
371 if (!phys_devs) return VK_ERROR_OUT_OF_HOST_MEMORY;
372 if (inst->ptr_phys_devs) delete[] inst->ptr_phys_devs;
373 inst->ptr_phys_devs = phys_devs;
374 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
375 if (inst->pfn_inst_init == NULL) {
376 phys_devs[i].loader_disp = *(reinterpret_cast<VkLayerInstanceDispatchTable **>(pPhysicalDevices[i]));
377 } else {
378 result = inst->pfn_inst_init(vk_inst, reinterpret_cast<void *>(&phys_devs[i]));
379 if (VK_SUCCESS != result) return result;
380 }
381 phys_devs[i].obj = reinterpret_cast<void *>(pPhysicalDevices[i]);
382 phys_devs[i].inst = inst;
383 pPhysicalDevices[i] = reinterpret_cast<VkPhysicalDevice>(&phys_devs[i]);
384 }
385 }
386 return result;
387 }
388
vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,VkPhysicalDeviceProperties * pProperties)389 VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) {
390 wrapped_phys_dev_obj *phys_dev;
391 auto vk_phys_dev = unwrap_phys_dev(physicalDevice, &phys_dev);
392 phys_dev->inst->layer_disp.GetPhysicalDeviceProperties(vk_phys_dev, pProperties);
393 }
394
wrap_vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties)395 VKAPI_ATTR void VKAPI_CALL wrap_vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
396 uint32_t *pQueueFamilyPropertyCount,
397 VkQueueFamilyProperties *pQueueFamilyProperties) {
398 wrapped_phys_dev_obj *phys_dev;
399 auto vk_phys_dev = unwrap_phys_dev(physicalDevice, &phys_dev);
400 phys_dev->inst->layer_disp.GetPhysicalDeviceQueueFamilyProperties(vk_phys_dev, pQueueFamilyPropertyCount,
401 pQueueFamilyProperties);
402 }
403
wrap_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,const char * pLayerName,uint32_t * pPropertyCount,VkExtensionProperties * pProperties)404 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
405 uint32_t *pPropertyCount,
406 VkExtensionProperties *pProperties) {
407 VkResult result = VK_SUCCESS;
408 wrapped_phys_dev_obj *phys_dev;
409 auto vk_phys_dev = unwrap_phys_dev(physicalDevice, &phys_dev);
410
411 if (phys_dev->inst->layer_is_implicit || (pLayerName && !strcmp(pLayerName, global_layer.layerName))) {
412 uint32_t ext_count = 0;
413 #if TEST_LAYER_EXPORT_MAINT_1
414 ext_count++;
415 #endif
416 #if TEST_LAYER_EXPORT_PRESENT_IMAGE
417 ext_count++;
418 #endif
419 if (pPropertyCount) {
420 if (pProperties) {
421 uint32_t count = ext_count;
422 if (count > *pPropertyCount) {
423 count = *pPropertyCount;
424 result = VK_INCOMPLETE;
425 }
426
427 ext_count = 0;
428 #if TEST_LAYER_EXPORT_MAINT_1
429 if (ext_count < count) {
430 #if defined(_WIN32)
431 strncpy_s(pProperties[ext_count].extensionName, VK_MAX_EXTENSION_NAME_SIZE, VK_KHR_MAINTENANCE1_EXTENSION_NAME,
432 strlen(VK_KHR_MAINTENANCE1_EXTENSION_NAME) + 1);
433 #else
434 strncpy(pProperties[ext_count].extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE);
435 #endif
436 pProperties[ext_count].specVersion = 2;
437 ext_count++;
438 }
439 #endif
440 #if TEST_LAYER_EXPORT_PRESENT_IMAGE
441 if (ext_count < count) {
442 #if defined(_WIN32)
443 strncpy_s(pProperties[ext_count].extensionName, VK_MAX_EXTENSION_NAME_SIZE,
444 VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME,
445 strlen(VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME) + 1);
446 #else
447 strncpy(pProperties[ext_count].extensionName, VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME,
448 VK_MAX_EXTENSION_NAME_SIZE);
449 #endif
450 pProperties[ext_count].specVersion = 1;
451 ext_count++;
452 }
453 #endif
454 }
455 *pPropertyCount = ext_count;
456 }
457 return result;
458 } else {
459 return phys_dev->inst->layer_disp.EnumerateDeviceExtensionProperties(vk_phys_dev, pLayerName, pPropertyCount, pProperties);
460 }
461 }
462
wrap_vkCreateDevice(VkPhysicalDevice physicalDevice,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice)463 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
464 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
465 wrapped_phys_dev_obj *phys_dev;
466 auto vk_phys_dev = unwrap_phys_dev(physicalDevice, &phys_dev);
467 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
468 PFN_vkGetInstanceProcAddr pfn_get_inst_proc_addr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
469 PFN_vkGetDeviceProcAddr pfn_get_dev_proc_addr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
470 PFN_vkCreateDevice pfn_create_device = (PFN_vkCreateDevice)pfn_get_inst_proc_addr(phys_dev->inst->obj, "vkCreateDevice");
471 if (pfn_create_device == NULL) {
472 return VK_ERROR_INITIALIZATION_FAILED;
473 }
474 // Advance the link info for the next element on the chain
475 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
476 VkResult result = pfn_create_device(vk_phys_dev, pCreateInfo, pAllocator, pDevice);
477 if (result != VK_SUCCESS) {
478 return result;
479 }
480 auto dev = new wrapped_dev_obj;
481 if (!dev) {
482 return VK_ERROR_OUT_OF_HOST_MEMORY;
483 }
484 memset(dev, 0, sizeof(*dev));
485 dev->obj = *pDevice;
486 dev->pfn_get_dev_proc_addr = pfn_get_dev_proc_addr;
487 *pDevice = reinterpret_cast<VkDevice>(dev);
488
489 // Store the loader callback for initializing created dispatchable objects
490 chain_info = get_chain_info(pCreateInfo, VK_LOADER_DATA_CALLBACK);
491 if (chain_info) {
492 dev->pfn_dev_init = chain_info->u.pfnSetDeviceLoaderData;
493 result = dev->pfn_dev_init(dev->obj, reinterpret_cast<void *>(dev));
494 if (VK_SUCCESS != result) {
495 return result;
496 }
497 } else {
498 dev->pfn_dev_init = NULL;
499 }
500
501 // Initialize layer's dispatch table
502 layer_init_device_dispatch_table(dev->obj, &dev->disp, pfn_get_dev_proc_addr);
503
504 for (uint32_t ext = 0; ext < pCreateInfo->enabledExtensionCount; ++ext) {
505 if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_KHR_MAINTENANCE1_EXTENSION_NAME)) {
506 #if TEST_LAYER_EXPORT_MAINT_1
507 dev->maintanence_1_enabled = true;
508 #endif
509 }
510 if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME)) {
511 #if TEST_LAYER_EXPORT_PRESENT_IMAGE
512 dev->present_image_enabled = true;
513 #endif
514 }
515 }
516
517 return result;
518 }
519
wrap_vkDestroyDevice(VkDevice device,const VkAllocationCallbacks * pAllocator)520 VKAPI_ATTR void VKAPI_CALL wrap_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
521 wrapped_dev_obj *dev;
522 auto vk_dev = unwrap_device(device, &dev);
523 dev->disp.DestroyDevice(vk_dev, pAllocator);
524 delete dev;
525 }
526
527 // Fake instance extension support
wrap_vkReleaseDisplayEXT(VkPhysicalDevice physicalDevice,VkDisplayKHR display)528 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkReleaseDisplayEXT(VkPhysicalDevice physicalDevice, VkDisplayKHR display) {
529 return VK_SUCCESS;
530 }
531
wrap_vkGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilities2EXT * pSurfaceCapabilities)532 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
533 VkSurfaceKHR surface,
534 VkSurfaceCapabilities2EXT *pSurfaceCapabilities) {
535 if (nullptr != pSurfaceCapabilities) {
536 pSurfaceCapabilities->minImageCount = 7;
537 pSurfaceCapabilities->maxImageCount = 12;
538 pSurfaceCapabilities->maxImageArrayLayers = 365;
539 }
540 return VK_SUCCESS;
541 }
542
543 // Fake device extension support
wrap_vkTrimCommandPoolKHR(VkDevice device,VkCommandPool commandPool,VkCommandPoolTrimFlags flags)544 VKAPI_ATTR void VKAPI_CALL wrap_vkTrimCommandPoolKHR(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags) {}
545
546 // Return an odd error so we can verify that this actually got called
wrap_vkGetSwapchainStatusKHR(VkDevice device,VkSwapchainKHR swapchain)547 VKAPI_ATTR VkResult VKAPI_CALL wrap_vkGetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR swapchain) {
548 return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR;
549 }
550
layer_intercept_device_proc(wrapped_dev_obj * dev,const char * name)551 PFN_vkVoidFunction layer_intercept_device_proc(wrapped_dev_obj *dev, const char *name) {
552 if (!name || name[0] != 'v' || name[1] != 'k') return NULL;
553
554 name += 2;
555 if (!strcmp(name, "CreateDevice")) return (PFN_vkVoidFunction)wrap_vkCreateDevice;
556 if (!strcmp(name, "DestroyDevice")) return (PFN_vkVoidFunction)wrap_vkDestroyDevice;
557
558 if (dev->maintanence_1_enabled && !strcmp(name, "TrimCommandPoolKHR")) return (PFN_vkVoidFunction)wrap_vkTrimCommandPoolKHR;
559 if (dev->present_image_enabled && !strcmp(name, "GetSwapchainStatusKHR"))
560 return (PFN_vkVoidFunction)wrap_vkGetSwapchainStatusKHR;
561
562 return NULL;
563 }
564
wrap_vkGetDeviceProcAddr(VkDevice device,const char * funcName)565 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL wrap_vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
566 PFN_vkVoidFunction addr;
567
568 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
569 return (PFN_vkVoidFunction)wrap_vkGetDeviceProcAddr;
570 }
571
572 if (device == VK_NULL_HANDLE) {
573 return NULL;
574 }
575
576 wrapped_dev_obj *dev;
577 unwrap_device(device, &dev);
578
579 addr = layer_intercept_device_proc(dev, funcName);
580 if (addr) return addr;
581
582 return dev->pfn_get_dev_proc_addr(dev->obj, funcName);
583 }
584
layer_intercept_instance_proc(wrapped_inst_obj * inst,const char * name)585 PFN_vkVoidFunction layer_intercept_instance_proc(wrapped_inst_obj *inst, const char *name) {
586 if (!name || name[0] != 'v' || name[1] != 'k') return NULL;
587
588 name += 2;
589 if (!strcmp(name, "DestroyInstance")) return (PFN_vkVoidFunction)wrap_vkDestroyInstance;
590 if (!strcmp(name, "CreateDevice")) return (PFN_vkVoidFunction)wrap_vkCreateDevice;
591 if (!strcmp(name, "EnumeratePhysicalDevices")) return (PFN_vkVoidFunction)wrap_vkEnumeratePhysicalDevices;
592
593 if (!strcmp(name, "EnumerateDeviceExtensionProperties")) return (PFN_vkVoidFunction)wrap_vkEnumerateDeviceExtensionProperties;
594
595 if (!strcmp(name, "CreateDebugUtilsMessengerEXT")) return (PFN_vkVoidFunction)wrap_vkCreateDebugUtilsMessengerEXT;
596 if (!strcmp(name, "DestroyDebugUtilsMessengerEXT")) return (PFN_vkVoidFunction)wrap_vkDestroyDebugUtilsMessengerEXT;
597
598 if (!strcmp(name, "GetPhysicalDeviceProperties")) return (PFN_vkVoidFunction)vkGetPhysicalDeviceProperties;
599 if (!strcmp(name, "GetPhysicalDeviceQueueFamilyProperties"))
600 return (PFN_vkVoidFunction)wrap_vkGetPhysicalDeviceQueueFamilyProperties;
601
602 #ifdef VK_USE_PLATFORM_ANDROID_KHR
603 if (!strcmp(name, "CreateAndroidSurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateAndroidSurfaceKHR;
604 #endif // VK_USE_PLATFORM_ANDROID_KHR
605
606 #ifdef VK_USE_PLATFORM_WIN32_KHR
607 if (!strcmp(name, "CreateWin32SurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateWin32SurfaceKHR;
608 #endif // VK_USE_PLATFORM_WIN32_KHR
609
610 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
611 if (!strcmp(name, "CreateWaylandSurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateWaylandSurfaceKHR;
612 #endif // VK_USE_PLATFORM_WAYLAND_KHR
613
614 #ifdef VK_USE_PLATFORM_XCB_KHR
615 if (!strcmp(name, "CreateXcbSurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateXcbSurfaceKHR;
616 #endif // VK_USE_PLATFORM_XCB_KHR
617
618 #ifdef VK_USE_PLATFORM_XLIB_KHR
619 if (!strcmp(name, "CreateXlibSurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateXlibSurfaceKHR;
620 #endif // VK_USE_PLATFORM_XLIB_KHR
621
622 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
623 if (!strcmp(name, "CreateDirectFBSurfaceEXT")) return (PFN_vkVoidFunction)wrap_vkCreateDirectFBSurfaceEXT;
624 #endif // VK_USE_PLATFORM_DIRECTFB_EXT
625
626 #ifdef VK_USE_PLATFORM_MACOS_MVK
627 if (!strcmp(name, "CreateMacOSSurfaceMVK")) return (PFN_vkVoidFunction)wrap_vkCreateMacOSSurfaceMVK;
628 #endif // VK_USE_PLATFORM_MACOS_MVK
629
630 #ifdef VK_USE_PLATFORM_IOS_MVK
631 if (!strcmp(name, "CreateIOSSurfaceMVK")) return (PFN_vkVoidFunction)wrap_vkCreateIOSSurfaceMVK;
632 #endif // VK_USE_PLATFORM_IOS_MVK
633
634 #ifdef VK_USE_PLATFORM_GGP
635 if (!strcmp(name, "CreateStreamDescriptorSurfaceGGP")) return (PFN_vkVoidFunction)wrap_vkCreateStreamDescriptorSurfaceGGP;
636 #endif // VK_USE_PLATFORM_GGP
637
638 #if defined(VK_USE_PLATFORM_METAL_EXT)
639 if (!strcmp(name, "CreateMetalSurfaceEXT")) return (PFN_vkVoidFunction)wrap_vkCreateMetalSurfaceEXT;
640 #endif // VK_USE_PLATFORM_METAL_EXT
641
642 #ifdef VK_USE_PLATFORM_SCREEN_QNX
643 if (!strcmp(name, "CreateScreenSurfaceQNX")) return (PFN_vkVoidFunction)wrap_vkCreateScreenSurfaceQNX;
644 #endif // VK_USE_PLATFORM_SCREEN_QNX
645 if (!strcmp(name, "DestroySurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkDestroySurfaceKHR;
646
647 if (inst->direct_display_enabled && !strcmp(name, "ReleaseDisplayEXT")) return (PFN_vkVoidFunction)wrap_vkReleaseDisplayEXT;
648 if (inst->display_surf_counter_enabled && !strcmp(name, "GetPhysicalDeviceSurfaceCapabilities2EXT"))
649 return (PFN_vkVoidFunction)wrap_vkGetPhysicalDeviceSurfaceCapabilities2EXT;
650
651 return NULL;
652 }
653
wrap_vkGetInstanceProcAddr(VkInstance instance,const char * funcName)654 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL wrap_vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
655 PFN_vkVoidFunction addr;
656
657 if (!strcmp(funcName, "vkGetInstanceProcAddr")) return (PFN_vkVoidFunction)wrap_vkGetInstanceProcAddr;
658 if (!strcmp(funcName, "vkCreateInstance")) return (PFN_vkVoidFunction)wrap_vkCreateInstance;
659
660 if (instance == VK_NULL_HANDLE) {
661 return NULL;
662 }
663
664 wrapped_inst_obj *inst;
665 (void)unwrap_instance(instance, &inst);
666
667 addr = layer_intercept_instance_proc(inst, funcName);
668 if (addr) return addr;
669
670 VkLayerInstanceDispatchTable *pTable = &inst->layer_disp;
671
672 if (pTable->GetInstanceProcAddr == NULL) return NULL;
673 return pTable->GetInstanceProcAddr(instance, funcName);
674 }
675
GetPhysicalDeviceProcAddr(VkInstance instance,const char * funcName)676 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
677 assert(instance);
678
679 wrapped_inst_obj *inst;
680 (void)unwrap_instance(instance, &inst);
681 VkLayerInstanceDispatchTable *pTable = &inst->layer_disp;
682
683 if (pTable->GetPhysicalDeviceProcAddr == NULL) return NULL;
684 return pTable->GetPhysicalDeviceProcAddr(instance, funcName);
685 }
686
687 } // namespace wrap_objects
688
689 extern "C" {
690 // loader-layer interface v0, just wrappers since there is only a layer
vkGetInstanceProcAddr(VkInstance instance,const char * funcName)691 VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
692 return wrap_objects::wrap_vkGetInstanceProcAddr(instance, funcName);
693 }
694
vkGetDeviceProcAddr(VkDevice device,const char * funcName)695 VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
696 return wrap_objects::wrap_vkGetDeviceProcAddr(device, funcName);
697 }
698
vkEnumerateInstanceExtensionProperties(const char * pLayerName,uint32_t * pCount,VkExtensionProperties * pProperties)699 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
700 VkExtensionProperties *pProperties) {
701 assert(0); // TODO return wrap_objects::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
702 return VK_SUCCESS;
703 }
704
vkEnumerateInstanceLayerProperties(uint32_t * pCount,VkLayerProperties * pProperties)705 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
706 VkLayerProperties *pProperties) {
707 assert(0); // TODO return wrap_objects::EnumerateInstanceLayerProperties(pCount, pProperties);
708 return VK_SUCCESS;
709 }
710
vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,const char * pLayerName,uint32_t * pCount,VkExtensionProperties * pProperties)711 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
712 const char *pLayerName, uint32_t *pCount,
713 VkExtensionProperties *pProperties) {
714 // the layer command handles VK_NULL_HANDLE just fine internally
715 assert(physicalDevice == VK_NULL_HANDLE);
716 return wrap_objects::wrap_vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
717 }
718
vkCreateDebugUtilsMessengerEXT(VkInstance instance,const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDebugUtilsMessengerEXT * pMessenger)719 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance,
720 const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo,
721 const VkAllocationCallbacks *pAllocator,
722 VkDebugUtilsMessengerEXT *pMessenger) {
723 return wrap_objects::wrap_vkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
724 }
725
vkDestroyDebugUtilsMessengerEXT(VkInstance instance,VkDebugUtilsMessengerEXT messenger,const VkAllocationCallbacks * pAllocator)726 VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
727 const VkAllocationCallbacks *pAllocator) {
728 return wrap_objects::wrap_vkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
729 }
730
vkDestroySurfaceKHR(VkInstance instance,VkSurfaceKHR surface,const VkAllocationCallbacks * pAllocator)731 VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator) {
732 return wrap_objects::wrap_vkDestroySurfaceKHR(instance, surface, pAllocator);
733 }
734
735 #ifdef VK_USE_PLATFORM_ANDROID_KHR
test_vkCreateAndroidSurfaceKHR(VkInstance instance,const VkAndroidSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)736 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
737 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
738 return wrap_objects::wrap_vkCreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
739 }
740 #endif // VK_USE_PLATFORM_WIN32_KHR
741
742 #ifdef VK_USE_PLATFORM_WIN32_KHR
vkCreateWin32SurfaceKHR(VkInstance instance,const VkWin32SurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)743 VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
744 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
745 return wrap_objects::wrap_vkCreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
746 }
747 #endif // VK_USE_PLATFORM_WIN32_KHR
748
749 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
vkCreateWaylandSurfaceKHR(VkInstance instance,const VkWaylandSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)750 VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
751 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
752 return wrap_objects::wrap_vkCreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
753 }
754 #endif // VK_USE_PLATFORM_WAYLAND_KHR
755
756 #ifdef VK_USE_PLATFORM_XCB_KHR
vkCreateXcbSurfaceKHR(VkInstance instance,const VkXcbSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)757 VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
758 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
759 return wrap_objects::wrap_vkCreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
760 }
761 #endif // VK_USE_PLATFORM_XCB_KHR
762
763 #ifdef VK_USE_PLATFORM_XLIB_KHR
vkCreateXlibSurfaceKHR(VkInstance instance,const VkXlibSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)764 VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
765 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
766 return wrap_objects::wrap_vkCreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
767 }
768 #endif // VK_USE_PLATFORM_XLIB_KHR
769
770 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
vkCreateDirectFBSurfaceEXT(VkInstance instance,const VkDirectFBSurfaceCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)771 VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT(VkInstance instance, const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo,
772 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
773 return wrap_objects::wrap_vkCreateDirectFBSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
774 }
775 #endif // VK_USE_PLATFORM_DIRECTFB_EXT
776
777 #ifdef VK_USE_PLATFORM_MACOS_MVK
vkCreateMacOSSurfaceMVK(VkInstance instance,const VkMacOSSurfaceCreateInfoMVK * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)778 VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
779 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
780 return wrap_objects::wrap_vkCreateMacOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
781 }
782 #endif // VK_USE_PLATFORM_MACOS_MVK
783
784 #ifdef VK_USE_PLATFORM_IOS_MVK
vkCreateIOSSurfaceMVK(VkInstance instance,const VkIOSSurfaceCreateInfoMVK * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)785 VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
786 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
787 return wrap_objects::wrap_vkCreateIOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
788 }
789 #endif // VK_USE_PLATFORM_IOS_MVK
790
791 #ifdef VK_USE_PLATFORM_GGP
vkCreateStreamDescriptorSurfaceGGP(VkInstance instance,const VkStreamDescriptorSurfaceCreateInfoGGP * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)792 VKAPI_ATTR VkResult VKAPI_CALL vkCreateStreamDescriptorSurfaceGGP(VkInstance instance,
793 const VkStreamDescriptorSurfaceCreateInfoGGP *pCreateInfo,
794 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
795 return wrap_objects::wrap_vkCreateStreamDescriptorSurfaceGGP(instance, pCreateInfo, pAllocator, pSurface);
796 }
797 #endif // VK_USE_PLATFORM_GGP
798
799 #if defined(VK_USE_PLATFORM_METAL_EXT)
vkCreateMetalSurfaceEXT(VkInstance instance,const VkMetalSurfaceCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)800 VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT(VkInstance instance, const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
801 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
802 return wrap_objects::wrap_vkCreateMetalSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
803 }
804 #endif // VK_USE_PLATFORM_METAL_EXT
805
806 #ifdef VK_USE_PLATFORM_SCREEN_QNX
vkCreateScreenSurfaceQNX(VkInstance instance,const VkScreenSurfaceCreateInfoQNX * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)807 VKAPI_ATTR VkResult VKAPI_CALL vkCreateScreenSurfaceQNX(VkInstance instance, const VkScreenSurfaceCreateInfoQNX *pCreateInfo,
808 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
809 return wrap_objects::wrap_vkCreateScreenSurfaceQNX(instance, pCreateInfo, pAllocator, pSurface);
810 }
811 #endif // VK_USE_PLATFORM_SCREEN_QNX
812
vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,const char * funcName)813 VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
814 const char *funcName) {
815 return wrap_objects::GetPhysicalDeviceProcAddr(instance, funcName);
816 }
817
vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface * pVersionStruct)818 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
819 assert(pVersionStruct != NULL);
820 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
821
822 // Fill in the function pointers if our version is at least capable of having the structure contain them.
823 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
824 pVersionStruct->pfnGetInstanceProcAddr = wrap_objects::wrap_vkGetInstanceProcAddr;
825 pVersionStruct->pfnGetDeviceProcAddr = wrap_objects::wrap_vkGetDeviceProcAddr;
826 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
827 }
828
829 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
830 wrap_objects::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
831 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
832 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
833 }
834
835 return VK_SUCCESS;
836 }
837 }
838