blob: 257e1141c454b147950195728aac3b70a8d80e9d [file] [log] [blame]
Ian Elliott54cea232015-10-30 15:28:23 -06001/*
Jon Ashburn1c75aec2016-02-02 17:47:28 -07002 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 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>
Ian Elliott54cea232015-10-30 15:28:23 -060022 */
23
Ian Elliott54cea232015-10-30 15:28:23 -060024#define _GNU_SOURCE
Ian Elliott0d4ffa32016-03-24 13:59:22 -060025#include <stdio.h>
Ian Elliott54cea232015-10-30 15:28:23 -060026#include <stdlib.h>
27#include <string.h>
28#include "vk_loader_platform.h"
29#include "loader.h"
30#include "wsi.h"
Ian Elliott7c352552015-11-19 13:14:05 -070031#include <vulkan/vk_icd.h>
Ian Elliott54cea232015-10-30 15:28:23 -060032
Mark Young5467d672016-06-28 10:52:43 -060033// The first ICD/Loader interface that support querying the SurfaceKHR from
34// the ICDs.
35#define ICD_VER_SUPPORTS_ICD_SURFACE_KHR 3
36
Mark Lobodzinski91c10752017-01-26 12:16:30 -070037void wsi_create_instance(struct loader_instance *ptr_instance, const VkInstanceCreateInfo *pCreateInfo) {
Ian Elliott5fb891a2015-10-30 17:45:05 -060038 ptr_instance->wsi_surface_enabled = false;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070039
40#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburncc370d02016-03-08 09:30:30 -070041 ptr_instance->wsi_win32_surface_enabled = false;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070042#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070043#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060044 ptr_instance->wsi_mir_surface_enabled = false;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070045#endif // VK_USE_PLATFORM_MIR_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
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070055#ifdef VK_USE_PLATFORM_ANDROID_KHR
56 ptr_instance->wsi_android_surface_enabled = false;
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070057#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060058
Jon Ashburncc370d02016-03-08 09:30:30 -070059 ptr_instance->wsi_display_enabled = false;
60
Jon Ashburna0673ab2016-01-11 13:12:43 -070061 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -070062 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060063 ptr_instance->wsi_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070064 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060065 }
Ian Elliottb1849742015-11-19 11:58:08 -070066#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070067 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott1693f592015-11-23 10:17:23 -070068 ptr_instance->wsi_win32_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070069 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060070 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070071#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060072#ifdef VK_USE_PLATFORM_MIR_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070073 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060074 ptr_instance->wsi_mir_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070075 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060076 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070077#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060078#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070079 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060080 ptr_instance->wsi_wayland_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070081 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060082 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070083#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060084#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070085 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060086 ptr_instance->wsi_xcb_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070087 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060088 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070089#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060090#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070091 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060092 ptr_instance->wsi_xlib_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070093 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060094 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -070095#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070096#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -070097 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070098 ptr_instance->wsi_android_surface_enabled = true;
99 continue;
100 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700101#endif // VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700102 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) {
Jon Ashburncc370d02016-03-08 09:30:30 -0700103 ptr_instance->wsi_display_enabled = true;
104 continue;
105 }
Ian Elliott54cea232015-10-30 15:28:23 -0600106 }
107}
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600108
109// Linux WSI surface extensions are not always compiled into the loader. (Assume
110// for Windows the KHR_win32_surface is always compiled into loader). A given
111// Linux build environment might not have the headers required for building one
112// of the four extensions (Xlib, Xcb, Mir, Wayland). Thus, need to check if
113// the built loader actually supports the particular Linux surface extension.
114// If not supported by the built loader it will not be included in the list of
115// enumerated instance extensions. This solves the issue where an ICD or layer
116// advertises support for a given Linux surface extension but the loader was not
117// built to support the extension.
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600118bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop) {
119#ifndef VK_USE_PLATFORM_MIR_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700120 if (!strcmp(ext_prop->extensionName, "VK_KHR_mir_surface")) return true;
121#endif // VK_USE_PLATFORM_MIR_KHR
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600122#ifndef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700123 if (!strcmp(ext_prop->extensionName, "VK_KHR_wayland_surface")) return true;
124#endif // VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600125#ifndef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700126 if (!strcmp(ext_prop->extensionName, "VK_KHR_xcb_surface")) return true;
127#endif // VK_USE_PLATFORM_XCB_KHR
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600128#ifndef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700129 if (!strcmp(ext_prop->extensionName, "VK_KHR_xlib_surface")) return true;
130#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600131
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600132 return false;
133}
Ian Elliott7c352552015-11-19 13:14:05 -0700134
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600135// Functions for the VK_KHR_surface extension:
136
137// This is the trampoline entrypoint for DestroySurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700138LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
139 const VkAllocationCallbacks *pAllocator) {
Ian Elliottabf50662015-11-25 14:43:02 -0700140 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700141 disp = loader_get_instance_layer_dispatch(instance);
Ian Elliottabf50662015-11-25 14:43:02 -0700142 disp->DestroySurfaceKHR(instance, surface, pAllocator);
143}
144
Jon Ashburncc370d02016-03-08 09:30:30 -0700145// TODO probably need to lock around all the loader_get_instance() calls.
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600146
147// This is the instance chain terminator function for DestroySurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700148VKAPI_ATTR void VKAPI_CALL terminator_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
149 const VkAllocationCallbacks *pAllocator) {
Ian Elliott1693f592015-11-23 10:17:23 -0700150 struct loader_instance *ptr_instance = loader_get_instance(instance);
151
Karl Schultza9e989f2016-11-19 09:02:27 -0700152 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young11e9d472016-10-17 12:27:36 -0600153 if (NULL != icd_surface) {
154 if (NULL != icd_surface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600155 uint32_t i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700156 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
157 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
158 if (NULL != icd_term->DestroySurfaceKHR && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[i]) {
159 icd_term->DestroySurfaceKHR(icd_term->instance, icd_surface->real_icd_surfaces[i], pAllocator);
Mark Young3eda5882016-12-01 10:42:21 -0700160 icd_surface->real_icd_surfaces[i] = (VkSurfaceKHR)NULL;
Mark Young11e9d472016-10-17 12:27:36 -0600161 }
162 } else {
163 // The real_icd_surface for any ICD not supporting the
164 // proper interface version should be NULL. If not, then
165 // we have a problem.
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700166 assert((VkSurfaceKHR)NULL == icd_surface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600167 }
Mark Young5467d672016-06-28 10:52:43 -0600168 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700169 loader_instance_heap_free(ptr_instance, icd_surface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600170 }
Mark Young5467d672016-06-28 10:52:43 -0600171
Karl Schultza9e989f2016-11-19 09:02:27 -0700172 loader_instance_heap_free(ptr_instance, (void *)(uintptr_t)surface);
Mark Young11e9d472016-10-17 12:27:36 -0600173 }
Ian Elliott7c352552015-11-19 13:14:05 -0700174}
175
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600176// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700177LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
178 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
179 VkBool32 *pSupported) {
Ian Elliott54cea232015-10-30 15:28:23 -0600180 const VkLayerInstanceDispatchTable *disp;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700181 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Mark Young274e4bc2017-01-19 21:10:49 -0700182 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700183 VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott54cea232015-10-30 15:28:23 -0600184 return res;
185}
186
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600187// This is the instance chain terminator function for
188// GetPhysicalDeviceSurfaceSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700189VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
190 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
191 VkBool32 *pSupported) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600192 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700193 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600194 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700195 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600196 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700197 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
198 "VK_KHR_VK_KHR_surface extension not enabled. "
199 "vkGetPhysicalDeviceSurfaceSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600200 return VK_SUCCESS;
201 }
202
203 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700204 assert(pSupported && "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
Ian Elliott54cea232015-10-30 15:28:23 -0600205 *pSupported = false;
206
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700207 assert(icd_term->GetPhysicalDeviceSurfaceSupportKHR && "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
Ian Elliott54cea232015-10-30 15:28:23 -0600208
Karl Schultza9e989f2016-11-19 09:02:27 -0700209 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700210 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
211 return icd_term->GetPhysicalDeviceSurfaceSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex,
212 icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pSupported);
Mark Young5467d672016-06-28 10:52:43 -0600213 }
Mark Young5467d672016-06-28 10:52:43 -0600214
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700215 return icd_term->GetPhysicalDeviceSurfaceSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott54cea232015-10-30 15:28:23 -0600216}
217
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600218// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceCapabilitiesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700219LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
220 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Ian Elliottea666b22015-11-19 16:05:09 -0700221 const VkLayerInstanceDispatchTable *disp;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700222 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Mark Young274e4bc2017-01-19 21:10:49 -0700223 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700224 VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(unwrapped_phys_dev, surface, pSurfaceCapabilities);
Ian Elliottea666b22015-11-19 16:05:09 -0700225 return res;
226}
227
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600228// This is the instance chain terminator function for
229// GetPhysicalDeviceSurfaceCapabilitiesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700230VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
231 VkSurfaceKHR surface,
232 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600233 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700234 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600235 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700236 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600237 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700238 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
239 "VK_KHR_surface extension not enabled. "
240 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600241 return VK_SUCCESS;
242 }
243
244 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700245 assert(pSurfaceCapabilities &&
246 "GetPhysicalDeviceSurfaceCapabilitiesKHR: "
247 "Error, null pSurfaceCapabilities");
Ian Elliottea666b22015-11-19 16:05:09 -0700248
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700249 assert(icd_term->GetPhysicalDeviceSurfaceCapabilitiesKHR && "loader: null GetPhysicalDeviceSurfaceCapabilitiesKHR ICD pointer");
Ian Elliottea666b22015-11-19 16:05:09 -0700250
Karl Schultza9e989f2016-11-19 09:02:27 -0700251 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700252 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young26c19372016-11-03 14:27:13 -0600253 return icd_term->GetPhysicalDeviceSurfaceCapabilitiesKHR(
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700254 phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pSurfaceCapabilities);
Mark Young5467d672016-06-28 10:52:43 -0600255 }
Mark Young5467d672016-06-28 10:52:43 -0600256
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700257 return icd_term->GetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev_term->phys_dev, surface, pSurfaceCapabilities);
Ian Elliottea666b22015-11-19 16:05:09 -0700258}
259
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600260// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceFormatsKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700261LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
262 VkSurfaceKHR surface,
263 uint32_t *pSurfaceFormatCount,
264 VkSurfaceFormatKHR *pSurfaceFormats) {
265 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700266 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700267 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700268 VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliottea666b22015-11-19 16:05:09 -0700269 return res;
270}
271
Mark Young573a7a12016-11-02 09:37:08 -0600272// This is the instance chain terminator function for
273// GetPhysicalDeviceSurfaceFormatsKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700274VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
275 uint32_t *pSurfaceFormatCount,
276 VkSurfaceFormatKHR *pSurfaceFormats) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600277 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700278 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600279 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700280 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600281 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700282 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
283 "VK_KHR_surface extension not enabled. "
284 "vkGetPhysicalDeviceSurfaceFormatsKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600285 return VK_SUCCESS;
286 }
287
288 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700289 assert(pSurfaceFormatCount && "GetPhysicalDeviceSurfaceFormatsKHR: Error, null pSurfaceFormatCount");
Ian Elliottea666b22015-11-19 16:05:09 -0700290
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700291 assert(icd_term->GetPhysicalDeviceSurfaceFormatsKHR && "loader: null GetPhysicalDeviceSurfaceFormatsKHR ICD pointer");
Ian Elliottea666b22015-11-19 16:05:09 -0700292
Karl Schultza9e989f2016-11-19 09:02:27 -0700293 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700294 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
295 return icd_term->GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev,
296 icd_surface->real_icd_surfaces[phys_dev_term->icd_index],
297 pSurfaceFormatCount, pSurfaceFormats);
Mark Young5467d672016-06-28 10:52:43 -0600298 }
Mark Young5467d672016-06-28 10:52:43 -0600299
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700300 return icd_term->GetPhysicalDeviceSurfaceFormatsKHR(phys_dev_term->phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliottea666b22015-11-19 16:05:09 -0700301}
302
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600303// This is the trampoline entrypoint for GetPhysicalDeviceSurfacePresentModesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700304LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
305 VkSurfaceKHR surface,
306 uint32_t *pPresentModeCount,
307 VkPresentModeKHR *pPresentModes) {
308 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700309 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700310 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700311 VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliottea666b22015-11-19 16:05:09 -0700312 return res;
313}
314
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600315// This is the instance chain terminator function for
316// GetPhysicalDeviceSurfacePresentModesKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700317VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
318 VkSurfaceKHR surface, uint32_t *pPresentModeCount,
319 VkPresentModeKHR *pPresentModes) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600320 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700321 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600322 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700323 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600324 if (!ptr_instance->wsi_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700325 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
326 "VK_KHR_surface extension not enabled. "
327 "vkGetPhysicalDeviceSurfacePresentModesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600328 return VK_SUCCESS;
329 }
330
331 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700332 assert(pPresentModeCount &&
333 "GetPhysicalDeviceSurfacePresentModesKHR: "
334 "Error, null pPresentModeCount");
Ian Elliottea666b22015-11-19 16:05:09 -0700335
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700336 assert(icd_term->GetPhysicalDeviceSurfacePresentModesKHR && "loader: null GetPhysicalDeviceSurfacePresentModesKHR ICD pointer");
Ian Elliottea666b22015-11-19 16:05:09 -0700337
Karl Schultza9e989f2016-11-19 09:02:27 -0700338 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700339 if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young26c19372016-11-03 14:27:13 -0600340 return icd_term->GetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700341 phys_dev_term->phys_dev, icd_surface->real_icd_surfaces[phys_dev_term->icd_index], pPresentModeCount, pPresentModes);
Mark Young5467d672016-06-28 10:52:43 -0600342 }
Mark Young5467d672016-06-28 10:52:43 -0600343
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700344 return icd_term->GetPhysicalDeviceSurfacePresentModesKHR(phys_dev_term->phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliottea666b22015-11-19 16:05:09 -0700345}
346
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600347// Functions for the VK_KHR_swapchain extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700348
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600349// This is the trampoline entrypoint for CreateSwapchainKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700350LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
351 const VkAllocationCallbacks *pAllocator,
352 VkSwapchainKHR *pSwapchain) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700353 const VkLayerDispatchTable *disp;
354 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700355 return disp->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Ian Elliott9b89a472015-11-19 16:39:21 -0700356}
Ian Elliott7c352552015-11-19 13:14:05 -0700357
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700358VKAPI_ATTR VkResult VKAPI_CALL terminator_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
359 const VkAllocationCallbacks *pAllocator,
360 VkSwapchainKHR *pSwapchain) {
Mark Young5467d672016-06-28 10:52:43 -0600361 uint32_t icd_index = 0;
362 struct loader_device *dev;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700363 struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
Mark Young26c19372016-11-03 14:27:13 -0600364 if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700365 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pCreateInfo->surface;
Mark Young5467d672016-06-28 10:52:43 -0600366 if (NULL != icd_surface->real_icd_surfaces) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700367 if ((VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
Mark Young5467d672016-06-28 10:52:43 -0600368 // We found the ICD, and there is an ICD KHR surface
369 // associated with it, so copy the CreateInfo struct
370 // and point it at the ICD's surface.
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700371 VkSwapchainCreateInfoKHR *pCreateCopy = loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR));
Mark Young5467d672016-06-28 10:52:43 -0600372 if (NULL == pCreateCopy) {
373 return VK_ERROR_OUT_OF_HOST_MEMORY;
374 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700375 memcpy(pCreateCopy, pCreateInfo, sizeof(VkSwapchainCreateInfoKHR));
376 pCreateCopy->surface = icd_surface->real_icd_surfaces[icd_index];
377 return icd_term->CreateSwapchainKHR(device, pCreateCopy, pAllocator, pSwapchain);
Mark Young5467d672016-06-28 10:52:43 -0600378 }
379 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700380 return icd_term->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Mark Young5467d672016-06-28 10:52:43 -0600381 }
382 return VK_SUCCESS;
383}
384
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600385// This is the trampoline entrypoint for DestroySwapchainKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700386LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
387 const VkAllocationCallbacks *pAllocator) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700388 const VkLayerDispatchTable *disp;
389 disp = loader_get_dispatch(device);
390 disp->DestroySwapchainKHR(device, swapchain, pAllocator);
391}
Ian Elliott7c352552015-11-19 13:14:05 -0700392
Mark Young5467d672016-06-28 10:52:43 -0600393/*
394 * This is the trampoline entrypoint
395 * for GetSwapchainImagesKHR
396 */
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700397LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
398 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700399 const VkLayerDispatchTable *disp;
400 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700401 return disp->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
Ian Elliott9b89a472015-11-19 16:39:21 -0700402}
403
Mark Young5467d672016-06-28 10:52:43 -0600404/*
405 * This is the trampoline entrypoint
406 * for AcquireNextImageKHR
407 */
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700408LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
409 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700410 const VkLayerDispatchTable *disp;
411 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700412 return disp->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
Ian Elliott9b89a472015-11-19 16:39:21 -0700413}
414
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600415// This is the trampoline entrypoint for QueuePresentKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700416LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700417 const VkLayerDispatchTable *disp;
418 disp = loader_get_dispatch(queue);
Mark Young76b3fe02016-09-08 12:28:38 -0600419 return disp->QueuePresentKHR(queue, pPresentInfo);
Ian Elliott9b89a472015-11-19 16:39:21 -0700420}
Ian Elliott7c352552015-11-19 13:14:05 -0700421
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700422static VkIcdSurface *AllocateIcdSurfaceStruct(struct loader_instance *instance, size_t base_size, size_t platform_size) {
Mark Youngf27962c2016-09-16 10:18:42 -0600423 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700424 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Youngf27962c2016-09-16 10:18:42 -0600425 if (pIcdSurface != NULL) {
426 // Setup the new sizes and offsets so we can grow the structures in the
427 // future without having problems
428 pIcdSurface->base_size = (uint32_t)base_size;
429 pIcdSurface->platform_size = (uint32_t)platform_size;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700430 pIcdSurface->non_platform_offset = (uint32_t)((uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
Mark Youngf27962c2016-09-16 10:18:42 -0600431 pIcdSurface->entire_size = sizeof(VkIcdSurface);
432
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700433 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(instance, sizeof(VkSurfaceKHR) * instance->total_icd_count,
434 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Young5117fdc2016-12-13 17:19:32 -0700435 if (pIcdSurface->real_icd_surfaces == NULL) {
436 loader_instance_heap_free(instance, pIcdSurface);
437 pIcdSurface = NULL;
Mark Youngf27962c2016-09-16 10:18:42 -0600438 } else {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700439 memset(pIcdSurface->real_icd_surfaces, 0, sizeof(VkSurfaceKHR) * instance->total_icd_count);
Mark Youngf27962c2016-09-16 10:18:42 -0600440 }
441 }
442 return pIcdSurface;
443}
444
Ian Elliott7c352552015-11-19 13:14:05 -0700445#ifdef VK_USE_PLATFORM_WIN32_KHR
446
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600447// Functions for the VK_KHR_win32_surface extension:
448
449// This is the trampoline entrypoint for CreateWin32SurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700450LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance,
451 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
452 const VkAllocationCallbacks *pAllocator,
453 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700454 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700455 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700456 VkResult res;
457
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700458 res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700459 return res;
460}
461
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600462// This is the instance chain terminator function for CreateWin32SurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700463VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
464 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600465 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600466 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600467 uint32_t i = 0;
468
Mark Youngf27962c2016-09-16 10:18:42 -0600469 // Initialize pSurface to NULL just to be safe.
470 *pSurface = VK_NULL_HANDLE;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600471 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700472 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600473 if (!ptr_instance->wsi_win32_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700474 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
475 "VK_KHR_win32_surface extension not enabled. "
476 "vkCreateWin32SurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600477 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
478 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600479 }
480
481 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700482 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->win_surf.base), sizeof(pIcdSurface->win_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700483 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600484 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
485 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700486 }
487
Mark Young5467d672016-06-28 10:52:43 -0600488 pIcdSurface->win_surf.base.platform = VK_ICD_WSI_PLATFORM_WIN32;
489 pIcdSurface->win_surf.hinstance = pCreateInfo->hinstance;
490 pIcdSurface->win_surf.hwnd = pCreateInfo->hwnd;
Ian Elliott7c352552015-11-19 13:14:05 -0700491
Mark Young5467d672016-06-28 10:52:43 -0600492 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700493 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
494 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600495 if (NULL != icd_term->CreateWin32SurfaceKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700496 vkRes = icd_term->CreateWin32SurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
497 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600498 if (VK_SUCCESS != vkRes) {
499 goto out;
500 }
501 }
502 }
503 }
504
505 *pSurface = (VkSurfaceKHR)(pIcdSurface);
506
507out:
508
509 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
510 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600511 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700512 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
513 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->DestroySurfaceKHR) {
514 icd_term->DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600515 }
516 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700517 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600518 }
519 loader_instance_heap_free(ptr_instance, pIcdSurface);
520 }
521
522 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700523}
Ian Elliotte851dd62015-11-24 15:39:10 -0700524
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600525// This is the trampoline entrypoint for
526// GetPhysicalDeviceWin32PresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700527LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
528 uint32_t queueFamilyIndex) {
529 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700530 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700531 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700532 VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex);
Ian Elliotte851dd62015-11-24 15:39:10 -0700533 return res;
534}
535
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600536// This is the instance chain terminator function for
537// GetPhysicalDeviceWin32PresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700538VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
539 uint32_t queueFamilyIndex) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600540 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700541 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600542 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700543 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600544 if (!ptr_instance->wsi_win32_surface_enabled) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700545 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
546 "VK_KHR_win32_surface extension not enabled. "
547 "vkGetPhysicalDeviceWin32PresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600548 return VK_SUCCESS;
549 }
550
551 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -0600552 assert(icd_term->GetPhysicalDeviceWin32PresentationSupportKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700553 "loader: null GetPhysicalDeviceWin32PresentationSupportKHR ICD "
554 "pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -0700555
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700556 return icd_term->GetPhysicalDeviceWin32PresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex);
Ian Elliotte851dd62015-11-24 15:39:10 -0700557}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700558#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700559
560#ifdef VK_USE_PLATFORM_MIR_KHR
561
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600562// Functions for the VK_KHR_mir_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700563
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600564// This is the trampoline entrypoint for CreateMirSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700565LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(VkInstance instance,
566 const VkMirSurfaceCreateInfoKHR *pCreateInfo,
567 const VkAllocationCallbacks *pAllocator,
568 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700569 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700570 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700571 VkResult res;
572
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700573 res = disp->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700574 return res;
575}
576
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600577// This is the instance chain terminator function for CreateMirSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700578VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMirSurfaceKHR(VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
579 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600580 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600581 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600582 uint32_t i = 0;
583
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600584 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700585 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600586 if (!ptr_instance->wsi_mir_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700587 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
588 "VK_KHR_mir_surface extension not enabled. "
589 "vkCreateMirSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600590 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
591 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600592 }
593
594 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700595 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->mir_surf.base), sizeof(pIcdSurface->mir_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700596 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600597 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
598 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700599 }
600
Mark Young5467d672016-06-28 10:52:43 -0600601 pIcdSurface->mir_surf.base.platform = VK_ICD_WSI_PLATFORM_MIR;
602 pIcdSurface->mir_surf.connection = pCreateInfo->connection;
603 pIcdSurface->mir_surf.mirSurface = pCreateInfo->mirSurface;
604
Mark Young5467d672016-06-28 10:52:43 -0600605 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700606 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
607 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600608 if (NULL != icd_term->CreateMirSurfaceKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700609 vkRes =
610 icd_term->CreateMirSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator, &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600611 if (VK_SUCCESS != vkRes) {
612 goto out;
613 }
614 }
615 }
616 }
Ian Elliott7c352552015-11-19 13:14:05 -0700617
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700618 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700619
Mark Young5467d672016-06-28 10:52:43 -0600620out:
621
622 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
623 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600624 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700625 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
626 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->DestroySurfaceKHR) {
627 icd_term->DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600628 }
629 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700630 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600631 }
632 loader_instance_heap_free(ptr_instance, pIcdSurface);
633 }
634
635 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700636}
Ian Elliotte851dd62015-11-24 15:39:10 -0700637
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600638// This is the trampoline entrypoint for
639// GetPhysicalDeviceMirPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700640LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,
641 uint32_t queueFamilyIndex,
642 MirConnection *connection) {
643 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700644 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700645 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700646 VkBool32 res = disp->GetPhysicalDeviceMirPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, connection);
Ian Elliotte851dd62015-11-24 15:39:10 -0700647 return res;
648}
649
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600650// This is the instance chain terminator function for
651// GetPhysicalDeviceMirPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700652VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,
653 uint32_t queueFamilyIndex,
654 MirConnection *connection) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600655 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700656 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600657 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700658 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600659 if (!ptr_instance->wsi_mir_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700660 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
661 "VK_KHR_mir_surface extension not enabled. "
662 "vkGetPhysicalDeviceMirPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600663 return VK_SUCCESS;
664 }
665
666 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700667 assert(icd_term->GetPhysicalDeviceMirPresentationSupportKHR &&
668 "loader: null GetPhysicalDeviceMirPresentationSupportKHR ICD pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -0700669
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700670 return icd_term->GetPhysicalDeviceMirPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, connection);
Ian Elliotte851dd62015-11-24 15:39:10 -0700671}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700672#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700673
674#ifdef VK_USE_PLATFORM_WAYLAND_KHR
675
Mark Young5467d672016-06-28 10:52:43 -0600676/*
677 * This is the trampoline entrypoint
678 * for CreateWaylandSurfaceKHR
679 */
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700680LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance,
681 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
682 const VkAllocationCallbacks *pAllocator,
683 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700684 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700685 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700686 VkResult res;
687
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700688 res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700689 return res;
690}
691
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600692// This is the instance chain terminator function for CreateWaylandSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700693VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(VkInstance instance,
694 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
695 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600696 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600697 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600698 uint32_t i = 0;
699
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600700 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700701 struct loader_instance *ptr_instance = loader_get_instance(instance);
Jon Ashburn436d6a32016-03-24 17:26:59 -0600702 if (!ptr_instance->wsi_wayland_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700703 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
704 "VK_KHR_wayland_surface extension not enabled. "
705 "vkCreateWaylandSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600706 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
707 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600708 }
709
710 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700711 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->wayland_surf.base), sizeof(pIcdSurface->wayland_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700712 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600713 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
714 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700715 }
716
Mark Young5467d672016-06-28 10:52:43 -0600717 pIcdSurface->wayland_surf.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
718 pIcdSurface->wayland_surf.display = pCreateInfo->display;
719 pIcdSurface->wayland_surf.surface = pCreateInfo->surface;
720
Mark Young5467d672016-06-28 10:52:43 -0600721 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700722 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
723 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600724 if (NULL != icd_term->CreateWaylandSurfaceKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700725 vkRes = icd_term->CreateWaylandSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
726 &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600727 if (VK_SUCCESS != vkRes) {
728 goto out;
729 }
730 }
731 }
732 }
Ian Elliott7c352552015-11-19 13:14:05 -0700733
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700734 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700735
Mark Young5467d672016-06-28 10:52:43 -0600736out:
737
738 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
739 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600740 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700741 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
742 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->DestroySurfaceKHR) {
743 icd_term->DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600744 }
745 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700746 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600747 }
748 loader_instance_heap_free(ptr_instance, pIcdSurface);
749 }
750
751 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700752}
Ian Elliotte851dd62015-11-24 15:39:10 -0700753
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600754// This is the trampoline entrypoint for
755// GetPhysicalDeviceWaylandPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700756LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
757 uint32_t queueFamilyIndex,
758 struct wl_display *display) {
759 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700760 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700761 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700762 VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, display);
Ian Elliotte851dd62015-11-24 15:39:10 -0700763 return res;
764}
765
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600766// This is the instance chain terminator function for
767// GetPhysicalDeviceWaylandPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700768VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
769 uint32_t queueFamilyIndex,
770 struct wl_display *display) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600771 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700772 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600773 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700774 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Jon Ashburn436d6a32016-03-24 17:26:59 -0600775 if (!ptr_instance->wsi_wayland_surface_enabled) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700776 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
777 "VK_KHR_wayland_surface extension not enabled. "
778 "vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600779 return VK_SUCCESS;
780 }
781
782 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -0600783 assert(icd_term->GetPhysicalDeviceWaylandPresentationSupportKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700784 "loader: null GetPhysicalDeviceWaylandPresentationSupportKHR ICD "
785 "pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -0700786
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700787 return icd_term->GetPhysicalDeviceWaylandPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, display);
Ian Elliotte851dd62015-11-24 15:39:10 -0700788}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700789#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700790
791#ifdef VK_USE_PLATFORM_XCB_KHR
792
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600793// Functions for the VK_KHR_xcb_surface extension:
794
795// This is the trampoline entrypoint for CreateXcbSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700796LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(VkInstance instance,
797 const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
798 const VkAllocationCallbacks *pAllocator,
799 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700800 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700801 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700802 VkResult res;
803
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700804 res = disp->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700805 return res;
806}
807
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600808// This is the instance chain terminator function for CreateXcbSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700809VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
810 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600811 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600812 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600813 uint32_t i = 0;
814
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600815 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700816 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600817 if (!ptr_instance->wsi_xcb_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700818 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
819 "VK_KHR_xcb_surface extension not enabled. "
820 "vkCreateXcbSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600821 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
822 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600823 }
824
825 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700826 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->xcb_surf.base), sizeof(pIcdSurface->xcb_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700827 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600828 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
829 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700830 }
831
Mark Young5467d672016-06-28 10:52:43 -0600832 pIcdSurface->xcb_surf.base.platform = VK_ICD_WSI_PLATFORM_XCB;
833 pIcdSurface->xcb_surf.connection = pCreateInfo->connection;
834 pIcdSurface->xcb_surf.window = pCreateInfo->window;
835
Mark Young5467d672016-06-28 10:52:43 -0600836 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700837 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
838 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600839 if (NULL != icd_term->CreateXcbSurfaceKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700840 vkRes =
841 icd_term->CreateXcbSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator, &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600842 if (VK_SUCCESS != vkRes) {
843 goto out;
844 }
845 }
846 }
847 }
Ian Elliott7c352552015-11-19 13:14:05 -0700848
Mark Young3eda5882016-12-01 10:42:21 -0700849 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700850
Mark Young5467d672016-06-28 10:52:43 -0600851out:
852
853 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
854 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600855 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700856 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
857 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->DestroySurfaceKHR) {
858 icd_term->DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600859 }
860 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700861 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600862 }
863 loader_instance_heap_free(ptr_instance, pIcdSurface);
864 }
865
866 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700867}
Ian Elliotte851dd62015-11-24 15:39:10 -0700868
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600869// This is the trampoline entrypoint for
870// GetPhysicalDeviceXcbPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700871LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
872 uint32_t queueFamilyIndex,
873 xcb_connection_t *connection,
874 xcb_visualid_t visual_id) {
875 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700876 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700877 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700878 VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliotte851dd62015-11-24 15:39:10 -0700879 return res;
880}
881
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600882// This is the instance chain terminator function for
883// GetPhysicalDeviceXcbPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700884VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
885 uint32_t queueFamilyIndex,
886 xcb_connection_t *connection,
887 xcb_visualid_t visual_id) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600888 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700889 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -0600890 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700891 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600892 if (!ptr_instance->wsi_xcb_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700893 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
894 "VK_KHR_xcb_surface extension not enabled. "
895 "vkGetPhysicalDeviceXcbPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600896 return VK_SUCCESS;
897 }
898
899 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700900 assert(icd_term->GetPhysicalDeviceXcbPresentationSupportKHR &&
901 "loader: null GetPhysicalDeviceXcbPresentationSupportKHR ICD pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -0700902
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700903 return icd_term->GetPhysicalDeviceXcbPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliotte851dd62015-11-24 15:39:10 -0700904}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700905#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700906
907#ifdef VK_USE_PLATFORM_XLIB_KHR
908
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600909// Functions for the VK_KHR_xlib_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700910
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600911// This is the trampoline entrypoint for CreateXlibSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700912LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance,
913 const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
914 const VkAllocationCallbacks *pAllocator,
915 VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700916 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700917 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700918 VkResult res;
919
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700920 res = disp->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700921 return res;
922}
923
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600924// This is the instance chain terminator function for CreateXlibSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700925VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
926 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600927 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600928 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600929 uint32_t i = 0;
930
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600931 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700932 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600933 if (!ptr_instance->wsi_xlib_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -0700934 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
935 "VK_KHR_xlib_surface extension not enabled. "
936 "vkCreateXlibSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600937 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
938 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600939 }
940
941 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700942 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance, sizeof(pIcdSurface->xlib_surf.base), sizeof(pIcdSurface->xlib_surf));
Ian Elliott7c352552015-11-19 13:14:05 -0700943 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600944 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
945 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700946 }
947
Mark Young5467d672016-06-28 10:52:43 -0600948 pIcdSurface->xlib_surf.base.platform = VK_ICD_WSI_PLATFORM_XLIB;
949 pIcdSurface->xlib_surf.dpy = pCreateInfo->dpy;
950 pIcdSurface->xlib_surf.window = pCreateInfo->window;
951
Mark Young5467d672016-06-28 10:52:43 -0600952 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700953 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
954 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600955 if (NULL != icd_term->CreateXlibSurfaceKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700956 vkRes =
957 icd_term->CreateXlibSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator, &pIcdSurface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600958 if (VK_SUCCESS != vkRes) {
959 goto out;
960 }
961 }
962 }
963 }
Ian Elliott7c352552015-11-19 13:14:05 -0700964
Mark Young3eda5882016-12-01 10:42:21 -0700965 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700966
Mark Young5467d672016-06-28 10:52:43 -0600967out:
968
969 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
970 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600971 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700972 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
973 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->DestroySurfaceKHR) {
974 icd_term->DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600975 }
976 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700977 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600978 }
979 loader_instance_heap_free(ptr_instance, pIcdSurface);
980 }
981
982 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700983}
Ian Elliotte851dd62015-11-24 15:39:10 -0700984
Mark Young573a7a12016-11-02 09:37:08 -0600985// This is the trampoline entrypoint for
986// GetPhysicalDeviceXlibPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700987LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
988 uint32_t queueFamilyIndex, Display *dpy,
989 VisualID visualID) {
990 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700991 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -0700992 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700993 VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliotte851dd62015-11-24 15:39:10 -0700994 return res;
995}
996
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600997// This is the instance chain terminator function for
998// GetPhysicalDeviceXlibPresentationSupportKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -0700999VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
1000 uint32_t queueFamilyIndex, Display *dpy,
1001 VisualID visualID) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001002 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001003 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001004 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001005 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001006 if (!ptr_instance->wsi_xlib_surface_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001007 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1008 "VK_KHR_xlib_surface extension not enabled. "
1009 "vkGetPhysicalDeviceXlibPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001010 return VK_SUCCESS;
1011 }
1012
1013 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001014 assert(icd_term->GetPhysicalDeviceXlibPresentationSupportKHR &&
1015 "loader: null GetPhysicalDeviceXlibPresentationSupportKHR ICD pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -07001016
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001017 return icd_term->GetPhysicalDeviceXlibPresentationSupportKHR(phys_dev_term->phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliotte851dd62015-11-24 15:39:10 -07001018}
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001019#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001020
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001021#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001022
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001023// Functions for the VK_KHR_android_surface extension:
1024
1025// This is the trampoline entrypoint for CreateAndroidSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001026LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(VkInstance instance, ANativeWindow *window,
1027 const VkAllocationCallbacks *pAllocator,
1028 VkSurfaceKHR *pSurface) {
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001029 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001030 disp = loader_get_instance_layer_dispatch(instance);
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001031 VkResult res;
1032
1033 res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
1034 return res;
1035}
1036
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001037// This is the instance chain terminator function for CreateAndroidSurfaceKHR
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001038VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(VkInstance instance, Window window,
1039 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001040 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001041 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001042 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001043 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1044 "VK_KHR_display extension not enabled. "
1045 "vkCreateAndroidSurfaceKHR not executed!\n");
Jeremy Hayes0231e1c2016-06-14 11:50:02 -06001046 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001047 }
1048
1049 // Next, if so, proceed with the implementation of this function:
Mark Young5467d672016-06-28 10:52:43 -06001050 VkIcdSurfaceAndroid *pIcdSurface =
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001051 loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceAndroid), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001052 if (pIcdSurface == NULL) {
1053 return VK_ERROR_OUT_OF_HOST_MEMORY;
1054 }
1055
1056 pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_ANDROID;
1057 pIcdSurface->dpy = dpy;
1058 pIcdSurface->window = window;
1059
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001060 *pSurface = (VkSurfaceKHR)pIcdSurface;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001061
1062 return VK_SUCCESS;
1063}
1064
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001065#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001066
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001067// Functions for the VK_KHR_display instance extension:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001068LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1069 uint32_t *pPropertyCount,
1070 VkDisplayPropertiesKHR *pProperties) {
1071 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001072 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001073 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001074 VkResult res = disp->GetPhysicalDeviceDisplayPropertiesKHR(unwrapped_phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001075 return res;
1076}
1077
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001078VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1079 uint32_t *pPropertyCount,
1080 VkDisplayPropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001081 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001082 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001083 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001084 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001085 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001086 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1087 "VK_KHR_display extension not enabled. "
1088 "vkGetPhysicalDeviceDisplayPropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001089 return VK_SUCCESS;
1090 }
1091
1092 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001093 assert(icd_term->GetPhysicalDeviceDisplayPropertiesKHR && "loader: null GetPhysicalDeviceDisplayPropertiesKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001094
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001095 return icd_term->GetPhysicalDeviceDisplayPropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001096}
1097
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001098LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
1099 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlanePropertiesKHR *pProperties) {
1100 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001101 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001102 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001103 VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(unwrapped_phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001104 return res;
1105}
1106
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001107VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
1108 uint32_t *pPropertyCount,
1109 VkDisplayPlanePropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001110 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001111 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001112 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001113 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001114 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001115 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1116 "VK_KHR_display extension not enabled. "
1117 "vkGetPhysicalDeviceDisplayPlanePropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001118 return VK_SUCCESS;
1119 }
1120
1121 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001122 assert(icd_term->GetPhysicalDeviceDisplayPlanePropertiesKHR &&
1123 "loader: null GetPhysicalDeviceDisplayPlanePropertiesKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001124
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001125 return icd_term->GetPhysicalDeviceDisplayPlanePropertiesKHR(phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001126}
1127
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001128LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
1129 uint32_t planeIndex, uint32_t *pDisplayCount,
1130 VkDisplayKHR *pDisplays) {
1131 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001132 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001133 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001134 VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
Jon Ashburncc370d02016-03-08 09:30:30 -07001135 return res;
1136}
1137
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001138VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1139 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001140 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001141 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001142 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001143 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001144 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001145 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1146 "VK_KHR_display extension not enabled. "
1147 "vkGetDisplayPlaneSupportedDisplaysKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001148 return VK_SUCCESS;
1149 }
1150
1151 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001152 assert(icd_term->GetDisplayPlaneSupportedDisplaysKHR && "loader: null GetDisplayPlaneSupportedDisplaysKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001153
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001154 return icd_term->GetDisplayPlaneSupportedDisplaysKHR(phys_dev_term->phys_dev, planeIndex, pDisplayCount, pDisplays);
Jon Ashburncc370d02016-03-08 09:30:30 -07001155}
1156
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001157LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1158 uint32_t *pPropertyCount,
1159 VkDisplayModePropertiesKHR *pProperties) {
1160 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001161 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001162 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001163 VkResult res = disp->GetDisplayModePropertiesKHR(unwrapped_phys_dev, display, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001164 return res;
1165}
1166
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001167VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1168 uint32_t *pPropertyCount,
1169 VkDisplayModePropertiesKHR *pProperties) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001170 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001171 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001172 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001173 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001174 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001175 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1176 "VK_KHR_display extension not enabled. "
1177 "vkGetDisplayModePropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001178 return VK_SUCCESS;
1179 }
1180
1181 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001182 assert(icd_term->GetDisplayModePropertiesKHR && "loader: null GetDisplayModePropertiesKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001183
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001184 return icd_term->GetDisplayModePropertiesKHR(phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001185}
1186
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001187LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1188 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1189 const VkAllocationCallbacks *pAllocator,
1190 VkDisplayModeKHR *pMode) {
1191 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001192 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001193 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001194 VkResult res = disp->CreateDisplayModeKHR(unwrapped_phys_dev, display, pCreateInfo, pAllocator, pMode);
Jon Ashburncc370d02016-03-08 09:30:30 -07001195 return res;
1196}
1197
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001198VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1199 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1200 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001201 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001202 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001203 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001204 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001205 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001206 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1207 "VK_KHR_display extension not enabled. "
1208 "vkCreateDisplayModeKHR not executed!\n");
Jeremy Hayes0231e1c2016-06-14 11:50:02 -06001209 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001210 }
1211
1212 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001213 assert(icd_term->CreateDisplayModeKHR && "loader: null CreateDisplayModeKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001214
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001215 return icd_term->CreateDisplayModeKHR(phys_dev_term->phys_dev, display, pCreateInfo, pAllocator, pMode);
Jon Ashburncc370d02016-03-08 09:30:30 -07001216}
1217
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001218LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,
1219 VkDisplayModeKHR mode, uint32_t planeIndex,
1220 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
1221 VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
Jon Ashburncc370d02016-03-08 09:30:30 -07001222 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001223 disp = loader_get_instance_layer_dispatch(physicalDevice);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001224 VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(unwrapped_phys_dev, mode, planeIndex, pCapabilities);
Jon Ashburncc370d02016-03-08 09:30:30 -07001225 return res;
1226}
1227
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001228VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode,
1229 uint32_t planeIndex,
1230 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001231 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001232 struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
Mark Young26c19372016-11-03 14:27:13 -06001233 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001234 struct loader_instance *ptr_instance = (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001235 if (!ptr_instance->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001236 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1237 "VK_KHR_display extension not enabled. "
1238 "vkGetDisplayPlaneCapabilitiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001239 return VK_SUCCESS;
1240 }
1241
1242 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001243 assert(icd_term->GetDisplayPlaneCapabilitiesKHR && "loader: null GetDisplayPlaneCapabilitiesKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001244
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001245 return icd_term->GetDisplayPlaneCapabilitiesKHR(phys_dev_term->phys_dev, mode, planeIndex, pCapabilities);
Jon Ashburncc370d02016-03-08 09:30:30 -07001246}
1247
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001248LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(VkInstance instance,
1249 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1250 const VkAllocationCallbacks *pAllocator,
1251 VkSurfaceKHR *pSurface) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001252 const VkLayerInstanceDispatchTable *disp;
Mark Young274e4bc2017-01-19 21:10:49 -07001253 disp = loader_get_instance_layer_dispatch(instance);
Jon Ashburncc370d02016-03-08 09:30:30 -07001254 VkResult res;
1255
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001256 res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburncc370d02016-03-08 09:30:30 -07001257 return res;
1258}
1259
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001260VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayPlaneSurfaceKHR(VkInstance instance,
1261 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1262 const VkAllocationCallbacks *pAllocator,
1263 VkSurfaceKHR *pSurface) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001264 struct loader_instance *inst = loader_get_instance(instance);
Mark Young5467d672016-06-28 10:52:43 -06001265 VkIcdSurface *pIcdSurface = NULL;
Mark Youngf06def92016-11-01 19:20:41 -06001266 VkResult vkRes = VK_SUCCESS;
Mark Young573a7a12016-11-02 09:37:08 -06001267 uint32_t i = 0;
Jon Ashburncc370d02016-03-08 09:30:30 -07001268
Mark Youngf06def92016-11-01 19:20:41 -06001269 if (!inst->wsi_display_enabled) {
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001270 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1271 "VK_KHR_surface extension not enabled. "
1272 "vkCreateDisplayPlaneSurfaceKHR not executed!\n");
Mark Youngf06def92016-11-01 19:20:41 -06001273 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1274 goto out;
Petros Bantolasf3095862016-04-14 12:50:42 +01001275 }
1276
Piers Daniellc21fde52016-12-13 16:51:49 -07001277 // Next, if so, proceed with the implementation of this function:
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001278 pIcdSurface = AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->display_surf.base), sizeof(pIcdSurface->display_surf));
Jon Ashburncc370d02016-03-08 09:30:30 -07001279 if (pIcdSurface == NULL) {
Mark Youngf06def92016-11-01 19:20:41 -06001280 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1281 goto out;
Jon Ashburncc370d02016-03-08 09:30:30 -07001282 }
1283
Mark Young5467d672016-06-28 10:52:43 -06001284 pIcdSurface->display_surf.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
1285 pIcdSurface->display_surf.displayMode = pCreateInfo->displayMode;
1286 pIcdSurface->display_surf.planeIndex = pCreateInfo->planeIndex;
1287 pIcdSurface->display_surf.planeStackIndex = pCreateInfo->planeStackIndex;
1288 pIcdSurface->display_surf.transform = pCreateInfo->transform;
1289 pIcdSurface->display_surf.globalAlpha = pCreateInfo->globalAlpha;
1290 pIcdSurface->display_surf.alphaMode = pCreateInfo->alphaMode;
1291 pIcdSurface->display_surf.imageExtent = pCreateInfo->imageExtent;
1292
Mark Youngf06def92016-11-01 19:20:41 -06001293 // Loop through each ICD and determine if they need to create a surface
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001294 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1295 if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -06001296 if (NULL != icd_term->CreateDisplayPlaneSurfaceKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001297 vkRes = icd_term->CreateDisplayPlaneSurfaceKHR(icd_term->instance, pCreateInfo, pAllocator,
1298 &pIcdSurface->real_icd_surfaces[i]);
Mark Youngf06def92016-11-01 19:20:41 -06001299 if (VK_SUCCESS != vkRes) {
1300 goto out;
1301 }
1302 }
1303 }
1304 }
1305
Mark Young3eda5882016-12-01 10:42:21 -07001306 *pSurface = (VkSurfaceKHR)pIcdSurface;
Jon Ashburncc370d02016-03-08 09:30:30 -07001307
Mark Youngf06def92016-11-01 19:20:41 -06001308out:
1309
1310 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1311 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -06001312 i = 0;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001313 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) {
1314 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->DestroySurfaceKHR) {
1315 icd_term->DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
Mark Youngf06def92016-11-01 19:20:41 -06001316 }
1317 }
1318 loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
1319 }
1320 loader_instance_heap_free(inst, pIcdSurface);
1321 }
1322
1323 return vkRes;
Jon Ashburncc370d02016-03-08 09:30:30 -07001324}
1325
Mark Young274e4bc2017-01-19 21:10:49 -07001326// EXT_display_swapchain Extension command
1327
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001328LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
1329 const VkSwapchainCreateInfoKHR *pCreateInfos,
1330 const VkAllocationCallbacks *pAllocator,
1331 VkSwapchainKHR *pSwapchains) {
Mark Young2a2122f2016-09-08 18:36:32 -06001332 const VkLayerDispatchTable *disp;
1333 disp = loader_get_dispatch(device);
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001334 return disp->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
Mark Youngf2eabea2016-07-01 15:18:27 -06001335}
1336
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001337VKAPI_ATTR VkResult VKAPI_CALL terminator_vkCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
1338 const VkSwapchainCreateInfoKHR *pCreateInfos,
1339 const VkAllocationCallbacks *pAllocator,
1340 VkSwapchainKHR *pSwapchains) {
Mark Young274e4bc2017-01-19 21:10:49 -07001341 uint32_t icd_index = 0;
1342 struct loader_device *dev;
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001343 struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
Mark Young274e4bc2017-01-19 21:10:49 -07001344 if (NULL != icd_term && NULL != icd_term->CreateSharedSwapchainsKHR) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001345 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pCreateInfos->surface;
Mark Young274e4bc2017-01-19 21:10:49 -07001346 if (NULL != icd_surface->real_icd_surfaces) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001347 if ((VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
Mark Young274e4bc2017-01-19 21:10:49 -07001348 // We found the ICD, and there is an ICD KHR surface
1349 // associated with it, so copy the CreateInfo struct
1350 // and point it at the ICD's surface.
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001351 VkSwapchainCreateInfoKHR *pCreateCopy = loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
Mark Young274e4bc2017-01-19 21:10:49 -07001352 if (NULL == pCreateCopy) {
1353 return VK_ERROR_OUT_OF_HOST_MEMORY;
1354 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001355 memcpy(pCreateCopy, pCreateInfos, sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
Mark Young274e4bc2017-01-19 21:10:49 -07001356 for (uint32_t sc = 0; sc < swapchainCount; sc++) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001357 pCreateCopy[sc].surface = icd_surface->real_icd_surfaces[icd_index];
Mark Young274e4bc2017-01-19 21:10:49 -07001358 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001359 return icd_term->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateCopy, pAllocator, pSwapchains);
Mark Young274e4bc2017-01-19 21:10:49 -07001360 }
1361 }
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001362 return icd_term->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
Mark Young274e4bc2017-01-19 21:10:49 -07001363 }
1364 return VK_SUCCESS;
1365}
1366
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001367bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance, const char *name, void **addr) {
Ian Elliott54cea232015-10-30 15:28:23 -06001368 *addr = NULL;
1369
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001370 // Functions for the VK_KHR_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07001371 if (!strcmp("vkDestroySurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001372 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkDestroySurfaceKHR : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07001373 return true;
1374 }
Ian Elliott54cea232015-10-30 15:28:23 -06001375 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001376 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceSupportKHR : NULL;
Ian Elliott54cea232015-10-30 15:28:23 -06001377 return true;
1378 }
Ian Elliottea666b22015-11-19 16:05:09 -07001379 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001380 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceCapabilitiesKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07001381 return true;
1382 }
1383 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001384 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfaceFormatsKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07001385 return true;
1386 }
1387 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001388 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkGetPhysicalDeviceSurfacePresentModesKHR : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07001389 return true;
1390 }
Ian Elliott9b89a472015-11-19 16:39:21 -07001391
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001392 // Functions for the VK_KHR_swapchain extension:
1393
1394 // Note: This is a device extension, and its functions are statically
1395 // exported from the loader. Per Khronos decisions, the loader's GIPA
1396 // function will return the trampoline function for such device-extension
1397 // functions, regardless of whether the extension has been enabled.
Ian Elliott9b89a472015-11-19 16:39:21 -07001398 if (!strcmp("vkCreateSwapchainKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001399 *addr = (void *)vkCreateSwapchainKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001400 return true;
1401 }
1402 if (!strcmp("vkDestroySwapchainKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001403 *addr = (void *)vkDestroySwapchainKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001404 return true;
1405 }
1406 if (!strcmp("vkGetSwapchainImagesKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001407 *addr = (void *)vkGetSwapchainImagesKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001408 return true;
1409 }
1410 if (!strcmp("vkAcquireNextImageKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001411 *addr = (void *)vkAcquireNextImageKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001412 return true;
1413 }
1414 if (!strcmp("vkQueuePresentKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001415 *addr = (void *)vkQueuePresentKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001416 return true;
1417 }
1418
Ian Elliott7c352552015-11-19 13:14:05 -07001419#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001420
1421 // Functions for the VK_KHR_win32_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07001422 if (!strcmp("vkCreateWin32SurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001423 *addr = ptr_instance->wsi_win32_surface_enabled ? (void *)vkCreateWin32SurfaceKHR : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07001424 return true;
1425 }
Ian Elliotte851dd62015-11-24 15:39:10 -07001426 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001427 *addr = ptr_instance->wsi_win32_surface_enabled ? (void *)vkGetPhysicalDeviceWin32PresentationSupportKHR : NULL;
Ian Elliotte851dd62015-11-24 15:39:10 -07001428 return true;
1429 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001430#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001431#ifdef VK_USE_PLATFORM_MIR_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001432
1433 // Functions for the VK_KHR_mir_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07001434 if (!strcmp("vkCreateMirSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001435 *addr = ptr_instance->wsi_mir_surface_enabled ? (void *)vkCreateMirSurfaceKHR : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07001436 return true;
1437 }
Ian Elliotte851dd62015-11-24 15:39:10 -07001438 if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001439 *addr = ptr_instance->wsi_mir_surface_enabled ? (void *)vkGetPhysicalDeviceMirPresentationSupportKHR : NULL;
Ian Elliotte851dd62015-11-24 15:39:10 -07001440 return true;
Jason Ekstrand3bfebc92016-02-12 17:25:03 -08001441 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001442#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001443#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001444
1445 // Functions for the VK_KHR_wayland_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001446 if (!strcmp("vkCreateWaylandSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001447 *addr = ptr_instance->wsi_wayland_surface_enabled ? (void *)vkCreateWaylandSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001448 return true;
1449 }
1450 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001451 *addr = ptr_instance->wsi_wayland_surface_enabled ? (void *)vkGetPhysicalDeviceWaylandPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001452 return true;
1453 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001454#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001455#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001456
1457 // Functions for the VK_KHR_xcb_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001458 if (!strcmp("vkCreateXcbSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001459 *addr = ptr_instance->wsi_xcb_surface_enabled ? (void *)vkCreateXcbSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001460 return true;
1461 }
1462 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001463 *addr = ptr_instance->wsi_xcb_surface_enabled ? (void *)vkGetPhysicalDeviceXcbPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001464 return true;
1465 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001466#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001467#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001468
1469 // Functions for the VK_KHR_xlib_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001470 if (!strcmp("vkCreateXlibSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001471 *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkCreateXlibSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001472 return true;
1473 }
1474 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001475 *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkGetPhysicalDeviceXlibPresentationSupportKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001476 return true;
1477 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001478#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001479#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001480
1481 // Functions for the VK_KHR_android_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001482 if (!strcmp("vkCreateAndroidSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001483 *addr = ptr_instance->wsi_xlib_surface_enabled ? (void *)vkCreateAndroidSurfaceKHR : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001484 return true;
1485 }
Mark Lobodzinskie2859eb2017-01-26 13:34:13 -07001486#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001487
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001488 // Functions for VK_KHR_display extension:
Jon Ashburncc370d02016-03-08 09:30:30 -07001489 if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001490 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07001491 return true;
1492 }
1493 if (!strcmp("vkGetPhysicalDeviceDisplayPlanePropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001494 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPlanePropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07001495 return true;
1496 }
1497 if (!strcmp("vkGetDisplayPlaneSupportedDisplaysKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001498 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayPlaneSupportedDisplaysKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07001499 return true;
1500 }
1501 if (!strcmp("vkGetDisplayModePropertiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001502 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayModePropertiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07001503 return true;
1504 }
1505 if (!strcmp("vkCreateDisplayModeKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001506 *addr = ptr_instance->wsi_display_enabled ? (void *)vkCreateDisplayModeKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07001507 return true;
1508 }
1509 if (!strcmp("vkGetDisplayPlaneCapabilitiesKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001510 *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetDisplayPlaneCapabilitiesKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07001511 return true;
1512 }
1513 if (!strcmp("vkCreateDisplayPlaneSurfaceKHR", name)) {
Mark Lobodzinski91c10752017-01-26 12:16:30 -07001514 *addr = ptr_instance->wsi_display_enabled ? (void *)vkCreateDisplayPlaneSurfaceKHR : NULL;
Jon Ashburncc370d02016-03-08 09:30:30 -07001515 return true;
1516 }
Mark Youngf2eabea2016-07-01 15:18:27 -06001517
1518 // Functions for KHR_display_swapchain extension:
1519 if (!strcmp("vkCreateSharedSwapchainsKHR", name)) {
1520 *addr = (void *)vkCreateSharedSwapchainsKHR;
1521 return true;
1522 }
1523
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001524 return false;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001525}