blob: c577063b8e4e63273f7cd45a72373333cd80fe6e [file] [log] [blame]
Ian Elliott954fa342015-10-30 15:28:23 -06001/*
Jon Ashburn23d36b12016-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 Elliott954fa342015-10-30 15:28:23 -06005 *
Jon Ashburn3ebf1252016-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 Elliott954fa342015-10-30 15:28:23 -06009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Ian Elliott954fa342015-10-30 15:28:23 -060011 *
Jon Ashburn3ebf1252016-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 Elliott954fa342015-10-30 15:28:23 -060017 *
18 * Author: Ian Elliott <ian@lunarg.com>
Jon Ashburn23d36b12016-02-02 17:47:28 -070019 * Author: Jon Ashburn <jon@lunarg.com>
Ian Elliottc2e9aee2015-11-19 11:58:08 -070020 * Author: Ian Elliott <ianelliott@google.com>
Jon Ashburn23d36b12016-02-02 17:47:28 -070021 * Author: Mark Lobodzinski <mark@lunarg.com>
Ian Elliott954fa342015-10-30 15:28:23 -060022 */
23
Ian Elliott954fa342015-10-30 15:28:23 -060024#define _GNU_SOURCE
Ian Elliott2b8965a2016-03-24 13:59:22 -060025#include <stdio.h>
Ian Elliott954fa342015-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 Elliott2c05e222015-11-19 13:14:05 -070031#include <vulkan/vk_icd.h>
Ian Elliott954fa342015-10-30 15:28:23 -060032
Mark Young16573c72016-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 Ashburn23d36b12016-02-02 17:47:28 -070037void wsi_create_instance(struct loader_instance *ptr_instance,
38 const VkInstanceCreateInfo *pCreateInfo) {
Ian Elliottaf7d6362015-10-30 17:45:05 -060039 ptr_instance->wsi_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070040
41#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburnc7d3e732016-03-08 09:30:30 -070042 ptr_instance->wsi_win32_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070043#endif // VK_USE_PLATFORM_WIN32_KHR
44#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060045 ptr_instance->wsi_mir_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070046#endif // VK_USE_PLATFORM_MIR_KHR
47#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060048 ptr_instance->wsi_wayland_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070049#endif // VK_USE_PLATFORM_WAYLAND_KHR
50#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060051 ptr_instance->wsi_xcb_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070052#endif // VK_USE_PLATFORM_XCB_KHR
53#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060054 ptr_instance->wsi_xlib_surface_enabled = false;
Mark Lobodzinskia8a5f852015-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 Elliott954fa342015-10-30 15:28:23 -060059
Jon Ashburnc7d3e732016-03-08 09:30:30 -070060 ptr_instance->wsi_display_enabled = false;
61
Jon Ashburnf19916e2016-01-11 13:12:43 -070062 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Jon Ashburn23d36b12016-02-02 17:47:28 -070063 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
64 VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -060065 ptr_instance->wsi_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -070066 continue;
Ian Elliott954fa342015-10-30 15:28:23 -060067 }
Ian Elliottc2e9aee2015-11-19 11:58:08 -070068#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -070069 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
70 VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliottdb4300a2015-11-23 10:17:23 -070071 ptr_instance->wsi_win32_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -070072 continue;
Ian Elliott954fa342015-10-30 15:28:23 -060073 }
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070074#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliottaf7d6362015-10-30 17:45:05 -060075#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -070076 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
77 VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -060078 ptr_instance->wsi_mir_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -070079 continue;
Ian Elliott954fa342015-10-30 15:28:23 -060080 }
Ian Elliottaf7d6362015-10-30 17:45:05 -060081#endif // VK_USE_PLATFORM_MIR_KHR
82#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -070083 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
84 VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -060085 ptr_instance->wsi_wayland_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -070086 continue;
Ian Elliott954fa342015-10-30 15:28:23 -060087 }
Ian Elliottaf7d6362015-10-30 17:45:05 -060088#endif // VK_USE_PLATFORM_WAYLAND_KHR
89#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -070090 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
91 VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -060092 ptr_instance->wsi_xcb_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -070093 continue;
Ian Elliott954fa342015-10-30 15:28:23 -060094 }
Ian Elliottaf7d6362015-10-30 17:45:05 -060095#endif // VK_USE_PLATFORM_XCB_KHR
96#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -070097 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
98 VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -060099 ptr_instance->wsi_xlib_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -0700100 continue;
Ian Elliott954fa342015-10-30 15:28:23 -0600101 }
Ian Elliottaf7d6362015-10-30 17:45:05 -0600102#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700103#ifdef VK_USE_PLATFORM_ANDROID_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700104 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
105 VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700106 ptr_instance->wsi_android_surface_enabled = true;
107 continue;
108 }
109#endif // VK_USE_PLATFORM_ANDROID_KHR
Jon Ashburnc7d3e732016-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 Elliott954fa342015-10-30 15:28:23 -0600115 }
116}
Mark Lobodzinski6e45fe72016-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 Ashburn6fa520f2016-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 Elliott954fa342015-10-30 15:28:23 -0600144
Jon Ashburn6fa520f2016-03-25 12:49:35 -0600145 return false;
146}
Ian Elliott2c05e222015-11-19 13:14:05 -0700147
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600148// Functions for the VK_KHR_surface extension:
149
150// This is the trampoline entrypoint for DestroySurfaceKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700151LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL
152vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
153 const VkAllocationCallbacks *pAllocator) {
Ian Elliottfb42cd72015-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 Ashburnc7d3e732016-03-08 09:30:30 -0700159// TODO probably need to lock around all the loader_get_instance() calls.
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600160
161// This is the instance chain terminator function for DestroySurfaceKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700162VKAPI_ATTR void VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -0700163terminator_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
164 const VkAllocationCallbacks *pAllocator) {
Ian Elliottdb4300a2015-11-23 10:17:23 -0700165 struct loader_instance *ptr_instance = loader_get_instance(instance);
166
Karl Schultz94971292016-11-19 09:02:27 -0700167 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young4a62fa32016-10-17 12:27:36 -0600168 if (NULL != icd_surface) {
169 if (NULL != icd_surface->real_icd_surfaces) {
Mark Young49f39db2016-11-02 09:37:08 -0600170 uint32_t i = 0;
Mark Young0153e0b2016-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 Young4a62fa32016-10-17 12:27:36 -0600174 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young0153e0b2016-11-03 14:27:13 -0600175 if (NULL != icd_term->DestroySurfaceKHR &&
Mark Young786fb102016-12-01 10:42:21 -0700176 (VkSurfaceKHR)NULL !=
177 icd_surface->real_icd_surfaces[i]) {
Mark Young0153e0b2016-11-03 14:27:13 -0600178 icd_term->DestroySurfaceKHR(
179 icd_term->instance,
180 icd_surface->real_icd_surfaces[i], pAllocator);
Mark Young786fb102016-12-01 10:42:21 -0700181 icd_surface->real_icd_surfaces[i] = (VkSurfaceKHR)NULL;
Mark Young4a62fa32016-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 Young786fb102016-12-01 10:42:21 -0700187 assert((VkSurfaceKHR)NULL ==
188 icd_surface->real_icd_surfaces[i]);
Mark Young16573c72016-06-28 10:52:43 -0600189 }
Mark Young16573c72016-06-28 10:52:43 -0600190 }
Mark Young4a62fa32016-10-17 12:27:36 -0600191 loader_instance_heap_free(ptr_instance,
192 icd_surface->real_icd_surfaces);
Mark Young16573c72016-06-28 10:52:43 -0600193 }
Mark Young16573c72016-06-28 10:52:43 -0600194
Karl Schultz94971292016-11-19 09:02:27 -0700195 loader_instance_heap_free(ptr_instance, (void *)(uintptr_t)surface);
Mark Young4a62fa32016-10-17 12:27:36 -0600196 }
Ian Elliott2c05e222015-11-19 13:14:05 -0700197}
198
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600199// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceSupportKHR
Jon Ashburn23d36b12016-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 Elliott954fa342015-10-30 15:28:23 -0600205 const VkLayerInstanceDispatchTable *disp;
Jon Ashburn014438f2016-03-01 19:51:07 -0700206 VkPhysicalDevice unwrapped_phys_dev =
207 loader_unwrap_physical_device(physicalDevice);
Ian Elliott954fa342015-10-30 15:28:23 -0600208 disp = loader_get_instance_dispatch(physicalDevice);
209 VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700210 unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott954fa342015-10-30 15:28:23 -0600211 return res;
212}
213
Mark Lobodzinski6e45fe72016-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 Young0153e0b2016-11-03 14:27:13 -0600219
Ian Elliott2b8965a2016-03-24 13:59:22 -0600220 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-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 Elliott2b8965a2016-03-24 13:59:22 -0600224 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -0600225 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600226 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott31f72842016-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 Elliott2b8965a2016-03-24 13:59:22 -0600230 return VK_SUCCESS;
231 }
232
233 // Next, if so, proceed with the implementation of this function:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700234 assert(pSupported &&
235 "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
Ian Elliott954fa342015-10-30 15:28:23 -0600236 *pSupported = false;
237
Mark Young0153e0b2016-11-03 14:27:13 -0600238 assert(icd_term->GetPhysicalDeviceSurfaceSupportKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700239 "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
Ian Elliott954fa342015-10-30 15:28:23 -0600240
Karl Schultz94971292016-11-19 09:02:27 -0700241 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young16573c72016-06-28 10:52:43 -0600242 if (NULL != icd_surface->real_icd_surfaces &&
Mark Young786fb102016-12-01 10:42:21 -0700243 (VkSurfaceKHR)NULL !=
244 icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young0153e0b2016-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 Young16573c72016-06-28 10:52:43 -0600249 }
Mark Young16573c72016-06-28 10:52:43 -0600250
Mark Young0153e0b2016-11-03 14:27:13 -0600251 return icd_term->GetPhysicalDeviceSurfaceSupportKHR(
252 phys_dev_term->phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott954fa342015-10-30 15:28:23 -0600253}
254
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600255// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceCapabilitiesKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700256LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
257vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
258 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
259 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700260
Ian Elliott486c5502015-11-19 16:05:09 -0700261 const VkLayerInstanceDispatchTable *disp;
Jon Ashburn014438f2016-03-01 19:51:07 -0700262 VkPhysicalDevice unwrapped_phys_dev =
263 loader_unwrap_physical_device(physicalDevice);
Ian Elliott486c5502015-11-19 16:05:09 -0700264 disp = loader_get_instance_dispatch(physicalDevice);
265 VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700266 unwrapped_phys_dev, surface, pSurfaceCapabilities);
Ian Elliott486c5502015-11-19 16:05:09 -0700267 return res;
268}
269
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600270// This is the instance chain terminator function for
271// GetPhysicalDeviceSurfaceCapabilitiesKHR
Jon Ashburn1530c342016-02-26 13:14:27 -0700272VKAPI_ATTR VkResult VKAPI_CALL
273terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700274 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
275 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Mark Young0153e0b2016-11-03 14:27:13 -0600276
Ian Elliott2b8965a2016-03-24 13:59:22 -0600277 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-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 Elliott2b8965a2016-03-24 13:59:22 -0600281 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -0600282 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600283 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott31f72842016-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 Elliott2b8965a2016-03-24 13:59:22 -0600287 return VK_SUCCESS;
288 }
289
290 // Next, if so, proceed with the implementation of this function:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700291 assert(pSurfaceCapabilities && "GetPhysicalDeviceSurfaceCapabilitiesKHR: "
292 "Error, null pSurfaceCapabilities");
Ian Elliott486c5502015-11-19 16:05:09 -0700293
Mark Young0153e0b2016-11-03 14:27:13 -0600294 assert(icd_term->GetPhysicalDeviceSurfaceCapabilitiesKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700295 "loader: null GetPhysicalDeviceSurfaceCapabilitiesKHR ICD pointer");
Ian Elliott486c5502015-11-19 16:05:09 -0700296
Karl Schultz94971292016-11-19 09:02:27 -0700297 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young16573c72016-06-28 10:52:43 -0600298 if (NULL != icd_surface->real_icd_surfaces &&
Mark Young786fb102016-12-01 10:42:21 -0700299 (VkSurfaceKHR)NULL !=
300 icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young0153e0b2016-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 Young16573c72016-06-28 10:52:43 -0600304 pSurfaceCapabilities);
305 }
Mark Young16573c72016-06-28 10:52:43 -0600306
Mark Young0153e0b2016-11-03 14:27:13 -0600307 return icd_term->GetPhysicalDeviceSurfaceCapabilitiesKHR(
308 phys_dev_term->phys_dev, surface, pSurfaceCapabilities);
Ian Elliott486c5502015-11-19 16:05:09 -0700309}
310
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600311// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceFormatsKHR
Jon Ashburn23d36b12016-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 Ashburn014438f2016-03-01 19:51:07 -0700317 VkPhysicalDevice unwrapped_phys_dev =
318 loader_unwrap_physical_device(physicalDevice);
Ian Elliott486c5502015-11-19 16:05:09 -0700319 const VkLayerInstanceDispatchTable *disp;
320 disp = loader_get_instance_dispatch(physicalDevice);
321 VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700322 unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliott486c5502015-11-19 16:05:09 -0700323 return res;
324}
325
Mark Young49f39db2016-11-02 09:37:08 -0600326// This is the instance chain terminator function for
327// GetPhysicalDeviceSurfaceFormatsKHR
Jon Ashburn1530c342016-02-26 13:14:27 -0700328VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormatsKHR(
329 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
330 uint32_t *pSurfaceFormatCount, VkSurfaceFormatKHR *pSurfaceFormats) {
Mark Young0153e0b2016-11-03 14:27:13 -0600331
Ian Elliott2b8965a2016-03-24 13:59:22 -0600332 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-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 Elliott2b8965a2016-03-24 13:59:22 -0600336 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -0600337 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600338 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott31f72842016-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 Elliott2b8965a2016-03-24 13:59:22 -0600342 return VK_SUCCESS;
343 }
344
345 // Next, if so, proceed with the implementation of this function:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700346 assert(
347 pSurfaceFormatCount &&
348 "GetPhysicalDeviceSurfaceFormatsKHR: Error, null pSurfaceFormatCount");
Ian Elliott486c5502015-11-19 16:05:09 -0700349
Mark Young0153e0b2016-11-03 14:27:13 -0600350 assert(icd_term->GetPhysicalDeviceSurfaceFormatsKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700351 "loader: null GetPhysicalDeviceSurfaceFormatsKHR ICD pointer");
Ian Elliott486c5502015-11-19 16:05:09 -0700352
Karl Schultz94971292016-11-19 09:02:27 -0700353 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young16573c72016-06-28 10:52:43 -0600354 if (NULL != icd_surface->real_icd_surfaces &&
Mark Young786fb102016-12-01 10:42:21 -0700355 (VkSurfaceKHR)NULL !=
356 icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young0153e0b2016-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 Young16573c72016-06-28 10:52:43 -0600360 pSurfaceFormatCount, pSurfaceFormats);
361 }
Mark Young16573c72016-06-28 10:52:43 -0600362
Mark Young0153e0b2016-11-03 14:27:13 -0600363 return icd_term->GetPhysicalDeviceSurfaceFormatsKHR(
364 phys_dev_term->phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliott486c5502015-11-19 16:05:09 -0700365}
366
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600367// This is the trampoline entrypoint for GetPhysicalDeviceSurfacePresentModesKHR
Jon Ashburn23d36b12016-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 Ashburn014438f2016-03-01 19:51:07 -0700373 VkPhysicalDevice unwrapped_phys_dev =
374 loader_unwrap_physical_device(physicalDevice);
Ian Elliott486c5502015-11-19 16:05:09 -0700375 const VkLayerInstanceDispatchTable *disp;
376 disp = loader_get_instance_dispatch(physicalDevice);
377 VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700378 unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliott486c5502015-11-19 16:05:09 -0700379 return res;
380}
381
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600382// This is the instance chain terminator function for
383// GetPhysicalDeviceSurfacePresentModesKHR
Jon Ashburn1530c342016-02-26 13:14:27 -0700384VKAPI_ATTR VkResult VKAPI_CALL
385terminator_GetPhysicalDeviceSurfacePresentModesKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700386 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
387 uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes) {
Mark Young0153e0b2016-11-03 14:27:13 -0600388
Ian Elliott2b8965a2016-03-24 13:59:22 -0600389 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-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 Elliott2b8965a2016-03-24 13:59:22 -0600393 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -0600394 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600395 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott31f72842016-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 Elliott2b8965a2016-03-24 13:59:22 -0600399 return VK_SUCCESS;
400 }
401
402 // Next, if so, proceed with the implementation of this function:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700403 assert(pPresentModeCount && "GetPhysicalDeviceSurfacePresentModesKHR: "
404 "Error, null pPresentModeCount");
Ian Elliott486c5502015-11-19 16:05:09 -0700405
Mark Young0153e0b2016-11-03 14:27:13 -0600406 assert(icd_term->GetPhysicalDeviceSurfacePresentModesKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700407 "loader: null GetPhysicalDeviceSurfacePresentModesKHR ICD pointer");
Ian Elliott486c5502015-11-19 16:05:09 -0700408
Karl Schultz94971292016-11-19 09:02:27 -0700409 VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)surface;
Mark Young16573c72016-06-28 10:52:43 -0600410 if (NULL != icd_surface->real_icd_surfaces &&
Mark Young786fb102016-12-01 10:42:21 -0700411 (VkSurfaceKHR)NULL !=
412 icd_surface->real_icd_surfaces[phys_dev_term->icd_index]) {
Mark Young0153e0b2016-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 Young16573c72016-06-28 10:52:43 -0600416 pPresentModeCount, pPresentModes);
417 }
Mark Young16573c72016-06-28 10:52:43 -0600418
Mark Young0153e0b2016-11-03 14:27:13 -0600419 return icd_term->GetPhysicalDeviceSurfacePresentModesKHR(
420 phys_dev_term->phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliott486c5502015-11-19 16:05:09 -0700421}
422
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600423// Functions for the VK_KHR_swapchain extension:
Ian Elliott2c05e222015-11-19 13:14:05 -0700424
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600425// This is the trampoline entrypoint for CreateSwapchainKHR
Mark Young0ad83132016-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 Elliott934d0d52015-11-19 16:39:21 -0700429 const VkLayerDispatchTable *disp;
430 disp = loader_get_dispatch(device);
Mark Youngead9b932016-09-08 12:28:38 -0600431 return disp->CreateSwapchainKHR(device, pCreateInfo, pAllocator,
432 pSwapchain);
Ian Elliott934d0d52015-11-19 16:39:21 -0700433}
Ian Elliott2c05e222015-11-19 13:14:05 -0700434
Mark Young16573c72016-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 Young0153e0b2016-11-03 14:27:13 -0600440 struct loader_icd_term *icd_term =
Mark Young49f39db2016-11-02 09:37:08 -0600441 loader_get_icd_and_device(device, &dev, &icd_index);
Mark Young0153e0b2016-11-03 14:27:13 -0600442 if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) {
Karl Schultz94971292016-11-19 09:02:27 -0700443 VkIcdSurface *icd_surface =
444 (VkIcdSurface *)(uintptr_t)pCreateInfo->surface;
Mark Young16573c72016-06-28 10:52:43 -0600445 if (NULL != icd_surface->real_icd_surfaces) {
Mark Young786fb102016-12-01 10:42:21 -0700446 if ((VkSurfaceKHR)NULL !=
447 icd_surface->real_icd_surfaces[icd_index]) {
Mark Young16573c72016-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 Young49f39db2016-11-02 09:37:08 -0600456 memcpy(pCreateCopy, pCreateInfo,
457 sizeof(VkSwapchainCreateInfoKHR));
Mark Young16573c72016-06-28 10:52:43 -0600458 pCreateCopy->surface =
459 icd_surface->real_icd_surfaces[icd_index];
Mark Young0153e0b2016-11-03 14:27:13 -0600460 return icd_term->CreateSwapchainKHR(device, pCreateCopy,
461 pAllocator, pSwapchain);
Mark Young16573c72016-06-28 10:52:43 -0600462 }
463 }
Mark Young0153e0b2016-11-03 14:27:13 -0600464 return icd_term->CreateSwapchainKHR(device, pCreateInfo, pAllocator,
465 pSwapchain);
Mark Young16573c72016-06-28 10:52:43 -0600466 }
467 return VK_SUCCESS;
468}
469
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600470// This is the trampoline entrypoint for DestroySwapchainKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700471LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL
472vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
473 const VkAllocationCallbacks *pAllocator) {
Ian Elliott934d0d52015-11-19 16:39:21 -0700474 const VkLayerDispatchTable *disp;
475 disp = loader_get_dispatch(device);
476 disp->DestroySwapchainKHR(device, swapchain, pAllocator);
477}
Ian Elliott2c05e222015-11-19 13:14:05 -0700478
Mark Young16573c72016-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 Elliott934d0d52015-11-19 16:39:21 -0700486 const VkLayerDispatchTable *disp;
487 disp = loader_get_dispatch(device);
Mark Young49f39db2016-11-02 09:37:08 -0600488 return disp->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount,
489 pSwapchainImages);
Ian Elliott934d0d52015-11-19 16:39:21 -0700490}
491
Mark Young16573c72016-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 Elliott934d0d52015-11-19 16:39:21 -0700499 const VkLayerDispatchTable *disp;
500 disp = loader_get_dispatch(device);
Mark Young49f39db2016-11-02 09:37:08 -0600501 return disp->AcquireNextImageKHR(device, swapchain, timeout, semaphore,
502 fence, pImageIndex);
Ian Elliott934d0d52015-11-19 16:39:21 -0700503}
504
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600505// This is the trampoline entrypoint for QueuePresentKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700506LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
507vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
Ian Elliott934d0d52015-11-19 16:39:21 -0700508 const VkLayerDispatchTable *disp;
509 disp = loader_get_dispatch(queue);
Mark Youngead9b932016-09-08 12:28:38 -0600510 return disp->QueuePresentKHR(queue, pPresentInfo);
Ian Elliott934d0d52015-11-19 16:39:21 -0700511}
Ian Elliott2c05e222015-11-19 13:14:05 -0700512
Mark Younga7c51fd2016-09-16 10:18:42 -0600513static VkIcdSurface *AllocateIcdSurfaceStruct(struct loader_instance *instance,
514 size_t base_size,
Mark Younga60f1342016-12-13 17:19:32 -0700515 size_t platform_size) {
Mark Younga7c51fd2016-09-16 10:18:42 -0600516 // Next, if so, proceed with the implementation of this function:
517 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(
518 instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
519 if (pIcdSurface != NULL) {
520 // Setup the new sizes and offsets so we can grow the structures in the
521 // future without having problems
522 pIcdSurface->base_size = (uint32_t)base_size;
523 pIcdSurface->platform_size = (uint32_t)platform_size;
524 pIcdSurface->non_platform_offset = (uint32_t)(
525 (uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
526 pIcdSurface->entire_size = sizeof(VkIcdSurface);
527
Mark Younga60f1342016-12-13 17:19:32 -0700528 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(
529 instance, sizeof(VkSurfaceKHR) * instance->total_icd_count,
530 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
531 if (pIcdSurface->real_icd_surfaces == NULL) {
532 loader_instance_heap_free(instance, pIcdSurface);
533 pIcdSurface = NULL;
Mark Younga7c51fd2016-09-16 10:18:42 -0600534 } else {
Mark Younga60f1342016-12-13 17:19:32 -0700535 memset(pIcdSurface->real_icd_surfaces, 0,
536 sizeof(VkSurfaceKHR) * instance->total_icd_count);
Mark Younga7c51fd2016-09-16 10:18:42 -0600537 }
538 }
539 return pIcdSurface;
540}
541
Ian Elliott2c05e222015-11-19 13:14:05 -0700542#ifdef VK_USE_PLATFORM_WIN32_KHR
543
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600544// Functions for the VK_KHR_win32_surface extension:
545
546// This is the trampoline entrypoint for CreateWin32SurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600547LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
548 VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
549 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700550 const VkLayerInstanceDispatchTable *disp;
551 disp = loader_get_instance_dispatch(instance);
552 VkResult res;
553
Jon Ashburn23d36b12016-02-02 17:47:28 -0700554 res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator,
555 pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700556 return res;
557}
558
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600559// This is the instance chain terminator function for CreateWin32SurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600560VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWin32SurfaceKHR(
561 VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
562 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -0600563 VkResult vkRes = VK_SUCCESS;
Mark Youngad46cec2016-10-12 14:18:44 -0600564 VkIcdSurface *pIcdSurface = NULL;
Mark Young49f39db2016-11-02 09:37:08 -0600565 uint32_t i = 0;
566
Mark Younga7c51fd2016-09-16 10:18:42 -0600567 // Initialize pSurface to NULL just to be safe.
568 *pSurface = VK_NULL_HANDLE;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600569 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -0700570 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -0600571 if (!ptr_instance->wsi_win32_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600572 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
573 "VK_KHR_win32_surface extension not enabled. "
574 "vkCreateWin32SurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -0600575 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
576 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600577 }
578
579 // Next, if so, proceed with the implementation of this function:
Mark Young49f39db2016-11-02 09:37:08 -0600580 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance,
581 sizeof(pIcdSurface->win_surf.base),
Mark Younga60f1342016-12-13 17:19:32 -0700582 sizeof(pIcdSurface->win_surf));
Ian Elliott2c05e222015-11-19 13:14:05 -0700583 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -0600584 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
585 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -0700586 }
587
Mark Young16573c72016-06-28 10:52:43 -0600588 pIcdSurface->win_surf.base.platform = VK_ICD_WSI_PLATFORM_WIN32;
589 pIcdSurface->win_surf.hinstance = pCreateInfo->hinstance;
590 pIcdSurface->win_surf.hwnd = pCreateInfo->hwnd;
Ian Elliott2c05e222015-11-19 13:14:05 -0700591
Mark Young16573c72016-06-28 10:52:43 -0600592 // Loop through each ICD and determine if they need to create a surface
Mark Young0153e0b2016-11-03 14:27:13 -0600593 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
594 icd_term != NULL; icd_term = icd_term->next, i++) {
595 if (icd_term->scanned_icd->interface_version >=
Mark Young16573c72016-06-28 10:52:43 -0600596 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young0153e0b2016-11-03 14:27:13 -0600597 if (NULL != icd_term->CreateWin32SurfaceKHR) {
598 vkRes = icd_term->CreateWin32SurfaceKHR(
599 icd_term->instance, pCreateInfo, pAllocator,
Mark Young16573c72016-06-28 10:52:43 -0600600 &pIcdSurface->real_icd_surfaces[i]);
601 if (VK_SUCCESS != vkRes) {
602 goto out;
603 }
604 }
605 }
606 }
607
608 *pSurface = (VkSurfaceKHR)(pIcdSurface);
609
610out:
611
612 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
613 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young49f39db2016-11-02 09:37:08 -0600614 i = 0;
Mark Young0153e0b2016-11-03 14:27:13 -0600615 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
616 icd_term != NULL; icd_term = icd_term->next, i++) {
Jamie Madill0b70c622016-11-30 12:47:45 -0500617 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young0153e0b2016-11-03 14:27:13 -0600618 NULL != icd_term->DestroySurfaceKHR) {
619 icd_term->DestroySurfaceKHR(
620 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
621 pAllocator);
Mark Young16573c72016-06-28 10:52:43 -0600622 }
623 }
Mark Young49f39db2016-11-02 09:37:08 -0600624 loader_instance_heap_free(ptr_instance,
625 pIcdSurface->real_icd_surfaces);
Mark Young16573c72016-06-28 10:52:43 -0600626 }
627 loader_instance_heap_free(ptr_instance, pIcdSurface);
628 }
629
630 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -0700631}
Ian Elliott919fa302015-11-24 15:39:10 -0700632
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600633// This is the trampoline entrypoint for
634// GetPhysicalDeviceWin32PresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700635LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
636vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
637 uint32_t queueFamilyIndex) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700638 VkPhysicalDevice unwrapped_phys_dev =
639 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -0700640 const VkLayerInstanceDispatchTable *disp;
641 disp = loader_get_instance_dispatch(physicalDevice);
642 VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700643 unwrapped_phys_dev, queueFamilyIndex);
Ian Elliott919fa302015-11-24 15:39:10 -0700644 return res;
645}
646
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600647// This is the instance chain terminator function for
648// GetPhysicalDeviceWin32PresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700649VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -0700650terminator_GetPhysicalDeviceWin32PresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700651 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex) {
Ian Elliott2b8965a2016-03-24 13:59:22 -0600652 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -0600653 struct loader_physical_device_term *phys_dev_term =
654 (struct loader_physical_device_term *)physicalDevice;
655 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600656 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -0600657 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600658 if (!ptr_instance->wsi_win32_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -0600659 loader_log(
660 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
661 "VK_KHR_win32_surface extension not enabled. "
662 "vkGetPhysicalDeviceWin32PresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600663 return VK_SUCCESS;
664 }
665
666 // Next, if so, proceed with the implementation of this function:
Mark Young0153e0b2016-11-03 14:27:13 -0600667 assert(icd_term->GetPhysicalDeviceWin32PresentationSupportKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700668 "loader: null GetPhysicalDeviceWin32PresentationSupportKHR ICD "
669 "pointer");
Ian Elliott919fa302015-11-24 15:39:10 -0700670
Mark Young0153e0b2016-11-03 14:27:13 -0600671 return icd_term->GetPhysicalDeviceWin32PresentationSupportKHR(
672 phys_dev_term->phys_dev, queueFamilyIndex);
Ian Elliott919fa302015-11-24 15:39:10 -0700673}
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700674#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -0700675
676#ifdef VK_USE_PLATFORM_MIR_KHR
677
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600678// Functions for the VK_KHR_mir_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -0700679
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600680// This is the trampoline entrypoint for CreateMirSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600681LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(
682 VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
683 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700684 const VkLayerInstanceDispatchTable *disp;
685 disp = loader_get_instance_dispatch(instance);
686 VkResult res;
687
Jon Ashburn23d36b12016-02-02 17:47:28 -0700688 res =
689 disp->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700690 return res;
691}
692
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600693// This is the instance chain terminator function for CreateMirSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600694VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMirSurfaceKHR(
695 VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
696 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -0600697 VkResult vkRes = VK_SUCCESS;
Mark Youngad46cec2016-10-12 14:18:44 -0600698 VkIcdSurface *pIcdSurface = NULL;
Mark Young49f39db2016-11-02 09:37:08 -0600699 uint32_t i = 0;
700
Ian Elliott2b8965a2016-03-24 13:59:22 -0600701 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -0700702 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -0600703 if (!ptr_instance->wsi_mir_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600704 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
705 "VK_KHR_mir_surface extension not enabled. "
706 "vkCreateMirSurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -0600707 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
708 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600709 }
710
711 // Next, if so, proceed with the implementation of this function:
Mark Young49f39db2016-11-02 09:37:08 -0600712 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance,
713 sizeof(pIcdSurface->mir_surf.base),
Mark Younga60f1342016-12-13 17:19:32 -0700714 sizeof(pIcdSurface->mir_surf));
Ian Elliott2c05e222015-11-19 13:14:05 -0700715 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -0600716 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
717 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -0700718 }
719
Mark Young16573c72016-06-28 10:52:43 -0600720 pIcdSurface->mir_surf.base.platform = VK_ICD_WSI_PLATFORM_MIR;
721 pIcdSurface->mir_surf.connection = pCreateInfo->connection;
722 pIcdSurface->mir_surf.mirSurface = pCreateInfo->mirSurface;
723
Mark Young16573c72016-06-28 10:52:43 -0600724 // Loop through each ICD and determine if they need to create a surface
Mark Young0153e0b2016-11-03 14:27:13 -0600725 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
726 icd_term != NULL; icd_term = icd_term->next, i++) {
727 if (icd_term->scanned_icd->interface_version >=
Mark Young16573c72016-06-28 10:52:43 -0600728 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young0153e0b2016-11-03 14:27:13 -0600729 if (NULL != icd_term->CreateMirSurfaceKHR) {
730 vkRes = icd_term->CreateMirSurfaceKHR(
731 icd_term->instance, pCreateInfo, pAllocator,
Mark Young16573c72016-06-28 10:52:43 -0600732 &pIcdSurface->real_icd_surfaces[i]);
733 if (VK_SUCCESS != vkRes) {
734 goto out;
735 }
736 }
737 }
738 }
Ian Elliott2c05e222015-11-19 13:14:05 -0700739
Jon Ashburn23d36b12016-02-02 17:47:28 -0700740 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott2c05e222015-11-19 13:14:05 -0700741
Mark Young16573c72016-06-28 10:52:43 -0600742out:
743
744 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
745 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young49f39db2016-11-02 09:37:08 -0600746 i = 0;
Mark Young0153e0b2016-11-03 14:27:13 -0600747 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
748 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young786fb102016-12-01 10:42:21 -0700749 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young0153e0b2016-11-03 14:27:13 -0600750 NULL != icd_term->DestroySurfaceKHR) {
751 icd_term->DestroySurfaceKHR(
752 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
753 pAllocator);
Mark Young16573c72016-06-28 10:52:43 -0600754 }
755 }
Mark Young49f39db2016-11-02 09:37:08 -0600756 loader_instance_heap_free(ptr_instance,
757 pIcdSurface->real_icd_surfaces);
Mark Young16573c72016-06-28 10:52:43 -0600758 }
759 loader_instance_heap_free(ptr_instance, pIcdSurface);
760 }
761
762 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -0700763}
Ian Elliott919fa302015-11-24 15:39:10 -0700764
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600765// This is the trampoline entrypoint for
766// GetPhysicalDeviceMirPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700767LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
768vkGetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,
769 uint32_t queueFamilyIndex,
770 MirConnection *connection) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700771 VkPhysicalDevice unwrapped_phys_dev =
772 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -0700773 const VkLayerInstanceDispatchTable *disp;
774 disp = loader_get_instance_dispatch(physicalDevice);
775 VkBool32 res = disp->GetPhysicalDeviceMirPresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700776 unwrapped_phys_dev, queueFamilyIndex, connection);
Ian Elliott919fa302015-11-24 15:39:10 -0700777 return res;
778}
779
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600780// This is the instance chain terminator function for
781// GetPhysicalDeviceMirPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700782VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -0700783terminator_GetPhysicalDeviceMirPresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700784 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
785 MirConnection *connection) {
Mark Young0153e0b2016-11-03 14:27:13 -0600786
Ian Elliott2b8965a2016-03-24 13:59:22 -0600787 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -0600788 struct loader_physical_device_term *phys_dev_term =
789 (struct loader_physical_device_term *)physicalDevice;
790 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600791 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -0600792 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600793 if (!ptr_instance->wsi_mir_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -0600794 loader_log(
795 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
796 "VK_KHR_mir_surface extension not enabled. "
797 "vkGetPhysicalDeviceMirPresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600798 return VK_SUCCESS;
799 }
800
801 // Next, if so, proceed with the implementation of this function:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700802 assert(
Mark Young0153e0b2016-11-03 14:27:13 -0600803 icd_term->GetPhysicalDeviceMirPresentationSupportKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700804 "loader: null GetPhysicalDeviceMirPresentationSupportKHR ICD pointer");
Ian Elliott919fa302015-11-24 15:39:10 -0700805
Mark Young0153e0b2016-11-03 14:27:13 -0600806 return icd_term->GetPhysicalDeviceMirPresentationSupportKHR(
807 phys_dev_term->phys_dev, queueFamilyIndex, connection);
Ian Elliott919fa302015-11-24 15:39:10 -0700808}
Ian Elliott2c05e222015-11-19 13:14:05 -0700809#endif // VK_USE_PLATFORM_MIR_KHR
810
811#ifdef VK_USE_PLATFORM_WAYLAND_KHR
812
Mark Young16573c72016-06-28 10:52:43 -0600813/*
814 * This is the trampoline entrypoint
815 * for CreateWaylandSurfaceKHR
816 */
817LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
818 VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
819 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700820 const VkLayerInstanceDispatchTable *disp;
821 disp = loader_get_instance_dispatch(instance);
822 VkResult res;
823
Jon Ashburn23d36b12016-02-02 17:47:28 -0700824 res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator,
825 pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700826 return res;
827}
828
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600829// This is the instance chain terminator function for CreateWaylandSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600830VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(
Jon Ashburn1530c342016-02-26 13:14:27 -0700831 VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
832 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -0600833 VkResult vkRes = VK_SUCCESS;
Mark Youngad46cec2016-10-12 14:18:44 -0600834 VkIcdSurface *pIcdSurface = NULL;
Mark Young49f39db2016-11-02 09:37:08 -0600835 uint32_t i = 0;
836
Ian Elliott2b8965a2016-03-24 13:59:22 -0600837 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -0700838 struct loader_instance *ptr_instance = loader_get_instance(instance);
Jon Ashburnd76b51c2016-03-24 17:26:59 -0600839 if (!ptr_instance->wsi_wayland_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600840 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
841 "VK_KHR_wayland_surface extension not enabled. "
842 "vkCreateWaylandSurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -0600843 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
844 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600845 }
846
847 // Next, if so, proceed with the implementation of this function:
Mark Youngad46cec2016-10-12 14:18:44 -0600848 pIcdSurface = AllocateIcdSurfaceStruct(
Mark Younga7c51fd2016-09-16 10:18:42 -0600849 ptr_instance, sizeof(pIcdSurface->wayland_surf.base),
Mark Younga60f1342016-12-13 17:19:32 -0700850 sizeof(pIcdSurface->wayland_surf));
Ian Elliott2c05e222015-11-19 13:14:05 -0700851 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -0600852 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
853 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -0700854 }
855
Mark Young16573c72016-06-28 10:52:43 -0600856 pIcdSurface->wayland_surf.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
857 pIcdSurface->wayland_surf.display = pCreateInfo->display;
858 pIcdSurface->wayland_surf.surface = pCreateInfo->surface;
859
Mark Young16573c72016-06-28 10:52:43 -0600860 // Loop through each ICD and determine if they need to create a surface
Mark Young0153e0b2016-11-03 14:27:13 -0600861 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
862 icd_term != NULL; icd_term = icd_term->next, i++) {
863 if (icd_term->scanned_icd->interface_version >=
Mark Young16573c72016-06-28 10:52:43 -0600864 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young0153e0b2016-11-03 14:27:13 -0600865 if (NULL != icd_term->CreateWaylandSurfaceKHR) {
866 vkRes = icd_term->CreateWaylandSurfaceKHR(
867 icd_term->instance, pCreateInfo, pAllocator,
Mark Young16573c72016-06-28 10:52:43 -0600868 &pIcdSurface->real_icd_surfaces[i]);
869 if (VK_SUCCESS != vkRes) {
870 goto out;
871 }
872 }
873 }
874 }
Ian Elliott2c05e222015-11-19 13:14:05 -0700875
Jon Ashburn23d36b12016-02-02 17:47:28 -0700876 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott2c05e222015-11-19 13:14:05 -0700877
Mark Young16573c72016-06-28 10:52:43 -0600878out:
879
880 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
881 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young49f39db2016-11-02 09:37:08 -0600882 i = 0;
Mark Young0153e0b2016-11-03 14:27:13 -0600883 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
884 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young786fb102016-12-01 10:42:21 -0700885 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young0153e0b2016-11-03 14:27:13 -0600886 NULL != icd_term->DestroySurfaceKHR) {
887 icd_term->DestroySurfaceKHR(
888 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
889 pAllocator);
Mark Young16573c72016-06-28 10:52:43 -0600890 }
891 }
Mark Young49f39db2016-11-02 09:37:08 -0600892 loader_instance_heap_free(ptr_instance,
893 pIcdSurface->real_icd_surfaces);
Mark Young16573c72016-06-28 10:52:43 -0600894 }
895 loader_instance_heap_free(ptr_instance, pIcdSurface);
896 }
897
898 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -0700899}
Ian Elliott919fa302015-11-24 15:39:10 -0700900
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600901// This is the trampoline entrypoint for
902// GetPhysicalDeviceWaylandPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700903LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
904vkGetPhysicalDeviceWaylandPresentationSupportKHR(
905 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
906 struct wl_display *display) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700907 VkPhysicalDevice unwrapped_phys_dev =
908 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -0700909 const VkLayerInstanceDispatchTable *disp;
910 disp = loader_get_instance_dispatch(physicalDevice);
911 VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700912 unwrapped_phys_dev, queueFamilyIndex, display);
Ian Elliott919fa302015-11-24 15:39:10 -0700913 return res;
914}
915
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600916// This is the instance chain terminator function for
917// GetPhysicalDeviceWaylandPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700918VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -0700919terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700920 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
921 struct wl_display *display) {
Mark Young0153e0b2016-11-03 14:27:13 -0600922
Ian Elliott2b8965a2016-03-24 13:59:22 -0600923 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -0600924 struct loader_physical_device_term *phys_dev_term =
925 (struct loader_physical_device_term *)physicalDevice;
926 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600927 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -0600928 (struct loader_instance *)icd_term->this_instance;
Jon Ashburnd76b51c2016-03-24 17:26:59 -0600929 if (!ptr_instance->wsi_wayland_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -0600930 loader_log(
931 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
932 "VK_KHR_wayland_surface extension not enabled. "
933 "vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600934 return VK_SUCCESS;
935 }
936
937 // Next, if so, proceed with the implementation of this function:
Mark Young0153e0b2016-11-03 14:27:13 -0600938 assert(icd_term->GetPhysicalDeviceWaylandPresentationSupportKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -0700939 "loader: null GetPhysicalDeviceWaylandPresentationSupportKHR ICD "
940 "pointer");
Ian Elliott919fa302015-11-24 15:39:10 -0700941
Mark Young0153e0b2016-11-03 14:27:13 -0600942 return icd_term->GetPhysicalDeviceWaylandPresentationSupportKHR(
943 phys_dev_term->phys_dev, queueFamilyIndex, display);
Ian Elliott919fa302015-11-24 15:39:10 -0700944}
Ian Elliott2c05e222015-11-19 13:14:05 -0700945#endif // VK_USE_PLATFORM_WAYLAND_KHR
946
947#ifdef VK_USE_PLATFORM_XCB_KHR
948
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600949// Functions for the VK_KHR_xcb_surface extension:
950
951// This is the trampoline entrypoint for CreateXcbSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600952LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
953 VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
954 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700955 const VkLayerInstanceDispatchTable *disp;
956 disp = loader_get_instance_dispatch(instance);
957 VkResult res;
958
Jon Ashburn23d36b12016-02-02 17:47:28 -0700959 res =
960 disp->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700961 return res;
962}
963
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600964// This is the instance chain terminator function for CreateXcbSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600965VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXcbSurfaceKHR(
966 VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
967 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -0600968 VkResult vkRes = VK_SUCCESS;
Mark Youngad46cec2016-10-12 14:18:44 -0600969 VkIcdSurface *pIcdSurface = NULL;
Mark Young49f39db2016-11-02 09:37:08 -0600970 uint32_t i = 0;
971
Ian Elliott2b8965a2016-03-24 13:59:22 -0600972 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -0700973 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -0600974 if (!ptr_instance->wsi_xcb_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600975 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
976 "VK_KHR_xcb_surface extension not enabled. "
977 "vkCreateXcbSurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -0600978 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
979 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600980 }
981
982 // Next, if so, proceed with the implementation of this function:
Mark Young49f39db2016-11-02 09:37:08 -0600983 pIcdSurface = AllocateIcdSurfaceStruct(ptr_instance,
984 sizeof(pIcdSurface->xcb_surf.base),
Mark Younga60f1342016-12-13 17:19:32 -0700985 sizeof(pIcdSurface->xcb_surf));
Ian Elliott2c05e222015-11-19 13:14:05 -0700986 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -0600987 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
988 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -0700989 }
990
Mark Young16573c72016-06-28 10:52:43 -0600991 pIcdSurface->xcb_surf.base.platform = VK_ICD_WSI_PLATFORM_XCB;
992 pIcdSurface->xcb_surf.connection = pCreateInfo->connection;
993 pIcdSurface->xcb_surf.window = pCreateInfo->window;
994
Mark Young16573c72016-06-28 10:52:43 -0600995 // Loop through each ICD and determine if they need to create a surface
Mark Young0153e0b2016-11-03 14:27:13 -0600996 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
997 icd_term != NULL; icd_term = icd_term->next, i++) {
998 if (icd_term->scanned_icd->interface_version >=
Mark Young16573c72016-06-28 10:52:43 -0600999 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young0153e0b2016-11-03 14:27:13 -06001000 if (NULL != icd_term->CreateXcbSurfaceKHR) {
1001 vkRes = icd_term->CreateXcbSurfaceKHR(
1002 icd_term->instance, pCreateInfo, pAllocator,
Mark Young16573c72016-06-28 10:52:43 -06001003 &pIcdSurface->real_icd_surfaces[i]);
1004 if (VK_SUCCESS != vkRes) {
1005 goto out;
1006 }
1007 }
1008 }
1009 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001010
Mark Young786fb102016-12-01 10:42:21 -07001011 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott2c05e222015-11-19 13:14:05 -07001012
Mark Young16573c72016-06-28 10:52:43 -06001013out:
1014
1015 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1016 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young49f39db2016-11-02 09:37:08 -06001017 i = 0;
Mark Young0153e0b2016-11-03 14:27:13 -06001018 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
1019 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young786fb102016-12-01 10:42:21 -07001020 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young0153e0b2016-11-03 14:27:13 -06001021 NULL != icd_term->DestroySurfaceKHR) {
1022 icd_term->DestroySurfaceKHR(
1023 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
1024 pAllocator);
Mark Young16573c72016-06-28 10:52:43 -06001025 }
1026 }
Mark Young49f39db2016-11-02 09:37:08 -06001027 loader_instance_heap_free(ptr_instance,
1028 pIcdSurface->real_icd_surfaces);
Mark Young16573c72016-06-28 10:52:43 -06001029 }
1030 loader_instance_heap_free(ptr_instance, pIcdSurface);
1031 }
1032
1033 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -07001034}
Ian Elliott919fa302015-11-24 15:39:10 -07001035
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001036// This is the trampoline entrypoint for
1037// GetPhysicalDeviceXcbPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -07001038LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
1039vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
1040 uint32_t queueFamilyIndex,
1041 xcb_connection_t *connection,
1042 xcb_visualid_t visual_id) {
Jon Ashburn014438f2016-03-01 19:51:07 -07001043 VkPhysicalDevice unwrapped_phys_dev =
1044 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -07001045 const VkLayerInstanceDispatchTable *disp;
1046 disp = loader_get_instance_dispatch(physicalDevice);
1047 VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -07001048 unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliott919fa302015-11-24 15:39:10 -07001049 return res;
1050}
1051
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001052// This is the instance chain terminator function for
1053// GetPhysicalDeviceXcbPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -07001054VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -07001055terminator_GetPhysicalDeviceXcbPresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -07001056 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
1057 xcb_connection_t *connection, xcb_visualid_t visual_id) {
Mark Young0153e0b2016-11-03 14:27:13 -06001058
Ian Elliott2b8965a2016-03-24 13:59:22 -06001059 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -06001060 struct loader_physical_device_term *phys_dev_term =
1061 (struct loader_physical_device_term *)physicalDevice;
1062 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001063 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -06001064 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001065 if (!ptr_instance->wsi_xcb_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -06001066 loader_log(
1067 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1068 "VK_KHR_xcb_surface extension not enabled. "
1069 "vkGetPhysicalDeviceXcbPresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001070 return VK_SUCCESS;
1071 }
1072
1073 // Next, if so, proceed with the implementation of this function:
Jon Ashburn23d36b12016-02-02 17:47:28 -07001074 assert(
Mark Young0153e0b2016-11-03 14:27:13 -06001075 icd_term->GetPhysicalDeviceXcbPresentationSupportKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -07001076 "loader: null GetPhysicalDeviceXcbPresentationSupportKHR ICD pointer");
Ian Elliott919fa302015-11-24 15:39:10 -07001077
Mark Young0153e0b2016-11-03 14:27:13 -06001078 return icd_term->GetPhysicalDeviceXcbPresentationSupportKHR(
1079 phys_dev_term->phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliott919fa302015-11-24 15:39:10 -07001080}
Ian Elliott2c05e222015-11-19 13:14:05 -07001081#endif // VK_USE_PLATFORM_XCB_KHR
1082
1083#ifdef VK_USE_PLATFORM_XLIB_KHR
1084
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001085// Functions for the VK_KHR_xlib_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -07001086
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001087// This is the trampoline entrypoint for CreateXlibSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001088LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
1089 VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
1090 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -07001091 const VkLayerInstanceDispatchTable *disp;
1092 disp = loader_get_instance_dispatch(instance);
1093 VkResult res;
1094
Jon Ashburn23d36b12016-02-02 17:47:28 -07001095 res =
1096 disp->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -07001097 return res;
1098}
1099
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001100// This is the instance chain terminator function for CreateXlibSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001101VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXlibSurfaceKHR(
1102 VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
1103 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -06001104 VkResult vkRes = VK_SUCCESS;
Mark Youngad46cec2016-10-12 14:18:44 -06001105 VkIcdSurface *pIcdSurface = NULL;
Mark Young49f39db2016-11-02 09:37:08 -06001106 uint32_t i = 0;
1107
Ian Elliott2b8965a2016-03-24 13:59:22 -06001108 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -07001109 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -06001110 if (!ptr_instance->wsi_xlib_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001111 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1112 "VK_KHR_xlib_surface extension not enabled. "
1113 "vkCreateXlibSurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -06001114 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1115 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001116 }
1117
1118 // Next, if so, proceed with the implementation of this function:
Mark Youngad46cec2016-10-12 14:18:44 -06001119 pIcdSurface = AllocateIcdSurfaceStruct(
Mark Younga7c51fd2016-09-16 10:18:42 -06001120 ptr_instance, sizeof(pIcdSurface->xlib_surf.base),
Mark Younga60f1342016-12-13 17:19:32 -07001121 sizeof(pIcdSurface->xlib_surf));
Ian Elliott2c05e222015-11-19 13:14:05 -07001122 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -06001123 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1124 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -07001125 }
1126
Mark Young16573c72016-06-28 10:52:43 -06001127 pIcdSurface->xlib_surf.base.platform = VK_ICD_WSI_PLATFORM_XLIB;
1128 pIcdSurface->xlib_surf.dpy = pCreateInfo->dpy;
1129 pIcdSurface->xlib_surf.window = pCreateInfo->window;
1130
Mark Young16573c72016-06-28 10:52:43 -06001131 // Loop through each ICD and determine if they need to create a surface
Mark Young0153e0b2016-11-03 14:27:13 -06001132 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
1133 icd_term != NULL; icd_term = icd_term->next, i++) {
1134 if (icd_term->scanned_icd->interface_version >=
Mark Young16573c72016-06-28 10:52:43 -06001135 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young0153e0b2016-11-03 14:27:13 -06001136 if (NULL != icd_term->CreateXlibSurfaceKHR) {
1137 vkRes = icd_term->CreateXlibSurfaceKHR(
1138 icd_term->instance, pCreateInfo, pAllocator,
Mark Young16573c72016-06-28 10:52:43 -06001139 &pIcdSurface->real_icd_surfaces[i]);
1140 if (VK_SUCCESS != vkRes) {
1141 goto out;
1142 }
1143 }
1144 }
1145 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001146
Mark Young786fb102016-12-01 10:42:21 -07001147 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott2c05e222015-11-19 13:14:05 -07001148
Mark Young16573c72016-06-28 10:52:43 -06001149out:
1150
1151 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1152 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young49f39db2016-11-02 09:37:08 -06001153 i = 0;
Mark Young0153e0b2016-11-03 14:27:13 -06001154 for (struct loader_icd_term *icd_term = ptr_instance->icd_terms;
1155 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young786fb102016-12-01 10:42:21 -07001156 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young0153e0b2016-11-03 14:27:13 -06001157 NULL != icd_term->DestroySurfaceKHR) {
1158 icd_term->DestroySurfaceKHR(
1159 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
1160 pAllocator);
Mark Young16573c72016-06-28 10:52:43 -06001161 }
1162 }
Mark Young49f39db2016-11-02 09:37:08 -06001163 loader_instance_heap_free(ptr_instance,
1164 pIcdSurface->real_icd_surfaces);
Mark Young16573c72016-06-28 10:52:43 -06001165 }
1166 loader_instance_heap_free(ptr_instance, pIcdSurface);
1167 }
1168
1169 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -07001170}
Ian Elliott919fa302015-11-24 15:39:10 -07001171
Mark Young49f39db2016-11-02 09:37:08 -06001172// This is the trampoline entrypoint for
1173// GetPhysicalDeviceXlibPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -07001174LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
1175vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
1176 uint32_t queueFamilyIndex,
1177 Display *dpy, VisualID visualID) {
Jon Ashburn014438f2016-03-01 19:51:07 -07001178 VkPhysicalDevice unwrapped_phys_dev =
1179 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -07001180 const VkLayerInstanceDispatchTable *disp;
1181 disp = loader_get_instance_dispatch(physicalDevice);
1182 VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -07001183 unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliott919fa302015-11-24 15:39:10 -07001184 return res;
1185}
1186
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001187// This is the instance chain terminator function for
1188// GetPhysicalDeviceXlibPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -07001189VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -07001190terminator_GetPhysicalDeviceXlibPresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -07001191 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display *dpy,
1192 VisualID visualID) {
Mark Young0153e0b2016-11-03 14:27:13 -06001193
Ian Elliott2b8965a2016-03-24 13:59:22 -06001194 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -06001195 struct loader_physical_device_term *phys_dev_term =
1196 (struct loader_physical_device_term *)physicalDevice;
1197 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001198 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -06001199 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001200 if (!ptr_instance->wsi_xlib_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -06001201 loader_log(
1202 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1203 "VK_KHR_xlib_surface extension not enabled. "
1204 "vkGetPhysicalDeviceXlibPresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001205 return VK_SUCCESS;
1206 }
1207
1208 // Next, if so, proceed with the implementation of this function:
Jon Ashburn23d36b12016-02-02 17:47:28 -07001209 assert(
Mark Young0153e0b2016-11-03 14:27:13 -06001210 icd_term->GetPhysicalDeviceXlibPresentationSupportKHR &&
Jon Ashburn23d36b12016-02-02 17:47:28 -07001211 "loader: null GetPhysicalDeviceXlibPresentationSupportKHR ICD pointer");
Ian Elliott919fa302015-11-24 15:39:10 -07001212
Mark Young0153e0b2016-11-03 14:27:13 -06001213 return icd_term->GetPhysicalDeviceXlibPresentationSupportKHR(
1214 phys_dev_term->phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliott919fa302015-11-24 15:39:10 -07001215}
Ian Elliott2c05e222015-11-19 13:14:05 -07001216#endif // VK_USE_PLATFORM_XLIB_KHR
1217
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001218#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -07001219
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001220// Functions for the VK_KHR_android_surface extension:
1221
1222// This is the trampoline entrypoint for CreateAndroidSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001223LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
1224 VkInstance instance, ANativeWindow *window,
1225 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001226 const VkLayerInstanceDispatchTable *disp;
1227 disp = loader_get_instance_dispatch(instance);
1228 VkResult res;
1229
1230 res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
1231 return res;
1232}
1233
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001234// This is the instance chain terminator function for CreateAndroidSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001235VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(
1236 VkInstance instance, Window window, const VkAllocationCallbacks *pAllocator,
1237 VkSurfaceKHR *pSurface) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001238 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001239 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -06001240 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001241 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1242 "VK_KHR_display extension not enabled. "
1243 "vkCreateAndroidSurfaceKHR not executed!\n");
Jeremy Hayes9f1d0b62016-06-14 11:50:02 -06001244 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001245 }
1246
1247 // Next, if so, proceed with the implementation of this function:
Mark Young16573c72016-06-28 10:52:43 -06001248 VkIcdSurfaceAndroid *pIcdSurface =
Mark Young0ad83132016-06-30 13:02:42 -06001249 loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceAndroid),
Mark Young16573c72016-06-28 10:52:43 -06001250 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001251 if (pIcdSurface == NULL) {
1252 return VK_ERROR_OUT_OF_HOST_MEMORY;
1253 }
1254
1255 pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_ANDROID;
1256 pIcdSurface->dpy = dpy;
1257 pIcdSurface->window = window;
1258
Jon Ashburn23d36b12016-02-02 17:47:28 -07001259 *pSurface = (VkSurfaceKHR)pIcdSurface;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001260
1261 return VK_SUCCESS;
1262}
1263
1264#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -07001265
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001266// Functions for the VK_KHR_display instance extension:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001267LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
Jon Ashburncc407a22016-04-15 09:25:03 -06001268vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1269 uint32_t *pPropertyCount,
1270 VkDisplayPropertiesKHR *pProperties) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001271 VkPhysicalDevice unwrapped_phys_dev =
1272 loader_unwrap_physical_device(physicalDevice);
1273 const VkLayerInstanceDispatchTable *disp;
1274 disp = loader_get_instance_dispatch(physicalDevice);
1275 VkResult res = disp->GetPhysicalDeviceDisplayPropertiesKHR(
1276 unwrapped_phys_dev, pPropertyCount, pProperties);
1277 return res;
1278}
1279
Jon Ashburncc407a22016-04-15 09:25:03 -06001280VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPropertiesKHR(
1281 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1282 VkDisplayPropertiesKHR *pProperties) {
Mark Young0153e0b2016-11-03 14:27:13 -06001283
Ian Elliott2b8965a2016-03-24 13:59:22 -06001284 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -06001285 struct loader_physical_device_term *phys_dev_term =
1286 (struct loader_physical_device_term *)physicalDevice;
1287 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001288 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -06001289 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001290 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001291 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1292 "VK_KHR_display extension not enabled. "
1293 "vkGetPhysicalDeviceDisplayPropertiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001294 return VK_SUCCESS;
1295 }
1296
1297 // Next, if so, proceed with the implementation of this function:
Mark Young0153e0b2016-11-03 14:27:13 -06001298 assert(icd_term->GetPhysicalDeviceDisplayPropertiesKHR &&
Jon Ashburncc407a22016-04-15 09:25:03 -06001299 "loader: null GetPhysicalDeviceDisplayPropertiesKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001300
Mark Young0153e0b2016-11-03 14:27:13 -06001301 return icd_term->GetPhysicalDeviceDisplayPropertiesKHR(
1302 phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001303}
1304
1305LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
1306vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
Jon Ashburncc407a22016-04-15 09:25:03 -06001307 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1308 VkDisplayPlanePropertiesKHR *pProperties) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001309 VkPhysicalDevice unwrapped_phys_dev =
1310 loader_unwrap_physical_device(physicalDevice);
1311 const VkLayerInstanceDispatchTable *disp;
1312 disp = loader_get_instance_dispatch(physicalDevice);
1313 VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(
1314 unwrapped_phys_dev, pPropertyCount, pProperties);
1315 return res;
1316}
1317
1318VKAPI_ATTR VkResult VKAPI_CALL
1319terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(
Jon Ashburncc407a22016-04-15 09:25:03 -06001320 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1321 VkDisplayPlanePropertiesKHR *pProperties) {
Mark Young0153e0b2016-11-03 14:27:13 -06001322
Ian Elliott2b8965a2016-03-24 13:59:22 -06001323 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -06001324 struct loader_physical_device_term *phys_dev_term =
1325 (struct loader_physical_device_term *)physicalDevice;
1326 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001327 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -06001328 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001329 if (!ptr_instance->wsi_display_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -06001330 loader_log(
1331 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1332 "VK_KHR_display extension not enabled. "
1333 "vkGetPhysicalDeviceDisplayPlanePropertiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001334 return VK_SUCCESS;
1335 }
1336
1337 // Next, if so, proceed with the implementation of this function:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001338 assert(
Mark Young0153e0b2016-11-03 14:27:13 -06001339 icd_term->GetPhysicalDeviceDisplayPlanePropertiesKHR &&
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001340 "loader: null GetPhysicalDeviceDisplayPlanePropertiesKHR ICD pointer");
1341
Mark Young0153e0b2016-11-03 14:27:13 -06001342 return icd_term->GetPhysicalDeviceDisplayPlanePropertiesKHR(
1343 phys_dev_term->phys_dev, pPropertyCount, pProperties);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001344}
1345
1346LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
Jon Ashburncc407a22016-04-15 09:25:03 -06001347vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
1348 uint32_t planeIndex,
1349 uint32_t *pDisplayCount,
1350 VkDisplayKHR *pDisplays) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001351 VkPhysicalDevice unwrapped_phys_dev =
1352 loader_unwrap_physical_device(physicalDevice);
1353 const VkLayerInstanceDispatchTable *disp;
1354 disp = loader_get_instance_dispatch(physicalDevice);
1355 VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(
1356 unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
1357 return res;
1358}
1359
Mark Young16573c72016-06-28 10:52:43 -06001360VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneSupportedDisplaysKHR(
1361 VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1362 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
Mark Young0153e0b2016-11-03 14:27:13 -06001363
Ian Elliott2b8965a2016-03-24 13:59:22 -06001364 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -06001365 struct loader_physical_device_term *phys_dev_term =
1366 (struct loader_physical_device_term *)physicalDevice;
1367 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001368 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -06001369 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001370 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001371 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1372 "VK_KHR_display extension not enabled. "
1373 "vkGetDisplayPlaneSupportedDisplaysKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001374 return VK_SUCCESS;
1375 }
1376
1377 // Next, if so, proceed with the implementation of this function:
Mark Young0153e0b2016-11-03 14:27:13 -06001378 assert(icd_term->GetDisplayPlaneSupportedDisplaysKHR &&
Jon Ashburncc407a22016-04-15 09:25:03 -06001379 "loader: null GetDisplayPlaneSupportedDisplaysKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001380
Mark Young0153e0b2016-11-03 14:27:13 -06001381 return icd_term->GetDisplayPlaneSupportedDisplaysKHR(
1382 phys_dev_term->phys_dev, planeIndex, pDisplayCount, pDisplays);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001383}
1384
Mark Young16573c72016-06-28 10:52:43 -06001385LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(
1386 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1387 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001388 VkPhysicalDevice unwrapped_phys_dev =
1389 loader_unwrap_physical_device(physicalDevice);
1390 const VkLayerInstanceDispatchTable *disp;
1391 disp = loader_get_instance_dispatch(physicalDevice);
1392 VkResult res = disp->GetDisplayModePropertiesKHR(
1393 unwrapped_phys_dev, display, pPropertyCount, pProperties);
1394 return res;
1395}
1396
Jon Ashburncc407a22016-04-15 09:25:03 -06001397VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModePropertiesKHR(
1398 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1399 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
Mark Young0153e0b2016-11-03 14:27:13 -06001400
Ian Elliott2b8965a2016-03-24 13:59:22 -06001401 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -06001402 struct loader_physical_device_term *phys_dev_term =
1403 (struct loader_physical_device_term *)physicalDevice;
1404 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001405 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -06001406 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001407 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001408 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1409 "VK_KHR_display extension not enabled. "
1410 "vkGetDisplayModePropertiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001411 return VK_SUCCESS;
1412 }
1413
1414 // Next, if so, proceed with the implementation of this function:
Mark Young0153e0b2016-11-03 14:27:13 -06001415 assert(icd_term->GetDisplayModePropertiesKHR &&
Jon Ashburncc407a22016-04-15 09:25:03 -06001416 "loader: null GetDisplayModePropertiesKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001417
Mark Young0153e0b2016-11-03 14:27:13 -06001418 return icd_term->GetDisplayModePropertiesKHR(
1419 phys_dev_term->phys_dev, display, pPropertyCount, pProperties);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001420}
1421
Mark Young0ad83132016-06-30 13:02:42 -06001422LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR(
1423 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1424 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1425 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001426 VkPhysicalDevice unwrapped_phys_dev =
1427 loader_unwrap_physical_device(physicalDevice);
1428 const VkLayerInstanceDispatchTable *disp;
1429 disp = loader_get_instance_dispatch(physicalDevice);
Jon Ashburncc407a22016-04-15 09:25:03 -06001430 VkResult res = disp->CreateDisplayModeKHR(unwrapped_phys_dev, display,
1431 pCreateInfo, pAllocator, pMode);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001432 return res;
1433}
1434
Mark Young0ad83132016-06-30 13:02:42 -06001435VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayModeKHR(
1436 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1437 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1438 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Mark Young0153e0b2016-11-03 14:27:13 -06001439
Ian Elliott2b8965a2016-03-24 13:59:22 -06001440 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -06001441 struct loader_physical_device_term *phys_dev_term =
1442 (struct loader_physical_device_term *)physicalDevice;
1443 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001444 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -06001445 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001446 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001447 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1448 "VK_KHR_display extension not enabled. "
1449 "vkCreateDisplayModeKHR not executed!\n");
Jeremy Hayes9f1d0b62016-06-14 11:50:02 -06001450 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001451 }
1452
1453 // Next, if so, proceed with the implementation of this function:
Mark Young0153e0b2016-11-03 14:27:13 -06001454 assert(icd_term->CreateDisplayModeKHR &&
Jon Ashburncc407a22016-04-15 09:25:03 -06001455 "loader: null CreateDisplayModeKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001456
Mark Young0153e0b2016-11-03 14:27:13 -06001457 return icd_term->CreateDisplayModeKHR(phys_dev_term->phys_dev, display,
1458 pCreateInfo, pAllocator, pMode);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001459}
1460
Mark Young16573c72016-06-28 10:52:43 -06001461LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(
1462 VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex,
1463 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001464 VkPhysicalDevice unwrapped_phys_dev =
1465 loader_unwrap_physical_device(physicalDevice);
1466 const VkLayerInstanceDispatchTable *disp;
1467 disp = loader_get_instance_dispatch(physicalDevice);
1468 VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(
1469 unwrapped_phys_dev, mode, planeIndex, pCapabilities);
1470 return res;
1471}
1472
Jon Ashburncc407a22016-04-15 09:25:03 -06001473VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilitiesKHR(
1474 VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex,
1475 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Mark Young0153e0b2016-11-03 14:27:13 -06001476
Ian Elliott2b8965a2016-03-24 13:59:22 -06001477 // First, check to ensure the appropriate extension was enabled:
Mark Young0153e0b2016-11-03 14:27:13 -06001478 struct loader_physical_device_term *phys_dev_term =
1479 (struct loader_physical_device_term *)physicalDevice;
1480 struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001481 struct loader_instance *ptr_instance =
Mark Young0153e0b2016-11-03 14:27:13 -06001482 (struct loader_instance *)icd_term->this_instance;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001483 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001484 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1485 "VK_KHR_display extension not enabled. "
1486 "vkGetDisplayPlaneCapabilitiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001487 return VK_SUCCESS;
1488 }
1489
1490 // Next, if so, proceed with the implementation of this function:
Mark Young0153e0b2016-11-03 14:27:13 -06001491 assert(icd_term->GetDisplayPlaneCapabilitiesKHR &&
Jon Ashburncc407a22016-04-15 09:25:03 -06001492 "loader: null GetDisplayPlaneCapabilitiesKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001493
Mark Young0153e0b2016-11-03 14:27:13 -06001494 return icd_term->GetDisplayPlaneCapabilitiesKHR(
1495 phys_dev_term->phys_dev, mode, planeIndex, pCapabilities);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001496}
1497
Mark Young0ad83132016-06-30 13:02:42 -06001498LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(
1499 VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1500 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001501 const VkLayerInstanceDispatchTable *disp;
1502 disp = loader_get_instance_dispatch(instance);
1503 VkResult res;
1504
1505 res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator,
1506 pSurface);
1507 return res;
1508}
1509
Jon Ashburncc407a22016-04-15 09:25:03 -06001510VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayPlaneSurfaceKHR(
1511 VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1512 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001513 struct loader_instance *inst = loader_get_instance(instance);
Mark Young16573c72016-06-28 10:52:43 -06001514 VkIcdSurface *pIcdSurface = NULL;
Mark Young061ac722016-11-01 19:20:41 -06001515 VkResult vkRes = VK_SUCCESS;
Mark Young49f39db2016-11-02 09:37:08 -06001516 uint32_t i = 0;
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001517
Mark Young061ac722016-11-01 19:20:41 -06001518 if (!inst->wsi_display_enabled) {
Petros Bantolas25d27fe2016-04-14 12:50:42 +01001519 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1520 "VK_KHR_surface extension not enabled. "
1521 "vkCreateDisplayPlaneSurfaceKHR not executed!\n");
Mark Young061ac722016-11-01 19:20:41 -06001522 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1523 goto out;
Petros Bantolas25d27fe2016-04-14 12:50:42 +01001524 }
1525
Piers Daniell5a522602016-12-13 16:51:49 -07001526 // Next, if so, proceed with the implementation of this function:
Mark Younga7c51fd2016-09-16 10:18:42 -06001527 pIcdSurface =
1528 AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->display_surf.base),
Mark Younga60f1342016-12-13 17:19:32 -07001529 sizeof(pIcdSurface->display_surf));
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001530 if (pIcdSurface == NULL) {
Mark Young061ac722016-11-01 19:20:41 -06001531 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1532 goto out;
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001533 }
1534
Mark Young16573c72016-06-28 10:52:43 -06001535 pIcdSurface->display_surf.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
1536 pIcdSurface->display_surf.displayMode = pCreateInfo->displayMode;
1537 pIcdSurface->display_surf.planeIndex = pCreateInfo->planeIndex;
1538 pIcdSurface->display_surf.planeStackIndex = pCreateInfo->planeStackIndex;
1539 pIcdSurface->display_surf.transform = pCreateInfo->transform;
1540 pIcdSurface->display_surf.globalAlpha = pCreateInfo->globalAlpha;
1541 pIcdSurface->display_surf.alphaMode = pCreateInfo->alphaMode;
1542 pIcdSurface->display_surf.imageExtent = pCreateInfo->imageExtent;
1543
Mark Young061ac722016-11-01 19:20:41 -06001544 // Loop through each ICD and determine if they need to create a surface
Mark Young0153e0b2016-11-03 14:27:13 -06001545 for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL;
1546 icd_term = icd_term->next, i++) {
1547 if (icd_term->scanned_icd->interface_version >=
Mark Young061ac722016-11-01 19:20:41 -06001548 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
Mark Young0153e0b2016-11-03 14:27:13 -06001549 if (NULL != icd_term->CreateDisplayPlaneSurfaceKHR) {
1550 vkRes = icd_term->CreateDisplayPlaneSurfaceKHR(
1551 icd_term->instance, pCreateInfo, pAllocator,
Mark Young061ac722016-11-01 19:20:41 -06001552 &pIcdSurface->real_icd_surfaces[i]);
1553 if (VK_SUCCESS != vkRes) {
1554 goto out;
1555 }
1556 }
1557 }
1558 }
1559
Mark Young786fb102016-12-01 10:42:21 -07001560 *pSurface = (VkSurfaceKHR)pIcdSurface;
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001561
Mark Young061ac722016-11-01 19:20:41 -06001562out:
1563
1564 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1565 if (NULL != pIcdSurface->real_icd_surfaces) {
Mark Young49f39db2016-11-02 09:37:08 -06001566 i = 0;
Mark Young0153e0b2016-11-03 14:27:13 -06001567 for (struct loader_icd_term *icd_term = inst->icd_terms;
1568 icd_term != NULL; icd_term = icd_term->next, i++) {
Mark Young786fb102016-12-01 10:42:21 -07001569 if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] &&
Mark Young0153e0b2016-11-03 14:27:13 -06001570 NULL != icd_term->DestroySurfaceKHR) {
1571 icd_term->DestroySurfaceKHR(
1572 icd_term->instance, pIcdSurface->real_icd_surfaces[i],
1573 pAllocator);
Mark Young061ac722016-11-01 19:20:41 -06001574 }
1575 }
1576 loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces);
1577 }
1578 loader_instance_heap_free(inst, pIcdSurface);
1579 }
1580
1581 return vkRes;
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001582}
1583
Mark Young1a867442016-07-01 15:18:27 -06001584// This is the trampoline entrypoint
1585// for CreateSharedSwapchainsKHR
1586LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(
1587 VkDevice device, uint32_t swapchainCount,
1588 const VkSwapchainCreateInfoKHR *pCreateInfos,
1589 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchains) {
Mark Young5210abc2016-09-08 18:36:32 -06001590 const VkLayerDispatchTable *disp;
1591 disp = loader_get_dispatch(device);
Mark Young49f39db2016-11-02 09:37:08 -06001592 return disp->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos,
1593 pAllocator, pSwapchains);
Mark Young1a867442016-07-01 15:18:27 -06001594}
1595
Ian Elliott954fa342015-10-30 15:28:23 -06001596bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance,
Jon Ashburn23d36b12016-02-02 17:47:28 -07001597 const char *name, void **addr) {
Ian Elliott954fa342015-10-30 15:28:23 -06001598 *addr = NULL;
1599
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001600 // Functions for the VK_KHR_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -07001601 if (!strcmp("vkDestroySurfaceKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001602 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkDestroySurfaceKHR
1603 : NULL;
Ian Elliott2c05e222015-11-19 13:14:05 -07001604 return true;
1605 }
Ian Elliott954fa342015-10-30 15:28:23 -06001606 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001607 *addr = ptr_instance->wsi_surface_enabled
1608 ? (void *)vkGetPhysicalDeviceSurfaceSupportKHR
1609 : NULL;
Ian Elliott954fa342015-10-30 15:28:23 -06001610 return true;
1611 }
Ian Elliott486c5502015-11-19 16:05:09 -07001612 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001613 *addr = ptr_instance->wsi_surface_enabled
1614 ? (void *)vkGetPhysicalDeviceSurfaceCapabilitiesKHR
1615 : NULL;
Ian Elliott486c5502015-11-19 16:05:09 -07001616 return true;
1617 }
1618 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001619 *addr = ptr_instance->wsi_surface_enabled
1620 ? (void *)vkGetPhysicalDeviceSurfaceFormatsKHR
1621 : NULL;
Ian Elliott486c5502015-11-19 16:05:09 -07001622 return true;
1623 }
1624 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001625 *addr = ptr_instance->wsi_surface_enabled
1626 ? (void *)vkGetPhysicalDeviceSurfacePresentModesKHR
1627 : NULL;
Ian Elliott486c5502015-11-19 16:05:09 -07001628 return true;
1629 }
Ian Elliott934d0d52015-11-19 16:39:21 -07001630
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001631 // Functions for the VK_KHR_swapchain extension:
1632
1633 // Note: This is a device extension, and its functions are statically
1634 // exported from the loader. Per Khronos decisions, the loader's GIPA
1635 // function will return the trampoline function for such device-extension
1636 // functions, regardless of whether the extension has been enabled.
Ian Elliott934d0d52015-11-19 16:39:21 -07001637 if (!strcmp("vkCreateSwapchainKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001638 *addr = (void *)vkCreateSwapchainKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001639 return true;
1640 }
1641 if (!strcmp("vkDestroySwapchainKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001642 *addr = (void *)vkDestroySwapchainKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001643 return true;
1644 }
1645 if (!strcmp("vkGetSwapchainImagesKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001646 *addr = (void *)vkGetSwapchainImagesKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001647 return true;
1648 }
1649 if (!strcmp("vkAcquireNextImageKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001650 *addr = (void *)vkAcquireNextImageKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001651 return true;
1652 }
1653 if (!strcmp("vkQueuePresentKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001654 *addr = (void *)vkQueuePresentKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001655 return true;
1656 }
1657
Ian Elliott2c05e222015-11-19 13:14:05 -07001658#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001659
1660 // Functions for the VK_KHR_win32_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -07001661 if (!strcmp("vkCreateWin32SurfaceKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001662 *addr = ptr_instance->wsi_win32_surface_enabled
1663 ? (void *)vkCreateWin32SurfaceKHR
1664 : NULL;
Ian Elliott2c05e222015-11-19 13:14:05 -07001665 return true;
1666 }
Ian Elliott919fa302015-11-24 15:39:10 -07001667 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001668 *addr = ptr_instance->wsi_win32_surface_enabled
1669 ? (void *)vkGetPhysicalDeviceWin32PresentationSupportKHR
1670 : NULL;
Ian Elliott919fa302015-11-24 15:39:10 -07001671 return true;
1672 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001673#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -07001674#ifdef VK_USE_PLATFORM_MIR_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001675
1676 // Functions for the VK_KHR_mir_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -07001677 if (!strcmp("vkCreateMirSurfaceKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001678 *addr = ptr_instance->wsi_mir_surface_enabled
1679 ? (void *)vkCreateMirSurfaceKHR
1680 : NULL;
Ian Elliott2c05e222015-11-19 13:14:05 -07001681 return true;
1682 }
Ian Elliott919fa302015-11-24 15:39:10 -07001683 if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001684 *addr = ptr_instance->wsi_mir_surface_enabled
1685 ? (void *)vkGetPhysicalDeviceMirPresentationSupportKHR
1686 : NULL;
Ian Elliott919fa302015-11-24 15:39:10 -07001687 return true;
Jason Ekstranda5ebe8a2016-02-12 17:25:03 -08001688 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001689#endif // VK_USE_PLATFORM_MIR_KHR
1690#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001691
1692 // Functions for the VK_KHR_wayland_surface extension:
Jon Ashburn1530c342016-02-26 13:14:27 -07001693 if (!strcmp("vkCreateWaylandSurfaceKHR", name)) {
1694 *addr = ptr_instance->wsi_wayland_surface_enabled
1695 ? (void *)vkCreateWaylandSurfaceKHR
1696 : NULL;
1697 return true;
1698 }
1699 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", name)) {
1700 *addr = ptr_instance->wsi_wayland_surface_enabled
Jon Ashburn23d36b12016-02-02 17:47:28 -07001701 ? (void *)vkGetPhysicalDeviceWaylandPresentationSupportKHR
1702 : NULL;
Jon Ashburn1530c342016-02-26 13:14:27 -07001703 return true;
1704 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001705#endif // VK_USE_PLATFORM_WAYLAND_KHR
1706#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001707
1708 // Functions for the VK_KHR_xcb_surface extension:
Jon Ashburn1530c342016-02-26 13:14:27 -07001709 if (!strcmp("vkCreateXcbSurfaceKHR", name)) {
1710 *addr = ptr_instance->wsi_xcb_surface_enabled
1711 ? (void *)vkCreateXcbSurfaceKHR
1712 : NULL;
1713 return true;
1714 }
1715 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", name)) {
1716 *addr = ptr_instance->wsi_xcb_surface_enabled
1717 ? (void *)vkGetPhysicalDeviceXcbPresentationSupportKHR
1718 : NULL;
1719 return true;
1720 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001721#endif // VK_USE_PLATFORM_XCB_KHR
1722#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001723
1724 // Functions for the VK_KHR_xlib_surface extension:
Jon Ashburn1530c342016-02-26 13:14:27 -07001725 if (!strcmp("vkCreateXlibSurfaceKHR", name)) {
1726 *addr = ptr_instance->wsi_xlib_surface_enabled
1727 ? (void *)vkCreateXlibSurfaceKHR
1728 : NULL;
1729 return true;
1730 }
1731 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", name)) {
1732 *addr = ptr_instance->wsi_xlib_surface_enabled
1733 ? (void *)vkGetPhysicalDeviceXlibPresentationSupportKHR
1734 : NULL;
1735 return true;
1736 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001737#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001738#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001739
1740 // Functions for the VK_KHR_android_surface extension:
Jon Ashburn1530c342016-02-26 13:14:27 -07001741 if (!strcmp("vkCreateAndroidSurfaceKHR", name)) {
1742 *addr = ptr_instance->wsi_xlib_surface_enabled
1743 ? (void *)vkCreateAndroidSurfaceKHR
1744 : NULL;
1745 return true;
1746 }
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001747#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -07001748
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001749 // Functions for VK_KHR_display extension:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001750 if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) {
1751 *addr = ptr_instance->wsi_display_enabled
1752 ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR
1753 : NULL;
1754 return true;
1755 }
1756 if (!strcmp("vkGetPhysicalDeviceDisplayPlanePropertiesKHR", name)) {
1757 *addr = ptr_instance->wsi_display_enabled
1758 ? (void *)vkGetPhysicalDeviceDisplayPlanePropertiesKHR
1759 : NULL;
1760 return true;
1761 }
1762 if (!strcmp("vkGetDisplayPlaneSupportedDisplaysKHR", name)) {
1763 *addr = ptr_instance->wsi_display_enabled
1764 ? (void *)vkGetDisplayPlaneSupportedDisplaysKHR
1765 : NULL;
1766 return true;
1767 }
1768 if (!strcmp("vkGetDisplayModePropertiesKHR", name)) {
1769 *addr = ptr_instance->wsi_display_enabled
1770 ? (void *)vkGetDisplayModePropertiesKHR
1771 : NULL;
1772 return true;
1773 }
1774 if (!strcmp("vkCreateDisplayModeKHR", name)) {
1775 *addr = ptr_instance->wsi_display_enabled
1776 ? (void *)vkCreateDisplayModeKHR
1777 : NULL;
1778 return true;
1779 }
1780 if (!strcmp("vkGetDisplayPlaneCapabilitiesKHR", name)) {
1781 *addr = ptr_instance->wsi_display_enabled
1782 ? (void *)vkGetDisplayPlaneCapabilitiesKHR
1783 : NULL;
1784 return true;
1785 }
1786 if (!strcmp("vkCreateDisplayPlaneSurfaceKHR", name)) {
1787 *addr = ptr_instance->wsi_display_enabled
1788 ? (void *)vkCreateDisplayPlaneSurfaceKHR
1789 : NULL;
1790 return true;
1791 }
Mark Young1a867442016-07-01 15:18:27 -06001792
1793 // Functions for KHR_display_swapchain extension:
1794 if (!strcmp("vkCreateSharedSwapchainsKHR", name)) {
1795 *addr = (void *)vkCreateSharedSwapchainsKHR;
1796 return true;
1797 }
1798
Jon Ashburn1530c342016-02-26 13:14:27 -07001799 return false;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001800}