blob: 523f16a28021f53a9f9d41f5c9b2a0dc5d0f0df4 [file] [log] [blame]
Ian Elliott54cea232015-10-30 15:28:23 -06001/*
Lenny Komowa1b5e442019-09-16 16:14:36 -06002 * Copyright (c) 2015-2016, 2019 The Khronos Group Inc.
3 * Copyright (c) 2015-2016, 2019 Valve Corporation
4 * Copyright (c) 2015-2016, 2019 LunarG, Inc.
Ian Elliott54cea232015-10-30 15:28:23 -06005 *
Jon Ashburn4f80d672016-04-19 11:30:31 -06006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
Ian Elliott54cea232015-10-30 15:28:23 -06009 *
Jon Ashburn4f80d672016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Ian Elliott54cea232015-10-30 15:28:23 -060011 *
Jon Ashburn4f80d672016-04-19 11:30:31 -060012 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
Ian Elliott54cea232015-10-30 15:28:23 -060017 *
18 * Author: Ian Elliott <ian@lunarg.com>
Jon Ashburn1c75aec2016-02-02 17:47:28 -070019 * Author: Jon Ashburn <jon@lunarg.com>
Ian Elliottb1849742015-11-19 11:58:08 -070020 * Author: Ian Elliott <ianelliott@google.com>
Jon Ashburn1c75aec2016-02-02 17:47:28 -070021 * Author: Mark Lobodzinski <mark@lunarg.com>
Lenny Komowa1b5e442019-09-16 16:14:36 -060022 * Author: Lenny Komow <lenny@lunarg.com>
Ian Elliott54cea232015-10-30 15:28:23 -060023 */
24
Tom Andersona8358802018-07-25 17:10:16 -070025#ifndef _GNU_SOURCE
Ian Elliott54cea232015-10-30 15:28:23 -060026#define _GNU_SOURCE
Tom Andersona8358802018-07-25 17:10:16 -070027#endif
Ian Elliott0d4ffa32016-03-24 13:59:22 -060028#include <stdio.h>
Ian Elliott54cea232015-10-30 15:28:23 -060029#include <stdlib.h>
30#include <string.h>
31#include "vk_loader_platform.h"
32#include "loader.h"
33#include "wsi.h"
Ian Elliott7c352552015-11-19 13:14:05 -070034#include <vulkan/vk_icd.h>
Ian Elliott54cea232015-10-30 15:28:23 -060035
Mark Young5467d672016-06-28 10:52:43 -060036// The first ICD/Loader interface that support querying the SurfaceKHR from
37// the ICDs.
38#define ICD_VER_SUPPORTS_ICD_SURFACE_KHR 3
39
Mark Lobodzinski91c10752017-01-26 12:16:30 -070040void wsi_create_instance(struct loader_instance *ptr_instance, const VkInstanceCreateInfo *pCreateInfo) {
Ian Elliott5fb891a2015-10-30 17:45:05 -060041 ptr_instance->wsi_surface_enabled = false;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070042
43#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburncc370d02016-03-08 09:30:30 -070044 ptr_instance->wsi_win32_surface_enabled = false;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070045#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070046#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060047 ptr_instance->wsi_wayland_surface_enabled = false;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070048#endif // VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070049#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060050 ptr_instance->wsi_xcb_surface_enabled = false;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070051#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070052#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060053 ptr_instance->wsi_xlib_surface_enabled = false;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070054#endif // VK_USE_PLATFORM_XLIB_KHR
Nicolas Caramellifa696ca2020-07-04 22:53:59 +020055#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
56 ptr_instance->wsi_directfb_surface_enabled = false;
57#endif // VK_USE_PLATFORM_DIRECTFB_EXT
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070058#ifdef VK_USE_PLATFORM_ANDROID_KHR
59 ptr_instance->wsi_android_surface_enabled = false;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070060#endif // VK_USE_PLATFORM_ANDROID_KHR
Karl Schultzd81ebfb2017-12-12 10:33:01 -050061#ifdef VK_USE_PLATFORM_MACOS_MVK
62 ptr_instance->wsi_macos_surface_enabled = false;
63#endif // VK_USE_PLATFORM_MACOS_MVK
64#ifdef VK_USE_PLATFORM_IOS_MVK
65 ptr_instance->wsi_ios_surface_enabled = false;
66#endif // VK_USE_PLATFORM_IOS_MVK
J.D. Rouand7928a12020-11-16 15:36:42 -080067#ifdef VK_USE_PLATFORM_GGP
68 ptr_instance->wsi_ggp_surface_enabled = false;
69#endif // VK_USE_PLATFORM_GGP
Craig Stoutf3b74dc2020-10-26 12:05:15 -070070#ifdef VK_USE_PLATFORM_FUCHSIA
71 ptr_instance->wsi_imagepipe_surface_enabled = false;
72#endif // VK_USE_PLATFORM_FUCHSIA
Jon Ashburncc370d02016-03-08 09:30:30 -070073 ptr_instance->wsi_display_enabled = false;
Lenny Komow61139782018-05-31 11:32:31 -060074 ptr_instance->wsi_display_props2_enabled = false;
Lenny Komowa1b5e442019-09-16 16:14:36 -060075#ifdef VK_USE_PLATFORM_METAL_EXT
76 ptr_instance->wsi_metal_surface_enabled = false;
77#endif // VK_USE_PLATFORM_METAL_EXT
Jon Ashburncc370d02016-03-08 09:30:30 -070078
Jon Ashburna0673ab2016-01-11 13:12:43 -070079 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -070080 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060081 ptr_instance->wsi_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070082 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060083 }
Ian Elliottb1849742015-11-19 11:58:08 -070084#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070085 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott1693f592015-11-23 10:17:23 -070086 ptr_instance->wsi_win32_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070087 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060088 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070089#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060090#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070091 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060092 ptr_instance->wsi_wayland_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070093 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060094 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070095#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060096#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070097 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060098 ptr_instance->wsi_xcb_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070099 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600100 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700101#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -0600102#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700103 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -0600104 ptr_instance->wsi_xlib_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -0700105 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600106 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700107#endif // VK_USE_PLATFORM_XLIB_KHR
Nicolas Caramellifa696ca2020-07-04 22:53:59 +0200108#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
109 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME) == 0) {
110 ptr_instance->wsi_directfb_surface_enabled = true;
111 continue;
112 }
113#endif // VK_USE_PLATFORM_DIRECTFB_EXT
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700114#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700115 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700116 ptr_instance->wsi_android_surface_enabled = true;
117 continue;
118 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700119#endif // VK_USE_PLATFORM_ANDROID_KHR
Karl Schultzd81ebfb2017-12-12 10:33:01 -0500120#ifdef VK_USE_PLATFORM_MACOS_MVK
121 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_MVK_MACOS_SURFACE_EXTENSION_NAME) == 0) {
122 ptr_instance->wsi_macos_surface_enabled = true;
123 continue;
124 }
125#endif // VK_USE_PLATFORM_MACOS_MVK
126#ifdef VK_USE_PLATFORM_IOS_MVK
127 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_MVK_IOS_SURFACE_EXTENSION_NAME) == 0) {
128 ptr_instance->wsi_ios_surface_enabled = true;
129 continue;
130 }
131#endif // VK_USE_PLATFORM_IOS_MVK
J.D. Rouand7928a12020-11-16 15:36:42 -0800132#ifdef VK_USE_PLATFORM_GGP
133 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_GGP_STREAM_DESCRIPTOR_SURFACE_EXTENSION_NAME) == 0) {
134 ptr_instance->wsi_ggp_surface_enabled = true;
135 continue;
136 }
137#endif // VK_USE_PLATFORM_GGP
Craig Stoutf3b74dc2020-10-26 12:05:15 -0700138#ifdef VK_USE_PLATFORM_FUCHSIA
139 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_FUCHSIA_IMAGEPIPE_SURFACE_EXTENSION_NAME) == 0) {
140 ptr_instance->wsi_imagepipe_surface_enabled = true;
141 continue;
142 }
143#endif // VK_USE_PLATFORM_FUCHSIA
Bryan Law-Smith57305692019-04-01 09:45:55 +0100144 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME) == 0) {
145 ptr_instance->wsi_headless_surface_enabled = true;
146 continue;
147 }
Lenny Komowa1b5e442019-09-16 16:14:36 -0600148#if defined(VK_USE_PLATFORM_METAL_EXT)
149 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_METAL_SURFACE_EXTENSION_NAME) == 0) {
150 ptr_instance->wsi_metal_surface_enabled = true;
151 continue;
152 }
153#endif
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700154 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) {
Jon Ashburncc370d02016-03-08 09:30:30 -0700155 ptr_instance->wsi_display_enabled = true;
156 continue;
157 }
Lenny Komow61139782018-05-31 11:32:31 -0600158 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME) == 0) {
159 ptr_instance->wsi_display_props2_enabled = true;
160 continue;
161 }
Ian Elliott54cea232015-10-30 15:28:23 -0600162 }
163}
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600164
165// Linux WSI surface extensions are not always compiled into the loader. (Assume
166// for Windows the KHR_win32_surface is always compiled into loader). A given
167// Linux build environment might not have the headers required for building one
Tony-LunarG03667212018-10-23 14:08:03 -0600168// of the three extensions (Xlib, Xcb, Wayland). Thus, need to check if
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600169// the built loader actually supports the particular Linux surface extension.
170// If not supported by the built loader it will not be included in the list of
171// enumerated instance extensions. This solves the issue where an ICD or layer
172// advertises support for a given Linux surface extension but the loader was not
173// built to support the extension.
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600174bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop) {
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600175#ifndef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700176 if (!strcmp(ext_prop->extensionName, "VK_KHR_wayland_surface")) return true;
177#endif // VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600178#ifndef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700179 if (!strcmp(ext_prop->extensionName, "VK_KHR_xcb_surface")) return true;
180#endif // VK_USE_PLATFORM_XCB_KHR
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600181#ifndef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700182 if (!strcmp(ext_prop->extensionName, "VK_KHR_xlib_surface")) return true;
183#endif // VK_USE_PLATFORM_XLIB_KHR
Nicolas Caramellifa696ca2020-07-04 22:53:59 +0200184#ifndef VK_USE_PLATFORM_DIRECTFB_EXT
185 if (!strcmp(ext_prop->extensionName, "VK_EXT_directfb_surface")) return true;
186#endif // VK_USE_PLATFORM_DIRECTFB_EXT
Ian Elliott54cea232015-10-30 15:28:23 -0600187
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600188 return false;
189}
Ian Elliott7c352552015-11-19 13:14:05 -0700190
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600191// Functions for the VK_KHR_surface extension:
192
193// This is the trampoline entrypoint for DestroySurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700194LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
195 const VkAllocationCallbacks *pAllocator) {
Ian Elliottabf50662015-11-25 14:43:02 -0700196 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700197 disp = loader_get_instance_layer_dispatch(instance);
Ian Elliottabf50662015-11-25 14:43:02 -0700198 disp->DestroySurfaceKHR(instance, surface, pAllocator);
199}
200
Jon Ashburncc370d02016-03-08 09:30:30 -0700201// TODO probably need to lock around all the loader_get_instance() calls.
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600202
203// This is the instance chain terminator function for DestroySurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700204VKAPI_ATTR void VKAPI_CALL terminator_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
205 const VkAllocationCallbacks *pAllocator) {
Ian Elliott1693f592015-11-23 10:17:23 -0700206 struct loader_instance *ptr_instance = loader_get_instance(instance);
207
Karl Schultza9e989f2016-11-19 09:02:27 -0700208 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young11e9d472016-10-17 12:27:36 -0600209 if (NULL != icd_surface) {
210 if (NULL != icd_surface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600211 uint32_t i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700212 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
213 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700214 if (NULL != icd_term->dispatch.DestroySurfaceKHR && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[i]) {
215 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, icd_surface->real_icd_surfaces[i], pAllocator);
Mark Young3eda5882016-12-01 10:42:21 -0700216 icd_surface->real_icd_surfaces[i] = (VkSurfaceKHR)NULL;
Mark Young11e9d472016-10-17 12:27:36 -0600217 }
218 } else {
219 // The real_icd_surface for any ICD not supporting the
220 // proper interface version should be NULL. If not, then
221 // we have a problem.
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700222 assert((VkSurfaceKHR)NULL == icd_surface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600223 }
Mark Young5467d672016-06-28 10:52:43 -0600224 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700225 loader_instance_heap_free(ptr_instance, icd_surface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600226 }
Mark Young5467d672016-06-28 10:52:43 -0600227
Karl Schultza9e989f2016-11-19 09:02:27 -0700228 loader_instance_heap_free(ptr_instance, (void *)(uintptr_t)surface);
Mark Young11e9d472016-10-17 12:27:36 -0600229 }
Ian Elliott7c352552015-11-19 13:14:05 -0700230}
231
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600232// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700233LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
234 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
235 VkBool32 *pSupported) {
Ian Elliott54cea232015-10-30 15:28:23 -0600236 const VkLayerInstanceDispatchTable *disp;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700237 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Mark Young274e4bc2017-01-19 21:10:49 -0700238 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700239 VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott54cea232015-10-30 15:28:23 -0600240 return res;
241}
242
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600243// This is the instance chain terminator function for
244// GetPhysicalDeviceSurfaceSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700245VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
246 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
247 VkBool32 *pSupported) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600248 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700249 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600250 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700251 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600252 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700253 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700254 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600255 return VK_SUCCESS;
256 }
257
Mark Youngd4e5ba42017-02-28 09:58:04 -0700258 if (NULL == pSupported) {
259 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
260 "NULL pointer passed into vkGetPhysicalDeviceSurfaceSupportKHR for pSupported!\n");
261 assert(false && "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
262 }
Ian Elliott54cea232015-10-30 15:28:23 -0600263 *pSupported = false;
264
Mark Youngd4e5ba42017-02-28 09:58:04 -0700265 if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR) {
266 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
267 "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceSupportKHR!\n");
268 assert(false && "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
269 }
Ian Elliott54cea232015-10-30 15:28:23 -0600270
Karl Schultza9e989f2016-11-19 09:02:27 -0700271 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700272 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700273 return icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR(
274 phys_dev_term->phys_dev, queueFamilyIndex, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pSupported);
Mark Young5467d672016-06-28 10:52:43 -0600275 }
Mark Young5467d672016-06-28 10:52:43 -0600276
Mark Youngd4e5ba42017-02-28 09:58:04 -0700277 return icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott54cea232015-10-30 15:28:23 -0600278}
279
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600280// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceCapabilitiesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700281LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
282 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Ian Elliottea666b22015-11-19 16:05:09 -0700283 const VkLayerInstanceDispatchTable *disp;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700284 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Mark Young274e4bc2017-01-19 21:10:49 -0700285 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700286 VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(unwrapped_phys_dev, surface, pSurfaceCapabilities);
Ian Elliottea666b22015-11-19 16:05:09 -0700287 return res;
288}
289
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600290// This is the instance chain terminator function for
291// GetPhysicalDeviceSurfaceCapabilitiesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700292VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
293 VkSurfaceKHR surface,
294 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600295 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700296 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600297 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700298 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600299 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700300 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700301 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600302 return VK_SUCCESS;
303 }
304
Mark Youngd4e5ba42017-02-28 09:58:04 -0700305 if (NULL == pSurfaceCapabilities) {
306 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
307 "NULL pointer passed into vkGetPhysicalDeviceSurfaceCapabilitiesKHR for pSurfaceCapabilities!\n");
308 assert(false && "GetPhysicalDeviceSurfaceCapabilitiesKHR: Error, null pSurfaceCapabilities");
309 }
Ian Elliottea666b22015-11-19 16:05:09 -0700310
Mark Youngd4e5ba42017-02-28 09:58:04 -0700311 if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR) {
312 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
313 "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceCapabilitiesKHR!\n");
314 assert(false && "loader: null GetPhysicalDeviceSurfaceCapabilitiesKHR ICD pointer");
315 }
Ian Elliottea666b22015-11-19 16:05:09 -0700316
Karl Schultza9e989f2016-11-19 09:02:27 -0700317 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700318 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700319 return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700320 phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pSurfaceCapabilities);
Mark Young5467d672016-06-28 10:52:43 -0600321 }
Mark Young5467d672016-06-28 10:52:43 -0600322
Mark Youngd4e5ba42017-02-28 09:58:04 -0700323 return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev_term->phys_dev, surface, pSurfaceCapabilities);
Ian Elliottea666b22015-11-19 16:05:09 -0700324}
325
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600326// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceFormatsKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700327LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
328 VkSurfaceKHR surface,
329 uint32_t *pSurfaceFormatCount,
330 VkSurfaceFormatKHR *pSurfaceFormats) {
331 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700332 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700333 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700334 VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliottea666b22015-11-19 16:05:09 -0700335 return res;
336}
337
Mark Young573a7a12016-11-02 09:37:08 -0600338// This is the instance chain terminator function for
339// GetPhysicalDeviceSurfaceFormatsKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700340VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
341 uint32_t *pSurfaceFormatCount,
342 VkSurfaceFormatKHR *pSurfaceFormats) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600343 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700344 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600345 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700346 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600347 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700348 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700349 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceFormatsKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600350 return VK_SUCCESS;
351 }
352
Mark Youngd4e5ba42017-02-28 09:58:04 -0700353 if (NULL == pSurfaceFormatCount) {
354 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
355 "NULL pointer passed into vkGetPhysicalDeviceSurfaceFormatsKHR for pSurfaceFormatCount!\n");
356 assert(false && "GetPhysicalDeviceSurfaceFormatsKHR(: Error, null pSurfaceFormatCount");
357 }
Ian Elliottea666b22015-11-19 16:05:09 -0700358
Mark Youngd4e5ba42017-02-28 09:58:04 -0700359 if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR) {
360 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
361 "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceCapabilitiesKHR!\n");
362 assert(false && "loader: null GetPhysicalDeviceSurfaceFormatsKHR ICD pointer");
363 }
Ian Elliottea666b22015-11-19 16:05:09 -0700364
Karl Schultza9e989f2016-11-19 09:02:27 -0700365 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700366 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700367 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev,
368 icd_surface->real_icd_surfaces[phys_dev_term->icd_index],
369 pSurfaceFormatCount, pSurfaceFormats);
Mark Young5467d672016-06-28 10:52:43 -0600370 }
Mark Young5467d672016-06-28 10:52:43 -0600371
Mark Youngd4e5ba42017-02-28 09:58:04 -0700372 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface, pSurfaceFormatCount,
373 pSurfaceFormats);
Ian Elliottea666b22015-11-19 16:05:09 -0700374}
375
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600376// This is the trampoline entrypoint for GetPhysicalDeviceSurfacePresentModesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700377LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
378 VkSurfaceKHR surface,
379 uint32_t *pPresentModeCount,
380 VkPresentModeKHR *pPresentModes) {
381 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700382 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700383 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700384 VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliottea666b22015-11-19 16:05:09 -0700385 return res;
386}
387
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600388// This is the instance chain terminator function for
389// GetPhysicalDeviceSurfacePresentModesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700390VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
391 VkSurfaceKHR surface, uint32_t *pPresentModeCount,
392 VkPresentModeKHR *pPresentModes) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600393 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700394 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600395 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700396 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600397 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700398 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700399 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfacePresentModesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600400 return VK_SUCCESS;
401 }
402
Mark Youngd4e5ba42017-02-28 09:58:04 -0700403 if (NULL == pPresentModeCount) {
404 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
405 "NULL pointer passed into vkGetPhysicalDeviceSurfacePresentModesKHR for pPresentModeCount!\n");
406 assert(false && "GetPhysicalDeviceSurfacePresentModesKHR(: Error, null pPresentModeCount");
407 }
Ian Elliottea666b22015-11-19 16:05:09 -0700408
Mark Youngd4e5ba42017-02-28 09:58:04 -0700409 if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR) {
410 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
411 "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfacePresentModesKHR!\n");
412 assert(false && "loader: null GetPhysicalDeviceSurfacePresentModesKHR ICD pointer");
413 }
Ian Elliottea666b22015-11-19 16:05:09 -0700414
Karl Schultza9e989f2016-11-19 09:02:27 -0700415 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700416 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700417 return icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700418 phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pPresentModeCount, pPresentModes);
Mark Young5467d672016-06-28 10:52:43 -0600419 }
Mark Young5467d672016-06-28 10:52:43 -0600420
Mark Youngd4e5ba42017-02-28 09:58:04 -0700421 return icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR(phys_dev_term->phys_dev, surface, pPresentModeCount,
422 pPresentModes);
Ian Elliottea666b22015-11-19 16:05:09 -0700423}
424
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600425// Functions for the VK_KHR_swapchain extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700426
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600427// This is the trampoline entrypoint for CreateSwapchainKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700428LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
429 const VkAllocationCallbacks *pAllocator,
430 VkSwapchainKHR *pSwapchain) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700431 const VkLayerDispatchTable *disp;
432 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700433 return disp->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Ian Elliott9b89a472015-11-19 16:39:21 -0700434}
Ian Elliott7c352552015-11-19 13:14:05 -0700435
Mark Youngd4e5ba42017-02-28 09:58:04 -0700436VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
Karl Schultzd81ebfb2017-12-12 10:33:01 -0500437 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {
Mark Young5467d672016-06-28 10:52:43 -0600438 uint32_t icd_index = 0;
439 struct loader_device *dev;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700440 struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
Mark Youngd4e5ba42017-02-28 09:58:04 -0700441 if (NULL != icd_term && NULL != icd_term->dispatch.CreateSwapchainKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700442 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pCreateInfo->surface;
Mark Young5467d672016-06-28 10:52:43 -0600443 if (NULL != icd_surface->real_icd_surfaces) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700444 if ((VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
Mark Young5467d672016-06-28 10:52:43 -0600445 // We found the ICD, and there is an ICD KHR surface
446 // associated with it, so copy the CreateInfo struct
447 // and point it at the ICD's surface.
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700448 VkSwapchainCreateInfoKHR *pCreateCopy = loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR));
Mark Young5467d672016-06-28 10:52:43 -0600449 if (NULL == pCreateCopy) {
450 return VK_ERROR_OUT_OF_HOST_MEMORY;
451 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700452 memcpy(pCreateCopy, pCreateInfo, sizeof(VkSwapchainCreateInfoKHR));
453 pCreateCopy->surface = icd_surface->real_icd_surfaces[icd_index];
Mark Youngd4e5ba42017-02-28 09:58:04 -0700454 return icd_term->dispatch.CreateSwapchainKHR(device, pCreateCopy, pAllocator, pSwapchain);
Mark Young5467d672016-06-28 10:52:43 -0600455 }
456 }
Mark Youngd4e5ba42017-02-28 09:58:04 -0700457 return icd_term->dispatch.CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Mark Young5467d672016-06-28 10:52:43 -0600458 }
459 return VK_SUCCESS;
460}
461
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600462// This is the trampoline entrypoint for DestroySwapchainKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700463LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
464 const VkAllocationCallbacks *pAllocator) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700465 const VkLayerDispatchTable *disp;
466 disp = loader_get_dispatch(device);
467 disp->DestroySwapchainKHR(device, swapchain, pAllocator);
468}
Ian Elliott7c352552015-11-19 13:14:05 -0700469
Mark Youngd4e5ba42017-02-28 09:58:04 -0700470// This is the trampoline entrypoint for GetSwapchainImagesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700471LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
472 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700473 const VkLayerDispatchTable *disp;
474 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700475 return disp->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
Ian Elliott9b89a472015-11-19 16:39:21 -0700476}
477
Mark Youngd4e5ba42017-02-28 09:58:04 -0700478// This is the trampoline entrypoint for AcquireNextImageKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700479LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
480 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700481 const VkLayerDispatchTable *disp;
482 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700483 return disp->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
Ian Elliott9b89a472015-11-19 16:39:21 -0700484}
485
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600486// This is the trampoline entrypoint for QueuePresentKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700487LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700488 const VkLayerDispatchTable *disp;
489 disp = loader_get_dispatch(queue);
Mark Young76b3fe02016-09-08 12:28:38 -0600490 return disp->QueuePresentKHR(queue, pPresentInfo);
Ian Elliott9b89a472015-11-19 16:39:21 -0700491}
Ian Elliott7c352552015-11-19 13:14:05 -0700492
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700493static VkIcdSurface *AllocateIcdSurfaceStruct(struct loader_instance *instance, size_t base_size, size_t platform_size) {
Mark Youngf27962c2016-09-16 10:18:42 -0600494 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700495 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Youngf27962c2016-09-16 10:18:42 -0600496 if (pIcdSurface != NULL) {
497 // Setup the new sizes and offsets so we can grow the structures in the
498 // future without having problems
499 pIcdSurface->base_size = (uint32_t)base_size;
500 pIcdSurface->platform_size = (uint32_t)platform_size;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700501 pIcdSurface->non_platform_offset = (uint32_t)((uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
Mark Youngf27962c2016-09-16 10:18:42 -0600502 pIcdSurface->entire_size = sizeof(VkIcdSurface);
503
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700504 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(instance, sizeof(VkSurfaceKHR) * instance->total_icd_count,
505 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Young5117fdc2016-12-13 17:19:32 -0700506 if (pIcdSurface->real_icd_surfaces == NULL) {
507 loader_instance_heap_free(instance, pIcdSurface);
508 pIcdSurface = NULL;
Mark Youngf27962c2016-09-16 10:18:42 -0600509 } else {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700510 memset(pIcdSurface->real_icd_surfaces, 0, sizeof(VkSurfaceKHR) * instance->total_icd_count);
Mark Youngf27962c2016-09-16 10:18:42 -0600511 }
512 }
513 return pIcdSurface;
514}
515
Ian Elliott7c352552015-11-19 13:14:05 -0700516#ifdef VK_USE_PLATFORM_WIN32_KHR
517
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600518// Functions for the VK_KHR_win32_surface extension:
519
520// This is the trampoline entrypoint for CreateWin32SurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700521LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance,
522 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
523 const VkAllocationCallbacks *pAllocator,
524 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700525 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700526 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700527 VkResult res;
528
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700529 res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700530 return res;
531}
532
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600533// This is the instance chain terminator function for CreateWin32SurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700534VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
535 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600536 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600537 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600538 uint32_t i = 0;
539
Mark Youngf27962c2016-09-16 10:18:42 -0600540 // Initialize pSurface to NULL just to be safe.
541 *pSurface = VK_NULL_HANDLE;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600542 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700543 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600544 if (!ptr_instance->wsi_win32_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700545 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700546 "VK_KHR_win32_surface extension not enabled. vkCreateWin32SurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600547 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
548 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600549 }
550
551 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700552 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->win_surf.base), sizeof(pIcdSurface->win_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700553 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600554 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
555 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700556 }
557
Mark Young5467d672016-06-28 10:52:43 -0600558 pIcdSurface->win_surf.base.platform = VK_ICD_WSI_PLATFORM_WIN32;
559 pIcdSurface->win_surf.hinstance = pCreateInfo->hinstance;
560 pIcdSurface->win_surf.hwnd = pCreateInfo->hwnd;
Ian Elliott7c352552015-11-19 13:14:05 -0700561
Mark Young5467d672016-06-28 10:52:43 -0600562 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700563 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
564 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700565 if (NULL != icd_term->dispatch.CreateWin32SurfaceKHR) {
566 vkRes = icd_term->dispatch.CreateWin32SurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
567 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600568 if (VK_SUCCESS != vkRes) {
569 goto out;
570 }
571 }
572 }
573 }
574
575 *pSurface = (VkSurfaceKHR)(pIcdSurface);
576
577out:
578
579 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
580 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600581 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700582 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700583 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
584 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600585 }
586 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700587 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600588 }
589 loader_instance_heap_free(ptr_instance, pIcdSurface);
590 }
591
592 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700593}
Ian Elliotte851dd62015-11-24 15:39:10 -0700594
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600595// This is the trampoline entrypoint for
596// GetPhysicalDeviceWin32PresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700597LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
598 uint32_t queueFamilyIndex) {
599 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700600 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700601 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700602 VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex);
Ian Elliotte851dd62015-11-24 15:39:10 -0700603 return res;
604}
605
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600606// This is the instance chain terminator function for
607// GetPhysicalDeviceWin32PresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700608VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
609 uint32_t queueFamilyIndex) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600610 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700611 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600612 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700613 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600614 if (!ptr_instance->wsi_win32_surface_enabled) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700615 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700616 "VK_KHR_win32_surface extension not enabled. vkGetPhysicalDeviceWin32PresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600617 return VK_SUCCESS;
618 }
619
Mark Youngd4e5ba42017-02-28 09:58:04 -0700620 if (NULL == icd_term->dispatch.GetPhysicalDeviceWin32PresentationSupportKHR) {
621 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
622 "ICD for selected physical device is not exporting vkGetPhysicalDeviceWin32PresentationSupportKHR!\n");
623 assert(false && "loader: null GetPhysicalDeviceWin32PresentationSupportKHR ICD pointer");
624 }
Ian Elliotte851dd62015-11-24 15:39:10 -0700625
Mark Youngd4e5ba42017-02-28 09:58:04 -0700626 return icd_term->dispatch.GetPhysicalDeviceWin32PresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex);
Ian Elliotte851dd62015-11-24 15:39:10 -0700627}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700628#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700629
Ian Elliott7c352552015-11-19 13:14:05 -0700630#ifdef VK_USE_PLATFORM_WAYLAND_KHR
631
Mark Youngd4e5ba42017-02-28 09:58:04 -0700632// This is the trampoline entrypoint for CreateWaylandSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700633LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance,
634 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
635 const VkAllocationCallbacks *pAllocator,
636 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700637 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700638 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700639 VkResult res;
640
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700641 res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700642 return res;
643}
644
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600645// This is the instance chain terminator function for CreateWaylandSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700646VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(VkInstance instance,
647 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
648 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600649 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600650 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600651 uint32_t i = 0;
652
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600653 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700654 struct loader_instance *ptr_instance = loader_get_instance(instance);
Jon Ashburn436d6a32016-03-24 17:26:59 -0600655 if (!ptr_instance->wsi_wayland_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700656 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700657 "VK_KHR_wayland_surface extension not enabled. vkCreateWaylandSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600658 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
659 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600660 }
661
662 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700663 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->wayland_surf.base), sizeof(pIcdSurface->wayland_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700664 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600665 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
666 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700667 }
668
Mark Young5467d672016-06-28 10:52:43 -0600669 pIcdSurface->wayland_surf.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
670 pIcdSurface->wayland_surf.display = pCreateInfo->display;
671 pIcdSurface->wayland_surf.surface = pCreateInfo->surface;
672
Mark Young5467d672016-06-28 10:52:43 -0600673 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700674 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
675 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700676 if (NULL != icd_term->dispatch.CreateWaylandSurfaceKHR) {
677 vkRes = icd_term->dispatch.CreateWaylandSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
678 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600679 if (VK_SUCCESS != vkRes) {
680 goto out;
681 }
682 }
683 }
684 }
Ian Elliott7c352552015-11-19 13:14:05 -0700685
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700686 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700687
Mark Young5467d672016-06-28 10:52:43 -0600688out:
689
690 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
691 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600692 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700693 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700694 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
695 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600696 }
697 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700698 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600699 }
700 loader_instance_heap_free(ptr_instance, pIcdSurface);
701 }
702
703 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700704}
Ian Elliotte851dd62015-11-24 15:39:10 -0700705
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600706// This is the trampoline entrypoint for
707// GetPhysicalDeviceWaylandPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700708LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
709 uint32_t queueFamilyIndex,
710 struct wl_display *display) {
711 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700712 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700713 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700714 VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, display);
Ian Elliotte851dd62015-11-24 15:39:10 -0700715 return res;
716}
717
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600718// This is the instance chain terminator function for
719// GetPhysicalDeviceWaylandPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700720VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
721 uint32_t queueFamilyIndex,
722 struct wl_display *display) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600723 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700724 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600725 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700726 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Jon Ashburn436d6a32016-03-24 17:26:59 -0600727 if (!ptr_instance->wsi_wayland_surface_enabled) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700728 loader_log(
729 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
730 "VK_KHR_wayland_surface extension not enabled. vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600731 return VK_SUCCESS;
732 }
733
Mark Youngd4e5ba42017-02-28 09:58:04 -0700734 if (NULL == icd_term->dispatch.GetPhysicalDeviceWaylandPresentationSupportKHR) {
735 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
736 "ICD for selected physical device is not exporting vkGetPhysicalDeviceWaylandPresentationSupportKHR!\n");
737 assert(false && "loader: null GetPhysicalDeviceWaylandPresentationSupportKHR ICD pointer");
738 }
Ian Elliotte851dd62015-11-24 15:39:10 -0700739
Mark Youngd4e5ba42017-02-28 09:58:04 -0700740 return icd_term->dispatch.GetPhysicalDeviceWaylandPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, display);
Ian Elliotte851dd62015-11-24 15:39:10 -0700741}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700742#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700743
744#ifdef VK_USE_PLATFORM_XCB_KHR
745
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600746// Functions for the VK_KHR_xcb_surface extension:
747
748// This is the trampoline entrypoint for CreateXcbSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700749LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(VkInstance instance,
750 const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
751 const VkAllocationCallbacks *pAllocator,
752 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700753 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700754 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700755 VkResult res;
756
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700757 res = disp->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700758 return res;
759}
760
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600761// This is the instance chain terminator function for CreateXcbSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700762VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
763 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600764 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600765 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600766 uint32_t i = 0;
767
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600768 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700769 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600770 if (!ptr_instance->wsi_xcb_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700771 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700772 "VK_KHR_xcb_surface extension not enabled. vkCreateXcbSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600773 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
774 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600775 }
776
777 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700778 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->xcb_surf.base), sizeof(pIcdSurface->xcb_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700779 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600780 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
781 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700782 }
783
Mark Young5467d672016-06-28 10:52:43 -0600784 pIcdSurface->xcb_surf.base.platform = VK_ICD_WSI_PLATFORM_XCB;
785 pIcdSurface->xcb_surf.connection = pCreateInfo->connection;
786 pIcdSurface->xcb_surf.window = pCreateInfo->window;
787
Mark Young5467d672016-06-28 10:52:43 -0600788 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700789 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
790 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700791 if (NULL != icd_term->dispatch.CreateXcbSurfaceKHR) {
792 vkRes = icd_term->dispatch.CreateXcbSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
793 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600794 if (VK_SUCCESS != vkRes) {
795 goto out;
796 }
797 }
798 }
799 }
Ian Elliott7c352552015-11-19 13:14:05 -0700800
Mark Young3eda5882016-12-01 10:42:21 -0700801 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700802
Mark Young5467d672016-06-28 10:52:43 -0600803out:
804
805 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
806 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600807 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700808 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700809 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
810 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600811 }
812 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700813 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600814 }
815 loader_instance_heap_free(ptr_instance, pIcdSurface);
816 }
817
818 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700819}
Ian Elliotte851dd62015-11-24 15:39:10 -0700820
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600821// This is the trampoline entrypoint for
822// GetPhysicalDeviceXcbPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700823LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
824 uint32_t queueFamilyIndex,
825 xcb_connection_t *connection,
826 xcb_visualid_t visual_id) {
827 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700828 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700829 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700830 VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliotte851dd62015-11-24 15:39:10 -0700831 return res;
832}
833
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600834// This is the instance chain terminator function for
835// GetPhysicalDeviceXcbPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700836VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
837 uint32_t queueFamilyIndex,
838 xcb_connection_t *connection,
839 xcb_visualid_t visual_id) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600840 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700841 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600842 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700843 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600844 if (!ptr_instance->wsi_xcb_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700845 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700846 "VK_KHR_xcb_surface extension not enabled. vkGetPhysicalDeviceXcbPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600847 return VK_SUCCESS;
848 }
849
Mark Youngd4e5ba42017-02-28 09:58:04 -0700850 if (NULL == icd_term->dispatch.GetPhysicalDeviceXcbPresentationSupportKHR) {
851 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
852 "ICD for selected physical device is not exporting vkGetPhysicalDeviceXcbPresentationSupportKHR!\n");
853 assert(false && "loader: null GetPhysicalDeviceXcbPresentationSupportKHR ICD pointer");
854 }
Ian Elliotte851dd62015-11-24 15:39:10 -0700855
Mark Youngd4e5ba42017-02-28 09:58:04 -0700856 return icd_term->dispatch.GetPhysicalDeviceXcbPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, connection,
857 visual_id);
Ian Elliotte851dd62015-11-24 15:39:10 -0700858}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700859#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700860
861#ifdef VK_USE_PLATFORM_XLIB_KHR
862
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600863// Functions for the VK_KHR_xlib_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700864
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600865// This is the trampoline entrypoint for CreateXlibSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700866LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance,
867 const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
868 const VkAllocationCallbacks *pAllocator,
869 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700870 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700871 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700872 VkResult res;
873
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700874 res = disp->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700875 return res;
876}
877
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600878// This is the instance chain terminator function for CreateXlibSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700879VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
880 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600881 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600882 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600883 uint32_t i = 0;
884
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600885 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700886 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600887 if (!ptr_instance->wsi_xlib_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700888 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700889 "VK_KHR_xlib_surface extension not enabled. vkCreateXlibSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600890 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
891 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600892 }
893
894 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700895 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->xlib_surf.base), sizeof(pIcdSurface->xlib_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700896 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600897 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
898 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700899 }
900
Mark Young5467d672016-06-28 10:52:43 -0600901 pIcdSurface->xlib_surf.base.platform = VK_ICD_WSI_PLATFORM_XLIB;
902 pIcdSurface->xlib_surf.dpy = pCreateInfo->dpy;
903 pIcdSurface->xlib_surf.window = pCreateInfo->window;
904
Mark Young5467d672016-06-28 10:52:43 -0600905 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700906 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
907 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700908 if (NULL != icd_term->dispatch.CreateXlibSurfaceKHR) {
909 vkRes = icd_term->dispatch.CreateXlibSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
910 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600911 if (VK_SUCCESS != vkRes) {
912 goto out;
913 }
914 }
915 }
916 }
Ian Elliott7c352552015-11-19 13:14:05 -0700917
Mark Young3eda5882016-12-01 10:42:21 -0700918 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700919
Mark Young5467d672016-06-28 10:52:43 -0600920out:
921
922 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
923 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600924 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700925 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700926 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
927 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600928 }
929 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700930 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600931 }
932 loader_instance_heap_free(ptr_instance, pIcdSurface);
933 }
934
935 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700936}
Ian Elliotte851dd62015-11-24 15:39:10 -0700937
Mark Young573a7a12016-11-02 09:37:08 -0600938// This is the trampoline entrypoint for
939// GetPhysicalDeviceXlibPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700940LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
941 uint32_t queueFamilyIndex, Display *dpy,
942 VisualID visualID) {
943 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700944 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700945 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700946 VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliotte851dd62015-11-24 15:39:10 -0700947 return res;
948}
949
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600950// This is the instance chain terminator function for
951// GetPhysicalDeviceXlibPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700952VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
953 uint32_t queueFamilyIndex, Display *dpy,
954 VisualID visualID) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600955 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700956 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600957 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700958 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600959 if (!ptr_instance->wsi_xlib_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700960 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700961 "VK_KHR_xlib_surface extension not enabled. vkGetPhysicalDeviceXlibPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600962 return VK_SUCCESS;
963 }
964
Mark Youngd4e5ba42017-02-28 09:58:04 -0700965 if (NULL == icd_term->dispatch.GetPhysicalDeviceXlibPresentationSupportKHR) {
966 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
967 "ICD for selected physical device is not exporting vkGetPhysicalDeviceXlibPresentationSupportKHR!\n");
968 assert(false && "loader: null GetPhysicalDeviceXlibPresentationSupportKHR ICD pointer");
969 }
Ian Elliotte851dd62015-11-24 15:39:10 -0700970
Mark Youngd4e5ba42017-02-28 09:58:04 -0700971 return icd_term->dispatch.GetPhysicalDeviceXlibPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliotte851dd62015-11-24 15:39:10 -0700972}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700973#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700974
Nicolas Caramellifa696ca2020-07-04 22:53:59 +0200975#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
976
977// Functions for the VK_EXT_directfb_surface extension:
978
979// This is the trampoline entrypoint for CreateDirectFBSurfaceEXT
980LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT(VkInstance instance,
981 const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo,
982 const VkAllocationCallbacks *pAllocator,
983 VkSurfaceKHR *pSurface) {
984 const VkLayerInstanceDispatchTable *disp;
985 disp = loader_get_instance_layer_dispatch(instance);
986 VkResult res;
987
988 res = disp->CreateDirectFBSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
989 return res;
990}
991
992// This is the instance chain terminator function for CreateDirectFBSurfaceEXT
993VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDirectFBSurfaceEXT(VkInstance instance,
994 const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo,
995 const VkAllocationCallbacks *pAllocator,
996 VkSurfaceKHR *pSurface) {
997 VkResult vkRes = VK_SUCCESS;
998 VkIcdSurface *pIcdSurface = NULL;
999 uint32_t i = 0;
1000
1001 // First, check to ensure the appropriate extension was enabled:
1002 struct loader_instance *ptr_instance = loader_get_instance(instance);
1003 if (!ptr_instance->wsi_directfb_surface_enabled) {
1004 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1005 "VK_EXT_directfb_surface extension not enabled. vkCreateDirectFBSurfaceEXT not executed!\n");
1006 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1007 goto out;
1008 }
1009
1010 // Next, if so, proceed with the implementation of this function:
1011 pIcdSurface =
1012 AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->directfb_surf.base), sizeof(pIcdSurface->directfb_surf));
1013 if (pIcdSurface == NULL) {
1014 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1015 goto out;
1016 }
1017
1018 pIcdSurface->directfb_surf.base.platform = VK_ICD_WSI_PLATFORM_DIRECTFB;
1019 pIcdSurface->directfb_surf.dfb = pCreateInfo->dfb;
1020 pIcdSurface->directfb_surf.surface = pCreateInfo->surface;
1021
1022 // Loop through each ICD and determine if they need to create a surface
1023 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1024 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1025 if (NULL != icd_term->dispatch.CreateDirectFBSurfaceEXT) {
1026 vkRes = icd_term->dispatch.CreateDirectFBSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
1027 &pIcdSurface->real_icd_surfaces[i]);
1028 if (VK_SUCCESS != vkRes) {
1029 goto out;
1030 }
1031 }
1032 }
1033 }
1034
1035 *pSurface = (VkSurfaceKHR)pIcdSurface;
1036
1037out:
1038
1039 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1040 if (NULL != pIcdSurface->real_icd_surfaces) {
1041 i = 0;
1042 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1043 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1044 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1045 }
1046 }
1047 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
1048 }
1049 loader_instance_heap_free(ptr_instance, pIcdSurface);
1050 }
1051
1052 return vkRes;
1053}
1054
1055// This is the trampoline entrypoint for
1056// GetPhysicalDeviceDirectFBPresentationSupportEXT
1057LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,
1058 uint32_t queueFamilyIndex,
1059 IDirectFB *dfb) {
1060 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1061 const VkLayerInstanceDispatchTable *disp;
1062 disp = loader_get_instance_layer_dispatch(physicalDevice);
1063 VkBool32 res = disp->GetPhysicalDeviceDirectFBPresentationSupportEXT(unwrapped_phys_dev, queueFamilyIndex, dfb);
1064 return res;
1065}
1066
1067// This is the instance chain terminator function for
1068// GetPhysicalDeviceDirectFBPresentationSupportEXT
1069VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,
1070 uint32_t queueFamilyIndex,
1071 IDirectFB *dfb) {
1072 // First, check to ensure the appropriate extension was enabled:
1073 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1074 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1075 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
1076 if (!ptr_instance->wsi_directfb_surface_enabled) {
1077 loader_log(
1078 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1079 "VK_EXT_directfb_surface extension not enabled. vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
1080 return VK_SUCCESS;
1081 }
1082
1083 if (NULL == icd_term->dispatch.GetPhysicalDeviceDirectFBPresentationSupportEXT) {
1084 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1085 "ICD for selected physical device is not exporting vkGetPhysicalDeviceDirectFBPresentationSupportEXT!\n");
1086 assert(false && "loader: null GetPhysicalDeviceDirectFBPresentationSupportEXT ICD pointer");
1087 }
1088
1089 return icd_term->dispatch.GetPhysicalDeviceDirectFBPresentationSupportEXT(phys_dev_term->phys_dev, queueFamilyIndex, dfb);
1090}
1091#endif // VK_USE_PLATFORM_DIRECTFB_EXT
1092
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001093#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001094
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001095// Functions for the VK_KHR_android_surface extension:
1096
1097// This is the trampoline entrypoint for CreateAndroidSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001098LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(VkInstance instance, ANativeWindow *window,
1099 const VkAllocationCallbacks *pAllocator,
1100 VkSurfaceKHR *pSurface) {
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001101 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001102 disp = loader_get_instance_layer_dispatch(instance);
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001103 VkResult res;
1104
1105 res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
1106 return res;
1107}
1108
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001109// This is the instance chain terminator function for CreateAndroidSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001110VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(VkInstance instance, Window window,
1111 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001112 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001113 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001114 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001115 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001116 "VK_KHR_display extension not enabled. vkCreateAndroidSurfaceKHR not executed!\n");
Jeremy Hayes0231e1c2016-06-14 11:50:02 -06001117 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001118 }
1119
1120 // Next, if so, proceed with the implementation of this function:
Mark Young5467d672016-06-28 10:52:43 -06001121 VkIcdSurfaceAndroid *pIcdSurface =
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001122 loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceAndroid), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001123 if (pIcdSurface == NULL) {
1124 return VK_ERROR_OUT_OF_HOST_MEMORY;
1125 }
1126
1127 pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_ANDROID;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001128 pIcdSurface->window = window;
1129
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001130 *pSurface = (VkSurfaceKHR)pIcdSurface;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001131
1132 return VK_SUCCESS;
1133}
1134
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001135#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001136
Bryan Law-Smith57305692019-04-01 09:45:55 +01001137// Functions for the VK_EXT_headless_surface extension:
1138
1139VKAPI_ATTR VkResult VKAPI_CALL vkCreateHeadlessSurfaceEXT(VkInstance instance, const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
1140 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1141 const VkLayerInstanceDispatchTable *disp;
1142 disp = loader_get_instance_layer_dispatch(instance);
1143 VkResult res;
1144
1145 res = disp->CreateHeadlessSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
1146 return res;
1147}
1148
1149VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateHeadlessSurfaceEXT(VkInstance instance,
1150 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
1151 const VkAllocationCallbacks *pAllocator,
1152 VkSurfaceKHR *pSurface) {
1153 struct loader_instance *inst = loader_get_instance(instance);
1154 VkIcdSurface *pIcdSurface = NULL;
1155 VkResult vkRes = VK_SUCCESS;
1156 uint32_t i = 0;
1157
1158 if (!inst->wsi_headless_surface_enabled) {
1159 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1160 "VK_EXT_headless_surface extension not enabled. "
1161 "vkCreateHeadlessSurfaceEXT not executed!\n");
1162 return VK_SUCCESS;
1163 }
1164
1165 // Next, if so, proceed with the implementation of this function:
1166 pIcdSurface = AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->headless_surf.base), sizeof(pIcdSurface->headless_surf));
1167 if (pIcdSurface == NULL) {
1168 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1169 goto out;
1170 }
1171
1172 pIcdSurface->headless_surf.base.platform = VK_ICD_WSI_PLATFORM_HEADLESS;
1173 // Loop through each ICD and determine if they need to create a surface
1174 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1175 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1176 if (NULL != icd_term->dispatch.CreateHeadlessSurfaceEXT) {
1177 vkRes = icd_term->dispatch.CreateHeadlessSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
1178 &pIcdSurface->real_icd_surfaces[i]);
1179 if (VK_SUCCESS != vkRes) {
1180 goto out;
1181 }
1182 }
1183 }
1184 }
1185
1186 *pSurface = (VkSurfaceKHR)pIcdSurface;
1187
1188out:
1189
1190 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1191 if (NULL != pIcdSurface->real_icd_surfaces) {
1192 i = 0;
1193 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1194 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1195 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1196 }
1197 }
1198 loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
1199 }
1200 loader_instance_heap_free(inst, pIcdSurface);
1201 }
1202
1203 return vkRes;
1204}
1205
Karl Schultzd81ebfb2017-12-12 10:33:01 -05001206#ifdef VK_USE_PLATFORM_MACOS_MVK
1207
1208// Functions for the VK_MVK_macos_surface extension:
1209
1210// This is the trampoline entrypoint for CreateMacOSSurfaceMVK
1211LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(VkInstance instance,
1212 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
1213 const VkAllocationCallbacks *pAllocator,
1214 VkSurfaceKHR *pSurface) {
1215 const VkLayerInstanceDispatchTable *disp;
1216 disp = loader_get_instance_layer_dispatch(instance);
1217 VkResult res;
1218
1219 res = disp->CreateMacOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
1220 return res;
1221}
1222
1223// This is the instance chain terminator function for CreateMacOSSurfaceKHR
1224VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
1225 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1226 VkResult vkRes = VK_SUCCESS;
1227 VkIcdSurface *pIcdSurface = NULL;
1228 uint32_t i = 0;
1229
1230 // First, check to ensure the appropriate extension was enabled:
1231 struct loader_instance *ptr_instance = loader_get_instance(instance);
1232 if (!ptr_instance->wsi_macos_surface_enabled) {
1233 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1234 "VK_MVK_macos_surface extension not enabled. vkCreateMacOSSurfaceMVK not executed!\n");
1235 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1236 goto out;
1237 }
1238
1239 // Next, if so, proceed with the implementation of this function:
1240 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->macos_surf.base), sizeof(pIcdSurface->macos_surf));
1241 if (pIcdSurface == NULL) {
1242 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1243 goto out;
1244 }
1245
1246 pIcdSurface->macos_surf.base.platform = VK_ICD_WSI_PLATFORM_MACOS;
1247 pIcdSurface->macos_surf.pView = pCreateInfo->pView;
1248
1249 // Loop through each ICD and determine if they need to create a surface
1250 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1251 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1252 if (NULL != icd_term->dispatch.CreateMacOSSurfaceMVK) {
1253 vkRes = icd_term->dispatch.CreateMacOSSurfaceMVK(icd_term->instance, pCreateInfo, pAllocator,
1254 &pIcdSurface->real_icd_surfaces[i]);
1255 if (VK_SUCCESS != vkRes) {
1256 goto out;
1257 }
1258 }
1259 }
1260 }
1261
1262 *pSurface = (VkSurfaceKHR)pIcdSurface;
1263
1264out:
1265
1266 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1267 if (NULL != pIcdSurface->real_icd_surfaces) {
1268 i = 0;
1269 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1270 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1271 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1272 }
1273 }
1274 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
1275 }
1276 loader_instance_heap_free(ptr_instance, pIcdSurface);
1277 }
1278
1279 return vkRes;
1280}
1281
1282#endif // VK_USE_PLATFORM_MACOS_MVK
1283
1284#ifdef VK_USE_PLATFORM_IOS_MVK
1285
1286// Functions for the VK_MVK_ios_surface extension:
1287
1288// This is the trampoline entrypoint for CreateIOSSurfaceMVK
1289LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(VkInstance instance,
1290 const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
1291 const VkAllocationCallbacks *pAllocator,
1292 VkSurfaceKHR *pSurface) {
1293 const VkLayerInstanceDispatchTable *disp;
1294 disp = loader_get_instance_layer_dispatch(instance);
1295 VkResult res;
1296
1297 res = disp->CreateIOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
1298 return res;
1299}
1300
1301// This is the instance chain terminator function for CreateIOSSurfaceKHR
1302VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
1303 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1304 // First, check to ensure the appropriate extension was enabled:
1305 struct loader_instance *ptr_instance = loader_get_instance(instance);
1306 if (!ptr_instance->wsi_ios_surface_enabled) {
1307 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1308 "VK_MVK_ios_surface extension not enabled. vkCreateIOSSurfaceMVK not executed!\n");
1309 return VK_ERROR_EXTENSION_NOT_PRESENT;
1310 }
1311
1312 // Next, if so, proceed with the implementation of this function:
1313 VkIcdSurfaceIOS *pIcdSurface =
1314 loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceIOS), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
1315 if (pIcdSurface == NULL) {
1316 return VK_ERROR_OUT_OF_HOST_MEMORY;
1317 }
1318
1319 pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_IOS;
1320 pIcdSurface->pView = pCreateInfo->pView;
1321
1322 *pSurface = (VkSurfaceKHR)pIcdSurface;
1323
1324 return VK_SUCCESS;
1325}
1326
1327#endif // VK_USE_PLATFORM_IOS_MVK
1328
J.D. Rouand7928a12020-11-16 15:36:42 -08001329#ifdef VK_USE_PLATFORM_GGP
1330
1331// Functions for the VK_GGP_stream_descriptor_surface extension:
1332
1333// This is the trampoline entrypoint for CreateStreamDescriptorSurfaceGGP
1334LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
1335vkCreateStreamDescriptorSurfaceGGP(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP *pCreateInfo,
1336 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1337 const VkLayerInstanceDispatchTable *disp;
1338 disp = loader_get_instance_layer_dispatch(instance);
1339 VkResult res;
1340
1341 res = disp->CreateStreamDescriptorSurfaceGGP(instance, pCreateInfo, pAllocator, pSurface);
1342 return res;
1343}
1344
1345// This is the instance chain terminator function for CreateStreamDescriptorSurfaceGGP
1346VKAPI_ATTR VkResult VKAPI_CALL
1347terminator_CreateStreamDescriptorSurfaceGGP(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP *pCreateInfo,
1348 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1349 VkResult vkRes = VK_SUCCESS;
1350 VkIcdSurface *pIcdSurface = NULL;
1351 uint32_t i = 0;
1352
1353 // First, check to ensure the appropriate extension was enabled:
1354 struct loader_instance *ptr_instance = loader_get_instance(instance);
1355 if (!ptr_instance->wsi_ggp_surface_enabled) {
1356 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1357 "VK_GGP_stream_descriptor_surface extension not enabled. vkCreateStreamDescriptorSurfaceGGP not executed!\n");
1358 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1359 goto out;
1360 }
1361
1362 // Next, if so, proceed with the implementation of this function:
1363 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->ggp_surf.base), sizeof(pIcdSurface->ggp_surf));
1364 if (pIcdSurface == NULL) {
1365 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1366 goto out;
1367 }
1368
1369 pIcdSurface->ggp_surf.base.platform = VK_ICD_WSI_PLATFORM_GGP;
1370 pIcdSurface->ggp_surf.streamDescriptor = pCreateInfo->streamDescriptor;
1371
1372 // Loop through each ICD and determine if they need to create a surface
1373 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1374 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1375 if (NULL != icd_term->dispatch.CreateStreamDescriptorSurfaceGGP) {
1376 vkRes = icd_term->dispatch.CreateStreamDescriptorSurfaceGGP(icd_term->instance, pCreateInfo, pAllocator,
1377 &pIcdSurface->real_icd_surfaces[i]);
1378 if (VK_SUCCESS != vkRes) {
1379 goto out;
1380 }
1381 }
1382 }
1383 }
1384
1385 *pSurface = (VkSurfaceKHR)pIcdSurface;
1386
1387out:
1388
1389 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1390 if (NULL != pIcdSurface->real_icd_surfaces) {
1391 i = 0;
1392 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1393 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1394 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1395 }
1396 }
1397 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
1398 }
1399 loader_instance_heap_free(ptr_instance, pIcdSurface);
1400 }
1401 return vkRes;
1402}
1403
1404#endif // VK_USE_PLATFORM_GGP
1405
Lenny Komowa1b5e442019-09-16 16:14:36 -06001406#if defined(VK_USE_PLATFORM_METAL_EXT)
1407
1408LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT(VkInstance instance,
1409 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
1410 const VkAllocationCallbacks *pAllocator,
1411 VkSurfaceKHR *pSurface) {
1412 const VkLayerInstanceDispatchTable *disp = loader_get_instance_layer_dispatch(instance);
1413 return disp->CreateMetalSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
1414}
1415
1416VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMetalSurfaceEXT(VkInstance instance, const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
1417 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1418 VkResult result = VK_SUCCESS;
1419 VkIcdSurface *icd_surface = NULL;
1420 uint32_t i;
1421
1422 // First, check to ensure the appropriate extension was enabled:
1423 struct loader_instance *ptr_instance = loader_get_instance(instance);
1424 if (!ptr_instance->wsi_metal_surface_enabled) {
1425 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1426 "VK_EXT_metal_surface extension not enabled. vkCreateMetalSurfaceEXT will not be executed.\n");
1427 }
1428
1429 // Next, if so, proceed with the implementation of this function:
1430 icd_surface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(icd_surface->metal_surf.base), sizeof(icd_surface->metal_surf));
1431 if (icd_surface == NULL) {
1432 result = VK_ERROR_OUT_OF_HOST_MEMORY;
1433 goto out;
1434 }
1435
1436 icd_surface->metal_surf.base.platform = VK_ICD_WSI_PLATFORM_METAL;
1437 icd_surface->metal_surf.pLayer = pCreateInfo->pLayer;
1438
1439 // Loop through each ICD and determine if they need to create a surface
1440 i = 0;
1441 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, ++i) {
1442 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1443 if (icd_term->dispatch.CreateMetalSurfaceEXT != NULL) {
1444 result = icd_term->dispatch.CreateMetalSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
1445 &icd_surface->real_icd_surfaces[i]);
1446 if (result != VK_SUCCESS) {
1447 goto out;
1448 }
1449 }
1450 }
1451 }
1452 *pSurface = (VkSurfaceKHR)icd_surface;
1453
1454out:
1455 if (result != VK_SUCCESS && icd_surface != NULL) {
1456 if (icd_surface->real_icd_surfaces != NULL) {
1457 i = 0;
1458 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, ++i) {
1459 if (icd_surface->real_icd_surfaces[i] == VK_NULL_HANDLE && icd_term->dispatch.DestroySurfaceKHR != NULL) {
1460 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, icd_surface->real_icd_surfaces[i], pAllocator);
1461 }
1462 }
1463 loader_instance_heap_free(ptr_instance, icd_surface->real_icd_surfaces);
1464 }
1465 loader_instance_heap_free(ptr_instance, icd_surface);
1466 }
1467 return result;
1468}
1469
1470#endif
1471
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001472// Functions for the VK_KHR_display instance extension:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001473LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1474 uint32_t *pPropertyCount,
1475 VkDisplayPropertiesKHR *pProperties) {
1476 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001477 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001478 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001479 VkResult res = disp->GetPhysicalDeviceDisplayPropertiesKHR(unwrapped_phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001480 return res;
1481}
1482
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001483VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1484 uint32_t *pPropertyCount,
1485 VkDisplayPropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001486 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001487 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001488 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001489 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001490 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001491 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001492 "VK_KHR_display extension not enabled. vkGetPhysicalDeviceDisplayPropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001493 return VK_SUCCESS;
1494 }
1495
Mark Youngd4e5ba42017-02-28 09:58:04 -07001496 if (NULL == icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR) {
1497 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1498 "ICD for selected physical device is not exporting vkGetPhysicalDeviceDisplayPropertiesKHR!\n");
1499 assert(false && "loader: null GetPhysicalDeviceDisplayPropertiesKHR ICD pointer");
1500 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001501
Mark Youngd4e5ba42017-02-28 09:58:04 -07001502 return icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001503}
1504
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001505LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
1506 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlanePropertiesKHR *pProperties) {
1507 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001508 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001509 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001510 VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(unwrapped_phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001511 return res;
1512}
1513
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001514VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
1515 uint32_t *pPropertyCount,
1516 VkDisplayPlanePropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001517 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001518 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001519 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001520 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001521 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001522 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001523 "VK_KHR_display extension not enabled. vkGetPhysicalDeviceDisplayPlanePropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001524 return VK_SUCCESS;
1525 }
1526
Mark Youngd4e5ba42017-02-28 09:58:04 -07001527 if (NULL == icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR) {
1528 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1529 "ICD for selected physical device is not exporting vkGetPhysicalDeviceDisplayPlanePropertiesKHR!\n");
1530 assert(false && "loader: null GetPhysicalDeviceDisplayPlanePropertiesKHR ICD pointer");
1531 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001532
Mark Youngd4e5ba42017-02-28 09:58:04 -07001533 return icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001534}
1535
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001536LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
1537 uint32_t planeIndex, uint32_t *pDisplayCount,
1538 VkDisplayKHR *pDisplays) {
1539 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001540 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001541 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001542 VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
Jon Ashburncc370d02016-03-08 09:30:30 -07001543 return res;
1544}
1545
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001546VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1547 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001548 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001549 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001550 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001551 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001552 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001553 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001554 "VK_KHR_display extension not enabled. vkGetDisplayPlaneSupportedDisplaysKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001555 return VK_SUCCESS;
1556 }
1557
Mark Youngd4e5ba42017-02-28 09:58:04 -07001558 if (NULL == icd_term->dispatch.GetDisplayPlaneSupportedDisplaysKHR) {
1559 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1560 "ICD for selected physical device is not exporting vkGetDisplayPlaneSupportedDisplaysKHR!\n");
1561 assert(false && "loader: null GetDisplayPlaneSupportedDisplaysKHR ICD pointer");
1562 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001563
Mark Youngd4e5ba42017-02-28 09:58:04 -07001564 return icd_term->dispatch.GetDisplayPlaneSupportedDisplaysKHR(phys_dev_term->phys_dev, planeIndex, pDisplayCount, pDisplays);
Jon Ashburncc370d02016-03-08 09:30:30 -07001565}
1566
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001567LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1568 uint32_t *pPropertyCount,
1569 VkDisplayModePropertiesKHR *pProperties) {
1570 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001571 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001572 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001573 VkResult res = disp->GetDisplayModePropertiesKHR(unwrapped_phys_dev, display, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001574 return res;
1575}
1576
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001577VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1578 uint32_t *pPropertyCount,
1579 VkDisplayModePropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001580 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001581 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001582 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001583 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001584 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001585 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001586 "VK_KHR_display extension not enabled. vkGetDisplayModePropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001587 return VK_SUCCESS;
1588 }
1589
Mark Youngd4e5ba42017-02-28 09:58:04 -07001590 if (NULL == icd_term->dispatch.GetDisplayModePropertiesKHR) {
1591 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1592 "ICD for selected physical device is not exporting vkGetDisplayModePropertiesKHR!\n");
1593 assert(false && "loader: null GetDisplayModePropertiesKHR ICD pointer");
1594 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001595
Mark Youngd4e5ba42017-02-28 09:58:04 -07001596 return icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001597}
1598
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001599LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1600 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1601 const VkAllocationCallbacks *pAllocator,
1602 VkDisplayModeKHR *pMode) {
1603 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001604 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001605 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001606 VkResult res = disp->CreateDisplayModeKHR(unwrapped_phys_dev, display, pCreateInfo, pAllocator, pMode);
Jon Ashburncc370d02016-03-08 09:30:30 -07001607 return res;
1608}
1609
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001610VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1611 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1612 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001613 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001614 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001615 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001616 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001617 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001618 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001619 "VK_KHR_display extension not enabled. vkCreateDisplayModeKHR not executed!\n");
Jeremy Hayes0231e1c2016-06-14 11:50:02 -06001620 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001621 }
1622
Mark Youngd4e5ba42017-02-28 09:58:04 -07001623 if (NULL == icd_term->dispatch.CreateDisplayModeKHR) {
1624 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1625 "ICD for selected physical device is not exporting vkCreateDisplayModeKHR!\n");
1626 assert(false && "loader: null CreateDisplayModeKHR ICD pointer");
1627 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001628
Mark Youngd4e5ba42017-02-28 09:58:04 -07001629 return icd_term->dispatch.CreateDisplayModeKHR(phys_dev_term->phys_dev, display, pCreateInfo, pAllocator, pMode);
Jon Ashburncc370d02016-03-08 09:30:30 -07001630}
1631
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001632LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,
1633 VkDisplayModeKHR mode, uint32_t planeIndex,
1634 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
1635 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001636 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001637 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001638 VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(unwrapped_phys_dev, mode, planeIndex, pCapabilities);
Jon Ashburncc370d02016-03-08 09:30:30 -07001639 return res;
1640}
1641
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001642VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode,
1643 uint32_t planeIndex,
1644 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001645 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001646 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001647 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001648 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001649 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001650 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001651 "VK_KHR_display extension not enabled. vkGetDisplayPlaneCapabilitiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001652 return VK_SUCCESS;
1653 }
1654
Mark Youngd4e5ba42017-02-28 09:58:04 -07001655 if (NULL == icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR) {
1656 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1657 "ICD for selected physical device is not exporting vkGetDisplayPlaneCapabilitiesKHR!\n");
1658 assert(false && "loader: null GetDisplayPlaneCapabilitiesKHR ICD pointer");
1659 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001660
Mark Youngd4e5ba42017-02-28 09:58:04 -07001661 return icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR(phys_dev_term->phys_dev, mode, planeIndex, pCapabilities);
Jon Ashburncc370d02016-03-08 09:30:30 -07001662}
1663
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001664LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(VkInstance instance,
1665 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1666 const VkAllocationCallbacks *pAllocator,
1667 VkSurfaceKHR *pSurface) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001668 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001669 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburncc370d02016-03-08 09:30:30 -07001670 VkResult res;
1671
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001672 res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburncc370d02016-03-08 09:30:30 -07001673 return res;
1674}
1675
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001676VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayPlaneSurfaceKHR(VkInstance instance,
1677 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1678 const VkAllocationCallbacks *pAllocator,
1679 VkSurfaceKHR *pSurface) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001680 struct loader_instance *inst = loader_get_instance(instance);
Mark Young5467d672016-06-28 10:52:43 -06001681 VkIcdSurface *pIcdSurface = NULL;
Mark Youngf06def92016-11-01 19:20:41 -06001682 VkResult vkRes = VK_SUCCESS;
Mark Young573a7a12016-11-02 09:37:08 -06001683 uint32_t i = 0;
Jon Ashburncc370d02016-03-08 09:30:30 -07001684
Mark Youngf06def92016-11-01 19:20:41 -06001685 if (!inst->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001686 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001687 "VK_KHR_surface extension not enabled. vkCreateDisplayPlaneSurfaceKHR not executed!\n");
Mark Youngf06def92016-11-01 19:20:41 -06001688 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1689 goto out;
Petros Bantolasf3095862016-04-14 12:50:42 +01001690 }
1691
Piers Daniellc21fde52016-12-13 16:51:49 -07001692 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001693 pIcdSurface = AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->display_surf.base), sizeof(pIcdSurface->display_surf));
Jon Ashburncc370d02016-03-08 09:30:30 -07001694 if (pIcdSurface == NULL) {
Mark Youngf06def92016-11-01 19:20:41 -06001695 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1696 goto out;
Jon Ashburncc370d02016-03-08 09:30:30 -07001697 }
1698
Mark Young5467d672016-06-28 10:52:43 -06001699 pIcdSurface->display_surf.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
1700 pIcdSurface->display_surf.displayMode = pCreateInfo->displayMode;
1701 pIcdSurface->display_surf.planeIndex = pCreateInfo->planeIndex;
1702 pIcdSurface->display_surf.planeStackIndex = pCreateInfo->planeStackIndex;
1703 pIcdSurface->display_surf.transform = pCreateInfo->transform;
1704 pIcdSurface->display_surf.globalAlpha = pCreateInfo->globalAlpha;
1705 pIcdSurface->display_surf.alphaMode = pCreateInfo->alphaMode;
1706 pIcdSurface->display_surf.imageExtent = pCreateInfo->imageExtent;
1707
Mark Youngf06def92016-11-01 19:20:41 -06001708 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001709 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1710 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -07001711 if (NULL != icd_term->dispatch.CreateDisplayPlaneSurfaceKHR) {
1712 vkRes = icd_term->dispatch.CreateDisplayPlaneSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
1713 &pIcdSurface->real_icd_surfaces[i]);
Mark Youngf06def92016-11-01 19:20:41 -06001714 if (VK_SUCCESS != vkRes) {
1715 goto out;
1716 }
1717 }
1718 }
1719 }
1720
Mark Young3eda5882016-12-01 10:42:21 -07001721 *pSurface = (VkSurfaceKHR)pIcdSurface;
Jon Ashburncc370d02016-03-08 09:30:30 -07001722
Mark Youngf06def92016-11-01 19:20:41 -06001723out:
1724
1725 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1726 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -06001727 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001728 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Youngd4e5ba42017-02-28 09:58:04 -07001729 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1730 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Youngf06def92016-11-01 19:20:41 -06001731 }
1732 }
1733 loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
1734 }
1735 loader_instance_heap_free(inst, pIcdSurface);
1736 }
1737
1738 return vkRes;
Jon Ashburncc370d02016-03-08 09:30:30 -07001739}
1740
Mark Young274e4bc2017-01-19 21:10:49 -07001741// EXT_display_swapchain Extension command
1742
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001743LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
1744 const VkSwapchainCreateInfoKHR *pCreateInfos,
1745 const VkAllocationCallbacks *pAllocator,
1746 VkSwapchainKHR *pSwapchains) {
Mark Young2a2122f2016-09-08 18:36:32 -06001747 const VkLayerDispatchTable *disp;
1748 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001749 return disp->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
Mark Youngf2eabea2016-07-01 15:18:27 -06001750}
1751
Mark Youngd4e5ba42017-02-28 09:58:04 -07001752VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
1753 const VkSwapchainCreateInfoKHR *pCreateInfos,
1754 const VkAllocationCallbacks *pAllocator,
1755 VkSwapchainKHR *pSwapchains) {
Mark Young274e4bc2017-01-19 21:10:49 -07001756 uint32_t icd_index = 0;
1757 struct loader_device *dev;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001758 struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
Mark Youngd4e5ba42017-02-28 09:58:04 -07001759 if (NULL != icd_term && NULL != icd_term->dispatch.CreateSharedSwapchainsKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001760 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pCreateInfos->surface;
Mark Young274e4bc2017-01-19 21:10:49 -07001761 if (NULL != icd_surface->real_icd_surfaces) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001762 if ((VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
Mark Young274e4bc2017-01-19 21:10:49 -07001763 // We found the ICD, and there is an ICD KHR surface
1764 // associated with it, so copy the CreateInfo struct
1765 // and point it at the ICD's surface.
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001766 VkSwapchainCreateInfoKHR *pCreateCopy = loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
Mark Young274e4bc2017-01-19 21:10:49 -07001767 if (NULL == pCreateCopy) {
1768 return VK_ERROR_OUT_OF_HOST_MEMORY;
1769 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001770 memcpy(pCreateCopy, pCreateInfos, sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
Mark Young274e4bc2017-01-19 21:10:49 -07001771 for (uint32_t sc = 0; sc < swapchainCount; sc++) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001772 pCreateCopy[sc].surface = icd_surface->real_icd_surfaces[icd_index];
Mark Young274e4bc2017-01-19 21:10:49 -07001773 }
Mark Youngd4e5ba42017-02-28 09:58:04 -07001774 return icd_term->dispatch.CreateSharedSwapchainsKHR(device, swapchainCount, pCreateCopy, pAllocator, pSwapchains);
Mark Young274e4bc2017-01-19 21:10:49 -07001775 }
1776 }
Mark Youngd4e5ba42017-02-28 09:58:04 -07001777 return icd_term->dispatch.CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
Mark Young274e4bc2017-01-19 21:10:49 -07001778 }
1779 return VK_SUCCESS;
1780}
1781
Lenny Komowdbaaad62017-10-02 15:08:53 -06001782LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupPresentCapabilitiesKHR(
1783 VkDevice device,
1784 VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) {
1785 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
1786 return disp->GetDeviceGroupPresentCapabilitiesKHR(device, pDeviceGroupPresentCapabilities);
1787}
Lenny Komow31217432017-10-02 15:08:53 -06001788
Lenny Komowdbaaad62017-10-02 15:08:53 -06001789LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHR(
1790 VkDevice device,
1791 VkSurfaceKHR surface,
1792 VkDeviceGroupPresentModeFlagsKHR* pModes) {
1793 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
1794 return disp->GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
1795}
1796
Lenny Komow7871f782017-10-11 15:39:38 -06001797VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDeviceGroupSurfacePresentModesKHR(
1798 VkDevice device,
1799 VkSurfaceKHR surface,
1800 VkDeviceGroupPresentModeFlagsKHR* pModes) {
1801 uint32_t icd_index = 0;
1802 struct loader_device *dev;
1803 struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
1804 if (NULL != icd_term && NULL != icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR) {
1805 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
1806 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
1807 return icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR(device, icd_surface->real_icd_surfaces[icd_index], pModes);
1808 }
1809 return icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
1810 }
1811 return VK_SUCCESS;
1812}
1813
Lenny Komowdbaaad62017-10-02 15:08:53 -06001814LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHR(
Lenny Komow31217432017-10-02 15:08:53 -06001815 VkPhysicalDevice physicalDevice,
1816 VkSurfaceKHR surface,
1817 uint32_t* pRectCount,
1818 VkRect2D* pRects) {
1819 const VkLayerInstanceDispatchTable *disp;
1820 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1821 disp = loader_get_instance_layer_dispatch(physicalDevice);
1822 return disp->GetPhysicalDevicePresentRectanglesKHR(unwrapped_phys_dev, surface, pRectCount, pRects);
1823}
1824
1825VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDevicePresentRectanglesKHR(
1826 VkPhysicalDevice physicalDevice,
1827 VkSurfaceKHR surface,
1828 uint32_t* pRectCount,
1829 VkRect2D* pRects) {
1830 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1831 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1832 if (NULL == icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR) {
1833 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1834 "ICD associated with VkPhysicalDevice does not support GetPhysicalDevicePresentRectanglesKHX");
1835 }
1836 VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);
1837 uint8_t icd_index = phys_dev_term->icd_index;
1838 if (NULL != icd_surface->real_icd_surfaces && NULL != (void *)icd_surface->real_icd_surfaces[icd_index]) {
1839 return icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR(phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[icd_index], pRectCount, pRects);
1840 }
1841 return icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR(phys_dev_term->phys_dev, surface, pRectCount, pRects);
1842}
1843
Lenny Komowdbaaad62017-10-02 15:08:53 -06001844LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImage2KHR(
1845 VkDevice device,
1846 const VkAcquireNextImageInfoKHR* pAcquireInfo,
1847 uint32_t* pImageIndex) {
1848 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
1849 return disp->AcquireNextImage2KHR(device, pAcquireInfo, pImageIndex);
1850}
1851
Lenny Komow61139782018-05-31 11:32:31 -06001852// ---- VK_KHR_get_display_properties2 extension trampoline/terminators
1853
1854LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,
1855 uint32_t *pPropertyCount,
1856 VkDisplayProperties2KHR *pProperties) {
1857 const VkLayerInstanceDispatchTable *disp;
1858 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1859 disp = loader_get_instance_layer_dispatch(physicalDevice);
1860 return disp->GetPhysicalDeviceDisplayProperties2KHR(unwrapped_phys_dev, pPropertyCount, pProperties);
1861}
1862
1863VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,
1864 uint32_t *pPropertyCount,
1865 VkDisplayProperties2KHR *pProperties) {
1866 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1867 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1868
1869 // If the function is available in the driver, just call into it
1870 if (icd_term->dispatch.GetPhysicalDeviceDisplayProperties2KHR != NULL) {
1871 return icd_term->dispatch.GetPhysicalDeviceDisplayProperties2KHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
1872 }
1873
1874 // We have to emulate the function.
1875 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
1876 "vkGetPhysicalDeviceDisplayProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
1877
1878 // If the icd doesn't support VK_KHR_display, then no properties are available
1879 if (icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR == NULL) {
1880 *pPropertyCount = 0;
1881 return VK_SUCCESS;
1882 }
1883
1884 // If we aren't writing to pProperties, then emulation is straightforward
1885 if (pProperties == NULL || *pPropertyCount == 0) {
1886 return icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, NULL);
1887 }
1888
1889 // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayPropertiesKHR and copy it
1890 VkDisplayPropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayPropertiesKHR));
1891 if (properties == NULL) {
1892 return VK_ERROR_OUT_OF_HOST_MEMORY;
1893 }
1894 VkResult res = icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, properties);
1895 if (res < 0) {
1896 return res;
1897 }
1898 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
1899 memcpy(&pProperties[i].displayProperties, &properties[i], sizeof(VkDisplayPropertiesKHR));
1900 }
1901 return res;
1902}
1903
1904LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlaneProperties2KHR(
1905 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlaneProperties2KHR *pProperties) {
1906 const VkLayerInstanceDispatchTable *disp;
1907 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1908 disp = loader_get_instance_layer_dispatch(physicalDevice);
1909 return disp->GetPhysicalDeviceDisplayPlaneProperties2KHR(unwrapped_phys_dev, pPropertyCount, pProperties);
1910}
1911
1912VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
1913 uint32_t *pPropertyCount,
1914 VkDisplayPlaneProperties2KHR *pProperties) {
1915 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1916 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1917
1918 // If the function is available in the driver, just call into it
1919 if (icd_term->dispatch.GetPhysicalDeviceDisplayPlaneProperties2KHR != NULL) {
1920 return icd_term->dispatch.GetPhysicalDeviceDisplayPlaneProperties2KHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
1921 }
1922
1923 // We have to emulate the function.
1924 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
1925 "vkGetPhysicalDeviceDisplayPlaneProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
1926
1927 // If the icd doesn't support VK_KHR_display, then no properties are available
1928 if (icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR == NULL) {
1929 *pPropertyCount = 0;
1930 return VK_SUCCESS;
1931 }
1932
1933 // If we aren't writing to pProperties, then emulation is straightforward
1934 if (pProperties == NULL || *pPropertyCount == 0) {
1935 return icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, NULL);
1936 }
1937
1938 // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayPlanePropertiesKHR and copy it
1939 VkDisplayPlanePropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayPlanePropertiesKHR));
1940 if (properties == NULL) {
1941 return VK_ERROR_OUT_OF_HOST_MEMORY;
1942 }
1943 VkResult res =
1944 icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, properties);
1945 if (res < 0) {
1946 return res;
1947 }
1948 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
1949 memcpy(&pProperties[i].displayPlaneProperties, &properties[i], sizeof(VkDisplayPlanePropertiesKHR));
1950 }
1951 return res;
1952}
1953
1954LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1955 uint32_t *pPropertyCount,
1956 VkDisplayModeProperties2KHR *pProperties) {
1957 const VkLayerInstanceDispatchTable *disp;
1958 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1959 disp = loader_get_instance_layer_dispatch(physicalDevice);
1960 return disp->GetDisplayModeProperties2KHR(unwrapped_phys_dev, display, pPropertyCount, pProperties);
1961}
1962
1963VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1964 uint32_t *pPropertyCount,
1965 VkDisplayModeProperties2KHR *pProperties) {
1966 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1967 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1968
1969 // If the function is available in the driver, just call into it
1970 if (icd_term->dispatch.GetDisplayModeProperties2KHR != NULL) {
1971 return icd_term->dispatch.GetDisplayModeProperties2KHR(phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
1972 }
1973
1974 // We have to emulate the function.
1975 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
1976 "vkGetDisplayModeProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
1977
1978 // If the icd doesn't support VK_KHR_display, then no properties are available
1979 if (icd_term->dispatch.GetDisplayModePropertiesKHR == NULL) {
1980 *pPropertyCount = 0;
1981 return VK_SUCCESS;
1982 }
1983
1984 // If we aren't writing to pProperties, then emulation is straightforward
1985 if (pProperties == NULL || *pPropertyCount == 0) {
1986 return icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, NULL);
1987 }
1988
1989 // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayModePropertiesKHR and copy it
1990 VkDisplayModePropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayModePropertiesKHR));
1991 if (properties == NULL) {
1992 return VK_ERROR_OUT_OF_HOST_MEMORY;
1993 }
1994 VkResult res = icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, properties);
1995 if (res < 0) {
1996 return res;
1997 }
1998 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
1999 memcpy(&pProperties[i].displayModeProperties, &properties[i], sizeof(VkDisplayModePropertiesKHR));
2000 }
2001 return res;
2002}
2003
2004LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice,
2005 const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
2006 VkDisplayPlaneCapabilities2KHR *pCapabilities) {
2007 const VkLayerInstanceDispatchTable *disp;
2008 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
2009 disp = loader_get_instance_layer_dispatch(physicalDevice);
2010 return disp->GetDisplayPlaneCapabilities2KHR(unwrapped_phys_dev, pDisplayPlaneInfo, pCapabilities);
2011}
2012
2013VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice,
2014 const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
2015 VkDisplayPlaneCapabilities2KHR *pCapabilities) {
2016 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
2017 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
2018
2019 // If the function is abailable in the driver, just call into it
2020 if (icd_term->dispatch.GetDisplayPlaneCapabilities2KHR != NULL) {
2021 return icd_term->dispatch.GetDisplayPlaneCapabilities2KHR(phys_dev_term->phys_dev, pDisplayPlaneInfo, pCapabilities);
2022 }
2023
2024 // We have to emulate the function.
2025 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
2026 "vkGetDisplayPlaneCapabilities2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
2027
2028 // Just call into the old version of the function.
2029 // If the icd doesn't support VK_KHR_display, there are zero planes and this call is invalid (and will crash)
2030 return icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR(phys_dev_term->phys_dev, pDisplayPlaneInfo->mode,
2031 pDisplayPlaneInfo->planeIndex, &pCapabilities->capabilities);
2032}
2033
Craig Stoutf3b74dc2020-10-26 12:05:15 -07002034#ifdef VK_USE_PLATFORM_FUCHSIA
2035
2036// This is the trampoline entrypoint for CreateImagePipeSurfaceFUCHSIA
2037LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImagePipeSurfaceFUCHSIA(VkInstance instance,
2038 const VkImagePipeSurfaceCreateInfoFUCHSIA *pCreateInfo,
2039 const VkAllocationCallbacks *pAllocator,
2040 VkSurfaceKHR *pSurface) {
2041 const VkLayerInstanceDispatchTable *disp;
2042 disp = loader_get_instance_layer_dispatch(instance);
2043 VkResult res;
2044
2045 res = disp->CreateImagePipeSurfaceFUCHSIA(instance, pCreateInfo, pAllocator, pSurface);
2046 return res;
2047}
2048
2049// This is the instance chain terminator function for CreateImagePipeSurfaceFUCHSIA
2050VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateImagePipeSurfaceFUCHSIA(VkInstance instance,
2051 const VkImagePipeSurfaceCreateInfoFUCHSIA *pCreateInfo,
2052 const VkAllocationCallbacks *pAllocator,
2053 VkSurfaceKHR *pSurface) {
2054 VkResult vkRes = VK_SUCCESS;
2055 VkIcdSurface *pIcdSurface = NULL;
2056 uint32_t i = 0;
2057
2058 // Initialize pSurface to NULL just to be safe.
2059 *pSurface = VK_NULL_HANDLE;
2060 // First, check to ensure the appropriate extension was enabled:
2061 struct loader_instance *ptr_instance = loader_get_instance(instance);
2062 if (!ptr_instance->wsi_imagepipe_surface_enabled) {
2063 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
2064 "VK_FUCHSIA_imagepipe_surface extension not enabled. "
2065 "vkCreateImagePipeSurfaceFUCHSIA not executed!\n");
2066 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
2067 goto out;
2068 }
2069
2070 // Next, if so, proceed with the implementation of this function:
2071 pIcdSurface =
2072 AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->imagepipe_surf.base), sizeof(pIcdSurface->imagepipe_surf));
2073 if (pIcdSurface == NULL) {
2074 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
2075 goto out;
2076 }
2077
2078 pIcdSurface->imagepipe_surf.base.platform = VK_ICD_WSI_PLATFORM_FUCHSIA;
2079
2080 // Loop through each ICD and determine if they need to create a surface
2081 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
2082 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
2083 if (NULL != icd_term->dispatch.CreateImagePipeSurfaceFUCHSIA) {
2084 vkRes = icd_term->dispatch.CreateImagePipeSurfaceFUCHSIA(icd_term->instance, pCreateInfo, pAllocator,
2085 &pIcdSurface->real_icd_surfaces[i]);
2086 if (VK_SUCCESS != vkRes) {
2087 goto out;
2088 }
2089 }
2090 }
2091 }
2092
2093 *pSurface = (VkSurfaceKHR)(pIcdSurface);
2094
2095out:
2096
2097 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
2098 if (NULL != pIcdSurface->real_icd_surfaces) {
2099 i = 0;
2100 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
2101 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
2102 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
2103 }
2104 }
2105 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
2106 }
2107 loader_instance_heap_free(ptr_instance, pIcdSurface);
2108 }
2109
2110 return vkRes;
2111}
2112#endif // VK_USE_PLATFORM_FUCHSIA
2113
Joshua Ashton03cc64b2020-03-12 04:42:26 +00002114LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
2115vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
2116 VkSurfaceCapabilities2KHR *pSurfaceCapabilities) {
2117 const VkLayerInstanceDispatchTable *disp;
2118 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
2119 disp = loader_get_instance_layer_dispatch(physicalDevice);
2120 return disp->GetPhysicalDeviceSurfaceCapabilities2KHR(unwrapped_phys_dev, pSurfaceInfo, pSurfaceCapabilities);
2121}
2122
2123VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilities2KHR(
2124 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
2125 VkSurfaceCapabilities2KHR *pSurfaceCapabilities) {
2126 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
2127 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Joshua Ashton64c36932020-03-12 22:57:49 +00002128 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
2129
2130 if (!ptr_instance->wsi_surface_enabled) {
2131 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
2132 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceCapabilities2KHR not executed!\n");
2133 return VK_SUCCESS;
2134 }
Joshua Ashton03cc64b2020-03-12 04:42:26 +00002135
2136 VkIcdSurface *icd_surface = (VkIcdSurface *)(pSurfaceInfo->surface);
2137 uint8_t icd_index = phys_dev_term->icd_index;
2138
2139 if (icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR != NULL) {
2140 VkBaseOutStructure *pNext = (VkBaseOutStructure *)pSurfaceCapabilities->pNext;
2141 while (pNext != NULL) {
2142 if ((int)pNext->sType == VK_STRUCTURE_TYPE_SURFACE_PROTECTED_CAPABILITIES_KHR) {
2143 // Not all ICDs may be supporting VK_KHR_surface_protected_capabilities
2144 // Initialize VkSurfaceProtectedCapabilitiesKHR.supportsProtected to false and
2145 // if an ICD supports protected surfaces, it will reset it to true accordingly.
2146 ((VkSurfaceProtectedCapabilitiesKHR *)pNext)->supportsProtected = VK_FALSE;
2147 }
2148 pNext = (VkBaseOutStructure *)pNext->pNext;
2149 }
2150
2151 // Pass the call to the driver, possibly unwrapping the ICD surface
2152 if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
2153 VkPhysicalDeviceSurfaceInfo2KHR info_copy = *pSurfaceInfo;
2154 info_copy.surface = icd_surface->real_icd_surfaces[icd_index];
2155 return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev_term->phys_dev, &info_copy,
2156 pSurfaceCapabilities);
2157 } else {
2158 return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev_term->phys_dev, pSurfaceInfo,
2159 pSurfaceCapabilities);
2160 }
2161 } else {
2162 // Emulate the call
2163 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
2164 "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulating call in ICD \"%s\" using "
2165 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
2166 icd_term->scanned_icd->lib_name);
2167
2168 if (pSurfaceInfo->pNext != NULL) {
2169 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
2170 "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulation found unrecognized structure type in "
2171 "pSurfaceInfo->pNext - this struct will be ignored");
2172 }
2173
2174 // Write to the VkSurfaceCapabilities2KHR struct
2175 VkSurfaceKHR surface = pSurfaceInfo->surface;
2176 if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
2177 surface = icd_surface->real_icd_surfaces[icd_index];
2178 }
2179 VkResult res = icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev_term->phys_dev, surface,
2180 &pSurfaceCapabilities->surfaceCapabilities);
2181
2182 if (pSurfaceCapabilities->pNext != NULL) {
2183 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
2184 "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulation found unrecognized structure type in "
2185 "pSurfaceCapabilities->pNext - this struct will be ignored");
2186 }
2187 return res;
2188 }
2189}
2190
2191LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
2192vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
2193 uint32_t *pSurfaceFormatCount, VkSurfaceFormat2KHR *pSurfaceFormats) {
2194 const VkLayerInstanceDispatchTable *disp;
2195 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
2196 disp = loader_get_instance_layer_dispatch(physicalDevice);
2197 return disp->GetPhysicalDeviceSurfaceFormats2KHR(unwrapped_phys_dev, pSurfaceInfo, pSurfaceFormatCount, pSurfaceFormats);
2198}
2199
2200VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
2201 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
2202 uint32_t *pSurfaceFormatCount,
2203 VkSurfaceFormat2KHR *pSurfaceFormats) {
2204 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
2205 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Joshua Ashton64c36932020-03-12 22:57:49 +00002206 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
2207
2208 if (!ptr_instance->wsi_surface_enabled) {
2209 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
2210 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceFormats2KHR not executed!\n");
2211 return VK_SUCCESS;
2212 }
Joshua Ashton03cc64b2020-03-12 04:42:26 +00002213
2214 VkIcdSurface *icd_surface = (VkIcdSurface *)(pSurfaceInfo->surface);
2215 uint8_t icd_index = phys_dev_term->icd_index;
2216
2217 if (icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR != NULL) {
2218 // Pass the call to the driver, possibly unwrapping the ICD surface
2219 if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
2220 VkPhysicalDeviceSurfaceInfo2KHR info_copy = *pSurfaceInfo;
2221 info_copy.surface = icd_surface->real_icd_surfaces[icd_index];
2222 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR(phys_dev_term->phys_dev, &info_copy, pSurfaceFormatCount,
2223 pSurfaceFormats);
2224 } else {
2225 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR(phys_dev_term->phys_dev, pSurfaceInfo,
2226 pSurfaceFormatCount, pSurfaceFormats);
2227 }
2228 } else {
2229 // Emulate the call
2230 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
2231 "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceSurfaceFormatsKHR",
2232 icd_term->scanned_icd->lib_name);
2233
2234 if (pSurfaceInfo->pNext != NULL) {
2235 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
2236 "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulation found unrecognized structure type in pSurfaceInfo->pNext "
2237 "- this struct will be ignored");
2238 }
2239
2240 VkSurfaceKHR surface = pSurfaceInfo->surface;
2241 if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
2242 surface = icd_surface->real_icd_surfaces[icd_index];
2243 }
2244
2245 if (*pSurfaceFormatCount == 0 || pSurfaceFormats == NULL) {
2246 // Write to pSurfaceFormatCount
2247 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface, pSurfaceFormatCount,
2248 NULL);
2249 } else {
2250 // Allocate a temporary array for the output of the old function
2251 VkSurfaceFormatKHR *formats = loader_stack_alloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR));
2252 if (formats == NULL) {
2253 return VK_ERROR_OUT_OF_HOST_MEMORY;
2254 }
2255
2256 VkResult res = icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface,
2257 pSurfaceFormatCount, formats);
2258 for (uint32_t i = 0; i < *pSurfaceFormatCount; ++i) {
2259 pSurfaceFormats[i].surfaceFormat = formats[i];
2260 if (pSurfaceFormats[i].pNext != NULL) {
2261 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
2262 "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulation found unrecognized structure type in "
2263 "pSurfaceFormats[%d].pNext - this struct will be ignored",
2264 i);
2265 }
2266 }
2267 return res;
2268 }
2269 }
2270}
2271
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002272bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance, const char *name, void **addr) {
Ian Elliott54cea232015-10-30 15:28:23 -06002273 *addr = NULL;
2274
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002275 // Functions for the VK_KHR_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07002276 if (!strcmp("vkDestroySurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002277 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkDestroySurfaceKHR : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07002278 return true;
2279 }
Ian Elliott54cea232015-10-30 15:28:23 -06002280 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002281 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceSupportKHR : NULL;
Ian Elliott54cea232015-10-30 15:28:23 -06002282 return true;
2283 }
Ian Elliottea666b22015-11-19 16:05:09 -07002284 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002285 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceCapabilitiesKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07002286 return true;
2287 }
2288 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002289 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceFormatsKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07002290 return true;
2291 }
2292 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002293 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfacePresentModesKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07002294 return true;
2295 }
Ian Elliott9b89a472015-11-19 16:39:21 -07002296
Lenny Komowdbaaad62017-10-02 15:08:53 -06002297 if (!strcmp("vkGetDeviceGroupPresentCapabilitiesKHR", name)) {
2298 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetDeviceGroupPresentCapabilitiesKHR : NULL;
2299 return true;
2300 }
2301
2302 if (!strcmp("vkGetDeviceGroupSurfacePresentModesKHR", name)) {
2303 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetDeviceGroupSurfacePresentModesKHR : NULL;
2304 return true;
2305 }
2306
2307 if (!strcmp("vkGetPhysicalDevicePresentRectanglesKHR", name)) {
2308 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDevicePresentRectanglesKHR : NULL;
2309 return true;
2310 }
2311
Joshua Ashton03cc64b2020-03-12 04:42:26 +00002312 // Functions for VK_KHR_get_surface_capabilities2 extension:
2313 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilities2KHR", name)) {
2314 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceCapabilities2KHR : NULL;
2315 return true;
2316 }
2317
2318 if (!strcmp("vkGetPhysicalDeviceSurfaceFormats2KHR", name)) {
2319 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceFormats2KHR : NULL;
2320 return true;
2321 }
2322
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002323 // Functions for the VK_KHR_swapchain extension:
2324
2325 // Note: This is a device extension, and its functions are statically
2326 // exported from the loader. Per Khronos decisions, the loader's GIPA
2327 // function will return the trampoline function for such device-extension
2328 // functions, regardless of whether the extension has been enabled.
Ian Elliott9b89a472015-11-19 16:39:21 -07002329 if (!strcmp("vkCreateSwapchainKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002330 *addr = (void *)vkCreateSwapchainKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002331 return true;
2332 }
2333 if (!strcmp("vkDestroySwapchainKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002334 *addr = (void *)vkDestroySwapchainKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002335 return true;
2336 }
2337 if (!strcmp("vkGetSwapchainImagesKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002338 *addr = (void *)vkGetSwapchainImagesKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002339 return true;
2340 }
2341 if (!strcmp("vkAcquireNextImageKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002342 *addr = (void *)vkAcquireNextImageKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002343 return true;
2344 }
2345 if (!strcmp("vkQueuePresentKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002346 *addr = (void *)vkQueuePresentKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002347 return true;
2348 }
Lenny Komowdbaaad62017-10-02 15:08:53 -06002349 if (!strcmp("vkAcquireNextImage2KHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002350 *addr = (void *)vkAcquireNextImage2KHR;
Lenny Komowdbaaad62017-10-02 15:08:53 -06002351 return true;
2352 }
Ian Elliott9b89a472015-11-19 16:39:21 -07002353
Ian Elliott7c352552015-11-19 13:14:05 -07002354#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002355
2356 // Functions for the VK_KHR_win32_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07002357 if (!strcmp("vkCreateWin32SurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002358 *addr = ptr_instance->wsi_win32_surface_enabled ? (void *)vkCreateWin32SurfaceKHR : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07002359 return true;
2360 }
Ian Elliotte851dd62015-11-24 15:39:10 -07002361 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002362 *addr = ptr_instance->wsi_win32_surface_enabled ? (void *)vkGetPhysicalDeviceWin32PresentationSupportKHR : NULL;
Ian Elliotte851dd62015-11-24 15:39:10 -07002363 return true;
2364 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002365#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07002366#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002367
2368 // Functions for the VK_KHR_wayland_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002369 if (!strcmp("vkCreateWaylandSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002370 *addr = ptr_instance->wsi_wayland_surface_enabled ? (void *)vkCreateWaylandSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002371 return true;
2372 }
2373 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002374 *addr = ptr_instance->wsi_wayland_surface_enabled ? (void *)vkGetPhysicalDeviceWaylandPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002375 return true;
2376 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002377#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07002378#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002379
2380 // Functions for the VK_KHR_xcb_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002381 if (!strcmp("vkCreateXcbSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002382 *addr = ptr_instance->wsi_xcb_surface_enabled ? (void *)vkCreateXcbSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002383 return true;
2384 }
2385 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002386 *addr = ptr_instance->wsi_xcb_surface_enabled ? (void *)vkGetPhysicalDeviceXcbPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002387 return true;
2388 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002389#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07002390#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002391
2392 // Functions for the VK_KHR_xlib_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002393 if (!strcmp("vkCreateXlibSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002394 *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkCreateXlibSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002395 return true;
2396 }
2397 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002398 *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkGetPhysicalDeviceXlibPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002399 return true;
2400 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002401#endif // VK_USE_PLATFORM_XLIB_KHR
Nicolas Caramellifa696ca2020-07-04 22:53:59 +02002402#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
2403
2404 // Functions for the VK_EXT_directfb_surface extension:
2405 if (!strcmp("vkCreateDirectFBSurfaceEXT", name)) {
2406 *addr = ptr_instance->wsi_directfb_surface_enabled ? (void *)vkCreateDirectFBSurfaceEXT : NULL;
2407 return true;
2408 }
2409 if (!strcmp("vkGetPhysicalDeviceDirectFBPresentationSupportEXT", name)) {
2410 *addr = ptr_instance->wsi_directfb_surface_enabled ? (void *)vkGetPhysicalDeviceDirectFBPresentationSupportEXT : NULL;
2411 return true;
2412 }
2413#endif // VK_USE_PLATFORM_DIRECTFB_EXT
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07002414#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002415
2416 // Functions for the VK_KHR_android_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002417 if (!strcmp("vkCreateAndroidSurfaceKHR", name)) {
Karl Schultzd81ebfb2017-12-12 10:33:01 -05002418 *addr = ptr_instance->wsi_android_surface_enabled ? (void *)vkCreateAndroidSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002419 return true;
2420 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002421#endif // VK_USE_PLATFORM_ANDROID_KHR
Bryan Law-Smith57305692019-04-01 09:45:55 +01002422
Karl Schultzd81ebfb2017-12-12 10:33:01 -05002423#ifdef VK_USE_PLATFORM_MACOS_MVK
2424
2425 // Functions for the VK_MVK_macos_surface extension:
2426 if (!strcmp("vkCreateMacOSSurfaceMVK", name)) {
2427 *addr = ptr_instance->wsi_macos_surface_enabled ? (void *)vkCreateMacOSSurfaceMVK : NULL;
2428 return true;
2429 }
2430#endif // VK_USE_PLATFORM_MACOS_MVK
2431#ifdef VK_USE_PLATFORM_IOS_MVK
2432
2433 // Functions for the VK_MVK_ios_surface extension:
2434 if (!strcmp("vkCreateIOSSurfaceMVK", name)) {
2435 *addr = ptr_instance->wsi_ios_surface_enabled ? (void *)vkCreateIOSSurfaceMVK : NULL;
2436 return true;
2437 }
2438#endif // VK_USE_PLATFORM_IOS_MVK
J.D. Rouand7928a12020-11-16 15:36:42 -08002439#ifdef VK_USE_PLATFORM_GGP
2440
2441 // Functions for the VK_GGP_stream_descriptor_surface extension:
2442 if (!strcmp("vkCreateStreamDescriptorSurfaceGGP", name)) {
2443 *addr = ptr_instance->wsi_ggp_surface_enabled ? (void *)vkCreateStreamDescriptorSurfaceGGP : NULL;
2444 return true;
2445 }
2446#endif // VK_USE_PLATFORM_GGP
Craig Stoutf3b74dc2020-10-26 12:05:15 -07002447#ifdef VK_USE_PLATFORM_FUCHSIA
2448
2449 // Functions for the VK_FUCHSIA_imagepipe_surface extension:
2450 if (!strcmp("vkCreateImagePipeSurfaceFUCHSIA", name)) {
2451 *addr = ptr_instance->wsi_imagepipe_surface_enabled ? (void *)vkCreateImagePipeSurfaceFUCHSIA : NULL;
2452 return true;
2453 }
2454
2455#endif // VK_USE_PLATFORM_FUCHSIA
Ian Elliott7c352552015-11-19 13:14:05 -07002456
Bryan Law-Smith57305692019-04-01 09:45:55 +01002457 // Functions for the VK_EXT_headless_surface extension:
2458 if (!strcmp("vkCreateHeadlessSurfaceEXT", name)) {
2459 *addr = ptr_instance->wsi_headless_surface_enabled ? (void *)vkCreateHeadlessSurfaceEXT : NULL;
2460 return true;
2461 }
2462
Lenny Komowa1b5e442019-09-16 16:14:36 -06002463#if defined(VK_USE_PLATFORM_METAL_EXT)
2464 // Functions for the VK_MVK_macos_surface extension:
2465 if (!strcmp("vkCreateMetalSurfaceEXT", name)) {
2466 *addr = ptr_instance->wsi_metal_surface_enabled ? (void *)vkCreateMetalSurfaceEXT : NULL;
2467 return true;
2468 }
2469#endif // VK_USE_PLATFORM_METAL_EXT
2470
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002471 // Functions for VK_KHR_display extension:
Jon Ashburncc370d02016-03-08 09:30:30 -07002472 if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002473 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002474 return true;
2475 }
2476 if (!strcmp("vkGetPhysicalDeviceDisplayPlanePropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002477 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPlanePropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002478 return true;
2479 }
2480 if (!strcmp("vkGetDisplayPlaneSupportedDisplaysKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002481 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayPlaneSupportedDisplaysKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002482 return true;
2483 }
2484 if (!strcmp("vkGetDisplayModePropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002485 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayModePropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002486 return true;
2487 }
2488 if (!strcmp("vkCreateDisplayModeKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002489 *addr = ptr_instance->wsi_display_enabled ? (void *)vkCreateDisplayModeKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002490 return true;
2491 }
2492 if (!strcmp("vkGetDisplayPlaneCapabilitiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002493 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayPlaneCapabilitiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002494 return true;
2495 }
2496 if (!strcmp("vkCreateDisplayPlaneSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002497 *addr = ptr_instance->wsi_display_enabled ? (void *)vkCreateDisplayPlaneSurfaceKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002498 return true;
2499 }
Mark Youngf2eabea2016-07-01 15:18:27 -06002500
2501 // Functions for KHR_display_swapchain extension:
2502 if (!strcmp("vkCreateSharedSwapchainsKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002503 *addr = (void *)vkCreateSharedSwapchainsKHR;
Mark Youngf2eabea2016-07-01 15:18:27 -06002504 return true;
2505 }
2506
Lenny Komow61139782018-05-31 11:32:31 -06002507 // Functions for KHR_get_display_properties2
2508 if (!strcmp("vkGetPhysicalDeviceDisplayProperties2KHR", name)) {
2509 *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetPhysicalDeviceDisplayProperties2KHR : NULL;
2510 return true;
2511 }
2512 if (!strcmp("vkGetPhysicalDeviceDisplayPlaneProperties2KHR", name)) {
2513 *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetPhysicalDeviceDisplayPlaneProperties2KHR : NULL;
2514 return true;
2515 }
2516 if (!strcmp("vkGetDisplayModeProperties2KHR", name)) {
2517 *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetDisplayModeProperties2KHR : NULL;
2518 return true;
2519 }
2520 if (!strcmp("vkGetDisplayPlaneCapabilities2KHR", name)) {
2521 *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetDisplayPlaneCapabilities2KHR : NULL;
2522 return true;
2523 }
2524
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002525 return false;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06002526}