1 /*
2  * Copyright (c) 2015-2016 The Khronos Group Inc.
3  * Copyright (c) 2015-2016 Valve Corporation
4  * Copyright (c) 2015-2016 LunarG, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and/or associated documentation files (the "Materials"), to
8  * deal in the Materials without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Materials, and to permit persons to whom the Materials are
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice(s) and this permission notice shall be included in
14  * all copies or substantial portions of the Materials.
15  *
16  * THE MATERIALS ARE 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.
19  *
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23  * USE OR OTHER DEALINGS IN THE MATERIALS.
24  *
25  * Author: Ian Elliott <ian@lunarg.com>
26  * Author: Jon Ashburn <jon@lunarg.com>
27  * Author: Ian Elliott <ianelliott@google.com>
28  * Author: Mark Lobodzinski <mark@lunarg.com>
29  */
30 
31 //#define _ISOC11_SOURCE /* for aligned_alloc() */
32 #define _GNU_SOURCE
33 #include <stdlib.h>
34 #include <string.h>
35 #include "vk_loader_platform.h"
36 #include "loader.h"
37 #include "wsi.h"
38 #include <vulkan/vk_icd.h>
39 
40 static const VkExtensionProperties wsi_surface_extension_info = {
41     .extensionName = VK_KHR_SURFACE_EXTENSION_NAME,
42     .specVersion = VK_KHR_SURFACE_SPEC_VERSION,
43 };
44 
45 #ifdef VK_USE_PLATFORM_WIN32_KHR
46 static const VkExtensionProperties wsi_win32_surface_extension_info = {
47     .extensionName = VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
48     .specVersion = VK_KHR_WIN32_SURFACE_SPEC_VERSION,
49 };
50 #endif // VK_USE_PLATFORM_WIN32_KHR
51 
52 #ifdef VK_USE_PLATFORM_MIR_KHR
53 static const VkExtensionProperties wsi_mir_surface_extension_info = {
54     .extensionName = VK_KHR_MIR_SURFACE_EXTENSION_NAME,
55     .specVersion = VK_KHR_MIR_SURFACE_SPEC_VERSION,
56 };
57 #endif // VK_USE_PLATFORM_MIR_KHR
58 
59 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
60 static const VkExtensionProperties wsi_wayland_surface_extension_info = {
61     .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
62     .specVersion = VK_KHR_WAYLAND_SURFACE_SPEC_VERSION,
63 };
64 #endif // VK_USE_PLATFORM_WAYLAND_KHR
65 
66 #ifdef VK_USE_PLATFORM_XCB_KHR
67 static const VkExtensionProperties wsi_xcb_surface_extension_info = {
68     .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME,
69     .specVersion = VK_KHR_XCB_SURFACE_SPEC_VERSION,
70 };
71 #endif // VK_USE_PLATFORM_XCB_KHR
72 
73 #ifdef VK_USE_PLATFORM_XLIB_KHR
74 static const VkExtensionProperties wsi_xlib_surface_extension_info = {
75     .extensionName = VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
76     .specVersion = VK_KHR_XLIB_SURFACE_SPEC_VERSION,
77 };
78 #endif // VK_USE_PLATFORM_XLIB_KHR
79 
80 #ifdef VK_USE_PLATFORM_ANDROID_KHR
81 static const VkExtensionProperties wsi_android_surface_extension_info = {
82     .extensionName = VK_KHR_ANDROID_SURFACE_EXTENSION_NAME,
83     .specVersion = VK_KHR_ANDROID_SURFACE_REVISION,
84 };
85 #endif // VK_USE_PLATFORM_ANDROID_KHR
86 
87 // Note for VK_DISPLAY_KHR don't advertise support since we really need support
88 // to come from ICD, although the loader supplements the support from ICD
89 
wsi_add_instance_extensions(const struct loader_instance * inst,struct loader_extension_list * ext_list)90 void wsi_add_instance_extensions(const struct loader_instance *inst,
91                                  struct loader_extension_list *ext_list) {
92     loader_add_to_ext_list(inst, ext_list, 1, &wsi_surface_extension_info);
93 #ifdef VK_USE_PLATFORM_WIN32_KHR
94     loader_add_to_ext_list(inst, ext_list, 1,
95                            &wsi_win32_surface_extension_info);
96 #endif // VK_USE_PLATFORM_WIN32_KHR
97 #ifdef VK_USE_PLATFORM_MIR_KHR
98     loader_add_to_ext_list(inst, ext_list, 1, &wsi_mir_surface_extension_info);
99 #endif // VK_USE_PLATFORM_MIR_KHR
100 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
101     loader_add_to_ext_list(inst, ext_list, 1,
102                            &wsi_wayland_surface_extension_info);
103 #endif // VK_USE_PLATFORM_WAYLAND_KHR
104 #ifdef VK_USE_PLATFORM_XCB_KHR
105     loader_add_to_ext_list(inst, ext_list, 1, &wsi_xcb_surface_extension_info);
106 #endif // VK_USE_PLATFORM_XCB_KHR
107 #ifdef VK_USE_PLATFORM_XLIB_KHR
108     loader_add_to_ext_list(inst, ext_list, 1, &wsi_xlib_surface_extension_info);
109 #endif // VK_USE_PLATFORM_XLIB_KHR
110 #ifdef VK_USE_PLATFORM_ANDROID_KHR
111     loader_add_to_ext_list(inst, ext_list, 1,
112                            &wsi_android_surface_extension_info);
113 #endif // VK_USE_PLATFORM_ANDROID_KHR
114 }
115 
wsi_create_instance(struct loader_instance * ptr_instance,const VkInstanceCreateInfo * pCreateInfo)116 void wsi_create_instance(struct loader_instance *ptr_instance,
117                          const VkInstanceCreateInfo *pCreateInfo) {
118     ptr_instance->wsi_surface_enabled = false;
119 
120 #ifdef VK_USE_PLATFORM_WIN32_KHR
121     ptr_instance->wsi_win32_surface_enabled = false;
122 #endif // VK_USE_PLATFORM_WIN32_KHR
123 #ifdef VK_USE_PLATFORM_MIR_KHR
124     ptr_instance->wsi_mir_surface_enabled = false;
125 #endif // VK_USE_PLATFORM_MIR_KHR
126 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
127     ptr_instance->wsi_wayland_surface_enabled = false;
128 #endif // VK_USE_PLATFORM_WAYLAND_KHR
129 #ifdef VK_USE_PLATFORM_XCB_KHR
130     ptr_instance->wsi_xcb_surface_enabled = false;
131 #endif // VK_USE_PLATFORM_XCB_KHR
132 #ifdef VK_USE_PLATFORM_XLIB_KHR
133     ptr_instance->wsi_xlib_surface_enabled = false;
134 #endif // VK_USE_PLATFORM_XLIB_KHR
135 #ifdef VK_USE_PLATFORM_ANDROID_KHR
136     ptr_instance->wsi_android_surface_enabled = false;
137 #endif // VK_USE_PLATFORM_ANDROID_KHR
138 
139     ptr_instance->wsi_display_enabled = false;
140 
141     for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
142         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
143                    VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
144             ptr_instance->wsi_surface_enabled = true;
145             continue;
146         }
147 #ifdef VK_USE_PLATFORM_WIN32_KHR
148         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
149                    VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
150             ptr_instance->wsi_win32_surface_enabled = true;
151             continue;
152         }
153 #endif // VK_USE_PLATFORM_WIN32_KHR
154 #ifdef VK_USE_PLATFORM_MIR_KHR
155         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
156                    VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
157             ptr_instance->wsi_mir_surface_enabled = true;
158             continue;
159         }
160 #endif // VK_USE_PLATFORM_MIR_KHR
161 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
162         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
163                    VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
164             ptr_instance->wsi_wayland_surface_enabled = true;
165             continue;
166         }
167 #endif // VK_USE_PLATFORM_WAYLAND_KHR
168 #ifdef VK_USE_PLATFORM_XCB_KHR
169         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
170                    VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
171             ptr_instance->wsi_xcb_surface_enabled = true;
172             continue;
173         }
174 #endif // VK_USE_PLATFORM_XCB_KHR
175 #ifdef VK_USE_PLATFORM_XLIB_KHR
176         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
177                    VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
178             ptr_instance->wsi_xlib_surface_enabled = true;
179             continue;
180         }
181 #endif // VK_USE_PLATFORM_XLIB_KHR
182 #ifdef VK_USE_PLATFORM_ANDROID_KHR
183         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
184                    VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
185             ptr_instance->wsi_android_surface_enabled = true;
186             continue;
187         }
188 #endif // VK_USE_PLATFORM_ANDROID_KHR
189         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
190                    VK_KHR_DISPLAY_EXTENSION_NAME) == 0) {
191             ptr_instance->wsi_display_enabled = true;
192             continue;
193         }
194     }
195 }
196 
197 /*
198  * Functions for the VK_KHR_surface extension:
199  */
200 
201 /*
202  * This is the trampoline entrypoint
203  * for DestroySurfaceKHR
204  */
205 LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL
vkDestroySurfaceKHR(VkInstance instance,VkSurfaceKHR surface,const VkAllocationCallbacks * pAllocator)206 vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
207                     const VkAllocationCallbacks *pAllocator) {
208     const VkLayerInstanceDispatchTable *disp;
209     disp = loader_get_instance_dispatch(instance);
210     disp->DestroySurfaceKHR(instance, surface, pAllocator);
211 }
212 
213 // TODO probably need to lock around all the loader_get_instance() calls.
214 /*
215  * This is the instance chain terminator function
216  * for DestroySurfaceKHR
217  */
218 VKAPI_ATTR void VKAPI_CALL
terminator_DestroySurfaceKHR(VkInstance instance,VkSurfaceKHR surface,const VkAllocationCallbacks * pAllocator)219 terminator_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
220                              const VkAllocationCallbacks *pAllocator) {
221     struct loader_instance *ptr_instance = loader_get_instance(instance);
222 
223     loader_heap_free(ptr_instance, (void *)surface);
224 }
225 
226 /*
227  * This is the trampoline entrypoint
228  * for GetPhysicalDeviceSurfaceSupportKHR
229  */
230 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,VkSurfaceKHR surface,VkBool32 * pSupported)231 vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
232                                      uint32_t queueFamilyIndex,
233                                      VkSurfaceKHR surface,
234                                      VkBool32 *pSupported) {
235     const VkLayerInstanceDispatchTable *disp;
236     VkPhysicalDevice unwrapped_phys_dev =
237         loader_unwrap_physical_device(physicalDevice);
238     disp = loader_get_instance_dispatch(physicalDevice);
239     VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(
240         unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
241     return res;
242 }
243 
244 /*
245  * This is the instance chain terminator function
246  * for GetPhysicalDeviceSurfaceSupportKHR
247  */
248 VKAPI_ATTR VkResult VKAPI_CALL
terminator_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,VkSurfaceKHR surface,VkBool32 * pSupported)249 terminator_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
250                                               uint32_t queueFamilyIndex,
251                                               VkSurfaceKHR surface,
252                                               VkBool32 *pSupported) {
253     struct loader_physical_device *phys_dev =
254         (struct loader_physical_device *)physicalDevice;
255     struct loader_icd *icd = phys_dev->this_icd;
256 
257     assert(pSupported &&
258            "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
259     *pSupported = false;
260 
261     assert(icd->GetPhysicalDeviceSurfaceSupportKHR &&
262            "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
263 
264     return icd->GetPhysicalDeviceSurfaceSupportKHR(
265         phys_dev->phys_dev, queueFamilyIndex, surface, pSupported);
266 }
267 
268 /*
269  * This is the trampoline entrypoint
270  * for GetPhysicalDeviceSurfaceCapabilitiesKHR
271  */
272 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilitiesKHR * pSurfaceCapabilities)273 vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
274     VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
275     VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
276 
277     const VkLayerInstanceDispatchTable *disp;
278     VkPhysicalDevice unwrapped_phys_dev =
279         loader_unwrap_physical_device(physicalDevice);
280     disp = loader_get_instance_dispatch(physicalDevice);
281     VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(
282         unwrapped_phys_dev, surface, pSurfaceCapabilities);
283     return res;
284 }
285 
286 /*
287  * This is the instance chain terminator function
288  * for GetPhysicalDeviceSurfaceCapabilitiesKHR
289  */
290 VKAPI_ATTR VkResult VKAPI_CALL
terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilitiesKHR * pSurfaceCapabilities)291 terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(
292     VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
293     VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
294     struct loader_physical_device *phys_dev =
295         (struct loader_physical_device *)physicalDevice;
296     struct loader_icd *icd = phys_dev->this_icd;
297 
298     assert(pSurfaceCapabilities && "GetPhysicalDeviceSurfaceCapabilitiesKHR: "
299                                    "Error, null pSurfaceCapabilities");
300 
301     assert(icd->GetPhysicalDeviceSurfaceCapabilitiesKHR &&
302            "loader: null GetPhysicalDeviceSurfaceCapabilitiesKHR ICD pointer");
303 
304     return icd->GetPhysicalDeviceSurfaceCapabilitiesKHR(
305         phys_dev->phys_dev, surface, pSurfaceCapabilities);
306 }
307 
308 /*
309  * This is the trampoline entrypoint
310  * for GetPhysicalDeviceSurfaceFormatsKHR
311  */
312 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pSurfaceFormatCount,VkSurfaceFormatKHR * pSurfaceFormats)313 vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
314                                      VkSurfaceKHR surface,
315                                      uint32_t *pSurfaceFormatCount,
316                                      VkSurfaceFormatKHR *pSurfaceFormats) {
317     VkPhysicalDevice unwrapped_phys_dev =
318         loader_unwrap_physical_device(physicalDevice);
319     const VkLayerInstanceDispatchTable *disp;
320     disp = loader_get_instance_dispatch(physicalDevice);
321     VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(
322         unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
323     return res;
324 }
325 
326 /*
327  * This is the instance chain terminator function
328  * for GetPhysicalDeviceSurfaceFormatsKHR
329  */
terminator_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pSurfaceFormatCount,VkSurfaceFormatKHR * pSurfaceFormats)330 VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormatsKHR(
331     VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
332     uint32_t *pSurfaceFormatCount, VkSurfaceFormatKHR *pSurfaceFormats) {
333     struct loader_physical_device *phys_dev =
334         (struct loader_physical_device *)physicalDevice;
335     struct loader_icd *icd = phys_dev->this_icd;
336 
337     assert(
338         pSurfaceFormatCount &&
339         "GetPhysicalDeviceSurfaceFormatsKHR: Error, null pSurfaceFormatCount");
340 
341     assert(icd->GetPhysicalDeviceSurfaceFormatsKHR &&
342            "loader: null GetPhysicalDeviceSurfaceFormatsKHR ICD pointer");
343 
344     return icd->GetPhysicalDeviceSurfaceFormatsKHR(
345         phys_dev->phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
346 }
347 
348 /*
349  * This is the trampoline entrypoint
350  * for GetPhysicalDeviceSurfacePresentModesKHR
351  */
352 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pPresentModeCount,VkPresentModeKHR * pPresentModes)353 vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
354                                           VkSurfaceKHR surface,
355                                           uint32_t *pPresentModeCount,
356                                           VkPresentModeKHR *pPresentModes) {
357     VkPhysicalDevice unwrapped_phys_dev =
358         loader_unwrap_physical_device(physicalDevice);
359     const VkLayerInstanceDispatchTable *disp;
360     disp = loader_get_instance_dispatch(physicalDevice);
361     VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(
362         unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
363     return res;
364 }
365 
366 /*
367  * This is the instance chain terminator function
368  * for GetPhysicalDeviceSurfacePresentModesKHR
369  */
370 VKAPI_ATTR VkResult VKAPI_CALL
terminator_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pPresentModeCount,VkPresentModeKHR * pPresentModes)371 terminator_GetPhysicalDeviceSurfacePresentModesKHR(
372     VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
373     uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes) {
374     struct loader_physical_device *phys_dev =
375         (struct loader_physical_device *)physicalDevice;
376     struct loader_icd *icd = phys_dev->this_icd;
377 
378     assert(pPresentModeCount && "GetPhysicalDeviceSurfacePresentModesKHR: "
379                                 "Error, null pPresentModeCount");
380 
381     assert(icd->GetPhysicalDeviceSurfacePresentModesKHR &&
382            "loader: null GetPhysicalDeviceSurfacePresentModesKHR ICD pointer");
383 
384     return icd->GetPhysicalDeviceSurfacePresentModesKHR(
385         phys_dev->phys_dev, surface, pPresentModeCount, pPresentModes);
386 }
387 
388 /*
389  * Functions for the VK_KHR_swapchain extension:
390  */
391 
392 /*
393  * This is the trampoline entrypoint
394  * for CreateSwapchainKHR
395  */
396 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateSwapchainKHR(VkDevice device,const VkSwapchainCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSwapchainKHR * pSwapchain)397 vkCreateSwapchainKHR(VkDevice device,
398                      const VkSwapchainCreateInfoKHR *pCreateInfo,
399                      const VkAllocationCallbacks *pAllocator,
400                      VkSwapchainKHR *pSwapchain) {
401     const VkLayerDispatchTable *disp;
402     disp = loader_get_dispatch(device);
403     VkResult res =
404         disp->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
405     return res;
406 }
407 
408 /*
409  * This is the trampoline entrypoint
410  * for DestroySwapchainKHR
411  */
412 LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL
vkDestroySwapchainKHR(VkDevice device,VkSwapchainKHR swapchain,const VkAllocationCallbacks * pAllocator)413 vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
414                       const VkAllocationCallbacks *pAllocator) {
415     const VkLayerDispatchTable *disp;
416     disp = loader_get_dispatch(device);
417     disp->DestroySwapchainKHR(device, swapchain, pAllocator);
418 }
419 
420 /*
421  * This is the trampoline entrypoint
422  * for GetSwapchainImagesKHR
423  */
424 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetSwapchainImagesKHR(VkDevice device,VkSwapchainKHR swapchain,uint32_t * pSwapchainImageCount,VkImage * pSwapchainImages)425 vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
426                         uint32_t *pSwapchainImageCount,
427                         VkImage *pSwapchainImages) {
428     const VkLayerDispatchTable *disp;
429     disp = loader_get_dispatch(device);
430     VkResult res = disp->GetSwapchainImagesKHR(
431         device, swapchain, pSwapchainImageCount, pSwapchainImages);
432     return res;
433 }
434 
435 /*
436  * This is the trampoline entrypoint
437  * for AcquireNextImageKHR
438  */
439 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkAcquireNextImageKHR(VkDevice device,VkSwapchainKHR swapchain,uint64_t timeout,VkSemaphore semaphore,VkFence fence,uint32_t * pImageIndex)440 vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain,
441                       uint64_t timeout, VkSemaphore semaphore, VkFence fence,
442                       uint32_t *pImageIndex) {
443     const VkLayerDispatchTable *disp;
444     disp = loader_get_dispatch(device);
445     VkResult res = disp->AcquireNextImageKHR(device, swapchain, timeout,
446                                              semaphore, fence, pImageIndex);
447     return res;
448 }
449 
450 /*
451  * This is the trampoline entrypoint
452  * for QueuePresentKHR
453  */
454 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkQueuePresentKHR(VkQueue queue,const VkPresentInfoKHR * pPresentInfo)455 vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
456     const VkLayerDispatchTable *disp;
457     disp = loader_get_dispatch(queue);
458     VkResult res = disp->QueuePresentKHR(queue, pPresentInfo);
459     return res;
460 }
461 
462 #ifdef VK_USE_PLATFORM_WIN32_KHR
463 
464 /*
465  * Functions for the VK_KHR_win32_surface extension:
466  */
467 
468 /*
469  * This is the trampoline entrypoint
470  * for CreateWin32SurfaceKHR
471  */
472 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateWin32SurfaceKHR(VkInstance instance,const VkWin32SurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)473 vkCreateWin32SurfaceKHR(VkInstance instance,
474                         const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
475                         const VkAllocationCallbacks *pAllocator,
476                         VkSurfaceKHR *pSurface) {
477     const VkLayerInstanceDispatchTable *disp;
478     disp = loader_get_instance_dispatch(instance);
479     VkResult res;
480 
481     res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator,
482                                       pSurface);
483     return res;
484 }
485 
486 /*
487  * This is the instance chain terminator function
488  * for CreateWin32SurfaceKHR
489  */
490 VKAPI_ATTR VkResult VKAPI_CALL
terminator_CreateWin32SurfaceKHR(VkInstance instance,const VkWin32SurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)491 terminator_CreateWin32SurfaceKHR(VkInstance instance,
492                                  const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
493                                  const VkAllocationCallbacks *pAllocator,
494                                  VkSurfaceKHR *pSurface) {
495     struct loader_instance *ptr_instance = loader_get_instance(instance);
496     VkIcdSurfaceWin32 *pIcdSurface = NULL;
497 
498     pIcdSurface = loader_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceWin32),
499                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
500     if (pIcdSurface == NULL) {
501         return VK_ERROR_OUT_OF_HOST_MEMORY;
502     }
503 
504     pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_WIN32;
505     pIcdSurface->hinstance = pCreateInfo->hinstance;
506     pIcdSurface->hwnd = pCreateInfo->hwnd;
507 
508     *pSurface = (VkSurfaceKHR)pIcdSurface;
509 
510     return VK_SUCCESS;
511 }
512 
513 /*
514  * This is the trampoline entrypoint
515  * for GetPhysicalDeviceWin32PresentationSupportKHR
516  */
517 LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex)518 vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
519                                                uint32_t queueFamilyIndex) {
520     VkPhysicalDevice unwrapped_phys_dev =
521         loader_unwrap_physical_device(physicalDevice);
522     const VkLayerInstanceDispatchTable *disp;
523     disp = loader_get_instance_dispatch(physicalDevice);
524     VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(
525         unwrapped_phys_dev, queueFamilyIndex);
526     return res;
527 }
528 
529 /*
530  * This is the instance chain terminator function
531  * for GetPhysicalDeviceWin32PresentationSupportKHR
532  */
533 VKAPI_ATTR VkBool32 VKAPI_CALL
terminator_GetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex)534 terminator_GetPhysicalDeviceWin32PresentationSupportKHR(
535     VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex) {
536     struct loader_physical_device *phys_dev =
537         (struct loader_physical_device *)physicalDevice;
538     struct loader_icd *icd = phys_dev->this_icd;
539 
540     assert(icd->GetPhysicalDeviceWin32PresentationSupportKHR &&
541            "loader: null GetPhysicalDeviceWin32PresentationSupportKHR ICD "
542            "pointer");
543 
544     return icd->GetPhysicalDeviceWin32PresentationSupportKHR(phys_dev->phys_dev,
545                                                              queueFamilyIndex);
546 }
547 #endif // VK_USE_PLATFORM_WIN32_KHR
548 
549 #ifdef VK_USE_PLATFORM_MIR_KHR
550 
551 /*
552  * Functions for the VK_KHR_mir_surface extension:
553  */
554 
555 /*
556  * This is the trampoline entrypoint
557  * for CreateMirSurfaceKHR
558  */
559 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateMirSurfaceKHR(VkInstance instance,const VkMirSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)560 vkCreateMirSurfaceKHR(VkInstance instance,
561                       const VkMirSurfaceCreateInfoKHR *pCreateInfo,
562                       const VkAllocationCallbacks *pAllocator,
563                       VkSurfaceKHR *pSurface) {
564     const VkLayerInstanceDispatchTable *disp;
565     disp = loader_get_instance_dispatch(instance);
566     VkResult res;
567 
568     res =
569         disp->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
570     return res;
571 }
572 
573 /*
574  * This is the instance chain terminator function
575  * for CreateMirSurfaceKHR
576  */
577 VKAPI_ATTR VkResult VKAPI_CALL
terminator_CreateMirSurfaceKHR(VkInstance instance,const VkMirSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)578 terminator_CreateMirSurfaceKHR(VkInstance instance,
579                                const VkMirSurfaceCreateInfoKHR *pCreateInfo,
580                                const VkAllocationCallbacks *pAllocator,
581                                VkSurfaceKHR *pSurface) {
582     struct loader_instance *ptr_instance = loader_get_instance(instance);
583     VkIcdSurfaceMir *pIcdSurface = NULL;
584 
585     pIcdSurface = loader_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceMir),
586                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
587     if (pIcdSurface == NULL) {
588         return VK_ERROR_OUT_OF_HOST_MEMORY;
589     }
590 
591     pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_MIR;
592     pIcdSurface->connection = pCreateInfo->connection;
593     pIcdSurface->mirSurface = pCreateInfo->mirSurface;
594 
595     *pSurface = (VkSurfaceKHR)pIcdSurface;
596 
597     return VK_SUCCESS;
598 }
599 
600 /*
601  * This is the trampoline entrypoint
602  * for GetPhysicalDeviceMirPresentationSupportKHR
603  */
604 LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
vkGetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,MirConnection * connection)605 vkGetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,
606                                              uint32_t queueFamilyIndex,
607                                              MirConnection *connection) {
608     VkPhysicalDevice unwrapped_phys_dev =
609         loader_unwrap_physical_device(physicalDevice);
610     const VkLayerInstanceDispatchTable *disp;
611     disp = loader_get_instance_dispatch(physicalDevice);
612     VkBool32 res = disp->GetPhysicalDeviceMirPresentationSupportKHR(
613         unwrapped_phys_dev, queueFamilyIndex, connection);
614     return res;
615 }
616 
617 /*
618  * This is the instance chain terminator function
619  * for GetPhysicalDeviceMirPresentationSupportKHR
620  */
621 VKAPI_ATTR VkBool32 VKAPI_CALL
terminator_GetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,MirConnection * connection)622 terminator_GetPhysicalDeviceMirPresentationSupportKHR(
623     VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
624     MirConnection *connection) {
625     struct loader_physical_device *phys_dev =
626         (struct loader_physical_device *)physicalDevice;
627     struct loader_icd *icd = phys_dev->this_icd;
628 
629     assert(
630         icd->GetPhysicalDeviceMirPresentationSupportKHR &&
631         "loader: null GetPhysicalDeviceMirPresentationSupportKHR ICD pointer");
632 
633     return icd->GetPhysicalDeviceMirPresentationSupportKHR(
634         phys_dev->phys_dev, queueFamilyIndex, connection);
635 }
636 #endif // VK_USE_PLATFORM_MIR_KHR
637 
638 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
639 
640 /*
641  * Functions for the VK_KHR_wayland_surface extension:
642  */
643 
644 /*
645  * This is the trampoline entrypoint
646  * for CreateWaylandSurfaceKHR
647  */
648 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateWaylandSurfaceKHR(VkInstance instance,const VkWaylandSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)649 vkCreateWaylandSurfaceKHR(VkInstance instance,
650                           const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
651                           const VkAllocationCallbacks *pAllocator,
652                           VkSurfaceKHR *pSurface) {
653     const VkLayerInstanceDispatchTable *disp;
654     disp = loader_get_instance_dispatch(instance);
655     VkResult res;
656 
657     res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator,
658                                         pSurface);
659     return res;
660 }
661 
662 /*
663  * This is the instance chain terminator function
664  * for CreateWaylandSurfaceKHR
665  */
terminator_CreateWaylandSurfaceKHR(VkInstance instance,const VkWaylandSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)666 VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(
667     VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
668     const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
669     struct loader_instance *ptr_instance = loader_get_instance(instance);
670     VkIcdSurfaceWayland *pIcdSurface = NULL;
671 
672     pIcdSurface = loader_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceWayland),
673                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
674     if (pIcdSurface == NULL) {
675         return VK_ERROR_OUT_OF_HOST_MEMORY;
676     }
677 
678     pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
679     pIcdSurface->display = pCreateInfo->display;
680     pIcdSurface->surface = pCreateInfo->surface;
681 
682     *pSurface = (VkSurfaceKHR)pIcdSurface;
683 
684     return VK_SUCCESS;
685 }
686 
687 /*
688  * This is the trampoline entrypoint
689  * for GetPhysicalDeviceWaylandPresentationSupportKHR
690  */
691 LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,struct wl_display * display)692 vkGetPhysicalDeviceWaylandPresentationSupportKHR(
693     VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
694     struct wl_display *display) {
695     VkPhysicalDevice unwrapped_phys_dev =
696         loader_unwrap_physical_device(physicalDevice);
697     const VkLayerInstanceDispatchTable *disp;
698     disp = loader_get_instance_dispatch(physicalDevice);
699     VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(
700         unwrapped_phys_dev, queueFamilyIndex, display);
701     return res;
702 }
703 
704 /*
705  * This is the instance chain terminator function
706  * for GetPhysicalDeviceWaylandPresentationSupportKHR
707  */
708 VKAPI_ATTR VkBool32 VKAPI_CALL
terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,struct wl_display * display)709 terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(
710     VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
711     struct wl_display *display) {
712     struct loader_physical_device *phys_dev =
713         (struct loader_physical_device *)physicalDevice;
714     struct loader_icd *icd = phys_dev->this_icd;
715 
716     assert(icd->GetPhysicalDeviceWaylandPresentationSupportKHR &&
717            "loader: null GetPhysicalDeviceWaylandPresentationSupportKHR ICD "
718            "pointer");
719 
720     return icd->GetPhysicalDeviceWaylandPresentationSupportKHR(
721         phys_dev->phys_dev, queueFamilyIndex, display);
722 }
723 #endif // VK_USE_PLATFORM_WAYLAND_KHR
724 
725 #ifdef VK_USE_PLATFORM_XCB_KHR
726 
727 /*
728  * Functions for the VK_KHR_xcb_surface extension:
729  */
730 
731 /*
732  * This is the trampoline entrypoint
733  * for CreateXcbSurfaceKHR
734  */
735 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateXcbSurfaceKHR(VkInstance instance,const VkXcbSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)736 vkCreateXcbSurfaceKHR(VkInstance instance,
737                       const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
738                       const VkAllocationCallbacks *pAllocator,
739                       VkSurfaceKHR *pSurface) {
740     const VkLayerInstanceDispatchTable *disp;
741     disp = loader_get_instance_dispatch(instance);
742     VkResult res;
743 
744     res =
745         disp->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
746     return res;
747 }
748 
749 /*
750  * This is the instance chain terminator function
751  * for CreateXcbSurfaceKHR
752  */
753 VKAPI_ATTR VkResult VKAPI_CALL
terminator_CreateXcbSurfaceKHR(VkInstance instance,const VkXcbSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)754 terminator_CreateXcbSurfaceKHR(VkInstance instance,
755                                const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
756                                const VkAllocationCallbacks *pAllocator,
757                                VkSurfaceKHR *pSurface) {
758     struct loader_instance *ptr_instance = loader_get_instance(instance);
759     VkIcdSurfaceXcb *pIcdSurface = NULL;
760 
761     pIcdSurface = loader_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceXcb),
762                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
763     if (pIcdSurface == NULL) {
764         return VK_ERROR_OUT_OF_HOST_MEMORY;
765     }
766 
767     pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_XCB;
768     pIcdSurface->connection = pCreateInfo->connection;
769     pIcdSurface->window = pCreateInfo->window;
770 
771     *pSurface = (VkSurfaceKHR)pIcdSurface;
772 
773     return VK_SUCCESS;
774 }
775 
776 /*
777  * This is the trampoline entrypoint
778  * for GetPhysicalDeviceXcbPresentationSupportKHR
779  */
780 LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,xcb_connection_t * connection,xcb_visualid_t visual_id)781 vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
782                                              uint32_t queueFamilyIndex,
783                                              xcb_connection_t *connection,
784                                              xcb_visualid_t visual_id) {
785     VkPhysicalDevice unwrapped_phys_dev =
786         loader_unwrap_physical_device(physicalDevice);
787     const VkLayerInstanceDispatchTable *disp;
788     disp = loader_get_instance_dispatch(physicalDevice);
789     VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(
790         unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
791     return res;
792 }
793 
794 /*
795  * This is the instance chain terminator function
796  * for GetPhysicalDeviceXcbPresentationSupportKHR
797  */
798 VKAPI_ATTR VkBool32 VKAPI_CALL
terminator_GetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,xcb_connection_t * connection,xcb_visualid_t visual_id)799 terminator_GetPhysicalDeviceXcbPresentationSupportKHR(
800     VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
801     xcb_connection_t *connection, xcb_visualid_t visual_id) {
802     struct loader_physical_device *phys_dev =
803         (struct loader_physical_device *)physicalDevice;
804     struct loader_icd *icd = phys_dev->this_icd;
805 
806     assert(
807         icd->GetPhysicalDeviceXcbPresentationSupportKHR &&
808         "loader: null GetPhysicalDeviceXcbPresentationSupportKHR ICD pointer");
809 
810     return icd->GetPhysicalDeviceXcbPresentationSupportKHR(
811         phys_dev->phys_dev, queueFamilyIndex, connection, visual_id);
812 }
813 #endif // VK_USE_PLATFORM_XCB_KHR
814 
815 #ifdef VK_USE_PLATFORM_XLIB_KHR
816 
817 /*
818  * Functions for the VK_KHR_xlib_surface extension:
819  */
820 
821 /*
822  * This is the trampoline entrypoint
823  * for CreateXlibSurfaceKHR
824  */
825 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateXlibSurfaceKHR(VkInstance instance,const VkXlibSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)826 vkCreateXlibSurfaceKHR(VkInstance instance,
827                        const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
828                        const VkAllocationCallbacks *pAllocator,
829                        VkSurfaceKHR *pSurface) {
830     const VkLayerInstanceDispatchTable *disp;
831     disp = loader_get_instance_dispatch(instance);
832     VkResult res;
833 
834     res =
835         disp->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
836     return res;
837 }
838 
839 /*
840  * This is the instance chain terminator function
841  * for CreateXlibSurfaceKHR
842  */
843 VKAPI_ATTR VkResult VKAPI_CALL
terminator_CreateXlibSurfaceKHR(VkInstance instance,const VkXlibSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)844 terminator_CreateXlibSurfaceKHR(VkInstance instance,
845                                 const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
846                                 const VkAllocationCallbacks *pAllocator,
847                                 VkSurfaceKHR *pSurface) {
848     struct loader_instance *ptr_instance = loader_get_instance(instance);
849     VkIcdSurfaceXlib *pIcdSurface = NULL;
850 
851     pIcdSurface = loader_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceXlib),
852                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
853     if (pIcdSurface == NULL) {
854         return VK_ERROR_OUT_OF_HOST_MEMORY;
855     }
856 
857     pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_XLIB;
858     pIcdSurface->dpy = pCreateInfo->dpy;
859     pIcdSurface->window = pCreateInfo->window;
860 
861     *pSurface = (VkSurfaceKHR)pIcdSurface;
862 
863     return VK_SUCCESS;
864 }
865 
866 /*
867  * This is the trampoline entrypoint
868  * for GetPhysicalDeviceXlibPresentationSupportKHR
869  */
870 LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,Display * dpy,VisualID visualID)871 vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
872                                               uint32_t queueFamilyIndex,
873                                               Display *dpy, VisualID visualID) {
874     VkPhysicalDevice unwrapped_phys_dev =
875         loader_unwrap_physical_device(physicalDevice);
876     const VkLayerInstanceDispatchTable *disp;
877     disp = loader_get_instance_dispatch(physicalDevice);
878     VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(
879         unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
880     return res;
881 }
882 
883 /*
884  * This is the instance chain terminator function
885  * for GetPhysicalDeviceXlibPresentationSupportKHR
886  */
887 VKAPI_ATTR VkBool32 VKAPI_CALL
terminator_GetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,Display * dpy,VisualID visualID)888 terminator_GetPhysicalDeviceXlibPresentationSupportKHR(
889     VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display *dpy,
890     VisualID visualID) {
891     struct loader_physical_device *phys_dev =
892         (struct loader_physical_device *)physicalDevice;
893     struct loader_icd *icd = phys_dev->this_icd;
894 
895     assert(
896         icd->GetPhysicalDeviceXlibPresentationSupportKHR &&
897         "loader: null GetPhysicalDeviceXlibPresentationSupportKHR ICD pointer");
898 
899     return icd->GetPhysicalDeviceXlibPresentationSupportKHR(
900         phys_dev->phys_dev, queueFamilyIndex, dpy, visualID);
901 }
902 #endif // VK_USE_PLATFORM_XLIB_KHR
903 
904 #ifdef VK_USE_PLATFORM_ANDROID_KHR
905 
906 /*
907  * Functions for the VK_KHR_android_surface extension:
908  */
909 
910 /*
911  * This is the trampoline entrypoint
912  * for CreateAndroidSurfaceKHR
913  */
914 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateAndroidSurfaceKHR(VkInstance instance,ANativeWindow * window,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)915 vkCreateAndroidSurfaceKHR(VkInstance instance, ANativeWindow *window,
916                           const VkAllocationCallbacks *pAllocator,
917                           VkSurfaceKHR *pSurface) {
918     const VkLayerInstanceDispatchTable *disp;
919     disp = loader_get_instance_dispatch(instance);
920     VkResult res;
921 
922     res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
923     return res;
924 }
925 
926 /*
927  * This is the instance chain terminator function
928  * for CreateAndroidSurfaceKHR
929  */
930 VKAPI_ATTR VkResult VKAPI_CALL
terminator_CreateAndroidSurfaceKHR(VkInstance instance,Window window,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)931 terminator_CreateAndroidSurfaceKHR(VkInstance instance, Window window,
932                                    const VkAllocationCallbacks *pAllocator,
933                                    VkSurfaceKHR *pSurface) {
934     struct loader_instance *ptr_instance = loader_get_instance(instance);
935     VkIcdSurfaceAndroid *pIcdSurface = NULL;
936 
937     pIcdSurface = loader_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceAndroid),
938                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
939     if (pIcdSurface == NULL) {
940         return VK_ERROR_OUT_OF_HOST_MEMORY;
941     }
942 
943     pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_ANDROID;
944     pIcdSurface->dpy = dpy;
945     pIcdSurface->window = window;
946 
947     *pSurface = (VkSurfaceKHR)pIcdSurface;
948 
949     return VK_SUCCESS;
950 }
951 
952 #endif // VK_USE_PLATFORM_ANDROID_KHR
953 
954 
955 /*
956  * Functions for the VK_KHR_display instance extension:
957  */
958 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPropertiesKHR * pProperties)959 vkGetPhysicalDeviceDisplayPropertiesKHR(
960     VkPhysicalDevice                            physicalDevice,
961     uint32_t*                                   pPropertyCount,
962     VkDisplayPropertiesKHR*                     pProperties)
963 {
964     VkPhysicalDevice unwrapped_phys_dev =
965         loader_unwrap_physical_device(physicalDevice);
966     const VkLayerInstanceDispatchTable *disp;
967     disp = loader_get_instance_dispatch(physicalDevice);
968     VkResult res = disp->GetPhysicalDeviceDisplayPropertiesKHR(
969         unwrapped_phys_dev, pPropertyCount, pProperties);
970     return res;
971 }
972 
973 VKAPI_ATTR VkResult VKAPI_CALL
terminator_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPropertiesKHR * pProperties)974 terminator_GetPhysicalDeviceDisplayPropertiesKHR(
975     VkPhysicalDevice                            physicalDevice,
976     uint32_t*                                   pPropertyCount,
977     VkDisplayPropertiesKHR*                     pProperties)
978 {
979     struct loader_physical_device *phys_dev =
980         (struct loader_physical_device *)physicalDevice;
981     struct loader_icd *icd = phys_dev->this_icd;
982 
983     assert(
984         icd->GetPhysicalDeviceDisplayPropertiesKHR &&
985         "loader: null GetPhysicalDeviceDisplayPropertiesKHR ICD pointer");
986 
987     return icd->GetPhysicalDeviceDisplayPropertiesKHR(
988         phys_dev->phys_dev, pPropertyCount, pProperties);
989 }
990 
991 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPlanePropertiesKHR * pProperties)992 vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
993     VkPhysicalDevice                            physicalDevice,
994     uint32_t*                                   pPropertyCount,
995     VkDisplayPlanePropertiesKHR*                pProperties)
996 {
997     VkPhysicalDevice unwrapped_phys_dev =
998         loader_unwrap_physical_device(physicalDevice);
999     const VkLayerInstanceDispatchTable *disp;
1000     disp = loader_get_instance_dispatch(physicalDevice);
1001     VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(
1002         unwrapped_phys_dev, pPropertyCount, pProperties);
1003     return res;
1004 }
1005 
1006 VKAPI_ATTR VkResult VKAPI_CALL
terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPlanePropertiesKHR * pProperties)1007 terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(
1008     VkPhysicalDevice                            physicalDevice,
1009     uint32_t*                                   pPropertyCount,
1010     VkDisplayPlanePropertiesKHR*                pProperties)
1011 {
1012     struct loader_physical_device *phys_dev =
1013         (struct loader_physical_device *)physicalDevice;
1014     struct loader_icd *icd = phys_dev->this_icd;
1015 
1016     assert(
1017         icd->GetPhysicalDeviceDisplayPlanePropertiesKHR &&
1018         "loader: null GetPhysicalDeviceDisplayPlanePropertiesKHR ICD pointer");
1019 
1020     return icd->GetPhysicalDeviceDisplayPlanePropertiesKHR(
1021         phys_dev->phys_dev, pPropertyCount, pProperties);
1022 }
1023 
1024 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,uint32_t planeIndex,uint32_t * pDisplayCount,VkDisplayKHR * pDisplays)1025 vkGetDisplayPlaneSupportedDisplaysKHR(
1026     VkPhysicalDevice                            physicalDevice,
1027     uint32_t                                    planeIndex,
1028     uint32_t*                                   pDisplayCount,
1029     VkDisplayKHR*                               pDisplays)
1030 {
1031     VkPhysicalDevice unwrapped_phys_dev =
1032         loader_unwrap_physical_device(physicalDevice);
1033     const VkLayerInstanceDispatchTable *disp;
1034     disp = loader_get_instance_dispatch(physicalDevice);
1035     VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(
1036         unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
1037     return res;
1038 }
1039 
1040 VKAPI_ATTR VkResult VKAPI_CALL
terminator_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,uint32_t planeIndex,uint32_t * pDisplayCount,VkDisplayKHR * pDisplays)1041 terminator_GetDisplayPlaneSupportedDisplaysKHR(
1042     VkPhysicalDevice                            physicalDevice,
1043     uint32_t                                    planeIndex,
1044     uint32_t*                                   pDisplayCount,
1045     VkDisplayKHR*                               pDisplays)
1046 {
1047     struct loader_physical_device *phys_dev =
1048         (struct loader_physical_device *)physicalDevice;
1049     struct loader_icd *icd = phys_dev->this_icd;
1050 
1051     assert(
1052         icd->GetDisplayPlaneSupportedDisplaysKHR &&
1053         "loader: null GetDisplayPlaneSupportedDisplaysKHR ICD pointer");
1054 
1055     return icd->GetDisplayPlaneSupportedDisplaysKHR(
1056         phys_dev->phys_dev, planeIndex, pDisplayCount, pDisplays);
1057 }
1058 
1059 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,uint32_t * pPropertyCount,VkDisplayModePropertiesKHR * pProperties)1060 vkGetDisplayModePropertiesKHR(
1061     VkPhysicalDevice                            physicalDevice,
1062     VkDisplayKHR                                display,
1063     uint32_t*                                   pPropertyCount,
1064     VkDisplayModePropertiesKHR*                 pProperties)
1065 {
1066     VkPhysicalDevice unwrapped_phys_dev =
1067         loader_unwrap_physical_device(physicalDevice);
1068     const VkLayerInstanceDispatchTable *disp;
1069     disp = loader_get_instance_dispatch(physicalDevice);
1070     VkResult res = disp->GetDisplayModePropertiesKHR(
1071         unwrapped_phys_dev, display, pPropertyCount, pProperties);
1072     return res;
1073 }
1074 
1075 VKAPI_ATTR VkResult VKAPI_CALL
terminator_GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,uint32_t * pPropertyCount,VkDisplayModePropertiesKHR * pProperties)1076 terminator_GetDisplayModePropertiesKHR(
1077     VkPhysicalDevice                            physicalDevice,
1078     VkDisplayKHR                                display,
1079     uint32_t*                                   pPropertyCount,
1080     VkDisplayModePropertiesKHR*                 pProperties)
1081 {
1082     struct loader_physical_device *phys_dev =
1083         (struct loader_physical_device *)physicalDevice;
1084     struct loader_icd *icd = phys_dev->this_icd;
1085 
1086     assert(
1087         icd->GetDisplayModePropertiesKHR &&
1088         "loader: null GetDisplayModePropertiesKHR ICD pointer");
1089 
1090     return icd->GetDisplayModePropertiesKHR(
1091         phys_dev->phys_dev, display, pPropertyCount, pProperties);
1092 }
1093 
1094 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,const VkDisplayModeCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDisplayModeKHR * pMode)1095 vkCreateDisplayModeKHR(
1096     VkPhysicalDevice                            physicalDevice,
1097     VkDisplayKHR                                display,
1098     const VkDisplayModeCreateInfoKHR*           pCreateInfo,
1099     const VkAllocationCallbacks*                pAllocator,
1100     VkDisplayModeKHR*                           pMode)
1101 {
1102     VkPhysicalDevice unwrapped_phys_dev =
1103         loader_unwrap_physical_device(physicalDevice);
1104     const VkLayerInstanceDispatchTable *disp;
1105     disp = loader_get_instance_dispatch(physicalDevice);
1106     VkResult res = disp->CreateDisplayModeKHR(
1107         unwrapped_phys_dev, display, pCreateInfo, pAllocator, pMode);
1108     return res;
1109 }
1110 
1111 VKAPI_ATTR VkResult VKAPI_CALL
terminator_CreateDisplayModeKHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,const VkDisplayModeCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDisplayModeKHR * pMode)1112 terminator_CreateDisplayModeKHR(
1113     VkPhysicalDevice                            physicalDevice,
1114     VkDisplayKHR                                display,
1115     const VkDisplayModeCreateInfoKHR*           pCreateInfo,
1116     const VkAllocationCallbacks*                pAllocator,
1117     VkDisplayModeKHR*                           pMode)
1118 {
1119     struct loader_physical_device *phys_dev =
1120         (struct loader_physical_device *)physicalDevice;
1121     struct loader_icd *icd = phys_dev->this_icd;
1122 
1123     assert(
1124         icd->CreateDisplayModeKHR &&
1125         "loader: null CreateDisplayModeKHR ICD pointer");
1126 
1127     return icd->CreateDisplayModeKHR(
1128         phys_dev->phys_dev, display, pCreateInfo, pAllocator, pMode);
1129 }
1130 
1131 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,VkDisplayModeKHR mode,uint32_t planeIndex,VkDisplayPlaneCapabilitiesKHR * pCapabilities)1132 vkGetDisplayPlaneCapabilitiesKHR(
1133     VkPhysicalDevice                            physicalDevice,
1134     VkDisplayModeKHR                            mode,
1135     uint32_t                                    planeIndex,
1136     VkDisplayPlaneCapabilitiesKHR*              pCapabilities)
1137 {
1138     VkPhysicalDevice unwrapped_phys_dev =
1139         loader_unwrap_physical_device(physicalDevice);
1140     const VkLayerInstanceDispatchTable *disp;
1141     disp = loader_get_instance_dispatch(physicalDevice);
1142     VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(
1143         unwrapped_phys_dev, mode, planeIndex, pCapabilities);
1144     return res;
1145 }
1146 
1147 VKAPI_ATTR VkResult VKAPI_CALL
terminator_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,VkDisplayModeKHR mode,uint32_t planeIndex,VkDisplayPlaneCapabilitiesKHR * pCapabilities)1148 terminator_GetDisplayPlaneCapabilitiesKHR(
1149     VkPhysicalDevice                            physicalDevice,
1150     VkDisplayModeKHR                            mode,
1151     uint32_t                                    planeIndex,
1152     VkDisplayPlaneCapabilitiesKHR*              pCapabilities)
1153 {
1154     struct loader_physical_device *phys_dev =
1155         (struct loader_physical_device *)physicalDevice;
1156     struct loader_icd *icd = phys_dev->this_icd;
1157 
1158     assert(
1159         icd->GetDisplayPlaneCapabilitiesKHR &&
1160         "loader: null GetDisplayPlaneCapabilitiesKHR ICD pointer");
1161 
1162     return icd->GetDisplayPlaneCapabilitiesKHR(
1163         phys_dev->phys_dev, mode, planeIndex, pCapabilities);
1164 }
1165 
1166 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkCreateDisplayPlaneSurfaceKHR(VkInstance instance,const VkDisplaySurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)1167 vkCreateDisplayPlaneSurfaceKHR(
1168     VkInstance                                  instance,
1169     const VkDisplaySurfaceCreateInfoKHR*        pCreateInfo,
1170     const VkAllocationCallbacks*                pAllocator,
1171     VkSurfaceKHR*                               pSurface)
1172 {
1173     const VkLayerInstanceDispatchTable *disp;
1174     disp = loader_get_instance_dispatch(instance);
1175     VkResult res;
1176 
1177     res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator,
1178                                              pSurface);
1179     return res;
1180 }
1181 
1182 VKAPI_ATTR VkResult VKAPI_CALL
terminator_CreateDisplayPlaneSurfaceKHR(VkInstance instance,const VkDisplaySurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)1183 terminator_CreateDisplayPlaneSurfaceKHR(
1184     VkInstance                                  instance,
1185     const VkDisplaySurfaceCreateInfoKHR*        pCreateInfo,
1186     const VkAllocationCallbacks*                pAllocator,
1187     VkSurfaceKHR*                               pSurface)
1188 {
1189     struct loader_instance *inst = loader_get_instance(instance);
1190     VkIcdSurfaceDisplay *pIcdSurface = NULL;
1191 
1192     pIcdSurface = loader_heap_alloc(inst, sizeof(VkIcdSurfaceDisplay),
1193                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
1194     if (pIcdSurface == NULL) {
1195         return VK_ERROR_OUT_OF_HOST_MEMORY;
1196     }
1197 
1198     pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
1199     pIcdSurface->displayMode = pCreateInfo->displayMode;
1200     pIcdSurface->planeIndex = pCreateInfo->planeIndex;
1201     pIcdSurface->planeStackIndex = pCreateInfo->planeStackIndex;
1202     pIcdSurface->transform = pCreateInfo->transform;
1203     pIcdSurface->globalAlpha = pCreateInfo->globalAlpha;
1204     pIcdSurface->alphaMode = pCreateInfo->alphaMode;
1205     pIcdSurface->imageExtent = pCreateInfo->imageExtent;
1206 
1207     *pSurface = (VkSurfaceKHR)pIcdSurface;
1208 
1209     return VK_SUCCESS;
1210 }
1211 
wsi_swapchain_instance_gpa(struct loader_instance * ptr_instance,const char * name,void ** addr)1212 bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance,
1213                                 const char *name, void **addr) {
1214     *addr = NULL;
1215 
1216     /*
1217      * Functions for the VK_KHR_surface extension:
1218      */
1219     if (!strcmp("vkDestroySurfaceKHR", name)) {
1220         *addr = ptr_instance->wsi_surface_enabled ? (void *)vkDestroySurfaceKHR
1221                                                   : NULL;
1222         return true;
1223     }
1224     if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) {
1225         *addr = ptr_instance->wsi_surface_enabled
1226                     ? (void *)vkGetPhysicalDeviceSurfaceSupportKHR
1227                     : NULL;
1228         return true;
1229     }
1230     if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", name)) {
1231         *addr = ptr_instance->wsi_surface_enabled
1232                     ? (void *)vkGetPhysicalDeviceSurfaceCapabilitiesKHR
1233                     : NULL;
1234         return true;
1235     }
1236     if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", name)) {
1237         *addr = ptr_instance->wsi_surface_enabled
1238                     ? (void *)vkGetPhysicalDeviceSurfaceFormatsKHR
1239                     : NULL;
1240         return true;
1241     }
1242     if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", name)) {
1243         *addr = ptr_instance->wsi_surface_enabled
1244                     ? (void *)vkGetPhysicalDeviceSurfacePresentModesKHR
1245                     : NULL;
1246         return true;
1247     }
1248 
1249     /*
1250      * Functions for the VK_KHR_swapchain extension:
1251      *
1252      * Note: This is a device extension, and its functions are statically
1253      * exported from the loader.  Per Khronos decisions, the the loader's GIPA
1254      * function will return the trampoline function for such device-extension
1255      * functions, regardless of whether the extension has been enabled.
1256      */
1257     if (!strcmp("vkCreateSwapchainKHR", name)) {
1258         *addr = (void *)vkCreateSwapchainKHR;
1259         return true;
1260     }
1261     if (!strcmp("vkDestroySwapchainKHR", name)) {
1262         *addr = (void *)vkDestroySwapchainKHR;
1263         return true;
1264     }
1265     if (!strcmp("vkGetSwapchainImagesKHR", name)) {
1266         *addr = (void *)vkGetSwapchainImagesKHR;
1267         return true;
1268     }
1269     if (!strcmp("vkAcquireNextImageKHR", name)) {
1270         *addr = (void *)vkAcquireNextImageKHR;
1271         return true;
1272     }
1273     if (!strcmp("vkQueuePresentKHR", name)) {
1274         *addr = (void *)vkQueuePresentKHR;
1275         return true;
1276     }
1277 
1278 #ifdef VK_USE_PLATFORM_WIN32_KHR
1279     /*
1280      * Functions for the VK_KHR_win32_surface extension:
1281      */
1282     if (!strcmp("vkCreateWin32SurfaceKHR", name)) {
1283         *addr = ptr_instance->wsi_win32_surface_enabled
1284                     ? (void *)vkCreateWin32SurfaceKHR
1285                     : NULL;
1286         return true;
1287     }
1288     if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", name)) {
1289         *addr = ptr_instance->wsi_win32_surface_enabled
1290                     ? (void *)vkGetPhysicalDeviceWin32PresentationSupportKHR
1291                     : NULL;
1292         return true;
1293     }
1294 #endif // VK_USE_PLATFORM_WIN32_KHR
1295 #ifdef VK_USE_PLATFORM_MIR_KHR
1296     /*
1297      * Functions for the VK_KHR_mir_surface extension:
1298      */
1299     if (!strcmp("vkCreateMirSurfaceKHR", name)) {
1300         *addr = ptr_instance->wsi_mir_surface_enabled
1301                     ? (void *)vkCreateMirSurfaceKHR
1302                     : NULL;
1303         return true;
1304     }
1305     if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", name)) {
1306         *addr = ptr_instance->wsi_mir_surface_enabled
1307                     ? (void *)vkGetPhysicalDeviceMirPresentationSupportKHR
1308                     : NULL;
1309         return true;
1310     }
1311 #endif // VK_USE_PLATFORM_MIR_KHR
1312 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
1313     /*
1314      * Functions for the VK_KHR_wayland_surface extension:
1315      */
1316     if (!strcmp("vkCreateWaylandSurfaceKHR", name)) {
1317         *addr = ptr_instance->wsi_wayland_surface_enabled
1318                     ? (void *)vkCreateWaylandSurfaceKHR
1319                     : NULL;
1320         return true;
1321     }
1322     if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", name)) {
1323         *addr = ptr_instance->wsi_wayland_surface_enabled
1324                     ? (void *)vkGetPhysicalDeviceWaylandPresentationSupportKHR
1325                     : NULL;
1326         return true;
1327     }
1328 #endif // VK_USE_PLATFORM_WAYLAND_KHR
1329 #ifdef VK_USE_PLATFORM_XCB_KHR
1330     /*
1331      * Functions for the VK_KHR_xcb_surface extension:
1332      */
1333     if (!strcmp("vkCreateXcbSurfaceKHR", name)) {
1334         *addr = ptr_instance->wsi_xcb_surface_enabled
1335                     ? (void *)vkCreateXcbSurfaceKHR
1336                     : NULL;
1337         return true;
1338     }
1339     if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", name)) {
1340         *addr = ptr_instance->wsi_xcb_surface_enabled
1341                     ? (void *)vkGetPhysicalDeviceXcbPresentationSupportKHR
1342                     : NULL;
1343         return true;
1344     }
1345 #endif // VK_USE_PLATFORM_XCB_KHR
1346 #ifdef VK_USE_PLATFORM_XLIB_KHR
1347     /*
1348      * Functions for the VK_KHR_xlib_surface extension:
1349      */
1350     if (!strcmp("vkCreateXlibSurfaceKHR", name)) {
1351         *addr = ptr_instance->wsi_xlib_surface_enabled
1352                     ? (void *)vkCreateXlibSurfaceKHR
1353                     : NULL;
1354         return true;
1355     }
1356     if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", name)) {
1357         *addr = ptr_instance->wsi_xlib_surface_enabled
1358                     ? (void *)vkGetPhysicalDeviceXlibPresentationSupportKHR
1359                     : NULL;
1360         return true;
1361     }
1362 #endif // VK_USE_PLATFORM_XLIB_KHR
1363 #ifdef VK_USE_PLATFORM_ANDROID_KHR
1364     /*
1365      * Functions for the VK_KHR_android_surface extension:
1366      */
1367     if (!strcmp("vkCreateAndroidSurfaceKHR", name)) {
1368         *addr = ptr_instance->wsi_xlib_surface_enabled
1369                     ? (void *)vkCreateAndroidSurfaceKHR
1370                     : NULL;
1371         return true;
1372     }
1373 #endif // VK_USE_PLATFORM_ANDROID_KHR
1374 
1375     /*
1376      * Functions for VK_KHR_display extension:
1377      */
1378     if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) {
1379         *addr = ptr_instance->wsi_display_enabled
1380                     ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR
1381                     : NULL;
1382         return true;
1383     }
1384     if (!strcmp("vkGetPhysicalDeviceDisplayPlanePropertiesKHR", name)) {
1385         *addr = ptr_instance->wsi_display_enabled
1386                     ? (void *)vkGetPhysicalDeviceDisplayPlanePropertiesKHR
1387                     : NULL;
1388         return true;
1389     }
1390     if (!strcmp("vkGetDisplayPlaneSupportedDisplaysKHR", name)) {
1391         *addr = ptr_instance->wsi_display_enabled
1392                     ? (void *)vkGetDisplayPlaneSupportedDisplaysKHR
1393                     : NULL;
1394         return true;
1395     }
1396     if (!strcmp("vkGetDisplayModePropertiesKHR", name)) {
1397         *addr = ptr_instance->wsi_display_enabled
1398                     ? (void *)vkGetDisplayModePropertiesKHR
1399                     : NULL;
1400         return true;
1401     }
1402     if (!strcmp("vkCreateDisplayModeKHR", name)) {
1403         *addr = ptr_instance->wsi_display_enabled
1404                     ? (void *)vkCreateDisplayModeKHR
1405                     : NULL;
1406         return true;
1407     }
1408     if (!strcmp("vkGetDisplayPlaneCapabilitiesKHR", name)) {
1409         *addr = ptr_instance->wsi_display_enabled
1410                     ? (void *)vkGetDisplayPlaneCapabilitiesKHR
1411                     : NULL;
1412         return true;
1413     }
1414     if (!strcmp("vkCreateDisplayPlaneSurfaceKHR", name)) {
1415         *addr = ptr_instance->wsi_display_enabled
1416                     ? (void *)vkCreateDisplayPlaneSurfaceKHR
1417                     : NULL;
1418         return true;
1419     }
1420     return false;
1421 }