blob: 0d687b2a1b283054261ed8f740c308dc764539e9 [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
Craig Stoutf3b74dc2020-10-26 12:05:15 -070067#ifdef VK_USE_PLATFORM_FUCHSIA
68 ptr_instance->wsi_imagepipe_surface_enabled = false;
69#endif // VK_USE_PLATFORM_FUCHSIA
Jon Ashburncc370d02016-03-08 09:30:30 -070070 ptr_instance->wsi_display_enabled = false;
Lenny Komow61139782018-05-31 11:32:31 -060071 ptr_instance->wsi_display_props2_enabled = false;
Lenny Komowa1b5e442019-09-16 16:14:36 -060072#ifdef VK_USE_PLATFORM_METAL_EXT
73 ptr_instance->wsi_metal_surface_enabled = false;
74#endif // VK_USE_PLATFORM_METAL_EXT
Jon Ashburncc370d02016-03-08 09:30:30 -070075
Jon Ashburna0673ab2016-01-11 13:12:43 -070076 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -070077 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060078 ptr_instance->wsi_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070079 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060080 }
Ian Elliottb1849742015-11-19 11:58:08 -070081#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070082 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott1693f592015-11-23 10:17:23 -070083 ptr_instance->wsi_win32_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070084 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060085 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070086#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060087#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070088 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060089 ptr_instance->wsi_wayland_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070090 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060091 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070092#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060093#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070094 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060095 ptr_instance->wsi_xcb_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070096 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060097 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070098#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060099#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700100 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -0600101 ptr_instance->wsi_xlib_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -0700102 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600103 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700104#endif // VK_USE_PLATFORM_XLIB_KHR
Nicolas Caramellifa696ca2020-07-04 22:53:59 +0200105#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
106 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME) == 0) {
107 ptr_instance->wsi_directfb_surface_enabled = true;
108 continue;
109 }
110#endif // VK_USE_PLATFORM_DIRECTFB_EXT
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700111#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700112 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700113 ptr_instance->wsi_android_surface_enabled = true;
114 continue;
115 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700116#endif // VK_USE_PLATFORM_ANDROID_KHR
Karl Schultzd81ebfb2017-12-12 10:33:01 -0500117#ifdef VK_USE_PLATFORM_MACOS_MVK
118 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_MVK_MACOS_SURFACE_EXTENSION_NAME) == 0) {
119 ptr_instance->wsi_macos_surface_enabled = true;
120 continue;
121 }
122#endif // VK_USE_PLATFORM_MACOS_MVK
123#ifdef VK_USE_PLATFORM_IOS_MVK
124 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_MVK_IOS_SURFACE_EXTENSION_NAME) == 0) {
125 ptr_instance->wsi_ios_surface_enabled = true;
126 continue;
127 }
128#endif // VK_USE_PLATFORM_IOS_MVK
Craig Stoutf3b74dc2020-10-26 12:05:15 -0700129#ifdef VK_USE_PLATFORM_FUCHSIA
130 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_FUCHSIA_IMAGEPIPE_SURFACE_EXTENSION_NAME) == 0) {
131 ptr_instance->wsi_imagepipe_surface_enabled = true;
132 continue;
133 }
134#endif // VK_USE_PLATFORM_FUCHSIA
Bryan Law-Smith57305692019-04-01 09:45:55 +0100135 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME) == 0) {
136 ptr_instance->wsi_headless_surface_enabled = true;
137 continue;
138 }
Lenny Komowa1b5e442019-09-16 16:14:36 -0600139#if defined(VK_USE_PLATFORM_METAL_EXT)
140 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_METAL_SURFACE_EXTENSION_NAME) == 0) {
141 ptr_instance->wsi_metal_surface_enabled = true;
142 continue;
143 }
144#endif
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700145 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) {
Jon Ashburncc370d02016-03-08 09:30:30 -0700146 ptr_instance->wsi_display_enabled = true;
147 continue;
148 }
Lenny Komow61139782018-05-31 11:32:31 -0600149 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME) == 0) {
150 ptr_instance->wsi_display_props2_enabled = true;
151 continue;
152 }
Ian Elliott54cea232015-10-30 15:28:23 -0600153 }
154}
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600155
156// Linux WSI surface extensions are not always compiled into the loader. (Assume
157// for Windows the KHR_win32_surface is always compiled into loader). A given
158// Linux build environment might not have the headers required for building one
Tony-LunarG03667212018-10-23 14:08:03 -0600159// of the three extensions (Xlib, Xcb, Wayland). Thus, need to check if
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600160// the built loader actually supports the particular Linux surface extension.
161// If not supported by the built loader it will not be included in the list of
162// enumerated instance extensions. This solves the issue where an ICD or layer
163// advertises support for a given Linux surface extension but the loader was not
164// built to support the extension.
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600165bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop) {
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600166#ifndef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700167 if (!strcmp(ext_prop->extensionName, "VK_KHR_wayland_surface")) return true;
168#endif // VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600169#ifndef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700170 if (!strcmp(ext_prop->extensionName, "VK_KHR_xcb_surface")) return true;
171#endif // VK_USE_PLATFORM_XCB_KHR
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600172#ifndef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700173 if (!strcmp(ext_prop->extensionName, "VK_KHR_xlib_surface")) return true;
174#endif // VK_USE_PLATFORM_XLIB_KHR
Nicolas Caramellifa696ca2020-07-04 22:53:59 +0200175#ifndef VK_USE_PLATFORM_DIRECTFB_EXT
176 if (!strcmp(ext_prop->extensionName, "VK_EXT_directfb_surface")) return true;
177#endif // VK_USE_PLATFORM_DIRECTFB_EXT
Ian Elliott54cea232015-10-30 15:28:23 -0600178
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600179 return false;
180}
Ian Elliott7c352552015-11-19 13:14:05 -0700181
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600182// Functions for the VK_KHR_surface extension:
183
184// This is the trampoline entrypoint for DestroySurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700185LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
186 const VkAllocationCallbacks *pAllocator) {
Ian Elliottabf50662015-11-25 14:43:02 -0700187 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700188 disp = loader_get_instance_layer_dispatch(instance);
Ian Elliottabf50662015-11-25 14:43:02 -0700189 disp->DestroySurfaceKHR(instance, surface, pAllocator);
190}
191
Jon Ashburncc370d02016-03-08 09:30:30 -0700192// TODO probably need to lock around all the loader_get_instance() calls.
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600193
194// This is the instance chain terminator function for DestroySurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700195VKAPI_ATTR void VKAPI_CALL terminator_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
196 const VkAllocationCallbacks *pAllocator) {
Ian Elliott1693f592015-11-23 10:17:23 -0700197 struct loader_instance *ptr_instance = loader_get_instance(instance);
198
Karl Schultza9e989f2016-11-19 09:02:27 -0700199 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young11e9d472016-10-17 12:27:36 -0600200 if (NULL != icd_surface) {
201 if (NULL != icd_surface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600202 uint32_t i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700203 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
204 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700205 if (NULL != icd_term->dispatch.DestroySurfaceKHR && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[i]) {
206 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, icd_surface->real_icd_surfaces[i], pAllocator);
Mark Young3eda5882016-12-01 10:42:21 -0700207 icd_surface->real_icd_surfaces[i] = (VkSurfaceKHR)NULL;
Mark Young11e9d472016-10-17 12:27:36 -0600208 }
209 } else {
210 // The real_icd_surface for any ICD not supporting the
211 // proper interface version should be NULL. If not, then
212 // we have a problem.
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700213 assert((VkSurfaceKHR)NULL == icd_surface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600214 }
Mark Young5467d672016-06-28 10:52:43 -0600215 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700216 loader_instance_heap_free(ptr_instance, icd_surface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600217 }
Mark Young5467d672016-06-28 10:52:43 -0600218
Karl Schultza9e989f2016-11-19 09:02:27 -0700219 loader_instance_heap_free(ptr_instance, (void *)(uintptr_t)surface);
Mark Young11e9d472016-10-17 12:27:36 -0600220 }
Ian Elliott7c352552015-11-19 13:14:05 -0700221}
222
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600223// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700224LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
225 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
226 VkBool32 *pSupported) {
Ian Elliott54cea232015-10-30 15:28:23 -0600227 const VkLayerInstanceDispatchTable *disp;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700228 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Mark Young274e4bc2017-01-19 21:10:49 -0700229 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700230 VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott54cea232015-10-30 15:28:23 -0600231 return res;
232}
233
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600234// This is the instance chain terminator function for
235// GetPhysicalDeviceSurfaceSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700236VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
237 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
238 VkBool32 *pSupported) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600239 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700240 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600241 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700242 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600243 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700244 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700245 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600246 return VK_SUCCESS;
247 }
248
Mark Youngd4e5ba42017-02-28 09:58:04 -0700249 if (NULL == pSupported) {
250 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
251 "NULL pointer passed into vkGetPhysicalDeviceSurfaceSupportKHR for pSupported!\n");
252 assert(false && "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
253 }
Ian Elliott54cea232015-10-30 15:28:23 -0600254 *pSupported = false;
255
Mark Youngd4e5ba42017-02-28 09:58:04 -0700256 if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR) {
257 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
258 "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceSupportKHR!\n");
259 assert(false && "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
260 }
Ian Elliott54cea232015-10-30 15:28:23 -0600261
Karl Schultza9e989f2016-11-19 09:02:27 -0700262 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700263 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 -0700264 return icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR(
265 phys_dev_term->phys_dev, queueFamilyIndex, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pSupported);
Mark Young5467d672016-06-28 10:52:43 -0600266 }
Mark Young5467d672016-06-28 10:52:43 -0600267
Mark Youngd4e5ba42017-02-28 09:58:04 -0700268 return icd_term->dispatch.GetPhysicalDeviceSurfaceSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott54cea232015-10-30 15:28:23 -0600269}
270
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600271// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceCapabilitiesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700272LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
273 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Ian Elliottea666b22015-11-19 16:05:09 -0700274 const VkLayerInstanceDispatchTable *disp;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700275 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Mark Young274e4bc2017-01-19 21:10:49 -0700276 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700277 VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(unwrapped_phys_dev, surface, pSurfaceCapabilities);
Ian Elliottea666b22015-11-19 16:05:09 -0700278 return res;
279}
280
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600281// This is the instance chain terminator function for
282// GetPhysicalDeviceSurfaceCapabilitiesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700283VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
284 VkSurfaceKHR surface,
285 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600286 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700287 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600288 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700289 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600290 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700291 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700292 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600293 return VK_SUCCESS;
294 }
295
Mark Youngd4e5ba42017-02-28 09:58:04 -0700296 if (NULL == pSurfaceCapabilities) {
297 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
298 "NULL pointer passed into vkGetPhysicalDeviceSurfaceCapabilitiesKHR for pSurfaceCapabilities!\n");
299 assert(false && "GetPhysicalDeviceSurfaceCapabilitiesKHR: Error, null pSurfaceCapabilities");
300 }
Ian Elliottea666b22015-11-19 16:05:09 -0700301
Mark Youngd4e5ba42017-02-28 09:58:04 -0700302 if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR) {
303 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
304 "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceCapabilitiesKHR!\n");
305 assert(false && "loader: null GetPhysicalDeviceSurfaceCapabilitiesKHR ICD pointer");
306 }
Ian Elliottea666b22015-11-19 16:05:09 -0700307
Karl Schultza9e989f2016-11-19 09:02:27 -0700308 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700309 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 -0700310 return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700311 phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pSurfaceCapabilities);
Mark Young5467d672016-06-28 10:52:43 -0600312 }
Mark Young5467d672016-06-28 10:52:43 -0600313
Mark Youngd4e5ba42017-02-28 09:58:04 -0700314 return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev_term->phys_dev, surface, pSurfaceCapabilities);
Ian Elliottea666b22015-11-19 16:05:09 -0700315}
316
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600317// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceFormatsKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700318LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
319 VkSurfaceKHR surface,
320 uint32_t *pSurfaceFormatCount,
321 VkSurfaceFormatKHR *pSurfaceFormats) {
322 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700323 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700324 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700325 VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliottea666b22015-11-19 16:05:09 -0700326 return res;
327}
328
Mark Young573a7a12016-11-02 09:37:08 -0600329// This is the instance chain terminator function for
330// GetPhysicalDeviceSurfaceFormatsKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700331VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
332 uint32_t *pSurfaceFormatCount,
333 VkSurfaceFormatKHR *pSurfaceFormats) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600334 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700335 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600336 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700337 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600338 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700339 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700340 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceFormatsKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600341 return VK_SUCCESS;
342 }
343
Mark Youngd4e5ba42017-02-28 09:58:04 -0700344 if (NULL == pSurfaceFormatCount) {
345 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
346 "NULL pointer passed into vkGetPhysicalDeviceSurfaceFormatsKHR for pSurfaceFormatCount!\n");
347 assert(false && "GetPhysicalDeviceSurfaceFormatsKHR(: Error, null pSurfaceFormatCount");
348 }
Ian Elliottea666b22015-11-19 16:05:09 -0700349
Mark Youngd4e5ba42017-02-28 09:58:04 -0700350 if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR) {
351 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
352 "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfaceCapabilitiesKHR!\n");
353 assert(false && "loader: null GetPhysicalDeviceSurfaceFormatsKHR ICD pointer");
354 }
Ian Elliottea666b22015-11-19 16:05:09 -0700355
Karl Schultza9e989f2016-11-19 09:02:27 -0700356 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700357 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 -0700358 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev,
359 icd_surface->real_icd_surfaces[phys_dev_term->icd_index],
360 pSurfaceFormatCount, pSurfaceFormats);
Mark Young5467d672016-06-28 10:52:43 -0600361 }
Mark Young5467d672016-06-28 10:52:43 -0600362
Mark Youngd4e5ba42017-02-28 09:58:04 -0700363 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface, pSurfaceFormatCount,
364 pSurfaceFormats);
Ian Elliottea666b22015-11-19 16:05:09 -0700365}
366
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600367// This is the trampoline entrypoint for GetPhysicalDeviceSurfacePresentModesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700368LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
369 VkSurfaceKHR surface,
370 uint32_t *pPresentModeCount,
371 VkPresentModeKHR *pPresentModes) {
372 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700373 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700374 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700375 VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliottea666b22015-11-19 16:05:09 -0700376 return res;
377}
378
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600379// This is the instance chain terminator function for
380// GetPhysicalDeviceSurfacePresentModesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700381VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
382 VkSurfaceKHR surface, uint32_t *pPresentModeCount,
383 VkPresentModeKHR *pPresentModes) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600384 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700385 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600386 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700387 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600388 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700389 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700390 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfacePresentModesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600391 return VK_SUCCESS;
392 }
393
Mark Youngd4e5ba42017-02-28 09:58:04 -0700394 if (NULL == pPresentModeCount) {
395 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
396 "NULL pointer passed into vkGetPhysicalDeviceSurfacePresentModesKHR for pPresentModeCount!\n");
397 assert(false && "GetPhysicalDeviceSurfacePresentModesKHR(: Error, null pPresentModeCount");
398 }
Ian Elliottea666b22015-11-19 16:05:09 -0700399
Mark Youngd4e5ba42017-02-28 09:58:04 -0700400 if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR) {
401 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
402 "ICD for selected physical device is not exporting vkGetPhysicalDeviceSurfacePresentModesKHR!\n");
403 assert(false && "loader: null GetPhysicalDeviceSurfacePresentModesKHR ICD pointer");
404 }
Ian Elliottea666b22015-11-19 16:05:09 -0700405
Karl Schultza9e989f2016-11-19 09:02:27 -0700406 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700407 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 -0700408 return icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700409 phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pPresentModeCount, pPresentModes);
Mark Young5467d672016-06-28 10:52:43 -0600410 }
Mark Young5467d672016-06-28 10:52:43 -0600411
Mark Youngd4e5ba42017-02-28 09:58:04 -0700412 return icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR(phys_dev_term->phys_dev, surface, pPresentModeCount,
413 pPresentModes);
Ian Elliottea666b22015-11-19 16:05:09 -0700414}
415
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600416// Functions for the VK_KHR_swapchain extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700417
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600418// This is the trampoline entrypoint for CreateSwapchainKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700419LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
420 const VkAllocationCallbacks *pAllocator,
421 VkSwapchainKHR *pSwapchain) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700422 const VkLayerDispatchTable *disp;
423 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700424 return disp->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Ian Elliott9b89a472015-11-19 16:39:21 -0700425}
Ian Elliott7c352552015-11-19 13:14:05 -0700426
Mark Youngd4e5ba42017-02-28 09:58:04 -0700427VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
Karl Schultzd81ebfb2017-12-12 10:33:01 -0500428 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {
Mark Young5467d672016-06-28 10:52:43 -0600429 uint32_t icd_index = 0;
430 struct loader_device *dev;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700431 struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
Mark Youngd4e5ba42017-02-28 09:58:04 -0700432 if (NULL != icd_term && NULL != icd_term->dispatch.CreateSwapchainKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700433 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pCreateInfo->surface;
Mark Young5467d672016-06-28 10:52:43 -0600434 if (NULL != icd_surface->real_icd_surfaces) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700435 if ((VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
Mark Young5467d672016-06-28 10:52:43 -0600436 // We found the ICD, and there is an ICD KHR surface
437 // associated with it, so copy the CreateInfo struct
438 // and point it at the ICD's surface.
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700439 VkSwapchainCreateInfoKHR *pCreateCopy = loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR));
Mark Young5467d672016-06-28 10:52:43 -0600440 if (NULL == pCreateCopy) {
441 return VK_ERROR_OUT_OF_HOST_MEMORY;
442 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700443 memcpy(pCreateCopy, pCreateInfo, sizeof(VkSwapchainCreateInfoKHR));
444 pCreateCopy->surface = icd_surface->real_icd_surfaces[icd_index];
Mark Youngd4e5ba42017-02-28 09:58:04 -0700445 return icd_term->dispatch.CreateSwapchainKHR(device, pCreateCopy, pAllocator, pSwapchain);
Mark Young5467d672016-06-28 10:52:43 -0600446 }
447 }
Mark Youngd4e5ba42017-02-28 09:58:04 -0700448 return icd_term->dispatch.CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Mark Young5467d672016-06-28 10:52:43 -0600449 }
450 return VK_SUCCESS;
451}
452
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600453// This is the trampoline entrypoint for DestroySwapchainKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700454LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
455 const VkAllocationCallbacks *pAllocator) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700456 const VkLayerDispatchTable *disp;
457 disp = loader_get_dispatch(device);
458 disp->DestroySwapchainKHR(device, swapchain, pAllocator);
459}
Ian Elliott7c352552015-11-19 13:14:05 -0700460
Mark Youngd4e5ba42017-02-28 09:58:04 -0700461// This is the trampoline entrypoint for GetSwapchainImagesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700462LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
463 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700464 const VkLayerDispatchTable *disp;
465 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700466 return disp->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
Ian Elliott9b89a472015-11-19 16:39:21 -0700467}
468
Mark Youngd4e5ba42017-02-28 09:58:04 -0700469// This is the trampoline entrypoint for AcquireNextImageKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700470LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
471 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700472 const VkLayerDispatchTable *disp;
473 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700474 return disp->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
Ian Elliott9b89a472015-11-19 16:39:21 -0700475}
476
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600477// This is the trampoline entrypoint for QueuePresentKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700478LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700479 const VkLayerDispatchTable *disp;
480 disp = loader_get_dispatch(queue);
Mark Young76b3fe02016-09-08 12:28:38 -0600481 return disp->QueuePresentKHR(queue, pPresentInfo);
Ian Elliott9b89a472015-11-19 16:39:21 -0700482}
Ian Elliott7c352552015-11-19 13:14:05 -0700483
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700484static VkIcdSurface *AllocateIcdSurfaceStruct(struct loader_instance *instance, size_t base_size, size_t platform_size) {
Mark Youngf27962c2016-09-16 10:18:42 -0600485 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700486 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Youngf27962c2016-09-16 10:18:42 -0600487 if (pIcdSurface != NULL) {
488 // Setup the new sizes and offsets so we can grow the structures in the
489 // future without having problems
490 pIcdSurface->base_size = (uint32_t)base_size;
491 pIcdSurface->platform_size = (uint32_t)platform_size;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700492 pIcdSurface->non_platform_offset = (uint32_t)((uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
Mark Youngf27962c2016-09-16 10:18:42 -0600493 pIcdSurface->entire_size = sizeof(VkIcdSurface);
494
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700495 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(instance, sizeof(VkSurfaceKHR) * instance->total_icd_count,
496 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Young5117fdc2016-12-13 17:19:32 -0700497 if (pIcdSurface->real_icd_surfaces == NULL) {
498 loader_instance_heap_free(instance, pIcdSurface);
499 pIcdSurface = NULL;
Mark Youngf27962c2016-09-16 10:18:42 -0600500 } else {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700501 memset(pIcdSurface->real_icd_surfaces, 0, sizeof(VkSurfaceKHR) * instance->total_icd_count);
Mark Youngf27962c2016-09-16 10:18:42 -0600502 }
503 }
504 return pIcdSurface;
505}
506
Ian Elliott7c352552015-11-19 13:14:05 -0700507#ifdef VK_USE_PLATFORM_WIN32_KHR
508
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600509// Functions for the VK_KHR_win32_surface extension:
510
511// This is the trampoline entrypoint for CreateWin32SurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700512LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance,
513 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
514 const VkAllocationCallbacks *pAllocator,
515 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700516 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700517 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700518 VkResult res;
519
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700520 res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700521 return res;
522}
523
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600524// This is the instance chain terminator function for CreateWin32SurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700525VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
526 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600527 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600528 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600529 uint32_t i = 0;
530
Mark Youngf27962c2016-09-16 10:18:42 -0600531 // Initialize pSurface to NULL just to be safe.
532 *pSurface = VK_NULL_HANDLE;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600533 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700534 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600535 if (!ptr_instance->wsi_win32_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700536 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700537 "VK_KHR_win32_surface extension not enabled. vkCreateWin32SurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600538 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
539 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600540 }
541
542 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700543 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->win_surf.base), sizeof(pIcdSurface->win_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700544 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600545 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
546 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700547 }
548
Mark Young5467d672016-06-28 10:52:43 -0600549 pIcdSurface->win_surf.base.platform = VK_ICD_WSI_PLATFORM_WIN32;
550 pIcdSurface->win_surf.hinstance = pCreateInfo->hinstance;
551 pIcdSurface->win_surf.hwnd = pCreateInfo->hwnd;
Ian Elliott7c352552015-11-19 13:14:05 -0700552
Mark Young5467d672016-06-28 10:52:43 -0600553 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700554 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
555 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700556 if (NULL != icd_term->dispatch.CreateWin32SurfaceKHR) {
557 vkRes = icd_term->dispatch.CreateWin32SurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
558 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600559 if (VK_SUCCESS != vkRes) {
560 goto out;
561 }
562 }
563 }
564 }
565
566 *pSurface = (VkSurfaceKHR)(pIcdSurface);
567
568out:
569
570 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
571 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600572 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700573 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 -0700574 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
575 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600576 }
577 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700578 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600579 }
580 loader_instance_heap_free(ptr_instance, pIcdSurface);
581 }
582
583 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700584}
Ian Elliotte851dd62015-11-24 15:39:10 -0700585
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600586// This is the trampoline entrypoint for
587// GetPhysicalDeviceWin32PresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700588LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
589 uint32_t queueFamilyIndex) {
590 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700591 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700592 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700593 VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex);
Ian Elliotte851dd62015-11-24 15:39:10 -0700594 return res;
595}
596
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600597// This is the instance chain terminator function for
598// GetPhysicalDeviceWin32PresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700599VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
600 uint32_t queueFamilyIndex) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600601 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700602 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600603 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700604 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600605 if (!ptr_instance->wsi_win32_surface_enabled) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700606 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700607 "VK_KHR_win32_surface extension not enabled. vkGetPhysicalDeviceWin32PresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600608 return VK_SUCCESS;
609 }
610
Mark Youngd4e5ba42017-02-28 09:58:04 -0700611 if (NULL == icd_term->dispatch.GetPhysicalDeviceWin32PresentationSupportKHR) {
612 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
613 "ICD for selected physical device is not exporting vkGetPhysicalDeviceWin32PresentationSupportKHR!\n");
614 assert(false && "loader: null GetPhysicalDeviceWin32PresentationSupportKHR ICD pointer");
615 }
Ian Elliotte851dd62015-11-24 15:39:10 -0700616
Mark Youngd4e5ba42017-02-28 09:58:04 -0700617 return icd_term->dispatch.GetPhysicalDeviceWin32PresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex);
Ian Elliotte851dd62015-11-24 15:39:10 -0700618}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700619#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700620
Ian Elliott7c352552015-11-19 13:14:05 -0700621#ifdef VK_USE_PLATFORM_WAYLAND_KHR
622
Mark Youngd4e5ba42017-02-28 09:58:04 -0700623// This is the trampoline entrypoint for CreateWaylandSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700624LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance,
625 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
626 const VkAllocationCallbacks *pAllocator,
627 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700628 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700629 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700630 VkResult res;
631
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700632 res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700633 return res;
634}
635
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600636// This is the instance chain terminator function for CreateWaylandSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700637VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(VkInstance instance,
638 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
639 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600640 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600641 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600642 uint32_t i = 0;
643
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600644 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700645 struct loader_instance *ptr_instance = loader_get_instance(instance);
Jon Ashburn436d6a32016-03-24 17:26:59 -0600646 if (!ptr_instance->wsi_wayland_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700647 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700648 "VK_KHR_wayland_surface extension not enabled. vkCreateWaylandSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600649 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
650 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600651 }
652
653 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700654 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->wayland_surf.base), sizeof(pIcdSurface->wayland_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700655 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600656 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
657 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700658 }
659
Mark Young5467d672016-06-28 10:52:43 -0600660 pIcdSurface->wayland_surf.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
661 pIcdSurface->wayland_surf.display = pCreateInfo->display;
662 pIcdSurface->wayland_surf.surface = pCreateInfo->surface;
663
Mark Young5467d672016-06-28 10:52:43 -0600664 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700665 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
666 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700667 if (NULL != icd_term->dispatch.CreateWaylandSurfaceKHR) {
668 vkRes = icd_term->dispatch.CreateWaylandSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
669 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600670 if (VK_SUCCESS != vkRes) {
671 goto out;
672 }
673 }
674 }
675 }
Ian Elliott7c352552015-11-19 13:14:05 -0700676
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700677 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700678
Mark Young5467d672016-06-28 10:52:43 -0600679out:
680
681 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
682 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600683 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700684 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 -0700685 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
686 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600687 }
688 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700689 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600690 }
691 loader_instance_heap_free(ptr_instance, pIcdSurface);
692 }
693
694 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700695}
Ian Elliotte851dd62015-11-24 15:39:10 -0700696
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600697// This is the trampoline entrypoint for
698// GetPhysicalDeviceWaylandPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700699LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
700 uint32_t queueFamilyIndex,
701 struct wl_display *display) {
702 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700703 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700704 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700705 VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, display);
Ian Elliotte851dd62015-11-24 15:39:10 -0700706 return res;
707}
708
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600709// This is the instance chain terminator function for
710// GetPhysicalDeviceWaylandPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700711VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
712 uint32_t queueFamilyIndex,
713 struct wl_display *display) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600714 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700715 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600716 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700717 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Jon Ashburn436d6a32016-03-24 17:26:59 -0600718 if (!ptr_instance->wsi_wayland_surface_enabled) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700719 loader_log(
720 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
721 "VK_KHR_wayland_surface extension not enabled. vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600722 return VK_SUCCESS;
723 }
724
Mark Youngd4e5ba42017-02-28 09:58:04 -0700725 if (NULL == icd_term->dispatch.GetPhysicalDeviceWaylandPresentationSupportKHR) {
726 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
727 "ICD for selected physical device is not exporting vkGetPhysicalDeviceWaylandPresentationSupportKHR!\n");
728 assert(false && "loader: null GetPhysicalDeviceWaylandPresentationSupportKHR ICD pointer");
729 }
Ian Elliotte851dd62015-11-24 15:39:10 -0700730
Mark Youngd4e5ba42017-02-28 09:58:04 -0700731 return icd_term->dispatch.GetPhysicalDeviceWaylandPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, display);
Ian Elliotte851dd62015-11-24 15:39:10 -0700732}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700733#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700734
735#ifdef VK_USE_PLATFORM_XCB_KHR
736
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600737// Functions for the VK_KHR_xcb_surface extension:
738
739// This is the trampoline entrypoint for CreateXcbSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700740LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(VkInstance instance,
741 const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
742 const VkAllocationCallbacks *pAllocator,
743 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700744 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700745 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700746 VkResult res;
747
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700748 res = disp->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700749 return res;
750}
751
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600752// This is the instance chain terminator function for CreateXcbSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700753VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
754 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600755 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600756 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600757 uint32_t i = 0;
758
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600759 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700760 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600761 if (!ptr_instance->wsi_xcb_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700762 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700763 "VK_KHR_xcb_surface extension not enabled. vkCreateXcbSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600764 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
765 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600766 }
767
768 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700769 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->xcb_surf.base), sizeof(pIcdSurface->xcb_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700770 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600771 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
772 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700773 }
774
Mark Young5467d672016-06-28 10:52:43 -0600775 pIcdSurface->xcb_surf.base.platform = VK_ICD_WSI_PLATFORM_XCB;
776 pIcdSurface->xcb_surf.connection = pCreateInfo->connection;
777 pIcdSurface->xcb_surf.window = pCreateInfo->window;
778
Mark Young5467d672016-06-28 10:52:43 -0600779 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700780 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
781 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700782 if (NULL != icd_term->dispatch.CreateXcbSurfaceKHR) {
783 vkRes = icd_term->dispatch.CreateXcbSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
784 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600785 if (VK_SUCCESS != vkRes) {
786 goto out;
787 }
788 }
789 }
790 }
Ian Elliott7c352552015-11-19 13:14:05 -0700791
Mark Young3eda5882016-12-01 10:42:21 -0700792 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700793
Mark Young5467d672016-06-28 10:52:43 -0600794out:
795
796 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
797 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600798 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700799 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 -0700800 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
801 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600802 }
803 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700804 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600805 }
806 loader_instance_heap_free(ptr_instance, pIcdSurface);
807 }
808
809 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700810}
Ian Elliotte851dd62015-11-24 15:39:10 -0700811
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600812// This is the trampoline entrypoint for
813// GetPhysicalDeviceXcbPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700814LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
815 uint32_t queueFamilyIndex,
816 xcb_connection_t *connection,
817 xcb_visualid_t visual_id) {
818 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700819 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700820 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700821 VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliotte851dd62015-11-24 15:39:10 -0700822 return res;
823}
824
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600825// This is the instance chain terminator function for
826// GetPhysicalDeviceXcbPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700827VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
828 uint32_t queueFamilyIndex,
829 xcb_connection_t *connection,
830 xcb_visualid_t visual_id) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600831 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700832 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600833 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700834 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600835 if (!ptr_instance->wsi_xcb_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700836 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700837 "VK_KHR_xcb_surface extension not enabled. vkGetPhysicalDeviceXcbPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600838 return VK_SUCCESS;
839 }
840
Mark Youngd4e5ba42017-02-28 09:58:04 -0700841 if (NULL == icd_term->dispatch.GetPhysicalDeviceXcbPresentationSupportKHR) {
842 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
843 "ICD for selected physical device is not exporting vkGetPhysicalDeviceXcbPresentationSupportKHR!\n");
844 assert(false && "loader: null GetPhysicalDeviceXcbPresentationSupportKHR ICD pointer");
845 }
Ian Elliotte851dd62015-11-24 15:39:10 -0700846
Mark Youngd4e5ba42017-02-28 09:58:04 -0700847 return icd_term->dispatch.GetPhysicalDeviceXcbPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, connection,
848 visual_id);
Ian Elliotte851dd62015-11-24 15:39:10 -0700849}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700850#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700851
852#ifdef VK_USE_PLATFORM_XLIB_KHR
853
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600854// Functions for the VK_KHR_xlib_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700855
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600856// This is the trampoline entrypoint for CreateXlibSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700857LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance,
858 const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
859 const VkAllocationCallbacks *pAllocator,
860 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700861 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700862 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700863 VkResult res;
864
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700865 res = disp->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700866 return res;
867}
868
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600869// This is the instance chain terminator function for CreateXlibSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700870VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
871 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600872 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600873 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600874 uint32_t i = 0;
875
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600876 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700877 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600878 if (!ptr_instance->wsi_xlib_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700879 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700880 "VK_KHR_xlib_surface extension not enabled. vkCreateXlibSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600881 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
882 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600883 }
884
885 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700886 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->xlib_surf.base), sizeof(pIcdSurface->xlib_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700887 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600888 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
889 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700890 }
891
Mark Young5467d672016-06-28 10:52:43 -0600892 pIcdSurface->xlib_surf.base.platform = VK_ICD_WSI_PLATFORM_XLIB;
893 pIcdSurface->xlib_surf.dpy = pCreateInfo->dpy;
894 pIcdSurface->xlib_surf.window = pCreateInfo->window;
895
Mark Young5467d672016-06-28 10:52:43 -0600896 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700897 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
898 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -0700899 if (NULL != icd_term->dispatch.CreateXlibSurfaceKHR) {
900 vkRes = icd_term->dispatch.CreateXlibSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
901 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600902 if (VK_SUCCESS != vkRes) {
903 goto out;
904 }
905 }
906 }
907 }
Ian Elliott7c352552015-11-19 13:14:05 -0700908
Mark Young3eda5882016-12-01 10:42:21 -0700909 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700910
Mark Young5467d672016-06-28 10:52:43 -0600911out:
912
913 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
914 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600915 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700916 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 -0700917 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
918 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600919 }
920 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700921 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600922 }
923 loader_instance_heap_free(ptr_instance, pIcdSurface);
924 }
925
926 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700927}
Ian Elliotte851dd62015-11-24 15:39:10 -0700928
Mark Young573a7a12016-11-02 09:37:08 -0600929// This is the trampoline entrypoint for
930// GetPhysicalDeviceXlibPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700931LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
932 uint32_t queueFamilyIndex, Display *dpy,
933 VisualID visualID) {
934 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700935 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700936 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700937 VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliotte851dd62015-11-24 15:39:10 -0700938 return res;
939}
940
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600941// This is the instance chain terminator function for
942// GetPhysicalDeviceXlibPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700943VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
944 uint32_t queueFamilyIndex, Display *dpy,
945 VisualID visualID) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600946 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700947 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600948 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700949 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600950 if (!ptr_instance->wsi_xlib_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700951 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -0700952 "VK_KHR_xlib_surface extension not enabled. vkGetPhysicalDeviceXlibPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600953 return VK_SUCCESS;
954 }
955
Mark Youngd4e5ba42017-02-28 09:58:04 -0700956 if (NULL == icd_term->dispatch.GetPhysicalDeviceXlibPresentationSupportKHR) {
957 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
958 "ICD for selected physical device is not exporting vkGetPhysicalDeviceXlibPresentationSupportKHR!\n");
959 assert(false && "loader: null GetPhysicalDeviceXlibPresentationSupportKHR ICD pointer");
960 }
Ian Elliotte851dd62015-11-24 15:39:10 -0700961
Mark Youngd4e5ba42017-02-28 09:58:04 -0700962 return icd_term->dispatch.GetPhysicalDeviceXlibPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliotte851dd62015-11-24 15:39:10 -0700963}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700964#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700965
Nicolas Caramellifa696ca2020-07-04 22:53:59 +0200966#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
967
968// Functions for the VK_EXT_directfb_surface extension:
969
970// This is the trampoline entrypoint for CreateDirectFBSurfaceEXT
971LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT(VkInstance instance,
972 const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo,
973 const VkAllocationCallbacks *pAllocator,
974 VkSurfaceKHR *pSurface) {
975 const VkLayerInstanceDispatchTable *disp;
976 disp = loader_get_instance_layer_dispatch(instance);
977 VkResult res;
978
979 res = disp->CreateDirectFBSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
980 return res;
981}
982
983// This is the instance chain terminator function for CreateDirectFBSurfaceEXT
984VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDirectFBSurfaceEXT(VkInstance instance,
985 const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo,
986 const VkAllocationCallbacks *pAllocator,
987 VkSurfaceKHR *pSurface) {
988 VkResult vkRes = VK_SUCCESS;
989 VkIcdSurface *pIcdSurface = NULL;
990 uint32_t i = 0;
991
992 // First, check to ensure the appropriate extension was enabled:
993 struct loader_instance *ptr_instance = loader_get_instance(instance);
994 if (!ptr_instance->wsi_directfb_surface_enabled) {
995 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
996 "VK_EXT_directfb_surface extension not enabled. vkCreateDirectFBSurfaceEXT not executed!\n");
997 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
998 goto out;
999 }
1000
1001 // Next, if so, proceed with the implementation of this function:
1002 pIcdSurface =
1003 AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->directfb_surf.base), sizeof(pIcdSurface->directfb_surf));
1004 if (pIcdSurface == NULL) {
1005 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1006 goto out;
1007 }
1008
1009 pIcdSurface->directfb_surf.base.platform = VK_ICD_WSI_PLATFORM_DIRECTFB;
1010 pIcdSurface->directfb_surf.dfb = pCreateInfo->dfb;
1011 pIcdSurface->directfb_surf.surface = pCreateInfo->surface;
1012
1013 // Loop through each ICD and determine if they need to create a surface
1014 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1015 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1016 if (NULL != icd_term->dispatch.CreateDirectFBSurfaceEXT) {
1017 vkRes = icd_term->dispatch.CreateDirectFBSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
1018 &pIcdSurface->real_icd_surfaces[i]);
1019 if (VK_SUCCESS != vkRes) {
1020 goto out;
1021 }
1022 }
1023 }
1024 }
1025
1026 *pSurface = (VkSurfaceKHR)pIcdSurface;
1027
1028out:
1029
1030 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1031 if (NULL != pIcdSurface->real_icd_surfaces) {
1032 i = 0;
1033 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1034 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1035 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1036 }
1037 }
1038 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
1039 }
1040 loader_instance_heap_free(ptr_instance, pIcdSurface);
1041 }
1042
1043 return vkRes;
1044}
1045
1046// This is the trampoline entrypoint for
1047// GetPhysicalDeviceDirectFBPresentationSupportEXT
1048LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,
1049 uint32_t queueFamilyIndex,
1050 IDirectFB *dfb) {
1051 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1052 const VkLayerInstanceDispatchTable *disp;
1053 disp = loader_get_instance_layer_dispatch(physicalDevice);
1054 VkBool32 res = disp->GetPhysicalDeviceDirectFBPresentationSupportEXT(unwrapped_phys_dev, queueFamilyIndex, dfb);
1055 return res;
1056}
1057
1058// This is the instance chain terminator function for
1059// GetPhysicalDeviceDirectFBPresentationSupportEXT
1060VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,
1061 uint32_t queueFamilyIndex,
1062 IDirectFB *dfb) {
1063 // First, check to ensure the appropriate extension was enabled:
1064 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1065 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1066 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
1067 if (!ptr_instance->wsi_directfb_surface_enabled) {
1068 loader_log(
1069 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1070 "VK_EXT_directfb_surface extension not enabled. vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
1071 return VK_SUCCESS;
1072 }
1073
1074 if (NULL == icd_term->dispatch.GetPhysicalDeviceDirectFBPresentationSupportEXT) {
1075 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1076 "ICD for selected physical device is not exporting vkGetPhysicalDeviceDirectFBPresentationSupportEXT!\n");
1077 assert(false && "loader: null GetPhysicalDeviceDirectFBPresentationSupportEXT ICD pointer");
1078 }
1079
1080 return icd_term->dispatch.GetPhysicalDeviceDirectFBPresentationSupportEXT(phys_dev_term->phys_dev, queueFamilyIndex, dfb);
1081}
1082#endif // VK_USE_PLATFORM_DIRECTFB_EXT
1083
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001084#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001085
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001086// Functions for the VK_KHR_android_surface extension:
1087
1088// This is the trampoline entrypoint for CreateAndroidSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001089LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(VkInstance instance, ANativeWindow *window,
1090 const VkAllocationCallbacks *pAllocator,
1091 VkSurfaceKHR *pSurface) {
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001092 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001093 disp = loader_get_instance_layer_dispatch(instance);
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001094 VkResult res;
1095
1096 res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
1097 return res;
1098}
1099
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001100// This is the instance chain terminator function for CreateAndroidSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001101VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(VkInstance instance, Window window,
1102 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001103 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001104 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001105 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001106 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001107 "VK_KHR_display extension not enabled. vkCreateAndroidSurfaceKHR not executed!\n");
Jeremy Hayes0231e1c2016-06-14 11:50:02 -06001108 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001109 }
1110
1111 // Next, if so, proceed with the implementation of this function:
Mark Young5467d672016-06-28 10:52:43 -06001112 VkIcdSurfaceAndroid *pIcdSurface =
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001113 loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceAndroid), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001114 if (pIcdSurface == NULL) {
1115 return VK_ERROR_OUT_OF_HOST_MEMORY;
1116 }
1117
1118 pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_ANDROID;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001119 pIcdSurface->window = window;
1120
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001121 *pSurface = (VkSurfaceKHR)pIcdSurface;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001122
1123 return VK_SUCCESS;
1124}
1125
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001126#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001127
Bryan Law-Smith57305692019-04-01 09:45:55 +01001128// Functions for the VK_EXT_headless_surface extension:
1129
1130VKAPI_ATTR VkResult VKAPI_CALL vkCreateHeadlessSurfaceEXT(VkInstance instance, const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
1131 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1132 const VkLayerInstanceDispatchTable *disp;
1133 disp = loader_get_instance_layer_dispatch(instance);
1134 VkResult res;
1135
1136 res = disp->CreateHeadlessSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
1137 return res;
1138}
1139
1140VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateHeadlessSurfaceEXT(VkInstance instance,
1141 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
1142 const VkAllocationCallbacks *pAllocator,
1143 VkSurfaceKHR *pSurface) {
1144 struct loader_instance *inst = loader_get_instance(instance);
1145 VkIcdSurface *pIcdSurface = NULL;
1146 VkResult vkRes = VK_SUCCESS;
1147 uint32_t i = 0;
1148
1149 if (!inst->wsi_headless_surface_enabled) {
1150 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1151 "VK_EXT_headless_surface extension not enabled. "
1152 "vkCreateHeadlessSurfaceEXT not executed!\n");
1153 return VK_SUCCESS;
1154 }
1155
1156 // Next, if so, proceed with the implementation of this function:
1157 pIcdSurface = AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->headless_surf.base), sizeof(pIcdSurface->headless_surf));
1158 if (pIcdSurface == NULL) {
1159 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1160 goto out;
1161 }
1162
1163 pIcdSurface->headless_surf.base.platform = VK_ICD_WSI_PLATFORM_HEADLESS;
1164 // Loop through each ICD and determine if they need to create a surface
1165 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1166 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1167 if (NULL != icd_term->dispatch.CreateHeadlessSurfaceEXT) {
1168 vkRes = icd_term->dispatch.CreateHeadlessSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
1169 &pIcdSurface->real_icd_surfaces[i]);
1170 if (VK_SUCCESS != vkRes) {
1171 goto out;
1172 }
1173 }
1174 }
1175 }
1176
1177 *pSurface = (VkSurfaceKHR)pIcdSurface;
1178
1179out:
1180
1181 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1182 if (NULL != pIcdSurface->real_icd_surfaces) {
1183 i = 0;
1184 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1185 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1186 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1187 }
1188 }
1189 loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
1190 }
1191 loader_instance_heap_free(inst, pIcdSurface);
1192 }
1193
1194 return vkRes;
1195}
1196
Karl Schultzd81ebfb2017-12-12 10:33:01 -05001197#ifdef VK_USE_PLATFORM_MACOS_MVK
1198
1199// Functions for the VK_MVK_macos_surface extension:
1200
1201// This is the trampoline entrypoint for CreateMacOSSurfaceMVK
1202LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(VkInstance instance,
1203 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
1204 const VkAllocationCallbacks *pAllocator,
1205 VkSurfaceKHR *pSurface) {
1206 const VkLayerInstanceDispatchTable *disp;
1207 disp = loader_get_instance_layer_dispatch(instance);
1208 VkResult res;
1209
1210 res = disp->CreateMacOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
1211 return res;
1212}
1213
1214// This is the instance chain terminator function for CreateMacOSSurfaceKHR
1215VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
1216 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1217 VkResult vkRes = VK_SUCCESS;
1218 VkIcdSurface *pIcdSurface = NULL;
1219 uint32_t i = 0;
1220
1221 // First, check to ensure the appropriate extension was enabled:
1222 struct loader_instance *ptr_instance = loader_get_instance(instance);
1223 if (!ptr_instance->wsi_macos_surface_enabled) {
1224 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1225 "VK_MVK_macos_surface extension not enabled. vkCreateMacOSSurfaceMVK not executed!\n");
1226 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1227 goto out;
1228 }
1229
1230 // Next, if so, proceed with the implementation of this function:
1231 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->macos_surf.base), sizeof(pIcdSurface->macos_surf));
1232 if (pIcdSurface == NULL) {
1233 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1234 goto out;
1235 }
1236
1237 pIcdSurface->macos_surf.base.platform = VK_ICD_WSI_PLATFORM_MACOS;
1238 pIcdSurface->macos_surf.pView = pCreateInfo->pView;
1239
1240 // Loop through each ICD and determine if they need to create a surface
1241 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1242 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1243 if (NULL != icd_term->dispatch.CreateMacOSSurfaceMVK) {
1244 vkRes = icd_term->dispatch.CreateMacOSSurfaceMVK(icd_term->instance, pCreateInfo, pAllocator,
1245 &pIcdSurface->real_icd_surfaces[i]);
1246 if (VK_SUCCESS != vkRes) {
1247 goto out;
1248 }
1249 }
1250 }
1251 }
1252
1253 *pSurface = (VkSurfaceKHR)pIcdSurface;
1254
1255out:
1256
1257 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1258 if (NULL != pIcdSurface->real_icd_surfaces) {
1259 i = 0;
1260 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1261 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1262 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1263 }
1264 }
1265 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
1266 }
1267 loader_instance_heap_free(ptr_instance, pIcdSurface);
1268 }
1269
1270 return vkRes;
1271}
1272
1273#endif // VK_USE_PLATFORM_MACOS_MVK
1274
1275#ifdef VK_USE_PLATFORM_IOS_MVK
1276
1277// Functions for the VK_MVK_ios_surface extension:
1278
1279// This is the trampoline entrypoint for CreateIOSSurfaceMVK
1280LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(VkInstance instance,
1281 const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
1282 const VkAllocationCallbacks *pAllocator,
1283 VkSurfaceKHR *pSurface) {
1284 const VkLayerInstanceDispatchTable *disp;
1285 disp = loader_get_instance_layer_dispatch(instance);
1286 VkResult res;
1287
1288 res = disp->CreateIOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
1289 return res;
1290}
1291
1292// This is the instance chain terminator function for CreateIOSSurfaceKHR
1293VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
1294 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1295 // First, check to ensure the appropriate extension was enabled:
1296 struct loader_instance *ptr_instance = loader_get_instance(instance);
1297 if (!ptr_instance->wsi_ios_surface_enabled) {
1298 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1299 "VK_MVK_ios_surface extension not enabled. vkCreateIOSSurfaceMVK not executed!\n");
1300 return VK_ERROR_EXTENSION_NOT_PRESENT;
1301 }
1302
1303 // Next, if so, proceed with the implementation of this function:
1304 VkIcdSurfaceIOS *pIcdSurface =
1305 loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceIOS), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
1306 if (pIcdSurface == NULL) {
1307 return VK_ERROR_OUT_OF_HOST_MEMORY;
1308 }
1309
1310 pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_IOS;
1311 pIcdSurface->pView = pCreateInfo->pView;
1312
1313 *pSurface = (VkSurfaceKHR)pIcdSurface;
1314
1315 return VK_SUCCESS;
1316}
1317
1318#endif // VK_USE_PLATFORM_IOS_MVK
1319
Lenny Komowa1b5e442019-09-16 16:14:36 -06001320#if defined(VK_USE_PLATFORM_METAL_EXT)
1321
1322LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT(VkInstance instance,
1323 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
1324 const VkAllocationCallbacks *pAllocator,
1325 VkSurfaceKHR *pSurface) {
1326 const VkLayerInstanceDispatchTable *disp = loader_get_instance_layer_dispatch(instance);
1327 return disp->CreateMetalSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
1328}
1329
1330VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMetalSurfaceEXT(VkInstance instance, const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
1331 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
1332 VkResult result = VK_SUCCESS;
1333 VkIcdSurface *icd_surface = NULL;
1334 uint32_t i;
1335
1336 // First, check to ensure the appropriate extension was enabled:
1337 struct loader_instance *ptr_instance = loader_get_instance(instance);
1338 if (!ptr_instance->wsi_metal_surface_enabled) {
1339 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1340 "VK_EXT_metal_surface extension not enabled. vkCreateMetalSurfaceEXT will not be executed.\n");
1341 }
1342
1343 // Next, if so, proceed with the implementation of this function:
1344 icd_surface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(icd_surface->metal_surf.base), sizeof(icd_surface->metal_surf));
1345 if (icd_surface == NULL) {
1346 result = VK_ERROR_OUT_OF_HOST_MEMORY;
1347 goto out;
1348 }
1349
1350 icd_surface->metal_surf.base.platform = VK_ICD_WSI_PLATFORM_METAL;
1351 icd_surface->metal_surf.pLayer = pCreateInfo->pLayer;
1352
1353 // Loop through each ICD and determine if they need to create a surface
1354 i = 0;
1355 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, ++i) {
1356 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1357 if (icd_term->dispatch.CreateMetalSurfaceEXT != NULL) {
1358 result = icd_term->dispatch.CreateMetalSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator,
1359 &icd_surface->real_icd_surfaces[i]);
1360 if (result != VK_SUCCESS) {
1361 goto out;
1362 }
1363 }
1364 }
1365 }
1366 *pSurface = (VkSurfaceKHR)icd_surface;
1367
1368out:
1369 if (result != VK_SUCCESS && icd_surface != NULL) {
1370 if (icd_surface->real_icd_surfaces != NULL) {
1371 i = 0;
1372 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, ++i) {
1373 if (icd_surface->real_icd_surfaces[i] == VK_NULL_HANDLE && icd_term->dispatch.DestroySurfaceKHR != NULL) {
1374 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, icd_surface->real_icd_surfaces[i], pAllocator);
1375 }
1376 }
1377 loader_instance_heap_free(ptr_instance, icd_surface->real_icd_surfaces);
1378 }
1379 loader_instance_heap_free(ptr_instance, icd_surface);
1380 }
1381 return result;
1382}
1383
1384#endif
1385
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001386// Functions for the VK_KHR_display instance extension:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001387LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1388 uint32_t *pPropertyCount,
1389 VkDisplayPropertiesKHR *pProperties) {
1390 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001391 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001392 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001393 VkResult res = disp->GetPhysicalDeviceDisplayPropertiesKHR(unwrapped_phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001394 return res;
1395}
1396
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001397VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1398 uint32_t *pPropertyCount,
1399 VkDisplayPropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001400 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001401 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001402 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001403 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001404 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001405 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001406 "VK_KHR_display extension not enabled. vkGetPhysicalDeviceDisplayPropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001407 return VK_SUCCESS;
1408 }
1409
Mark Youngd4e5ba42017-02-28 09:58:04 -07001410 if (NULL == icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR) {
1411 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1412 "ICD for selected physical device is not exporting vkGetPhysicalDeviceDisplayPropertiesKHR!\n");
1413 assert(false && "loader: null GetPhysicalDeviceDisplayPropertiesKHR ICD pointer");
1414 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001415
Mark Youngd4e5ba42017-02-28 09:58:04 -07001416 return icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001417}
1418
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001419LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
1420 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlanePropertiesKHR *pProperties) {
1421 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001422 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001423 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001424 VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(unwrapped_phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001425 return res;
1426}
1427
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001428VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
1429 uint32_t *pPropertyCount,
1430 VkDisplayPlanePropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001431 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001432 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001433 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001434 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001435 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001436 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001437 "VK_KHR_display extension not enabled. vkGetPhysicalDeviceDisplayPlanePropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001438 return VK_SUCCESS;
1439 }
1440
Mark Youngd4e5ba42017-02-28 09:58:04 -07001441 if (NULL == icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR) {
1442 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1443 "ICD for selected physical device is not exporting vkGetPhysicalDeviceDisplayPlanePropertiesKHR!\n");
1444 assert(false && "loader: null GetPhysicalDeviceDisplayPlanePropertiesKHR ICD pointer");
1445 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001446
Mark Youngd4e5ba42017-02-28 09:58:04 -07001447 return icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001448}
1449
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001450LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
1451 uint32_t planeIndex, uint32_t *pDisplayCount,
1452 VkDisplayKHR *pDisplays) {
1453 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001454 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001455 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001456 VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
Jon Ashburncc370d02016-03-08 09:30:30 -07001457 return res;
1458}
1459
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001460VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1461 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001462 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001463 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001464 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001465 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001466 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001467 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001468 "VK_KHR_display extension not enabled. vkGetDisplayPlaneSupportedDisplaysKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001469 return VK_SUCCESS;
1470 }
1471
Mark Youngd4e5ba42017-02-28 09:58:04 -07001472 if (NULL == icd_term->dispatch.GetDisplayPlaneSupportedDisplaysKHR) {
1473 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1474 "ICD for selected physical device is not exporting vkGetDisplayPlaneSupportedDisplaysKHR!\n");
1475 assert(false && "loader: null GetDisplayPlaneSupportedDisplaysKHR ICD pointer");
1476 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001477
Mark Youngd4e5ba42017-02-28 09:58:04 -07001478 return icd_term->dispatch.GetDisplayPlaneSupportedDisplaysKHR(phys_dev_term->phys_dev, planeIndex, pDisplayCount, pDisplays);
Jon Ashburncc370d02016-03-08 09:30:30 -07001479}
1480
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001481LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1482 uint32_t *pPropertyCount,
1483 VkDisplayModePropertiesKHR *pProperties) {
1484 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001485 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001486 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001487 VkResult res = disp->GetDisplayModePropertiesKHR(unwrapped_phys_dev, display, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001488 return res;
1489}
1490
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001491VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1492 uint32_t *pPropertyCount,
1493 VkDisplayModePropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001494 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001495 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001496 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001497 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001498 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001499 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001500 "VK_KHR_display extension not enabled. vkGetDisplayModePropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001501 return VK_SUCCESS;
1502 }
1503
Mark Youngd4e5ba42017-02-28 09:58:04 -07001504 if (NULL == icd_term->dispatch.GetDisplayModePropertiesKHR) {
1505 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1506 "ICD for selected physical device is not exporting vkGetDisplayModePropertiesKHR!\n");
1507 assert(false && "loader: null GetDisplayModePropertiesKHR ICD pointer");
1508 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001509
Mark Youngd4e5ba42017-02-28 09:58:04 -07001510 return icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001511}
1512
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001513LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1514 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1515 const VkAllocationCallbacks *pAllocator,
1516 VkDisplayModeKHR *pMode) {
1517 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001518 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001519 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001520 VkResult res = disp->CreateDisplayModeKHR(unwrapped_phys_dev, display, pCreateInfo, pAllocator, pMode);
Jon Ashburncc370d02016-03-08 09:30:30 -07001521 return res;
1522}
1523
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001524VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1525 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1526 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001527 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001528 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001529 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001530 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001531 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001532 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001533 "VK_KHR_display extension not enabled. vkCreateDisplayModeKHR not executed!\n");
Jeremy Hayes0231e1c2016-06-14 11:50:02 -06001534 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001535 }
1536
Mark Youngd4e5ba42017-02-28 09:58:04 -07001537 if (NULL == icd_term->dispatch.CreateDisplayModeKHR) {
1538 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1539 "ICD for selected physical device is not exporting vkCreateDisplayModeKHR!\n");
1540 assert(false && "loader: null CreateDisplayModeKHR ICD pointer");
1541 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001542
Mark Youngd4e5ba42017-02-28 09:58:04 -07001543 return icd_term->dispatch.CreateDisplayModeKHR(phys_dev_term->phys_dev, display, pCreateInfo, pAllocator, pMode);
Jon Ashburncc370d02016-03-08 09:30:30 -07001544}
1545
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001546LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,
1547 VkDisplayModeKHR mode, uint32_t planeIndex,
1548 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
1549 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001550 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001551 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001552 VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(unwrapped_phys_dev, mode, planeIndex, pCapabilities);
Jon Ashburncc370d02016-03-08 09:30:30 -07001553 return res;
1554}
1555
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001556VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode,
1557 uint32_t planeIndex,
1558 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001559 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001560 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001561 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001562 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001563 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001564 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001565 "VK_KHR_display extension not enabled. vkGetDisplayPlaneCapabilitiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001566 return VK_SUCCESS;
1567 }
1568
Mark Youngd4e5ba42017-02-28 09:58:04 -07001569 if (NULL == icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR) {
1570 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1571 "ICD for selected physical device is not exporting vkGetDisplayPlaneCapabilitiesKHR!\n");
1572 assert(false && "loader: null GetDisplayPlaneCapabilitiesKHR ICD pointer");
1573 }
Jon Ashburncc370d02016-03-08 09:30:30 -07001574
Mark Youngd4e5ba42017-02-28 09:58:04 -07001575 return icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR(phys_dev_term->phys_dev, mode, planeIndex, pCapabilities);
Jon Ashburncc370d02016-03-08 09:30:30 -07001576}
1577
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001578LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(VkInstance instance,
1579 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1580 const VkAllocationCallbacks *pAllocator,
1581 VkSurfaceKHR *pSurface) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001582 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001583 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburncc370d02016-03-08 09:30:30 -07001584 VkResult res;
1585
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001586 res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburncc370d02016-03-08 09:30:30 -07001587 return res;
1588}
1589
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001590VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayPlaneSurfaceKHR(VkInstance instance,
1591 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1592 const VkAllocationCallbacks *pAllocator,
1593 VkSurfaceKHR *pSurface) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001594 struct loader_instance *inst = loader_get_instance(instance);
Mark Young5467d672016-06-28 10:52:43 -06001595 VkIcdSurface *pIcdSurface = NULL;
Mark Youngf06def92016-11-01 19:20:41 -06001596 VkResult vkRes = VK_SUCCESS;
Mark Young573a7a12016-11-02 09:37:08 -06001597 uint32_t i = 0;
Jon Ashburncc370d02016-03-08 09:30:30 -07001598
Mark Youngf06def92016-11-01 19:20:41 -06001599 if (!inst->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001600 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
Mark Youngd4e5ba42017-02-28 09:58:04 -07001601 "VK_KHR_surface extension not enabled. vkCreateDisplayPlaneSurfaceKHR not executed!\n");
Mark Youngf06def92016-11-01 19:20:41 -06001602 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1603 goto out;
Petros Bantolasf3095862016-04-14 12:50:42 +01001604 }
1605
Piers Daniellc21fde52016-12-13 16:51:49 -07001606 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001607 pIcdSurface = AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->display_surf.base), sizeof(pIcdSurface->display_surf));
Jon Ashburncc370d02016-03-08 09:30:30 -07001608 if (pIcdSurface == NULL) {
Mark Youngf06def92016-11-01 19:20:41 -06001609 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1610 goto out;
Jon Ashburncc370d02016-03-08 09:30:30 -07001611 }
1612
Mark Young5467d672016-06-28 10:52:43 -06001613 pIcdSurface->display_surf.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
1614 pIcdSurface->display_surf.displayMode = pCreateInfo->displayMode;
1615 pIcdSurface->display_surf.planeIndex = pCreateInfo->planeIndex;
1616 pIcdSurface->display_surf.planeStackIndex = pCreateInfo->planeStackIndex;
1617 pIcdSurface->display_surf.transform = pCreateInfo->transform;
1618 pIcdSurface->display_surf.globalAlpha = pCreateInfo->globalAlpha;
1619 pIcdSurface->display_surf.alphaMode = pCreateInfo->alphaMode;
1620 pIcdSurface->display_surf.imageExtent = pCreateInfo->imageExtent;
1621
Mark Youngf06def92016-11-01 19:20:41 -06001622 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001623 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1624 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Youngd4e5ba42017-02-28 09:58:04 -07001625 if (NULL != icd_term->dispatch.CreateDisplayPlaneSurfaceKHR) {
1626 vkRes = icd_term->dispatch.CreateDisplayPlaneSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
1627 &pIcdSurface->real_icd_surfaces[i]);
Mark Youngf06def92016-11-01 19:20:41 -06001628 if (VK_SUCCESS != vkRes) {
1629 goto out;
1630 }
1631 }
1632 }
1633 }
1634
Mark Young3eda5882016-12-01 10:42:21 -07001635 *pSurface = (VkSurfaceKHR)pIcdSurface;
Jon Ashburncc370d02016-03-08 09:30:30 -07001636
Mark Youngf06def92016-11-01 19:20:41 -06001637out:
1638
1639 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1640 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -06001641 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001642 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 -07001643 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
1644 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Youngf06def92016-11-01 19:20:41 -06001645 }
1646 }
1647 loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
1648 }
1649 loader_instance_heap_free(inst, pIcdSurface);
1650 }
1651
1652 return vkRes;
Jon Ashburncc370d02016-03-08 09:30:30 -07001653}
1654
Mark Young274e4bc2017-01-19 21:10:49 -07001655// EXT_display_swapchain Extension command
1656
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001657LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
1658 const VkSwapchainCreateInfoKHR *pCreateInfos,
1659 const VkAllocationCallbacks *pAllocator,
1660 VkSwapchainKHR *pSwapchains) {
Mark Young2a2122f2016-09-08 18:36:32 -06001661 const VkLayerDispatchTable *disp;
1662 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001663 return disp->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
Mark Youngf2eabea2016-07-01 15:18:27 -06001664}
1665
Mark Youngd4e5ba42017-02-28 09:58:04 -07001666VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
1667 const VkSwapchainCreateInfoKHR *pCreateInfos,
1668 const VkAllocationCallbacks *pAllocator,
1669 VkSwapchainKHR *pSwapchains) {
Mark Young274e4bc2017-01-19 21:10:49 -07001670 uint32_t icd_index = 0;
1671 struct loader_device *dev;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001672 struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
Mark Youngd4e5ba42017-02-28 09:58:04 -07001673 if (NULL != icd_term && NULL != icd_term->dispatch.CreateSharedSwapchainsKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001674 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pCreateInfos->surface;
Mark Young274e4bc2017-01-19 21:10:49 -07001675 if (NULL != icd_surface->real_icd_surfaces) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001676 if ((VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
Mark Young274e4bc2017-01-19 21:10:49 -07001677 // We found the ICD, and there is an ICD KHR surface
1678 // associated with it, so copy the CreateInfo struct
1679 // and point it at the ICD's surface.
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001680 VkSwapchainCreateInfoKHR *pCreateCopy = loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
Mark Young274e4bc2017-01-19 21:10:49 -07001681 if (NULL == pCreateCopy) {
1682 return VK_ERROR_OUT_OF_HOST_MEMORY;
1683 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001684 memcpy(pCreateCopy, pCreateInfos, sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
Mark Young274e4bc2017-01-19 21:10:49 -07001685 for (uint32_t sc = 0; sc < swapchainCount; sc++) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001686 pCreateCopy[sc].surface = icd_surface->real_icd_surfaces[icd_index];
Mark Young274e4bc2017-01-19 21:10:49 -07001687 }
Mark Youngd4e5ba42017-02-28 09:58:04 -07001688 return icd_term->dispatch.CreateSharedSwapchainsKHR(device, swapchainCount, pCreateCopy, pAllocator, pSwapchains);
Mark Young274e4bc2017-01-19 21:10:49 -07001689 }
1690 }
Mark Youngd4e5ba42017-02-28 09:58:04 -07001691 return icd_term->dispatch.CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
Mark Young274e4bc2017-01-19 21:10:49 -07001692 }
1693 return VK_SUCCESS;
1694}
1695
Lenny Komowdbaaad62017-10-02 15:08:53 -06001696LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupPresentCapabilitiesKHR(
1697 VkDevice device,
1698 VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) {
1699 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
1700 return disp->GetDeviceGroupPresentCapabilitiesKHR(device, pDeviceGroupPresentCapabilities);
1701}
Lenny Komow31217432017-10-02 15:08:53 -06001702
Lenny Komowdbaaad62017-10-02 15:08:53 -06001703LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHR(
1704 VkDevice device,
1705 VkSurfaceKHR surface,
1706 VkDeviceGroupPresentModeFlagsKHR* pModes) {
1707 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
1708 return disp->GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
1709}
1710
Lenny Komow7871f782017-10-11 15:39:38 -06001711VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDeviceGroupSurfacePresentModesKHR(
1712 VkDevice device,
1713 VkSurfaceKHR surface,
1714 VkDeviceGroupPresentModeFlagsKHR* pModes) {
1715 uint32_t icd_index = 0;
1716 struct loader_device *dev;
1717 struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
1718 if (NULL != icd_term && NULL != icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR) {
1719 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
1720 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
1721 return icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR(device, icd_surface->real_icd_surfaces[icd_index], pModes);
1722 }
1723 return icd_term->dispatch.GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
1724 }
1725 return VK_SUCCESS;
1726}
1727
Lenny Komowdbaaad62017-10-02 15:08:53 -06001728LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHR(
Lenny Komow31217432017-10-02 15:08:53 -06001729 VkPhysicalDevice physicalDevice,
1730 VkSurfaceKHR surface,
1731 uint32_t* pRectCount,
1732 VkRect2D* pRects) {
1733 const VkLayerInstanceDispatchTable *disp;
1734 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1735 disp = loader_get_instance_layer_dispatch(physicalDevice);
1736 return disp->GetPhysicalDevicePresentRectanglesKHR(unwrapped_phys_dev, surface, pRectCount, pRects);
1737}
1738
1739VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDevicePresentRectanglesKHR(
1740 VkPhysicalDevice physicalDevice,
1741 VkSurfaceKHR surface,
1742 uint32_t* pRectCount,
1743 VkRect2D* pRects) {
1744 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1745 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1746 if (NULL == icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR) {
1747 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1748 "ICD associated with VkPhysicalDevice does not support GetPhysicalDevicePresentRectanglesKHX");
1749 }
1750 VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);
1751 uint8_t icd_index = phys_dev_term->icd_index;
1752 if (NULL != icd_surface->real_icd_surfaces && NULL != (void *)icd_surface->real_icd_surfaces[icd_index]) {
1753 return icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR(phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[icd_index], pRectCount, pRects);
1754 }
1755 return icd_term->dispatch.GetPhysicalDevicePresentRectanglesKHR(phys_dev_term->phys_dev, surface, pRectCount, pRects);
1756}
1757
Lenny Komowdbaaad62017-10-02 15:08:53 -06001758LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImage2KHR(
1759 VkDevice device,
1760 const VkAcquireNextImageInfoKHR* pAcquireInfo,
1761 uint32_t* pImageIndex) {
1762 const VkLayerDispatchTable *disp = loader_get_dispatch(device);
1763 return disp->AcquireNextImage2KHR(device, pAcquireInfo, pImageIndex);
1764}
1765
Lenny Komow61139782018-05-31 11:32:31 -06001766// ---- VK_KHR_get_display_properties2 extension trampoline/terminators
1767
1768LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,
1769 uint32_t *pPropertyCount,
1770 VkDisplayProperties2KHR *pProperties) {
1771 const VkLayerInstanceDispatchTable *disp;
1772 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1773 disp = loader_get_instance_layer_dispatch(physicalDevice);
1774 return disp->GetPhysicalDeviceDisplayProperties2KHR(unwrapped_phys_dev, pPropertyCount, pProperties);
1775}
1776
1777VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice,
1778 uint32_t *pPropertyCount,
1779 VkDisplayProperties2KHR *pProperties) {
1780 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1781 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1782
1783 // If the function is available in the driver, just call into it
1784 if (icd_term->dispatch.GetPhysicalDeviceDisplayProperties2KHR != NULL) {
1785 return icd_term->dispatch.GetPhysicalDeviceDisplayProperties2KHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
1786 }
1787
1788 // We have to emulate the function.
1789 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
1790 "vkGetPhysicalDeviceDisplayProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
1791
1792 // If the icd doesn't support VK_KHR_display, then no properties are available
1793 if (icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR == NULL) {
1794 *pPropertyCount = 0;
1795 return VK_SUCCESS;
1796 }
1797
1798 // If we aren't writing to pProperties, then emulation is straightforward
1799 if (pProperties == NULL || *pPropertyCount == 0) {
1800 return icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, NULL);
1801 }
1802
1803 // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayPropertiesKHR and copy it
1804 VkDisplayPropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayPropertiesKHR));
1805 if (properties == NULL) {
1806 return VK_ERROR_OUT_OF_HOST_MEMORY;
1807 }
1808 VkResult res = icd_term->dispatch.GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, properties);
1809 if (res < 0) {
1810 return res;
1811 }
1812 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
1813 memcpy(&pProperties[i].displayProperties, &properties[i], sizeof(VkDisplayPropertiesKHR));
1814 }
1815 return res;
1816}
1817
1818LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlaneProperties2KHR(
1819 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlaneProperties2KHR *pProperties) {
1820 const VkLayerInstanceDispatchTable *disp;
1821 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1822 disp = loader_get_instance_layer_dispatch(physicalDevice);
1823 return disp->GetPhysicalDeviceDisplayPlaneProperties2KHR(unwrapped_phys_dev, pPropertyCount, pProperties);
1824}
1825
1826VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
1827 uint32_t *pPropertyCount,
1828 VkDisplayPlaneProperties2KHR *pProperties) {
1829 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1830 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1831
1832 // If the function is available in the driver, just call into it
1833 if (icd_term->dispatch.GetPhysicalDeviceDisplayPlaneProperties2KHR != NULL) {
1834 return icd_term->dispatch.GetPhysicalDeviceDisplayPlaneProperties2KHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
1835 }
1836
1837 // We have to emulate the function.
1838 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
1839 "vkGetPhysicalDeviceDisplayPlaneProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
1840
1841 // If the icd doesn't support VK_KHR_display, then no properties are available
1842 if (icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR == NULL) {
1843 *pPropertyCount = 0;
1844 return VK_SUCCESS;
1845 }
1846
1847 // If we aren't writing to pProperties, then emulation is straightforward
1848 if (pProperties == NULL || *pPropertyCount == 0) {
1849 return icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, NULL);
1850 }
1851
1852 // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayPlanePropertiesKHR and copy it
1853 VkDisplayPlanePropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayPlanePropertiesKHR));
1854 if (properties == NULL) {
1855 return VK_ERROR_OUT_OF_HOST_MEMORY;
1856 }
1857 VkResult res =
1858 icd_term->dispatch.GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, properties);
1859 if (res < 0) {
1860 return res;
1861 }
1862 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
1863 memcpy(&pProperties[i].displayPlaneProperties, &properties[i], sizeof(VkDisplayPlanePropertiesKHR));
1864 }
1865 return res;
1866}
1867
1868LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1869 uint32_t *pPropertyCount,
1870 VkDisplayModeProperties2KHR *pProperties) {
1871 const VkLayerInstanceDispatchTable *disp;
1872 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1873 disp = loader_get_instance_layer_dispatch(physicalDevice);
1874 return disp->GetDisplayModeProperties2KHR(unwrapped_phys_dev, display, pPropertyCount, pProperties);
1875}
1876
1877VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1878 uint32_t *pPropertyCount,
1879 VkDisplayModeProperties2KHR *pProperties) {
1880 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1881 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1882
1883 // If the function is available in the driver, just call into it
1884 if (icd_term->dispatch.GetDisplayModeProperties2KHR != NULL) {
1885 return icd_term->dispatch.GetDisplayModeProperties2KHR(phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
1886 }
1887
1888 // We have to emulate the function.
1889 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
1890 "vkGetDisplayModeProperties2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
1891
1892 // If the icd doesn't support VK_KHR_display, then no properties are available
1893 if (icd_term->dispatch.GetDisplayModePropertiesKHR == NULL) {
1894 *pPropertyCount = 0;
1895 return VK_SUCCESS;
1896 }
1897
1898 // If we aren't writing to pProperties, then emulation is straightforward
1899 if (pProperties == NULL || *pPropertyCount == 0) {
1900 return icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, NULL);
1901 }
1902
1903 // If we do have to write to pProperties, then we need to write to a temporary array of VkDisplayModePropertiesKHR and copy it
1904 VkDisplayModePropertiesKHR *properties = loader_stack_alloc(*pPropertyCount * sizeof(VkDisplayModePropertiesKHR));
1905 if (properties == NULL) {
1906 return VK_ERROR_OUT_OF_HOST_MEMORY;
1907 }
1908 VkResult res = icd_term->dispatch.GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, properties);
1909 if (res < 0) {
1910 return res;
1911 }
1912 for (uint32_t i = 0; i < *pPropertyCount; ++i) {
1913 memcpy(&pProperties[i].displayModeProperties, &properties[i], sizeof(VkDisplayModePropertiesKHR));
1914 }
1915 return res;
1916}
1917
1918LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice,
1919 const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
1920 VkDisplayPlaneCapabilities2KHR *pCapabilities) {
1921 const VkLayerInstanceDispatchTable *disp;
1922 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
1923 disp = loader_get_instance_layer_dispatch(physicalDevice);
1924 return disp->GetDisplayPlaneCapabilities2KHR(unwrapped_phys_dev, pDisplayPlaneInfo, pCapabilities);
1925}
1926
1927VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice,
1928 const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
1929 VkDisplayPlaneCapabilities2KHR *pCapabilities) {
1930 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
1931 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
1932
1933 // If the function is abailable in the driver, just call into it
1934 if (icd_term->dispatch.GetDisplayPlaneCapabilities2KHR != NULL) {
1935 return icd_term->dispatch.GetDisplayPlaneCapabilities2KHR(phys_dev_term->phys_dev, pDisplayPlaneInfo, pCapabilities);
1936 }
1937
1938 // We have to emulate the function.
1939 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
1940 "vkGetDisplayPlaneCapabilities2KHR: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
1941
1942 // Just call into the old version of the function.
1943 // If the icd doesn't support VK_KHR_display, there are zero planes and this call is invalid (and will crash)
1944 return icd_term->dispatch.GetDisplayPlaneCapabilitiesKHR(phys_dev_term->phys_dev, pDisplayPlaneInfo->mode,
1945 pDisplayPlaneInfo->planeIndex, &pCapabilities->capabilities);
1946}
1947
Craig Stoutf3b74dc2020-10-26 12:05:15 -07001948#ifdef VK_USE_PLATFORM_FUCHSIA
1949
1950// This is the trampoline entrypoint for CreateImagePipeSurfaceFUCHSIA
1951LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImagePipeSurfaceFUCHSIA(VkInstance instance,
1952 const VkImagePipeSurfaceCreateInfoFUCHSIA *pCreateInfo,
1953 const VkAllocationCallbacks *pAllocator,
1954 VkSurfaceKHR *pSurface) {
1955 const VkLayerInstanceDispatchTable *disp;
1956 disp = loader_get_instance_layer_dispatch(instance);
1957 VkResult res;
1958
1959 res = disp->CreateImagePipeSurfaceFUCHSIA(instance, pCreateInfo, pAllocator, pSurface);
1960 return res;
1961}
1962
1963// This is the instance chain terminator function for CreateImagePipeSurfaceFUCHSIA
1964VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateImagePipeSurfaceFUCHSIA(VkInstance instance,
1965 const VkImagePipeSurfaceCreateInfoFUCHSIA *pCreateInfo,
1966 const VkAllocationCallbacks *pAllocator,
1967 VkSurfaceKHR *pSurface) {
1968 VkResult vkRes = VK_SUCCESS;
1969 VkIcdSurface *pIcdSurface = NULL;
1970 uint32_t i = 0;
1971
1972 // Initialize pSurface to NULL just to be safe.
1973 *pSurface = VK_NULL_HANDLE;
1974 // First, check to ensure the appropriate extension was enabled:
1975 struct loader_instance *ptr_instance = loader_get_instance(instance);
1976 if (!ptr_instance->wsi_imagepipe_surface_enabled) {
1977 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1978 "VK_FUCHSIA_imagepipe_surface extension not enabled. "
1979 "vkCreateImagePipeSurfaceFUCHSIA not executed!\n");
1980 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1981 goto out;
1982 }
1983
1984 // Next, if so, proceed with the implementation of this function:
1985 pIcdSurface =
1986 AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->imagepipe_surf.base), sizeof(pIcdSurface->imagepipe_surf));
1987 if (pIcdSurface == NULL) {
1988 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1989 goto out;
1990 }
1991
1992 pIcdSurface->imagepipe_surf.base.platform = VK_ICD_WSI_PLATFORM_FUCHSIA;
1993
1994 // Loop through each ICD and determine if they need to create a surface
1995 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1996 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1997 if (NULL != icd_term->dispatch.CreateImagePipeSurfaceFUCHSIA) {
1998 vkRes = icd_term->dispatch.CreateImagePipeSurfaceFUCHSIA(icd_term->instance, pCreateInfo, pAllocator,
1999 &pIcdSurface->real_icd_surfaces[i]);
2000 if (VK_SUCCESS != vkRes) {
2001 goto out;
2002 }
2003 }
2004 }
2005 }
2006
2007 *pSurface = (VkSurfaceKHR)(pIcdSurface);
2008
2009out:
2010
2011 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
2012 if (NULL != pIcdSurface->real_icd_surfaces) {
2013 i = 0;
2014 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
2015 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) {
2016 icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
2017 }
2018 }
2019 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
2020 }
2021 loader_instance_heap_free(ptr_instance, pIcdSurface);
2022 }
2023
2024 return vkRes;
2025}
2026#endif // VK_USE_PLATFORM_FUCHSIA
2027
Joshua Ashton03cc64b2020-03-12 04:42:26 +00002028LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
2029vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
2030 VkSurfaceCapabilities2KHR *pSurfaceCapabilities) {
2031 const VkLayerInstanceDispatchTable *disp;
2032 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
2033 disp = loader_get_instance_layer_dispatch(physicalDevice);
2034 return disp->GetPhysicalDeviceSurfaceCapabilities2KHR(unwrapped_phys_dev, pSurfaceInfo, pSurfaceCapabilities);
2035}
2036
2037VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilities2KHR(
2038 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
2039 VkSurfaceCapabilities2KHR *pSurfaceCapabilities) {
2040 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
2041 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Joshua Ashton64c36932020-03-12 22:57:49 +00002042 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
2043
2044 if (!ptr_instance->wsi_surface_enabled) {
2045 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
2046 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceCapabilities2KHR not executed!\n");
2047 return VK_SUCCESS;
2048 }
Joshua Ashton03cc64b2020-03-12 04:42:26 +00002049
2050 VkIcdSurface *icd_surface = (VkIcdSurface *)(pSurfaceInfo->surface);
2051 uint8_t icd_index = phys_dev_term->icd_index;
2052
2053 if (icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR != NULL) {
2054 VkBaseOutStructure *pNext = (VkBaseOutStructure *)pSurfaceCapabilities->pNext;
2055 while (pNext != NULL) {
2056 if ((int)pNext->sType == VK_STRUCTURE_TYPE_SURFACE_PROTECTED_CAPABILITIES_KHR) {
2057 // Not all ICDs may be supporting VK_KHR_surface_protected_capabilities
2058 // Initialize VkSurfaceProtectedCapabilitiesKHR.supportsProtected to false and
2059 // if an ICD supports protected surfaces, it will reset it to true accordingly.
2060 ((VkSurfaceProtectedCapabilitiesKHR *)pNext)->supportsProtected = VK_FALSE;
2061 }
2062 pNext = (VkBaseOutStructure *)pNext->pNext;
2063 }
2064
2065 // Pass the call to the driver, possibly unwrapping the ICD surface
2066 if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
2067 VkPhysicalDeviceSurfaceInfo2KHR info_copy = *pSurfaceInfo;
2068 info_copy.surface = icd_surface->real_icd_surfaces[icd_index];
2069 return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev_term->phys_dev, &info_copy,
2070 pSurfaceCapabilities);
2071 } else {
2072 return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev_term->phys_dev, pSurfaceInfo,
2073 pSurfaceCapabilities);
2074 }
2075 } else {
2076 // Emulate the call
2077 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
2078 "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulating call in ICD \"%s\" using "
2079 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
2080 icd_term->scanned_icd->lib_name);
2081
2082 if (pSurfaceInfo->pNext != NULL) {
2083 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
2084 "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulation found unrecognized structure type in "
2085 "pSurfaceInfo->pNext - this struct will be ignored");
2086 }
2087
2088 // Write to the VkSurfaceCapabilities2KHR struct
2089 VkSurfaceKHR surface = pSurfaceInfo->surface;
2090 if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
2091 surface = icd_surface->real_icd_surfaces[icd_index];
2092 }
2093 VkResult res = icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev_term->phys_dev, surface,
2094 &pSurfaceCapabilities->surfaceCapabilities);
2095
2096 if (pSurfaceCapabilities->pNext != NULL) {
2097 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
2098 "vkGetPhysicalDeviceSurfaceCapabilities2KHR: Emulation found unrecognized structure type in "
2099 "pSurfaceCapabilities->pNext - this struct will be ignored");
2100 }
2101 return res;
2102 }
2103}
2104
2105LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
2106vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
2107 uint32_t *pSurfaceFormatCount, VkSurfaceFormat2KHR *pSurfaceFormats) {
2108 const VkLayerInstanceDispatchTable *disp;
2109 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
2110 disp = loader_get_instance_layer_dispatch(physicalDevice);
2111 return disp->GetPhysicalDeviceSurfaceFormats2KHR(unwrapped_phys_dev, pSurfaceInfo, pSurfaceFormatCount, pSurfaceFormats);
2112}
2113
2114VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
2115 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
2116 uint32_t *pSurfaceFormatCount,
2117 VkSurfaceFormat2KHR *pSurfaceFormats) {
2118 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
2119 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Joshua Ashton64c36932020-03-12 22:57:49 +00002120 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
2121
2122 if (!ptr_instance->wsi_surface_enabled) {
2123 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
2124 "VK_KHR_surface extension not enabled. vkGetPhysicalDeviceSurfaceFormats2KHR not executed!\n");
2125 return VK_SUCCESS;
2126 }
Joshua Ashton03cc64b2020-03-12 04:42:26 +00002127
2128 VkIcdSurface *icd_surface = (VkIcdSurface *)(pSurfaceInfo->surface);
2129 uint8_t icd_index = phys_dev_term->icd_index;
2130
2131 if (icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR != NULL) {
2132 // Pass the call to the driver, possibly unwrapping the ICD surface
2133 if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
2134 VkPhysicalDeviceSurfaceInfo2KHR info_copy = *pSurfaceInfo;
2135 info_copy.surface = icd_surface->real_icd_surfaces[icd_index];
2136 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR(phys_dev_term->phys_dev, &info_copy, pSurfaceFormatCount,
2137 pSurfaceFormats);
2138 } else {
2139 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormats2KHR(phys_dev_term->phys_dev, pSurfaceInfo,
2140 pSurfaceFormatCount, pSurfaceFormats);
2141 }
2142 } else {
2143 // Emulate the call
2144 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
2145 "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceSurfaceFormatsKHR",
2146 icd_term->scanned_icd->lib_name);
2147
2148 if (pSurfaceInfo->pNext != NULL) {
2149 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
2150 "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulation found unrecognized structure type in pSurfaceInfo->pNext "
2151 "- this struct will be ignored");
2152 }
2153
2154 VkSurfaceKHR surface = pSurfaceInfo->surface;
2155 if (icd_surface->real_icd_surfaces != NULL && (void *)icd_surface->real_icd_surfaces[icd_index] != NULL) {
2156 surface = icd_surface->real_icd_surfaces[icd_index];
2157 }
2158
2159 if (*pSurfaceFormatCount == 0 || pSurfaceFormats == NULL) {
2160 // Write to pSurfaceFormatCount
2161 return icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface, pSurfaceFormatCount,
2162 NULL);
2163 } else {
2164 // Allocate a temporary array for the output of the old function
2165 VkSurfaceFormatKHR *formats = loader_stack_alloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR));
2166 if (formats == NULL) {
2167 return VK_ERROR_OUT_OF_HOST_MEMORY;
2168 }
2169
2170 VkResult res = icd_term->dispatch.GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface,
2171 pSurfaceFormatCount, formats);
2172 for (uint32_t i = 0; i < *pSurfaceFormatCount; ++i) {
2173 pSurfaceFormats[i].surfaceFormat = formats[i];
2174 if (pSurfaceFormats[i].pNext != NULL) {
2175 loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0,
2176 "vkGetPhysicalDeviceSurfaceFormats2KHR: Emulation found unrecognized structure type in "
2177 "pSurfaceFormats[%d].pNext - this struct will be ignored",
2178 i);
2179 }
2180 }
2181 return res;
2182 }
2183 }
2184}
2185
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002186bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance, const char *name, void **addr) {
Ian Elliott54cea232015-10-30 15:28:23 -06002187 *addr = NULL;
2188
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002189 // Functions for the VK_KHR_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07002190 if (!strcmp("vkDestroySurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002191 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkDestroySurfaceKHR : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07002192 return true;
2193 }
Ian Elliott54cea232015-10-30 15:28:23 -06002194 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002195 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceSupportKHR : NULL;
Ian Elliott54cea232015-10-30 15:28:23 -06002196 return true;
2197 }
Ian Elliottea666b22015-11-19 16:05:09 -07002198 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002199 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceCapabilitiesKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07002200 return true;
2201 }
2202 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002203 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceFormatsKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07002204 return true;
2205 }
2206 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002207 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfacePresentModesKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07002208 return true;
2209 }
Ian Elliott9b89a472015-11-19 16:39:21 -07002210
Lenny Komowdbaaad62017-10-02 15:08:53 -06002211 if (!strcmp("vkGetDeviceGroupPresentCapabilitiesKHR", name)) {
2212 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetDeviceGroupPresentCapabilitiesKHR : NULL;
2213 return true;
2214 }
2215
2216 if (!strcmp("vkGetDeviceGroupSurfacePresentModesKHR", name)) {
2217 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetDeviceGroupSurfacePresentModesKHR : NULL;
2218 return true;
2219 }
2220
2221 if (!strcmp("vkGetPhysicalDevicePresentRectanglesKHR", name)) {
2222 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDevicePresentRectanglesKHR : NULL;
2223 return true;
2224 }
2225
Joshua Ashton03cc64b2020-03-12 04:42:26 +00002226 // Functions for VK_KHR_get_surface_capabilities2 extension:
2227 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilities2KHR", name)) {
2228 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceCapabilities2KHR : NULL;
2229 return true;
2230 }
2231
2232 if (!strcmp("vkGetPhysicalDeviceSurfaceFormats2KHR", name)) {
2233 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceFormats2KHR : NULL;
2234 return true;
2235 }
2236
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002237 // Functions for the VK_KHR_swapchain extension:
2238
2239 // Note: This is a device extension, and its functions are statically
2240 // exported from the loader. Per Khronos decisions, the loader's GIPA
2241 // function will return the trampoline function for such device-extension
2242 // functions, regardless of whether the extension has been enabled.
Ian Elliott9b89a472015-11-19 16:39:21 -07002243 if (!strcmp("vkCreateSwapchainKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002244 *addr = (void *)vkCreateSwapchainKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002245 return true;
2246 }
2247 if (!strcmp("vkDestroySwapchainKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002248 *addr = (void *)vkDestroySwapchainKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002249 return true;
2250 }
2251 if (!strcmp("vkGetSwapchainImagesKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002252 *addr = (void *)vkGetSwapchainImagesKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002253 return true;
2254 }
2255 if (!strcmp("vkAcquireNextImageKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002256 *addr = (void *)vkAcquireNextImageKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002257 return true;
2258 }
2259 if (!strcmp("vkQueuePresentKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002260 *addr = (void *)vkQueuePresentKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07002261 return true;
2262 }
Lenny Komowdbaaad62017-10-02 15:08:53 -06002263 if (!strcmp("vkAcquireNextImage2KHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002264 *addr = (void *)vkAcquireNextImage2KHR;
Lenny Komowdbaaad62017-10-02 15:08:53 -06002265 return true;
2266 }
Ian Elliott9b89a472015-11-19 16:39:21 -07002267
Ian Elliott7c352552015-11-19 13:14:05 -07002268#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002269
2270 // Functions for the VK_KHR_win32_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07002271 if (!strcmp("vkCreateWin32SurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002272 *addr = ptr_instance->wsi_win32_surface_enabled ? (void *)vkCreateWin32SurfaceKHR : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07002273 return true;
2274 }
Ian Elliotte851dd62015-11-24 15:39:10 -07002275 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002276 *addr = ptr_instance->wsi_win32_surface_enabled ? (void *)vkGetPhysicalDeviceWin32PresentationSupportKHR : NULL;
Ian Elliotte851dd62015-11-24 15:39:10 -07002277 return true;
2278 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002279#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07002280#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002281
2282 // Functions for the VK_KHR_wayland_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002283 if (!strcmp("vkCreateWaylandSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002284 *addr = ptr_instance->wsi_wayland_surface_enabled ? (void *)vkCreateWaylandSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002285 return true;
2286 }
2287 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002288 *addr = ptr_instance->wsi_wayland_surface_enabled ? (void *)vkGetPhysicalDeviceWaylandPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002289 return true;
2290 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002291#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07002292#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002293
2294 // Functions for the VK_KHR_xcb_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002295 if (!strcmp("vkCreateXcbSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002296 *addr = ptr_instance->wsi_xcb_surface_enabled ? (void *)vkCreateXcbSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002297 return true;
2298 }
2299 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002300 *addr = ptr_instance->wsi_xcb_surface_enabled ? (void *)vkGetPhysicalDeviceXcbPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002301 return true;
2302 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002303#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07002304#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002305
2306 // Functions for the VK_KHR_xlib_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002307 if (!strcmp("vkCreateXlibSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002308 *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkCreateXlibSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002309 return true;
2310 }
2311 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002312 *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkGetPhysicalDeviceXlibPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002313 return true;
2314 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002315#endif // VK_USE_PLATFORM_XLIB_KHR
Nicolas Caramellifa696ca2020-07-04 22:53:59 +02002316#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
2317
2318 // Functions for the VK_EXT_directfb_surface extension:
2319 if (!strcmp("vkCreateDirectFBSurfaceEXT", name)) {
2320 *addr = ptr_instance->wsi_directfb_surface_enabled ? (void *)vkCreateDirectFBSurfaceEXT : NULL;
2321 return true;
2322 }
2323 if (!strcmp("vkGetPhysicalDeviceDirectFBPresentationSupportEXT", name)) {
2324 *addr = ptr_instance->wsi_directfb_surface_enabled ? (void *)vkGetPhysicalDeviceDirectFBPresentationSupportEXT : NULL;
2325 return true;
2326 }
2327#endif // VK_USE_PLATFORM_DIRECTFB_EXT
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07002328#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002329
2330 // Functions for the VK_KHR_android_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002331 if (!strcmp("vkCreateAndroidSurfaceKHR", name)) {
Karl Schultzd81ebfb2017-12-12 10:33:01 -05002332 *addr = ptr_instance->wsi_android_surface_enabled ? (void *)vkCreateAndroidSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002333 return true;
2334 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07002335#endif // VK_USE_PLATFORM_ANDROID_KHR
Bryan Law-Smith57305692019-04-01 09:45:55 +01002336
Karl Schultzd81ebfb2017-12-12 10:33:01 -05002337#ifdef VK_USE_PLATFORM_MACOS_MVK
2338
2339 // Functions for the VK_MVK_macos_surface extension:
2340 if (!strcmp("vkCreateMacOSSurfaceMVK", name)) {
2341 *addr = ptr_instance->wsi_macos_surface_enabled ? (void *)vkCreateMacOSSurfaceMVK : NULL;
2342 return true;
2343 }
2344#endif // VK_USE_PLATFORM_MACOS_MVK
2345#ifdef VK_USE_PLATFORM_IOS_MVK
2346
2347 // Functions for the VK_MVK_ios_surface extension:
2348 if (!strcmp("vkCreateIOSSurfaceMVK", name)) {
2349 *addr = ptr_instance->wsi_ios_surface_enabled ? (void *)vkCreateIOSSurfaceMVK : NULL;
2350 return true;
2351 }
2352#endif // VK_USE_PLATFORM_IOS_MVK
Craig Stoutf3b74dc2020-10-26 12:05:15 -07002353#ifdef VK_USE_PLATFORM_FUCHSIA
2354
2355 // Functions for the VK_FUCHSIA_imagepipe_surface extension:
2356 if (!strcmp("vkCreateImagePipeSurfaceFUCHSIA", name)) {
2357 *addr = ptr_instance->wsi_imagepipe_surface_enabled ? (void *)vkCreateImagePipeSurfaceFUCHSIA : NULL;
2358 return true;
2359 }
2360
2361#endif // VK_USE_PLATFORM_FUCHSIA
Ian Elliott7c352552015-11-19 13:14:05 -07002362
Bryan Law-Smith57305692019-04-01 09:45:55 +01002363 // Functions for the VK_EXT_headless_surface extension:
2364 if (!strcmp("vkCreateHeadlessSurfaceEXT", name)) {
2365 *addr = ptr_instance->wsi_headless_surface_enabled ? (void *)vkCreateHeadlessSurfaceEXT : NULL;
2366 return true;
2367 }
2368
Lenny Komowa1b5e442019-09-16 16:14:36 -06002369#if defined(VK_USE_PLATFORM_METAL_EXT)
2370 // Functions for the VK_MVK_macos_surface extension:
2371 if (!strcmp("vkCreateMetalSurfaceEXT", name)) {
2372 *addr = ptr_instance->wsi_metal_surface_enabled ? (void *)vkCreateMetalSurfaceEXT : NULL;
2373 return true;
2374 }
2375#endif // VK_USE_PLATFORM_METAL_EXT
2376
Mark Lobodzinskib16da052016-08-31 09:31:29 -06002377 // Functions for VK_KHR_display extension:
Jon Ashburncc370d02016-03-08 09:30:30 -07002378 if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002379 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002380 return true;
2381 }
2382 if (!strcmp("vkGetPhysicalDeviceDisplayPlanePropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002383 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPlanePropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002384 return true;
2385 }
2386 if (!strcmp("vkGetDisplayPlaneSupportedDisplaysKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002387 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayPlaneSupportedDisplaysKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002388 return true;
2389 }
2390 if (!strcmp("vkGetDisplayModePropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002391 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayModePropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002392 return true;
2393 }
2394 if (!strcmp("vkCreateDisplayModeKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002395 *addr = ptr_instance->wsi_display_enabled ? (void *)vkCreateDisplayModeKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002396 return true;
2397 }
2398 if (!strcmp("vkGetDisplayPlaneCapabilitiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002399 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayPlaneCapabilitiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002400 return true;
2401 }
2402 if (!strcmp("vkCreateDisplayPlaneSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07002403 *addr = ptr_instance->wsi_display_enabled ? (void *)vkCreateDisplayPlaneSurfaceKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07002404 return true;
2405 }
Mark Youngf2eabea2016-07-01 15:18:27 -06002406
2407 // Functions for KHR_display_swapchain extension:
2408 if (!strcmp("vkCreateSharedSwapchainsKHR", name)) {
Lenny Komowf1872d82018-02-23 11:28:38 -07002409 *addr = (void *)vkCreateSharedSwapchainsKHR;
Mark Youngf2eabea2016-07-01 15:18:27 -06002410 return true;
2411 }
2412
Lenny Komow61139782018-05-31 11:32:31 -06002413 // Functions for KHR_get_display_properties2
2414 if (!strcmp("vkGetPhysicalDeviceDisplayProperties2KHR", name)) {
2415 *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetPhysicalDeviceDisplayProperties2KHR : NULL;
2416 return true;
2417 }
2418 if (!strcmp("vkGetPhysicalDeviceDisplayPlaneProperties2KHR", name)) {
2419 *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetPhysicalDeviceDisplayPlaneProperties2KHR : NULL;
2420 return true;
2421 }
2422 if (!strcmp("vkGetDisplayModeProperties2KHR", name)) {
2423 *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetDisplayModeProperties2KHR : NULL;
2424 return true;
2425 }
2426 if (!strcmp("vkGetDisplayPlaneCapabilities2KHR", name)) {
2427 *addr = ptr_instance->wsi_display_props2_enabled ? (void *)vkGetDisplayPlaneCapabilities2KHR : NULL;
2428 return true;
2429 }
2430
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07002431 return false;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06002432}