blob: c6270268b177db7c8e7e7ddc9dc53b60179d8012 [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
Jon Ashburn1c75aec2016-02-02 17:47:28 -070037void wsi_create_instance(struct loader_instance *ptr_instance,
38 const VkInstanceCreateInfo *pCreateInfo) {
Ian Elliott5fb891a2015-10-30 17:45:05 -060039 ptr_instance->wsi_surface_enabled = false;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070040
41#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburncc370d02016-03-08 09:30:30 -070042 ptr_instance->wsi_win32_surface_enabled = false;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070043#endif // VK_USE_PLATFORM_WIN32_KHR
44#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060045 ptr_instance->wsi_mir_surface_enabled = false;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070046#endif // VK_USE_PLATFORM_MIR_KHR
47#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060048 ptr_instance->wsi_wayland_surface_enabled = false;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070049#endif // VK_USE_PLATFORM_WAYLAND_KHR
50#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060051 ptr_instance->wsi_xcb_surface_enabled = false;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070052#endif // VK_USE_PLATFORM_XCB_KHR
53#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060054 ptr_instance->wsi_xlib_surface_enabled = false;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070055#endif // VK_USE_PLATFORM_XLIB_KHR
56#ifdef VK_USE_PLATFORM_ANDROID_KHR
57 ptr_instance->wsi_android_surface_enabled = false;
58#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060059
Jon Ashburncc370d02016-03-08 09:30:30 -070060 ptr_instance->wsi_display_enabled = false;
61
Jon Ashburna0673ab2016-01-11 13:12:43 -070062 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -070063 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
64 VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060065 ptr_instance->wsi_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070066 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060067 }
Ian Elliottb1849742015-11-19 11:58:08 -070068#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -070069 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
70 VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott1693f592015-11-23 10:17:23 -070071 ptr_instance->wsi_win32_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070072 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060073 }
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -070074#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott5fb891a2015-10-30 17:45:05 -060075#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -070076 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
77 VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060078 ptr_instance->wsi_mir_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070079 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060080 }
Ian Elliott5fb891a2015-10-30 17:45:05 -060081#endif // VK_USE_PLATFORM_MIR_KHR
82#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -070083 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
84 VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060085 ptr_instance->wsi_wayland_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070086 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060087 }
Ian Elliott5fb891a2015-10-30 17:45:05 -060088#endif // VK_USE_PLATFORM_WAYLAND_KHR
89#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -070090 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
91 VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060092 ptr_instance->wsi_xcb_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -070093 continue;
Ian Elliott54cea232015-10-30 15:28:23 -060094 }
Ian Elliott5fb891a2015-10-30 17:45:05 -060095#endif // VK_USE_PLATFORM_XCB_KHR
96#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -070097 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
98 VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott54cea232015-10-30 15:28:23 -060099 ptr_instance->wsi_xlib_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -0700100 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600101 }
Ian Elliott5fb891a2015-10-30 17:45:05 -0600102#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700103#ifdef VK_USE_PLATFORM_ANDROID_KHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700104 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
105 VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700106 ptr_instance->wsi_android_surface_enabled = true;
107 continue;
108 }
109#endif // VK_USE_PLATFORM_ANDROID_KHR
Jon Ashburncc370d02016-03-08 09:30:30 -0700110 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
111 VK_KHR_DISPLAY_EXTENSION_NAME) == 0) {
112 ptr_instance->wsi_display_enabled = true;
113 continue;
114 }
Ian Elliott54cea232015-10-30 15:28:23 -0600115 }
116}
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600117
118// Linux WSI surface extensions are not always compiled into the loader. (Assume
119// for Windows the KHR_win32_surface is always compiled into loader). A given
120// Linux build environment might not have the headers required for building one
121// of the four extensions (Xlib, Xcb, Mir, Wayland). Thus, need to check if
122// the built loader actually supports the particular Linux surface extension.
123// If not supported by the built loader it will not be included in the list of
124// enumerated instance extensions. This solves the issue where an ICD or layer
125// advertises support for a given Linux surface extension but the loader was not
126// built to support the extension.
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600127bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop) {
128#ifndef VK_USE_PLATFORM_MIR_KHR
129 if (!strcmp(ext_prop->extensionName, "VK_KHR_mir_surface"))
130 return true;
131#endif // VK_USE_PLATFORM_MIR_KHR
132#ifndef VK_USE_PLATFORM_WAYLAND_KHR
133 if (!strcmp(ext_prop->extensionName, "VK_KHR_wayland_surface"))
134 return true;
135#endif // VK_USE_PLATFORM_WAYLAND_KHR
136#ifndef VK_USE_PLATFORM_XCB_KHR
137 if (!strcmp(ext_prop->extensionName, "VK_KHR_xcb_surface"))
138 return true;
139#endif // VK_USE_PLATFORM_XCB_KHR
140#ifndef VK_USE_PLATFORM_XLIB_KHR
141 if (!strcmp(ext_prop->extensionName, "VK_KHR_xlib_surface"))
142 return true;
143#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600144
Jon Ashburnae8f1e82016-03-25 12:49:35 -0600145 return false;
146}
Ian Elliott7c352552015-11-19 13:14:05 -0700147
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600148// Functions for the VK_KHR_surface extension:
149
150// This is the trampoline entrypoint for DestroySurfaceKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700151LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL
152vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
153 const VkAllocationCallbacks *pAllocator) {
Ian Elliottabf50662015-11-25 14:43:02 -0700154 const VkLayerInstanceDispatchTable *disp;
155 disp = loader_get_instance_dispatch(instance);
156 disp->DestroySurfaceKHR(instance, surface, pAllocator);
157}
158
Jon Ashburncc370d02016-03-08 09:30:30 -0700159// TODO probably need to lock around all the loader_get_instance() calls.
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600160
161// This is the instance chain terminator function for DestroySurfaceKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700162VKAPI_ATTR void VKAPI_CALL
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700163terminator_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
164 const VkAllocationCallbacks *pAllocator) {
Ian Elliott1693f592015-11-23 10:17:23 -0700165 struct loader_instance *ptr_instance = loader_get_instance(instance);
166
Karl Schultza9e989f2016-11-19 09:02:27 -0700167 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young11e9d472016-10-17 12:27:36 -0600168 if (NULL != icd_surface) {
169 if (NULL != icd_surface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600170 uint32_t i = 0;
Mark Young26c19372016-11-03 14:27:13 -0600171 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
172 icd_term != NULL; icd_term = icd_term->next, i++) {
173 if (icd_term->scanned_icd->interface_version >=
Mark Young11e9d472016-10-17 12:27:36 -0600174 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600175 if (NULL != icd_term->DestroySurfaceKHR &&
Mark Young3eda5882016-12-01 10:42:21 -0700176 (VkSurfaceKHR)NULL !=
177 icd_surface->real_icd_surfaces[i]) {
Mark Young26c19372016-11-03 14:27:13 -0600178 icd_term->DestroySurfaceKHR(
179 icd_term->instance,
180 icd_surface->real_icd_surfaces[i], pAllocator);
Mark Young3eda5882016-12-01 10:42:21 -0700181 icd_surface->real_icd_surfaces[i] = (VkSurfaceKHR)NULL;
Mark Young11e9d472016-10-17 12:27:36 -0600182 }
183 } else {
184 // The real_icd_surface for any ICD not supporting the
185 // proper interface version should be NULL. If not, then
186 // we have a problem.
Mark Young3eda5882016-12-01 10:42:21 -0700187 assert((VkSurfaceKHR)NULL ==
188 icd_surface->real_icd_surfaces[i]);
Mark Young5467d672016-06-28 10:52:43 -0600189 }
Mark Young5467d672016-06-28 10:52:43 -0600190 }
Mark Young11e9d472016-10-17 12:27:36 -0600191 loader_instance_heap_free(ptr_instance,
192 icd_surface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600193 }
Mark Young5467d672016-06-28 10:52:43 -0600194
Karl Schultza9e989f2016-11-19 09:02:27 -0700195 loader_instance_heap_free(ptr_instance, (void *)(uintptr_t)surface);
Mark Young11e9d472016-10-17 12:27:36 -0600196 }
Ian Elliott7c352552015-11-19 13:14:05 -0700197}
198
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600199// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700200LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
201vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
202 uint32_t queueFamilyIndex,
203 VkSurfaceKHR surface,
204 VkBool32 *pSupported) {
Ian Elliott54cea232015-10-30 15:28:23 -0600205 const VkLayerInstanceDispatchTable *disp;
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700206 VkPhysicalDevice unwrapped_phys_dev =
207 loader_unwrap_physical_device(physicalDevice);
Ian Elliott54cea232015-10-30 15:28:23 -0600208 disp = loader_get_instance_dispatch(physicalDevice);
209 VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700210 unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott54cea232015-10-30 15:28:23 -0600211 return res;
212}
213
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600214// This is the instance chain terminator function for
215// GetPhysicalDeviceSurfaceSupportKHR
216VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceSupportKHR(
217 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
218 VkSurfaceKHR surface, VkBool32 *pSupported) {
Mark Young26c19372016-11-03 14:27:13 -0600219
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600220 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -0600221 struct loader_physical_device_term *phys_dev_term =
222 (struct loader_physical_device_term *)physicalDevice;
223 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600224 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -0600225 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600226 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -0600227 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
228 "VK_KHR_VK_KHR_surface extension not enabled. "
229 "vkGetPhysicalDeviceSurfaceSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600230 return VK_SUCCESS;
231 }
232
233 // Next, if so, proceed with the implementation of this function:
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700234 assert(pSupported &&
235 "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
Ian Elliott54cea232015-10-30 15:28:23 -0600236 *pSupported = false;
237
Mark Young26c19372016-11-03 14:27:13 -0600238 assert(icd_term->GetPhysicalDeviceSurfaceSupportKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700239 "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
Ian Elliott54cea232015-10-30 15:28:23 -0600240
Karl Schultza9e989f2016-11-19 09:02:27 -0700241 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young5467d672016-06-28 10:52:43 -0600242 if (NULL != icd_surface->real_icd_surfaces &&
Mark Young3eda5882016-12-01 10:42:21 -0700243 (VkSurfaceKHR)NULL !=
244 icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young26c19372016-11-03 14:27:13 -0600245 return icd_term->GetPhysicalDeviceSurfaceSupportKHR(
246 phys_dev_term->phys_dev, queueFamilyIndex,
247 icd_surface->real_icd_surfaces[phys_dev_term->icd_index],
248 pSupported);
Mark Young5467d672016-06-28 10:52:43 -0600249 }
Mark Young5467d672016-06-28 10:52:43 -0600250
Mark Young26c19372016-11-03 14:27:13 -0600251 return icd_term->GetPhysicalDeviceSurfaceSupportKHR(
252 phys_dev_term->phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott54cea232015-10-30 15:28:23 -0600253}
254
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600255// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceCapabilitiesKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700256LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
257vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
258 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
259 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700260
Ian Elliottea666b22015-11-19 16:05:09 -0700261 const VkLayerInstanceDispatchTable *disp;
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700262 VkPhysicalDevice unwrapped_phys_dev =
263 loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700264 disp = loader_get_instance_dispatch(physicalDevice);
265 VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700266 unwrapped_phys_dev, surface, pSurfaceCapabilities);
Ian Elliottea666b22015-11-19 16:05:09 -0700267 return res;
268}
269
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600270// This is the instance chain terminator function for
271// GetPhysicalDeviceSurfaceCapabilitiesKHR
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700272VKAPI_ATTR VkResult VKAPI_CALL
273terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700274 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
275 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Mark Young26c19372016-11-03 14:27:13 -0600276
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600277 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -0600278 struct loader_physical_device_term *phys_dev_term =
279 (struct loader_physical_device_term *)physicalDevice;
280 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600281 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -0600282 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600283 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -0600284 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
285 "VK_KHR_surface extension not enabled. "
286 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600287 return VK_SUCCESS;
288 }
289
290 // Next, if so, proceed with the implementation of this function:
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700291 assert(pSurfaceCapabilities && "GetPhysicalDeviceSurfaceCapabilitiesKHR: "
292 "Error, null pSurfaceCapabilities");
Ian Elliottea666b22015-11-19 16:05:09 -0700293
Mark Young26c19372016-11-03 14:27:13 -0600294 assert(icd_term->GetPhysicalDeviceSurfaceCapabilitiesKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700295 "loader: null GetPhysicalDeviceSurfaceCapabilitiesKHR ICD pointer");
Ian Elliottea666b22015-11-19 16:05:09 -0700296
Karl Schultza9e989f2016-11-19 09:02:27 -0700297 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young5467d672016-06-28 10:52:43 -0600298 if (NULL != icd_surface->real_icd_surfaces &&
Mark Young3eda5882016-12-01 10:42:21 -0700299 (VkSurfaceKHR)NULL !=
300 icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young26c19372016-11-03 14:27:13 -0600301 return icd_term->GetPhysicalDeviceSurfaceCapabilitiesKHR(
302 phys_dev_term->phys_dev,
303 icd_surface->real_icd_surfaces[phys_dev_term->icd_index],
Mark Young5467d672016-06-28 10:52:43 -0600304 pSurfaceCapabilities);
305 }
Mark Young5467d672016-06-28 10:52:43 -0600306
Mark Young26c19372016-11-03 14:27:13 -0600307 return icd_term->GetPhysicalDeviceSurfaceCapabilitiesKHR(
308 phys_dev_term->phys_dev, surface, pSurfaceCapabilities);
Ian Elliottea666b22015-11-19 16:05:09 -0700309}
310
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600311// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceFormatsKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700312LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
313vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
314 VkSurfaceKHR surface,
315 uint32_t *pSurfaceFormatCount,
316 VkSurfaceFormatKHR *pSurfaceFormats) {
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700317 VkPhysicalDevice unwrapped_phys_dev =
318 loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700319 const VkLayerInstanceDispatchTable *disp;
320 disp = loader_get_instance_dispatch(physicalDevice);
321 VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700322 unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliottea666b22015-11-19 16:05:09 -0700323 return res;
324}
325
Mark Young573a7a12016-11-02 09:37:08 -0600326// This is the instance chain terminator function for
327// GetPhysicalDeviceSurfaceFormatsKHR
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700328VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormatsKHR(
329 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
330 uint32_t *pSurfaceFormatCount, VkSurfaceFormatKHR *pSurfaceFormats) {
Mark Young26c19372016-11-03 14:27:13 -0600331
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600332 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -0600333 struct loader_physical_device_term *phys_dev_term =
334 (struct loader_physical_device_term *)physicalDevice;
335 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600336 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -0600337 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600338 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -0600339 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
340 "VK_KHR_surface extension not enabled. "
341 "vkGetPhysicalDeviceSurfaceFormatsKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600342 return VK_SUCCESS;
343 }
344
345 // Next, if so, proceed with the implementation of this function:
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700346 assert(
347 pSurfaceFormatCount &&
348 "GetPhysicalDeviceSurfaceFormatsKHR: Error, null pSurfaceFormatCount");
Ian Elliottea666b22015-11-19 16:05:09 -0700349
Mark Young26c19372016-11-03 14:27:13 -0600350 assert(icd_term->GetPhysicalDeviceSurfaceFormatsKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700351 "loader: null GetPhysicalDeviceSurfaceFormatsKHR ICD pointer");
Ian Elliottea666b22015-11-19 16:05:09 -0700352
Karl Schultza9e989f2016-11-19 09:02:27 -0700353 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young5467d672016-06-28 10:52:43 -0600354 if (NULL != icd_surface->real_icd_surfaces &&
Mark Young3eda5882016-12-01 10:42:21 -0700355 (VkSurfaceKHR)NULL !=
356 icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young26c19372016-11-03 14:27:13 -0600357 return icd_term->GetPhysicalDeviceSurfaceFormatsKHR(
358 phys_dev_term->phys_dev,
359 icd_surface->real_icd_surfaces[phys_dev_term->icd_index],
Mark Young5467d672016-06-28 10:52:43 -0600360 pSurfaceFormatCount, pSurfaceFormats);
361 }
Mark Young5467d672016-06-28 10:52:43 -0600362
Mark Young26c19372016-11-03 14:27:13 -0600363 return icd_term->GetPhysicalDeviceSurfaceFormatsKHR(
364 phys_dev_term->phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliottea666b22015-11-19 16:05:09 -0700365}
366
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600367// This is the trampoline entrypoint for GetPhysicalDeviceSurfacePresentModesKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700368LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
369vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
370 VkSurfaceKHR surface,
371 uint32_t *pPresentModeCount,
372 VkPresentModeKHR *pPresentModes) {
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700373 VkPhysicalDevice unwrapped_phys_dev =
374 loader_unwrap_physical_device(physicalDevice);
Ian Elliottea666b22015-11-19 16:05:09 -0700375 const VkLayerInstanceDispatchTable *disp;
376 disp = loader_get_instance_dispatch(physicalDevice);
377 VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700378 unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliottea666b22015-11-19 16:05:09 -0700379 return res;
380}
381
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600382// This is the instance chain terminator function for
383// GetPhysicalDeviceSurfacePresentModesKHR
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700384VKAPI_ATTR VkResult VKAPI_CALL
385terminator_GetPhysicalDeviceSurfacePresentModesKHR(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700386 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
387 uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes) {
Mark Young26c19372016-11-03 14:27:13 -0600388
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600389 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -0600390 struct loader_physical_device_term *phys_dev_term =
391 (struct loader_physical_device_term *)physicalDevice;
392 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600393 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -0600394 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600395 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -0600396 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
397 "VK_KHR_surface extension not enabled. "
398 "vkGetPhysicalDeviceSurfacePresentModesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600399 return VK_SUCCESS;
400 }
401
402 // Next, if so, proceed with the implementation of this function:
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700403 assert(pPresentModeCount && "GetPhysicalDeviceSurfacePresentModesKHR: "
404 "Error, null pPresentModeCount");
Ian Elliottea666b22015-11-19 16:05:09 -0700405
Mark Young26c19372016-11-03 14:27:13 -0600406 assert(icd_term->GetPhysicalDeviceSurfacePresentModesKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700407 "loader: null GetPhysicalDeviceSurfacePresentModesKHR ICD pointer");
Ian Elliottea666b22015-11-19 16:05:09 -0700408
Karl Schultza9e989f2016-11-19 09:02:27 -0700409 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young5467d672016-06-28 10:52:43 -0600410 if (NULL != icd_surface->real_icd_surfaces &&
Mark Young3eda5882016-12-01 10:42:21 -0700411 (VkSurfaceKHR)NULL !=
412 icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young26c19372016-11-03 14:27:13 -0600413 return icd_term->GetPhysicalDeviceSurfacePresentModesKHR(
414 phys_dev_term->phys_dev,
415 icd_surface->real_icd_surfaces[phys_dev_term->icd_index],
Mark Young5467d672016-06-28 10:52:43 -0600416 pPresentModeCount, pPresentModes);
417 }
Mark Young5467d672016-06-28 10:52:43 -0600418
Mark Young26c19372016-11-03 14:27:13 -0600419 return icd_term->GetPhysicalDeviceSurfacePresentModesKHR(
420 phys_dev_term->phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliottea666b22015-11-19 16:05:09 -0700421}
422
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600423// Functions for the VK_KHR_swapchain extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700424
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600425// This is the trampoline entrypoint for CreateSwapchainKHR
Mark Young74dd5d12016-06-30 13:02:42 -0600426LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
427 VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
428 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700429 const VkLayerDispatchTable *disp;
430 disp = loader_get_dispatch(device);
Mark Young76b3fe02016-09-08 12:28:38 -0600431 return disp->CreateSwapchainKHR(device, pCreateInfo, pAllocator,
432 pSwapchain);
Ian Elliott9b89a472015-11-19 16:39:21 -0700433}
Ian Elliott7c352552015-11-19 13:14:05 -0700434
Mark Young5467d672016-06-28 10:52:43 -0600435VKAPI_ATTR VkResult VKAPI_CALL terminator_vkCreateSwapchainKHR(
436 VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
437 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {
438 uint32_t icd_index = 0;
439 struct loader_device *dev;
Mark Young26c19372016-11-03 14:27:13 -0600440 struct loader_icd_term *icd_term =
Mark Young573a7a12016-11-02 09:37:08 -0600441 loader_get_icd_and_device(device, &dev, &icd_index);
Mark Young26c19372016-11-03 14:27:13 -0600442 if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) {
Karl Schultza9e989f2016-11-19 09:02:27 -0700443 VkIcdSurface *icd_surface =
444 (VkIcdSurface *)(uintptr_t)pCreateInfo->surface;
Mark Young5467d672016-06-28 10:52:43 -0600445 if (NULL != icd_surface->real_icd_surfaces) {
Mark Young3eda5882016-12-01 10:42:21 -0700446 if ((VkSurfaceKHR)NULL !=
447 icd_surface->real_icd_surfaces[icd_index]) {
Mark Young5467d672016-06-28 10:52:43 -0600448 // We found the ICD, and there is an ICD KHR surface
449 // associated with it, so copy the CreateInfo struct
450 // and point it at the ICD's surface.
451 VkSwapchainCreateInfoKHR *pCreateCopy =
452 loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR));
453 if (NULL == pCreateCopy) {
454 return VK_ERROR_OUT_OF_HOST_MEMORY;
455 }
Mark Young573a7a12016-11-02 09:37:08 -0600456 memcpy(pCreateCopy, pCreateInfo,
457 sizeof(VkSwapchainCreateInfoKHR));
Mark Young5467d672016-06-28 10:52:43 -0600458 pCreateCopy->surface =
459 icd_surface->real_icd_surfaces[icd_index];
Mark Young26c19372016-11-03 14:27:13 -0600460 return icd_term->CreateSwapchainKHR(device, pCreateCopy,
461 pAllocator, pSwapchain);
Mark Young5467d672016-06-28 10:52:43 -0600462 }
463 }
Mark Young26c19372016-11-03 14:27:13 -0600464 return icd_term->CreateSwapchainKHR(device, pCreateInfo, pAllocator,
465 pSwapchain);
Mark Young5467d672016-06-28 10:52:43 -0600466 }
467 return VK_SUCCESS;
468}
469
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600470// This is the trampoline entrypoint for DestroySwapchainKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700471LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL
472vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
473 const VkAllocationCallbacks *pAllocator) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700474 const VkLayerDispatchTable *disp;
475 disp = loader_get_dispatch(device);
476 disp->DestroySwapchainKHR(device, swapchain, pAllocator);
477}
Ian Elliott7c352552015-11-19 13:14:05 -0700478
Mark Young5467d672016-06-28 10:52:43 -0600479/*
480 * This is the trampoline entrypoint
481 * for GetSwapchainImagesKHR
482 */
483LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
484 VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
485 VkImage *pSwapchainImages) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700486 const VkLayerDispatchTable *disp;
487 disp = loader_get_dispatch(device);
Mark Young573a7a12016-11-02 09:37:08 -0600488 return disp->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount,
489 pSwapchainImages);
Ian Elliott9b89a472015-11-19 16:39:21 -0700490}
491
Mark Young5467d672016-06-28 10:52:43 -0600492/*
493 * This is the trampoline entrypoint
494 * for AcquireNextImageKHR
495 */
496LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
497 VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
498 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700499 const VkLayerDispatchTable *disp;
500 disp = loader_get_dispatch(device);
Mark Young573a7a12016-11-02 09:37:08 -0600501 return disp->AcquireNextImageKHR(device, swapchain, timeout, semaphore,
502 fence, pImageIndex);
Ian Elliott9b89a472015-11-19 16:39:21 -0700503}
504
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600505// This is the trampoline entrypoint for QueuePresentKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700506LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
507vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
Ian Elliott9b89a472015-11-19 16:39:21 -0700508 const VkLayerDispatchTable *disp;
509 disp = loader_get_dispatch(queue);
Mark Young76b3fe02016-09-08 12:28:38 -0600510 return disp->QueuePresentKHR(queue, pPresentInfo);
Ian Elliott9b89a472015-11-19 16:39:21 -0700511}
Ian Elliott7c352552015-11-19 13:14:05 -0700512
Mark Youngf27962c2016-09-16 10:18:42 -0600513static VkIcdSurface *AllocateIcdSurfaceStruct(struct loader_instance *instance,
514 size_t base_size,
515 size_t platform_size,
516 bool create_icd_surfs) {
517 // Next, if so, proceed with the implementation of this function:
518 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(
519 instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
520 if (pIcdSurface != NULL) {
521 // Setup the new sizes and offsets so we can grow the structures in the
522 // future without having problems
523 pIcdSurface->base_size = (uint32_t)base_size;
524 pIcdSurface->platform_size = (uint32_t)platform_size;
525 pIcdSurface->non_platform_offset = (uint32_t)(
526 (uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
527 pIcdSurface->entire_size = sizeof(VkIcdSurface);
528
529 if (create_icd_surfs) {
530 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(
531 instance, sizeof(VkSurfaceKHR) * instance->total_icd_count,
532 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
533 if (pIcdSurface->real_icd_surfaces == NULL) {
534 loader_instance_heap_free(instance, pIcdSurface);
535 pIcdSurface = NULL;
536 } else {
537 memset(pIcdSurface->real_icd_surfaces, 0,
538 sizeof(VkSurfaceKHR) * instance->total_icd_count);
539 }
540 } else {
541 pIcdSurface->real_icd_surfaces = NULL;
542 }
543 }
544 return pIcdSurface;
545}
546
Ian Elliott7c352552015-11-19 13:14:05 -0700547#ifdef VK_USE_PLATFORM_WIN32_KHR
548
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600549// Functions for the VK_KHR_win32_surface extension:
550
551// This is the trampoline entrypoint for CreateWin32SurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -0600552LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
553 VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
554 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700555 const VkLayerInstanceDispatchTable *disp;
556 disp = loader_get_instance_dispatch(instance);
557 VkResult res;
558
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700559 res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator,
560 pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700561 return res;
562}
563
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600564// This is the instance chain terminator function for CreateWin32SurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -0600565VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWin32SurfaceKHR(
566 VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
567 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600568 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600569 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600570 uint32_t i = 0;
571
Mark Youngf27962c2016-09-16 10:18:42 -0600572 // Initialize pSurface to NULL just to be safe.
573 *pSurface = VK_NULL_HANDLE;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600574 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700575 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600576 if (!ptr_instance->wsi_win32_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -0600577 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
578 "VK_KHR_win32_surface extension not enabled. "
579 "vkCreateWin32SurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600580 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
581 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600582 }
583
584 // Next, if so, proceed with the implementation of this function:
Mark Young573a7a12016-11-02 09:37:08 -0600585 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance,
586 sizeof(pIcdSurface->win_surf.base),
587 sizeof(pIcdSurface->win_surf), true);
Ian Elliott7c352552015-11-19 13:14:05 -0700588 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600589 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
590 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700591 }
592
Mark Young5467d672016-06-28 10:52:43 -0600593 pIcdSurface->win_surf.base.platform = VK_ICD_WSI_PLATFORM_WIN32;
594 pIcdSurface->win_surf.hinstance = pCreateInfo->hinstance;
595 pIcdSurface->win_surf.hwnd = pCreateInfo->hwnd;
Ian Elliott7c352552015-11-19 13:14:05 -0700596
Mark Young5467d672016-06-28 10:52:43 -0600597 // Loop through each ICD and determine if they need to create a surface
Mark Young26c19372016-11-03 14:27:13 -0600598 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
599 icd_term != NULL; icd_term = icd_term->next, i++) {
600 if (icd_term->scanned_icd->interface_version >=
Mark Young5467d672016-06-28 10:52:43 -0600601 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600602 if (NULL != icd_term->CreateWin32SurfaceKHR) {
603 vkRes = icd_term->CreateWin32SurfaceKHR(
604 icd_term->instance, pCreateInfo, pAllocator,
Mark Young5467d672016-06-28 10:52:43 -0600605 &pIcdSurface->real_icd_surfaces[i]);
606 if (VK_SUCCESS != vkRes) {
607 goto out;
608 }
609 }
610 }
611 }
612
613 *pSurface = (VkSurfaceKHR)(pIcdSurface);
614
615out:
616
617 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
618 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600619 i = 0;
Mark Young26c19372016-11-03 14:27:13 -0600620 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
621 icd_term != NULL; icd_term = icd_term->next, i++) {
Jamie Madille416fcc2016-11-30 12:47:45 -0500622 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young26c19372016-11-03 14:27:13 -0600623 NULL != icd_term->DestroySurfaceKHR) {
624 icd_term->DestroySurfaceKHR(
625 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
626 pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600627 }
628 }
Mark Young573a7a12016-11-02 09:37:08 -0600629 loader_instance_heap_free(ptr_instance,
630 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// GetPhysicalDeviceWin32PresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700640LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
641vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
642 uint32_t queueFamilyIndex) {
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700643 VkPhysicalDevice unwrapped_phys_dev =
644 loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700645 const VkLayerInstanceDispatchTable *disp;
646 disp = loader_get_instance_dispatch(physicalDevice);
647 VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700648 unwrapped_phys_dev, queueFamilyIndex);
Ian Elliotte851dd62015-11-24 15:39:10 -0700649 return res;
650}
651
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600652// This is the instance chain terminator function for
653// GetPhysicalDeviceWin32PresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700654VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700655terminator_GetPhysicalDeviceWin32PresentationSupportKHR(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700656 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600657 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -0600658 struct loader_physical_device_term *phys_dev_term =
659 (struct loader_physical_device_term *)physicalDevice;
660 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600661 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -0600662 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600663 if (!ptr_instance->wsi_win32_surface_enabled) {
Jon Ashburnc466da52016-04-15 09:25:03 -0600664 loader_log(
665 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
666 "VK_KHR_win32_surface extension not enabled. "
667 "vkGetPhysicalDeviceWin32PresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600668 return VK_SUCCESS;
669 }
670
671 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -0600672 assert(icd_term->GetPhysicalDeviceWin32PresentationSupportKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700673 "loader: null GetPhysicalDeviceWin32PresentationSupportKHR ICD "
674 "pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -0700675
Mark Young26c19372016-11-03 14:27:13 -0600676 return icd_term->GetPhysicalDeviceWin32PresentationSupportKHR(
677 phys_dev_term->phys_dev, queueFamilyIndex);
Ian Elliotte851dd62015-11-24 15:39:10 -0700678}
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -0700679#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott7c352552015-11-19 13:14:05 -0700680
681#ifdef VK_USE_PLATFORM_MIR_KHR
682
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600683// Functions for the VK_KHR_mir_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -0700684
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600685// This is the trampoline entrypoint for CreateMirSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -0600686LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(
687 VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
688 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700689 const VkLayerInstanceDispatchTable *disp;
690 disp = loader_get_instance_dispatch(instance);
691 VkResult res;
692
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700693 res =
694 disp->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700695 return res;
696}
697
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600698// This is the instance chain terminator function for CreateMirSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -0600699VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMirSurfaceKHR(
700 VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
701 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600702 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600703 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600704 uint32_t i = 0;
705
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600706 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700707 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600708 if (!ptr_instance->wsi_mir_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -0600709 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
710 "VK_KHR_mir_surface extension not enabled. "
711 "vkCreateMirSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600712 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
713 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600714 }
715
716 // Next, if so, proceed with the implementation of this function:
Mark Young573a7a12016-11-02 09:37:08 -0600717 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance,
718 sizeof(pIcdSurface->mir_surf.base),
719 sizeof(pIcdSurface->mir_surf), true);
Ian Elliott7c352552015-11-19 13:14:05 -0700720 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600721 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
722 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700723 }
724
Mark Young5467d672016-06-28 10:52:43 -0600725 pIcdSurface->mir_surf.base.platform = VK_ICD_WSI_PLATFORM_MIR;
726 pIcdSurface->mir_surf.connection = pCreateInfo->connection;
727 pIcdSurface->mir_surf.mirSurface = pCreateInfo->mirSurface;
728
Mark Young5467d672016-06-28 10:52:43 -0600729 // Loop through each ICD and determine if they need to create a surface
Mark Young26c19372016-11-03 14:27:13 -0600730 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
731 icd_term != NULL; icd_term = icd_term->next, i++) {
732 if (icd_term->scanned_icd->interface_version >=
Mark Young5467d672016-06-28 10:52:43 -0600733 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600734 if (NULL != icd_term->CreateMirSurfaceKHR) {
735 vkRes = icd_term->CreateMirSurfaceKHR(
736 icd_term->instance, pCreateInfo, pAllocator,
Mark Young5467d672016-06-28 10:52:43 -0600737 &pIcdSurface->real_icd_surfaces[i]);
738 if (VK_SUCCESS != vkRes) {
739 goto out;
740 }
741 }
742 }
743 }
Ian Elliott7c352552015-11-19 13:14:05 -0700744
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700745 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700746
Mark Young5467d672016-06-28 10:52:43 -0600747out:
748
749 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
750 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600751 i = 0;
Mark Young26c19372016-11-03 14:27:13 -0600752 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
753 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young3eda5882016-12-01 10:42:21 -0700754 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young26c19372016-11-03 14:27:13 -0600755 NULL != icd_term->DestroySurfaceKHR) {
756 icd_term->DestroySurfaceKHR(
757 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
758 pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600759 }
760 }
Mark Young573a7a12016-11-02 09:37:08 -0600761 loader_instance_heap_free(ptr_instance,
762 pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600763 }
764 loader_instance_heap_free(ptr_instance, pIcdSurface);
765 }
766
767 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700768}
Ian Elliotte851dd62015-11-24 15:39:10 -0700769
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600770// This is the trampoline entrypoint for
771// GetPhysicalDeviceMirPresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700772LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
773vkGetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,
774 uint32_t queueFamilyIndex,
775 MirConnection *connection) {
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700776 VkPhysicalDevice unwrapped_phys_dev =
777 loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700778 const VkLayerInstanceDispatchTable *disp;
779 disp = loader_get_instance_dispatch(physicalDevice);
780 VkBool32 res = disp->GetPhysicalDeviceMirPresentationSupportKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700781 unwrapped_phys_dev, queueFamilyIndex, connection);
Ian Elliotte851dd62015-11-24 15:39:10 -0700782 return res;
783}
784
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600785// This is the instance chain terminator function for
786// GetPhysicalDeviceMirPresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700787VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700788terminator_GetPhysicalDeviceMirPresentationSupportKHR(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700789 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
790 MirConnection *connection) {
Mark Young26c19372016-11-03 14:27:13 -0600791
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600792 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -0600793 struct loader_physical_device_term *phys_dev_term =
794 (struct loader_physical_device_term *)physicalDevice;
795 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600796 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -0600797 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600798 if (!ptr_instance->wsi_mir_surface_enabled) {
Jon Ashburnc466da52016-04-15 09:25:03 -0600799 loader_log(
800 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
801 "VK_KHR_mir_surface extension not enabled. "
802 "vkGetPhysicalDeviceMirPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600803 return VK_SUCCESS;
804 }
805
806 // Next, if so, proceed with the implementation of this function:
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700807 assert(
Mark Young26c19372016-11-03 14:27:13 -0600808 icd_term->GetPhysicalDeviceMirPresentationSupportKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700809 "loader: null GetPhysicalDeviceMirPresentationSupportKHR ICD pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -0700810
Mark Young26c19372016-11-03 14:27:13 -0600811 return icd_term->GetPhysicalDeviceMirPresentationSupportKHR(
812 phys_dev_term->phys_dev, queueFamilyIndex, connection);
Ian Elliotte851dd62015-11-24 15:39:10 -0700813}
Ian Elliott7c352552015-11-19 13:14:05 -0700814#endif // VK_USE_PLATFORM_MIR_KHR
815
816#ifdef VK_USE_PLATFORM_WAYLAND_KHR
817
Mark Young5467d672016-06-28 10:52:43 -0600818/*
819 * This is the trampoline entrypoint
820 * for CreateWaylandSurfaceKHR
821 */
822LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
823 VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
824 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700825 const VkLayerInstanceDispatchTable *disp;
826 disp = loader_get_instance_dispatch(instance);
827 VkResult res;
828
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700829 res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator,
830 pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700831 return res;
832}
833
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600834// This is the instance chain terminator function for CreateWaylandSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -0600835VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700836 VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
837 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600838 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600839 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600840 uint32_t i = 0;
841
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600842 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700843 struct loader_instance *ptr_instance = loader_get_instance(instance);
Jon Ashburn436d6a32016-03-24 17:26:59 -0600844 if (!ptr_instance->wsi_wayland_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -0600845 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
846 "VK_KHR_wayland_surface extension not enabled. "
847 "vkCreateWaylandSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600848 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
849 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600850 }
851
852 // Next, if so, proceed with the implementation of this function:
Mark Youngd7fb1592016-10-12 14:18:44 -0600853 pIcdSurface = AllocateIcdSurfaceStruct(
Mark Youngf27962c2016-09-16 10:18:42 -0600854 ptr_instance, sizeof(pIcdSurface->wayland_surf.base),
855 sizeof(pIcdSurface->wayland_surf), true);
Ian Elliott7c352552015-11-19 13:14:05 -0700856 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600857 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
858 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700859 }
860
Mark Young5467d672016-06-28 10:52:43 -0600861 pIcdSurface->wayland_surf.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
862 pIcdSurface->wayland_surf.display = pCreateInfo->display;
863 pIcdSurface->wayland_surf.surface = pCreateInfo->surface;
864
Mark Young5467d672016-06-28 10:52:43 -0600865 // Loop through each ICD and determine if they need to create a surface
Mark Young26c19372016-11-03 14:27:13 -0600866 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
867 icd_term != NULL; icd_term = icd_term->next, i++) {
868 if (icd_term->scanned_icd->interface_version >=
Mark Young5467d672016-06-28 10:52:43 -0600869 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -0600870 if (NULL != icd_term->CreateWaylandSurfaceKHR) {
871 vkRes = icd_term->CreateWaylandSurfaceKHR(
872 icd_term->instance, pCreateInfo, pAllocator,
Mark Young5467d672016-06-28 10:52:43 -0600873 &pIcdSurface->real_icd_surfaces[i]);
874 if (VK_SUCCESS != vkRes) {
875 goto out;
876 }
877 }
878 }
879 }
Ian Elliott7c352552015-11-19 13:14:05 -0700880
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700881 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -0700882
Mark Young5467d672016-06-28 10:52:43 -0600883out:
884
885 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
886 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -0600887 i = 0;
Mark Young26c19372016-11-03 14:27:13 -0600888 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
889 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young3eda5882016-12-01 10:42:21 -0700890 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young26c19372016-11-03 14:27:13 -0600891 NULL != icd_term->DestroySurfaceKHR) {
892 icd_term->DestroySurfaceKHR(
893 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
894 pAllocator);
Mark Young5467d672016-06-28 10:52:43 -0600895 }
896 }
Mark Young573a7a12016-11-02 09:37:08 -0600897 loader_instance_heap_free(ptr_instance,
898 pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -0600899 }
900 loader_instance_heap_free(ptr_instance, pIcdSurface);
901 }
902
903 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -0700904}
Ian Elliotte851dd62015-11-24 15:39:10 -0700905
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600906// This is the trampoline entrypoint for
907// GetPhysicalDeviceWaylandPresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700908LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
909vkGetPhysicalDeviceWaylandPresentationSupportKHR(
910 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
911 struct wl_display *display) {
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700912 VkPhysicalDevice unwrapped_phys_dev =
913 loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -0700914 const VkLayerInstanceDispatchTable *disp;
915 disp = loader_get_instance_dispatch(physicalDevice);
916 VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -0700917 unwrapped_phys_dev, queueFamilyIndex, display);
Ian Elliotte851dd62015-11-24 15:39:10 -0700918 return res;
919}
920
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600921// This is the instance chain terminator function for
922// GetPhysicalDeviceWaylandPresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700923VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburnc4e9ae62016-02-26 13:14:27 -0700924terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700925 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
926 struct wl_display *display) {
Mark Young26c19372016-11-03 14:27:13 -0600927
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600928 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -0600929 struct loader_physical_device_term *phys_dev_term =
930 (struct loader_physical_device_term *)physicalDevice;
931 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600932 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -0600933 (struct loader_instance *)icd_term->this_instance;
Jon Ashburn436d6a32016-03-24 17:26:59 -0600934 if (!ptr_instance->wsi_wayland_surface_enabled) {
Jon Ashburnc466da52016-04-15 09:25:03 -0600935 loader_log(
936 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
937 "VK_KHR_wayland_surface extension not enabled. "
938 "vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600939 return VK_SUCCESS;
940 }
941
942 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -0600943 assert(icd_term->GetPhysicalDeviceWaylandPresentationSupportKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700944 "loader: null GetPhysicalDeviceWaylandPresentationSupportKHR ICD "
945 "pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -0700946
Mark Young26c19372016-11-03 14:27:13 -0600947 return icd_term->GetPhysicalDeviceWaylandPresentationSupportKHR(
948 phys_dev_term->phys_dev, queueFamilyIndex, display);
Ian Elliotte851dd62015-11-24 15:39:10 -0700949}
Ian Elliott7c352552015-11-19 13:14:05 -0700950#endif // VK_USE_PLATFORM_WAYLAND_KHR
951
952#ifdef VK_USE_PLATFORM_XCB_KHR
953
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600954// Functions for the VK_KHR_xcb_surface extension:
955
956// This is the trampoline entrypoint for CreateXcbSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -0600957LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
958 VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
959 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -0700960 const VkLayerInstanceDispatchTable *disp;
961 disp = loader_get_instance_dispatch(instance);
962 VkResult res;
963
Jon Ashburn1c75aec2016-02-02 17:47:28 -0700964 res =
965 disp->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -0700966 return res;
967}
968
Mark Lobodzinskib16da052016-08-31 09:31:29 -0600969// This is the instance chain terminator function for CreateXcbSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -0600970VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXcbSurfaceKHR(
971 VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
972 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -0600973 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -0600974 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -0600975 uint32_t i = 0;
976
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600977 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -0700978 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600979 if (!ptr_instance->wsi_xcb_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -0600980 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
981 "VK_KHR_xcb_surface extension not enabled. "
982 "vkCreateXcbSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -0600983 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
984 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -0600985 }
986
987 // Next, if so, proceed with the implementation of this function:
Mark Young573a7a12016-11-02 09:37:08 -0600988 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance,
989 sizeof(pIcdSurface->xcb_surf.base),
990 sizeof(pIcdSurface->xcb_surf), true);
Ian Elliott7c352552015-11-19 13:14:05 -0700991 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -0600992 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
993 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -0700994 }
995
Mark Young5467d672016-06-28 10:52:43 -0600996 pIcdSurface->xcb_surf.base.platform = VK_ICD_WSI_PLATFORM_XCB;
997 pIcdSurface->xcb_surf.connection = pCreateInfo->connection;
998 pIcdSurface->xcb_surf.window = pCreateInfo->window;
999
Mark Young5467d672016-06-28 10:52:43 -06001000 // Loop through each ICD and determine if they need to create a surface
Mark Young26c19372016-11-03 14:27:13 -06001001 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
1002 icd_term != NULL; icd_term = icd_term->next, i++) {
1003 if (icd_term->scanned_icd->interface_version >=
Mark Young5467d672016-06-28 10:52:43 -06001004 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -06001005 if (NULL != icd_term->CreateXcbSurfaceKHR) {
1006 vkRes = icd_term->CreateXcbSurfaceKHR(
1007 icd_term->instance, pCreateInfo, pAllocator,
Mark Young5467d672016-06-28 10:52:43 -06001008 &pIcdSurface->real_icd_surfaces[i]);
1009 if (VK_SUCCESS != vkRes) {
1010 goto out;
1011 }
1012 }
1013 }
1014 }
Ian Elliott7c352552015-11-19 13:14:05 -07001015
Mark Young3eda5882016-12-01 10:42:21 -07001016 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -07001017
Mark Young5467d672016-06-28 10:52:43 -06001018out:
1019
1020 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1021 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -06001022 i = 0;
Mark Young26c19372016-11-03 14:27:13 -06001023 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
1024 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young3eda5882016-12-01 10:42:21 -07001025 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young26c19372016-11-03 14:27:13 -06001026 NULL != icd_term->DestroySurfaceKHR) {
1027 icd_term->DestroySurfaceKHR(
1028 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
1029 pAllocator);
Mark Young5467d672016-06-28 10:52:43 -06001030 }
1031 }
Mark Young573a7a12016-11-02 09:37:08 -06001032 loader_instance_heap_free(ptr_instance,
1033 pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -06001034 }
1035 loader_instance_heap_free(ptr_instance, pIcdSurface);
1036 }
1037
1038 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -07001039}
Ian Elliotte851dd62015-11-24 15:39:10 -07001040
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001041// This is the trampoline entrypoint for
1042// GetPhysicalDeviceXcbPresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001043LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
1044vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
1045 uint32_t queueFamilyIndex,
1046 xcb_connection_t *connection,
1047 xcb_visualid_t visual_id) {
Jon Ashburnfd02a0f2016-03-01 19:51:07 -07001048 VkPhysicalDevice unwrapped_phys_dev =
1049 loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -07001050 const VkLayerInstanceDispatchTable *disp;
1051 disp = loader_get_instance_dispatch(physicalDevice);
1052 VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -07001053 unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliotte851dd62015-11-24 15:39:10 -07001054 return res;
1055}
1056
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001057// This is the instance chain terminator function for
1058// GetPhysicalDeviceXcbPresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001059VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001060terminator_GetPhysicalDeviceXcbPresentationSupportKHR(
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001061 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
1062 xcb_connection_t *connection, xcb_visualid_t visual_id) {
Mark Young26c19372016-11-03 14:27:13 -06001063
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001064 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -06001065 struct loader_physical_device_term *phys_dev_term =
1066 (struct loader_physical_device_term *)physicalDevice;
1067 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001068 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -06001069 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001070 if (!ptr_instance->wsi_xcb_surface_enabled) {
Jon Ashburnc466da52016-04-15 09:25:03 -06001071 loader_log(
1072 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1073 "VK_KHR_xcb_surface extension not enabled. "
1074 "vkGetPhysicalDeviceXcbPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001075 return VK_SUCCESS;
1076 }
1077
1078 // Next, if so, proceed with the implementation of this function:
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001079 assert(
Mark Young26c19372016-11-03 14:27:13 -06001080 icd_term->GetPhysicalDeviceXcbPresentationSupportKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001081 "loader: null GetPhysicalDeviceXcbPresentationSupportKHR ICD pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -07001082
Mark Young26c19372016-11-03 14:27:13 -06001083 return icd_term->GetPhysicalDeviceXcbPresentationSupportKHR(
1084 phys_dev_term->phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliotte851dd62015-11-24 15:39:10 -07001085}
Ian Elliott7c352552015-11-19 13:14:05 -07001086#endif // VK_USE_PLATFORM_XCB_KHR
1087
1088#ifdef VK_USE_PLATFORM_XLIB_KHR
1089
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001090// Functions for the VK_KHR_xlib_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07001091
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001092// This is the trampoline entrypoint for CreateXlibSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -06001093LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
1094 VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
1095 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburn16edfa62015-11-25 17:55:49 -07001096 const VkLayerInstanceDispatchTable *disp;
1097 disp = loader_get_instance_dispatch(instance);
1098 VkResult res;
1099
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001100 res =
1101 disp->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburn16edfa62015-11-25 17:55:49 -07001102 return res;
1103}
1104
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001105// This is the instance chain terminator function for CreateXlibSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -06001106VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXlibSurfaceKHR(
1107 VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
1108 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young5467d672016-06-28 10:52:43 -06001109 VkResult vkRes = VK_SUCCESS;
Mark Youngd7fb1592016-10-12 14:18:44 -06001110 VkIcdSurface *pIcdSurface = NULL;
Mark Young573a7a12016-11-02 09:37:08 -06001111 uint32_t i = 0;
1112
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001113 // First, check to ensure the appropriate extension was enabled:
Ian Elliott1693f592015-11-23 10:17:23 -07001114 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001115 if (!ptr_instance->wsi_xlib_surface_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -06001116 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1117 "VK_KHR_xlib_surface extension not enabled. "
1118 "vkCreateXlibSurfaceKHR not executed!\n");
Mark Young5467d672016-06-28 10:52:43 -06001119 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1120 goto out;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001121 }
1122
1123 // Next, if so, proceed with the implementation of this function:
Mark Youngd7fb1592016-10-12 14:18:44 -06001124 pIcdSurface = AllocateIcdSurfaceStruct(
Mark Youngf27962c2016-09-16 10:18:42 -06001125 ptr_instance, sizeof(pIcdSurface->xlib_surf.base),
1126 sizeof(pIcdSurface->xlib_surf), true);
Ian Elliott7c352552015-11-19 13:14:05 -07001127 if (pIcdSurface == NULL) {
Mark Young5467d672016-06-28 10:52:43 -06001128 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1129 goto out;
Ian Elliott7c352552015-11-19 13:14:05 -07001130 }
1131
Mark Young5467d672016-06-28 10:52:43 -06001132 pIcdSurface->xlib_surf.base.platform = VK_ICD_WSI_PLATFORM_XLIB;
1133 pIcdSurface->xlib_surf.dpy = pCreateInfo->dpy;
1134 pIcdSurface->xlib_surf.window = pCreateInfo->window;
1135
Mark Young5467d672016-06-28 10:52:43 -06001136 // Loop through each ICD and determine if they need to create a surface
Mark Young26c19372016-11-03 14:27:13 -06001137 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
1138 icd_term != NULL; icd_term = icd_term->next, i++) {
1139 if (icd_term->scanned_icd->interface_version >=
Mark Young5467d672016-06-28 10:52:43 -06001140 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -06001141 if (NULL != icd_term->CreateXlibSurfaceKHR) {
1142 vkRes = icd_term->CreateXlibSurfaceKHR(
1143 icd_term->instance, pCreateInfo, pAllocator,
Mark Young5467d672016-06-28 10:52:43 -06001144 &pIcdSurface->real_icd_surfaces[i]);
1145 if (VK_SUCCESS != vkRes) {
1146 goto out;
1147 }
1148 }
1149 }
1150 }
Ian Elliott7c352552015-11-19 13:14:05 -07001151
Mark Young3eda5882016-12-01 10:42:21 -07001152 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott7c352552015-11-19 13:14:05 -07001153
Mark Young5467d672016-06-28 10:52:43 -06001154out:
1155
1156 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1157 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -06001158 i = 0;
Mark Young26c19372016-11-03 14:27:13 -06001159 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
1160 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young3eda5882016-12-01 10:42:21 -07001161 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young26c19372016-11-03 14:27:13 -06001162 NULL != icd_term->DestroySurfaceKHR) {
1163 icd_term->DestroySurfaceKHR(
1164 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
1165 pAllocator);
Mark Young5467d672016-06-28 10:52:43 -06001166 }
1167 }
Mark Young573a7a12016-11-02 09:37:08 -06001168 loader_instance_heap_free(ptr_instance,
1169 pIcdSurface->real_icd_surfaces);
Mark Young5467d672016-06-28 10:52:43 -06001170 }
1171 loader_instance_heap_free(ptr_instance, pIcdSurface);
1172 }
1173
1174 return vkRes;
Ian Elliott7c352552015-11-19 13:14:05 -07001175}
Ian Elliotte851dd62015-11-24 15:39:10 -07001176
Mark Young573a7a12016-11-02 09:37:08 -06001177// This is the trampoline entrypoint for
1178// GetPhysicalDeviceXlibPresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001179LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
1180vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
1181 uint32_t queueFamilyIndex,
1182 Display *dpy, VisualID visualID) {
Jon Ashburnfd02a0f2016-03-01 19:51:07 -07001183 VkPhysicalDevice unwrapped_phys_dev =
1184 loader_unwrap_physical_device(physicalDevice);
Ian Elliotte851dd62015-11-24 15:39:10 -07001185 const VkLayerInstanceDispatchTable *disp;
1186 disp = loader_get_instance_dispatch(physicalDevice);
1187 VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(
Jon Ashburnfd02a0f2016-03-01 19:51:07 -07001188 unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliotte851dd62015-11-24 15:39:10 -07001189 return res;
1190}
1191
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001192// This is the instance chain terminator function for
1193// GetPhysicalDeviceXlibPresentationSupportKHR
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001194VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001195terminator_GetPhysicalDeviceXlibPresentationSupportKHR(
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001196 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display *dpy,
1197 VisualID visualID) {
Mark Young26c19372016-11-03 14:27:13 -06001198
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001199 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -06001200 struct loader_physical_device_term *phys_dev_term =
1201 (struct loader_physical_device_term *)physicalDevice;
1202 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001203 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -06001204 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001205 if (!ptr_instance->wsi_xlib_surface_enabled) {
Jon Ashburnc466da52016-04-15 09:25:03 -06001206 loader_log(
1207 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1208 "VK_KHR_xlib_surface extension not enabled. "
1209 "vkGetPhysicalDeviceXlibPresentationSupportKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001210 return VK_SUCCESS;
1211 }
1212
1213 // Next, if so, proceed with the implementation of this function:
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001214 assert(
Mark Young26c19372016-11-03 14:27:13 -06001215 icd_term->GetPhysicalDeviceXlibPresentationSupportKHR &&
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001216 "loader: null GetPhysicalDeviceXlibPresentationSupportKHR ICD pointer");
Ian Elliotte851dd62015-11-24 15:39:10 -07001217
Mark Young26c19372016-11-03 14:27:13 -06001218 return icd_term->GetPhysicalDeviceXlibPresentationSupportKHR(
1219 phys_dev_term->phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliotte851dd62015-11-24 15:39:10 -07001220}
Ian Elliott7c352552015-11-19 13:14:05 -07001221#endif // VK_USE_PLATFORM_XLIB_KHR
1222
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001223#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001224
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001225// Functions for the VK_KHR_android_surface extension:
1226
1227// This is the trampoline entrypoint for CreateAndroidSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -06001228LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
1229 VkInstance instance, ANativeWindow *window,
1230 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001231 const VkLayerInstanceDispatchTable *disp;
1232 disp = loader_get_instance_dispatch(instance);
1233 VkResult res;
1234
1235 res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
1236 return res;
1237}
1238
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001239// This is the instance chain terminator function for CreateAndroidSurfaceKHR
Mark Young74dd5d12016-06-30 13:02:42 -06001240VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(
1241 VkInstance instance, Window window, const VkAllocationCallbacks *pAllocator,
1242 VkSurfaceKHR *pSurface) {
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001243 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001244 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001245 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -06001246 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1247 "VK_KHR_display extension not enabled. "
1248 "vkCreateAndroidSurfaceKHR not executed!\n");
Jeremy Hayes0231e1c2016-06-14 11:50:02 -06001249 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001250 }
1251
1252 // Next, if so, proceed with the implementation of this function:
Mark Young5467d672016-06-28 10:52:43 -06001253 VkIcdSurfaceAndroid *pIcdSurface =
Mark Young74dd5d12016-06-30 13:02:42 -06001254 loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceAndroid),
Mark Young5467d672016-06-28 10:52:43 -06001255 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001256 if (pIcdSurface == NULL) {
1257 return VK_ERROR_OUT_OF_HOST_MEMORY;
1258 }
1259
1260 pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_ANDROID;
1261 pIcdSurface->dpy = dpy;
1262 pIcdSurface->window = window;
1263
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001264 *pSurface = (VkSurfaceKHR)pIcdSurface;
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001265
1266 return VK_SUCCESS;
1267}
1268
1269#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001270
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001271// Functions for the VK_KHR_display instance extension:
Jon Ashburncc370d02016-03-08 09:30:30 -07001272LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
Jon Ashburnc466da52016-04-15 09:25:03 -06001273vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1274 uint32_t *pPropertyCount,
1275 VkDisplayPropertiesKHR *pProperties) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001276 VkPhysicalDevice unwrapped_phys_dev =
1277 loader_unwrap_physical_device(physicalDevice);
1278 const VkLayerInstanceDispatchTable *disp;
1279 disp = loader_get_instance_dispatch(physicalDevice);
1280 VkResult res = disp->GetPhysicalDeviceDisplayPropertiesKHR(
1281 unwrapped_phys_dev, pPropertyCount, pProperties);
1282 return res;
1283}
1284
Jon Ashburnc466da52016-04-15 09:25:03 -06001285VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPropertiesKHR(
1286 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1287 VkDisplayPropertiesKHR *pProperties) {
Mark Young26c19372016-11-03 14:27:13 -06001288
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001289 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -06001290 struct loader_physical_device_term *phys_dev_term =
1291 (struct loader_physical_device_term *)physicalDevice;
1292 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001293 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -06001294 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001295 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -06001296 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1297 "VK_KHR_display extension not enabled. "
1298 "vkGetPhysicalDeviceDisplayPropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001299 return VK_SUCCESS;
1300 }
1301
1302 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -06001303 assert(icd_term->GetPhysicalDeviceDisplayPropertiesKHR &&
Jon Ashburnc466da52016-04-15 09:25:03 -06001304 "loader: null GetPhysicalDeviceDisplayPropertiesKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001305
Mark Young26c19372016-11-03 14:27:13 -06001306 return icd_term->GetPhysicalDeviceDisplayPropertiesKHR(
1307 phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001308}
1309
1310LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
1311vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
Jon Ashburnc466da52016-04-15 09:25:03 -06001312 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1313 VkDisplayPlanePropertiesKHR *pProperties) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001314 VkPhysicalDevice unwrapped_phys_dev =
1315 loader_unwrap_physical_device(physicalDevice);
1316 const VkLayerInstanceDispatchTable *disp;
1317 disp = loader_get_instance_dispatch(physicalDevice);
1318 VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(
1319 unwrapped_phys_dev, pPropertyCount, pProperties);
1320 return res;
1321}
1322
1323VKAPI_ATTR VkResult VKAPI_CALL
1324terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(
Jon Ashburnc466da52016-04-15 09:25:03 -06001325 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1326 VkDisplayPlanePropertiesKHR *pProperties) {
Mark Young26c19372016-11-03 14:27:13 -06001327
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001328 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -06001329 struct loader_physical_device_term *phys_dev_term =
1330 (struct loader_physical_device_term *)physicalDevice;
1331 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001332 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -06001333 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001334 if (!ptr_instance->wsi_display_enabled) {
Jon Ashburnc466da52016-04-15 09:25:03 -06001335 loader_log(
1336 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1337 "VK_KHR_display extension not enabled. "
1338 "vkGetPhysicalDeviceDisplayPlanePropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001339 return VK_SUCCESS;
1340 }
1341
1342 // Next, if so, proceed with the implementation of this function:
Jon Ashburncc370d02016-03-08 09:30:30 -07001343 assert(
Mark Young26c19372016-11-03 14:27:13 -06001344 icd_term->GetPhysicalDeviceDisplayPlanePropertiesKHR &&
Jon Ashburncc370d02016-03-08 09:30:30 -07001345 "loader: null GetPhysicalDeviceDisplayPlanePropertiesKHR ICD pointer");
1346
Mark Young26c19372016-11-03 14:27:13 -06001347 return icd_term->GetPhysicalDeviceDisplayPlanePropertiesKHR(
1348 phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001349}
1350
1351LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
Jon Ashburnc466da52016-04-15 09:25:03 -06001352vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
1353 uint32_t planeIndex,
1354 uint32_t *pDisplayCount,
1355 VkDisplayKHR *pDisplays) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001356 VkPhysicalDevice unwrapped_phys_dev =
1357 loader_unwrap_physical_device(physicalDevice);
1358 const VkLayerInstanceDispatchTable *disp;
1359 disp = loader_get_instance_dispatch(physicalDevice);
1360 VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(
1361 unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
1362 return res;
1363}
1364
Mark Young5467d672016-06-28 10:52:43 -06001365VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneSupportedDisplaysKHR(
1366 VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1367 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
Mark Young26c19372016-11-03 14:27:13 -06001368
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001369 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -06001370 struct loader_physical_device_term *phys_dev_term =
1371 (struct loader_physical_device_term *)physicalDevice;
1372 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001373 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -06001374 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001375 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -06001376 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1377 "VK_KHR_display extension not enabled. "
1378 "vkGetDisplayPlaneSupportedDisplaysKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001379 return VK_SUCCESS;
1380 }
1381
1382 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -06001383 assert(icd_term->GetDisplayPlaneSupportedDisplaysKHR &&
Jon Ashburnc466da52016-04-15 09:25:03 -06001384 "loader: null GetDisplayPlaneSupportedDisplaysKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001385
Mark Young26c19372016-11-03 14:27:13 -06001386 return icd_term->GetDisplayPlaneSupportedDisplaysKHR(
1387 phys_dev_term->phys_dev, planeIndex, pDisplayCount, pDisplays);
Jon Ashburncc370d02016-03-08 09:30:30 -07001388}
1389
Mark Young5467d672016-06-28 10:52:43 -06001390LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(
1391 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1392 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001393 VkPhysicalDevice unwrapped_phys_dev =
1394 loader_unwrap_physical_device(physicalDevice);
1395 const VkLayerInstanceDispatchTable *disp;
1396 disp = loader_get_instance_dispatch(physicalDevice);
1397 VkResult res = disp->GetDisplayModePropertiesKHR(
1398 unwrapped_phys_dev, display, pPropertyCount, pProperties);
1399 return res;
1400}
1401
Jon Ashburnc466da52016-04-15 09:25:03 -06001402VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModePropertiesKHR(
1403 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1404 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
Mark Young26c19372016-11-03 14:27:13 -06001405
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001406 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -06001407 struct loader_physical_device_term *phys_dev_term =
1408 (struct loader_physical_device_term *)physicalDevice;
1409 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001410 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -06001411 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001412 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -06001413 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1414 "VK_KHR_display extension not enabled. "
1415 "vkGetDisplayModePropertiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001416 return VK_SUCCESS;
1417 }
1418
1419 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -06001420 assert(icd_term->GetDisplayModePropertiesKHR &&
Jon Ashburnc466da52016-04-15 09:25:03 -06001421 "loader: null GetDisplayModePropertiesKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001422
Mark Young26c19372016-11-03 14:27:13 -06001423 return icd_term->GetDisplayModePropertiesKHR(
1424 phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
Jon Ashburncc370d02016-03-08 09:30:30 -07001425}
1426
Mark Young74dd5d12016-06-30 13:02:42 -06001427LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR(
1428 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1429 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1430 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001431 VkPhysicalDevice unwrapped_phys_dev =
1432 loader_unwrap_physical_device(physicalDevice);
1433 const VkLayerInstanceDispatchTable *disp;
1434 disp = loader_get_instance_dispatch(physicalDevice);
Jon Ashburnc466da52016-04-15 09:25:03 -06001435 VkResult res = disp->CreateDisplayModeKHR(unwrapped_phys_dev, display,
1436 pCreateInfo, pAllocator, pMode);
Jon Ashburncc370d02016-03-08 09:30:30 -07001437 return res;
1438}
1439
Mark Young74dd5d12016-06-30 13:02:42 -06001440VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayModeKHR(
1441 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1442 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1443 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Mark Young26c19372016-11-03 14:27:13 -06001444
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001445 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -06001446 struct loader_physical_device_term *phys_dev_term =
1447 (struct loader_physical_device_term *)physicalDevice;
1448 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001449 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -06001450 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001451 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -06001452 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1453 "VK_KHR_display extension not enabled. "
1454 "vkCreateDisplayModeKHR not executed!\n");
Jeremy Hayes0231e1c2016-06-14 11:50:02 -06001455 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001456 }
1457
1458 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -06001459 assert(icd_term->CreateDisplayModeKHR &&
Jon Ashburnc466da52016-04-15 09:25:03 -06001460 "loader: null CreateDisplayModeKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001461
Mark Young26c19372016-11-03 14:27:13 -06001462 return icd_term->CreateDisplayModeKHR(phys_dev_term->phys_dev, display,
1463 pCreateInfo, pAllocator, pMode);
Jon Ashburncc370d02016-03-08 09:30:30 -07001464}
1465
Mark Young5467d672016-06-28 10:52:43 -06001466LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(
1467 VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex,
1468 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001469 VkPhysicalDevice unwrapped_phys_dev =
1470 loader_unwrap_physical_device(physicalDevice);
1471 const VkLayerInstanceDispatchTable *disp;
1472 disp = loader_get_instance_dispatch(physicalDevice);
1473 VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(
1474 unwrapped_phys_dev, mode, planeIndex, pCapabilities);
1475 return res;
1476}
1477
Jon Ashburnc466da52016-04-15 09:25:03 -06001478VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilitiesKHR(
1479 VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex,
1480 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Mark Young26c19372016-11-03 14:27:13 -06001481
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001482 // First, check to ensure the appropriate extension was enabled:
Mark Young26c19372016-11-03 14:27:13 -06001483 struct loader_physical_device_term *phys_dev_term =
1484 (struct loader_physical_device_term *)physicalDevice;
1485 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001486 struct loader_instance *ptr_instance =
Mark Young26c19372016-11-03 14:27:13 -06001487 (struct loader_instance *)icd_term->this_instance;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001488 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott469ea4a2016-03-24 15:49:02 -06001489 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1490 "VK_KHR_display extension not enabled. "
1491 "vkGetDisplayPlaneCapabilitiesKHR not executed!\n");
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001492 return VK_SUCCESS;
1493 }
1494
1495 // Next, if so, proceed with the implementation of this function:
Mark Young26c19372016-11-03 14:27:13 -06001496 assert(icd_term->GetDisplayPlaneCapabilitiesKHR &&
Jon Ashburnc466da52016-04-15 09:25:03 -06001497 "loader: null GetDisplayPlaneCapabilitiesKHR ICD pointer");
Jon Ashburncc370d02016-03-08 09:30:30 -07001498
Mark Young26c19372016-11-03 14:27:13 -06001499 return icd_term->GetDisplayPlaneCapabilitiesKHR(
1500 phys_dev_term->phys_dev, mode, planeIndex, pCapabilities);
Jon Ashburncc370d02016-03-08 09:30:30 -07001501}
1502
Mark Young74dd5d12016-06-30 13:02:42 -06001503LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(
1504 VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1505 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001506 const VkLayerInstanceDispatchTable *disp;
1507 disp = loader_get_instance_dispatch(instance);
1508 VkResult res;
1509
1510 res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator,
1511 pSurface);
1512 return res;
1513}
1514
Jon Ashburnc466da52016-04-15 09:25:03 -06001515VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayPlaneSurfaceKHR(
1516 VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1517 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburncc370d02016-03-08 09:30:30 -07001518 struct loader_instance *inst = loader_get_instance(instance);
Mark Young5467d672016-06-28 10:52:43 -06001519 VkIcdSurface *pIcdSurface = NULL;
Mark Youngf06def92016-11-01 19:20:41 -06001520 VkResult vkRes = VK_SUCCESS;
Mark Young573a7a12016-11-02 09:37:08 -06001521 uint32_t i = 0;
Jon Ashburncc370d02016-03-08 09:30:30 -07001522
Mark Youngf06def92016-11-01 19:20:41 -06001523 if (!inst->wsi_display_enabled) {
Petros Bantolasf3095862016-04-14 12:50:42 +01001524 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1525 "VK_KHR_surface extension not enabled. "
1526 "vkCreateDisplayPlaneSurfaceKHR not executed!\n");
Mark Youngf06def92016-11-01 19:20:41 -06001527 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1528 goto out;
Petros Bantolasf3095862016-04-14 12:50:42 +01001529 }
1530
Mark Youngf27962c2016-09-16 10:18:42 -06001531 // The VK_KHR_display path will continue to use the old path (hence the
1532 // false as the last parameter).
1533 pIcdSurface =
1534 AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->display_surf.base),
1535 sizeof(pIcdSurface->display_surf), false);
Jon Ashburncc370d02016-03-08 09:30:30 -07001536 if (pIcdSurface == NULL) {
Mark Youngf06def92016-11-01 19:20:41 -06001537 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1538 goto out;
Jon Ashburncc370d02016-03-08 09:30:30 -07001539 }
1540
Mark Young5467d672016-06-28 10:52:43 -06001541 pIcdSurface->display_surf.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
1542 pIcdSurface->display_surf.displayMode = pCreateInfo->displayMode;
1543 pIcdSurface->display_surf.planeIndex = pCreateInfo->planeIndex;
1544 pIcdSurface->display_surf.planeStackIndex = pCreateInfo->planeStackIndex;
1545 pIcdSurface->display_surf.transform = pCreateInfo->transform;
1546 pIcdSurface->display_surf.globalAlpha = pCreateInfo->globalAlpha;
1547 pIcdSurface->display_surf.alphaMode = pCreateInfo->alphaMode;
1548 pIcdSurface->display_surf.imageExtent = pCreateInfo->imageExtent;
1549
Mark Youngf06def92016-11-01 19:20:41 -06001550 // Loop through each ICD and determine if they need to create a surface
Mark Young26c19372016-11-03 14:27:13 -06001551 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL;
1552 icd_term = icd_term->next, i++) {
1553 if (icd_term->scanned_icd->interface_version >=
Mark Youngf06def92016-11-01 19:20:41 -06001554 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young26c19372016-11-03 14:27:13 -06001555 if (NULL != icd_term->CreateDisplayPlaneSurfaceKHR) {
1556 vkRes = icd_term->CreateDisplayPlaneSurfaceKHR(
1557 icd_term->instance, pCreateInfo, pAllocator,
Mark Youngf06def92016-11-01 19:20:41 -06001558 &pIcdSurface->real_icd_surfaces[i]);
1559 if (VK_SUCCESS != vkRes) {
1560 goto out;
1561 }
1562 }
1563 }
1564 }
1565
Mark Young3eda5882016-12-01 10:42:21 -07001566 *pSurface = (VkSurfaceKHR)pIcdSurface;
Jon Ashburncc370d02016-03-08 09:30:30 -07001567
Mark Youngf06def92016-11-01 19:20:41 -06001568out:
1569
1570 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1571 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young573a7a12016-11-02 09:37:08 -06001572 i = 0;
Mark Young26c19372016-11-03 14:27:13 -06001573 for (struct loader_icd_term *icd_term = inst->icd_terms;
1574 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young3eda5882016-12-01 10:42:21 -07001575 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young26c19372016-11-03 14:27:13 -06001576 NULL != icd_term->DestroySurfaceKHR) {
1577 icd_term->DestroySurfaceKHR(
1578 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
1579 pAllocator);
Mark Youngf06def92016-11-01 19:20:41 -06001580 }
1581 }
1582 loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
1583 }
1584 loader_instance_heap_free(inst, pIcdSurface);
1585 }
1586
1587 return vkRes;
Jon Ashburncc370d02016-03-08 09:30:30 -07001588}
1589
Mark Youngf2eabea2016-07-01 15:18:27 -06001590// This is the trampoline entrypoint
1591// for CreateSharedSwapchainsKHR
1592LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(
1593 VkDevice device, uint32_t swapchainCount,
1594 const VkSwapchainCreateInfoKHR *pCreateInfos,
1595 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchains) {
Mark Young2a2122f2016-09-08 18:36:32 -06001596 const VkLayerDispatchTable *disp;
1597 disp = loader_get_dispatch(device);
Mark Young573a7a12016-11-02 09:37:08 -06001598 return disp->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos,
1599 pAllocator, pSwapchains);
Mark Youngf2eabea2016-07-01 15:18:27 -06001600}
1601
Ian Elliott54cea232015-10-30 15:28:23 -06001602bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance,
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001603 const char *name, void **addr) {
Ian Elliott54cea232015-10-30 15:28:23 -06001604 *addr = NULL;
1605
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001606 // Functions for the VK_KHR_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07001607 if (!strcmp("vkDestroySurfaceKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001608 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkDestroySurfaceKHR
1609 : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07001610 return true;
1611 }
Ian Elliott54cea232015-10-30 15:28:23 -06001612 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001613 *addr = ptr_instance->wsi_surface_enabled
1614 ? (void *)vkGetPhysicalDeviceSurfaceSupportKHR
1615 : NULL;
Ian Elliott54cea232015-10-30 15:28:23 -06001616 return true;
1617 }
Ian Elliottea666b22015-11-19 16:05:09 -07001618 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001619 *addr = ptr_instance->wsi_surface_enabled
1620 ? (void *)vkGetPhysicalDeviceSurfaceCapabilitiesKHR
1621 : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07001622 return true;
1623 }
1624 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001625 *addr = ptr_instance->wsi_surface_enabled
1626 ? (void *)vkGetPhysicalDeviceSurfaceFormatsKHR
1627 : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07001628 return true;
1629 }
1630 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001631 *addr = ptr_instance->wsi_surface_enabled
1632 ? (void *)vkGetPhysicalDeviceSurfacePresentModesKHR
1633 : NULL;
Ian Elliottea666b22015-11-19 16:05:09 -07001634 return true;
1635 }
Ian Elliott9b89a472015-11-19 16:39:21 -07001636
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001637 // Functions for the VK_KHR_swapchain extension:
1638
1639 // Note: This is a device extension, and its functions are statically
1640 // exported from the loader. Per Khronos decisions, the loader's GIPA
1641 // function will return the trampoline function for such device-extension
1642 // functions, regardless of whether the extension has been enabled.
Ian Elliott9b89a472015-11-19 16:39:21 -07001643 if (!strcmp("vkCreateSwapchainKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001644 *addr = (void *)vkCreateSwapchainKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001645 return true;
1646 }
1647 if (!strcmp("vkDestroySwapchainKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001648 *addr = (void *)vkDestroySwapchainKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001649 return true;
1650 }
1651 if (!strcmp("vkGetSwapchainImagesKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001652 *addr = (void *)vkGetSwapchainImagesKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001653 return true;
1654 }
1655 if (!strcmp("vkAcquireNextImageKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001656 *addr = (void *)vkAcquireNextImageKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001657 return true;
1658 }
1659 if (!strcmp("vkQueuePresentKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001660 *addr = (void *)vkQueuePresentKHR;
Ian Elliott9b89a472015-11-19 16:39:21 -07001661 return true;
1662 }
1663
Ian Elliott7c352552015-11-19 13:14:05 -07001664#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001665
1666 // Functions for the VK_KHR_win32_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07001667 if (!strcmp("vkCreateWin32SurfaceKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001668 *addr = ptr_instance->wsi_win32_surface_enabled
1669 ? (void *)vkCreateWin32SurfaceKHR
1670 : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07001671 return true;
1672 }
Ian Elliotte851dd62015-11-24 15:39:10 -07001673 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001674 *addr = ptr_instance->wsi_win32_surface_enabled
1675 ? (void *)vkGetPhysicalDeviceWin32PresentationSupportKHR
1676 : NULL;
Ian Elliotte851dd62015-11-24 15:39:10 -07001677 return true;
1678 }
Ian Elliott7c352552015-11-19 13:14:05 -07001679#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001680#ifdef VK_USE_PLATFORM_MIR_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001681
1682 // Functions for the VK_KHR_mir_surface extension:
Ian Elliott7c352552015-11-19 13:14:05 -07001683 if (!strcmp("vkCreateMirSurfaceKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001684 *addr = ptr_instance->wsi_mir_surface_enabled
1685 ? (void *)vkCreateMirSurfaceKHR
1686 : NULL;
Ian Elliott7c352552015-11-19 13:14:05 -07001687 return true;
1688 }
Ian Elliotte851dd62015-11-24 15:39:10 -07001689 if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", name)) {
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001690 *addr = ptr_instance->wsi_mir_surface_enabled
1691 ? (void *)vkGetPhysicalDeviceMirPresentationSupportKHR
1692 : NULL;
Ian Elliotte851dd62015-11-24 15:39:10 -07001693 return true;
Jason Ekstrand3bfebc92016-02-12 17:25:03 -08001694 }
Ian Elliott7c352552015-11-19 13:14:05 -07001695#endif // VK_USE_PLATFORM_MIR_KHR
1696#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001697
1698 // Functions for the VK_KHR_wayland_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001699 if (!strcmp("vkCreateWaylandSurfaceKHR", name)) {
1700 *addr = ptr_instance->wsi_wayland_surface_enabled
1701 ? (void *)vkCreateWaylandSurfaceKHR
1702 : NULL;
1703 return true;
1704 }
1705 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", name)) {
1706 *addr = ptr_instance->wsi_wayland_surface_enabled
Jon Ashburn1c75aec2016-02-02 17:47:28 -07001707 ? (void *)vkGetPhysicalDeviceWaylandPresentationSupportKHR
1708 : NULL;
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001709 return true;
1710 }
Ian Elliott7c352552015-11-19 13:14:05 -07001711#endif // VK_USE_PLATFORM_WAYLAND_KHR
1712#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001713
1714 // Functions for the VK_KHR_xcb_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001715 if (!strcmp("vkCreateXcbSurfaceKHR", name)) {
1716 *addr = ptr_instance->wsi_xcb_surface_enabled
1717 ? (void *)vkCreateXcbSurfaceKHR
1718 : NULL;
1719 return true;
1720 }
1721 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", name)) {
1722 *addr = ptr_instance->wsi_xcb_surface_enabled
1723 ? (void *)vkGetPhysicalDeviceXcbPresentationSupportKHR
1724 : NULL;
1725 return true;
1726 }
Ian Elliott7c352552015-11-19 13:14:05 -07001727#endif // VK_USE_PLATFORM_XCB_KHR
1728#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001729
1730 // Functions for the VK_KHR_xlib_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001731 if (!strcmp("vkCreateXlibSurfaceKHR", name)) {
1732 *addr = ptr_instance->wsi_xlib_surface_enabled
1733 ? (void *)vkCreateXlibSurfaceKHR
1734 : NULL;
1735 return true;
1736 }
1737 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", name)) {
1738 *addr = ptr_instance->wsi_xlib_surface_enabled
1739 ? (void *)vkGetPhysicalDeviceXlibPresentationSupportKHR
1740 : NULL;
1741 return true;
1742 }
Ian Elliott7c352552015-11-19 13:14:05 -07001743#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001744#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001745
1746 // Functions for the VK_KHR_android_surface extension:
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001747 if (!strcmp("vkCreateAndroidSurfaceKHR", name)) {
1748 *addr = ptr_instance->wsi_xlib_surface_enabled
1749 ? (void *)vkCreateAndroidSurfaceKHR
1750 : NULL;
1751 return true;
1752 }
Mark Lobodzinski1ad14b42015-12-10 16:25:21 -07001753#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott7c352552015-11-19 13:14:05 -07001754
Mark Lobodzinskib16da052016-08-31 09:31:29 -06001755 // Functions for VK_KHR_display extension:
Jon Ashburncc370d02016-03-08 09:30:30 -07001756 if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) {
1757 *addr = ptr_instance->wsi_display_enabled
1758 ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR
1759 : NULL;
1760 return true;
1761 }
1762 if (!strcmp("vkGetPhysicalDeviceDisplayPlanePropertiesKHR", name)) {
1763 *addr = ptr_instance->wsi_display_enabled
1764 ? (void *)vkGetPhysicalDeviceDisplayPlanePropertiesKHR
1765 : NULL;
1766 return true;
1767 }
1768 if (!strcmp("vkGetDisplayPlaneSupportedDisplaysKHR", name)) {
1769 *addr = ptr_instance->wsi_display_enabled
1770 ? (void *)vkGetDisplayPlaneSupportedDisplaysKHR
1771 : NULL;
1772 return true;
1773 }
1774 if (!strcmp("vkGetDisplayModePropertiesKHR", name)) {
1775 *addr = ptr_instance->wsi_display_enabled
1776 ? (void *)vkGetDisplayModePropertiesKHR
1777 : NULL;
1778 return true;
1779 }
1780 if (!strcmp("vkCreateDisplayModeKHR", name)) {
1781 *addr = ptr_instance->wsi_display_enabled
1782 ? (void *)vkCreateDisplayModeKHR
1783 : NULL;
1784 return true;
1785 }
1786 if (!strcmp("vkGetDisplayPlaneCapabilitiesKHR", name)) {
1787 *addr = ptr_instance->wsi_display_enabled
1788 ? (void *)vkGetDisplayPlaneCapabilitiesKHR
1789 : NULL;
1790 return true;
1791 }
1792 if (!strcmp("vkCreateDisplayPlaneSurfaceKHR", name)) {
1793 *addr = ptr_instance->wsi_display_enabled
1794 ? (void *)vkCreateDisplayPlaneSurfaceKHR
1795 : NULL;
1796 return true;
1797 }
Mark Youngf2eabea2016-07-01 15:18:27 -06001798
1799 // Functions for KHR_display_swapchain extension:
1800 if (!strcmp("vkCreateSharedSwapchainsKHR", name)) {
1801 *addr = (void *)vkCreateSharedSwapchainsKHR;
1802 return true;
1803 }
1804
Jon Ashburnc4e9ae62016-02-26 13:14:27 -07001805 return false;
Ian Elliott0d4ffa32016-03-24 13:59:22 -06001806}