blob: d38085d57e9ef69e7ebcb1ca660a63abf08043e4 [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
Ian Elliott954fa342015-10-30 15:28:23 -060037static const VkExtensionProperties wsi_surface_extension_info = {
Jon Ashburn23d36b12016-02-02 17:47:28 -070038 .extensionName = VK_KHR_SURFACE_EXTENSION_NAME,
39 .specVersion = VK_KHR_SURFACE_SPEC_VERSION,
Ian Elliott954fa342015-10-30 15:28:23 -060040};
41
Ian Elliottc2e9aee2015-11-19 11:58:08 -070042#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060043static const VkExtensionProperties wsi_win32_surface_extension_info = {
Jon Ashburn23d36b12016-02-02 17:47:28 -070044 .extensionName = VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
45 .specVersion = VK_KHR_WIN32_SURFACE_SPEC_VERSION,
Ian Elliott954fa342015-10-30 15:28:23 -060046};
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070047#endif // VK_USE_PLATFORM_WIN32_KHR
48
Ian Elliottaf7d6362015-10-30 17:45:05 -060049#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060050static const VkExtensionProperties wsi_mir_surface_extension_info = {
Jon Ashburn23d36b12016-02-02 17:47:28 -070051 .extensionName = VK_KHR_MIR_SURFACE_EXTENSION_NAME,
52 .specVersion = VK_KHR_MIR_SURFACE_SPEC_VERSION,
Ian Elliott954fa342015-10-30 15:28:23 -060053};
Ian Elliottaf7d6362015-10-30 17:45:05 -060054#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060055
Ian Elliottaf7d6362015-10-30 17:45:05 -060056#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060057static const VkExtensionProperties wsi_wayland_surface_extension_info = {
Jon Ashburn23d36b12016-02-02 17:47:28 -070058 .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
59 .specVersion = VK_KHR_WAYLAND_SURFACE_SPEC_VERSION,
Ian Elliott954fa342015-10-30 15:28:23 -060060};
Ian Elliottaf7d6362015-10-30 17:45:05 -060061#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060062
Ian Elliottaf7d6362015-10-30 17:45:05 -060063#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060064static const VkExtensionProperties wsi_xcb_surface_extension_info = {
Jon Ashburn23d36b12016-02-02 17:47:28 -070065 .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME,
66 .specVersion = VK_KHR_XCB_SURFACE_SPEC_VERSION,
Ian Elliott954fa342015-10-30 15:28:23 -060067};
Ian Elliottaf7d6362015-10-30 17:45:05 -060068#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060069
Ian Elliottaf7d6362015-10-30 17:45:05 -060070#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060071static const VkExtensionProperties wsi_xlib_surface_extension_info = {
Jon Ashburn23d36b12016-02-02 17:47:28 -070072 .extensionName = VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
73 .specVersion = VK_KHR_XLIB_SURFACE_SPEC_VERSION,
Ian Elliott954fa342015-10-30 15:28:23 -060074};
Ian Elliottaf7d6362015-10-30 17:45:05 -060075#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070076
77#ifdef VK_USE_PLATFORM_ANDROID_KHR
78static const VkExtensionProperties wsi_android_surface_extension_info = {
Jon Ashburn23d36b12016-02-02 17:47:28 -070079 .extensionName = VK_KHR_ANDROID_SURFACE_EXTENSION_NAME,
80 .specVersion = VK_KHR_ANDROID_SURFACE_REVISION,
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070081};
82#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060083
Jon Ashburn23d36b12016-02-02 17:47:28 -070084void wsi_create_instance(struct loader_instance *ptr_instance,
85 const VkInstanceCreateInfo *pCreateInfo) {
Ian Elliottaf7d6362015-10-30 17:45:05 -060086 ptr_instance->wsi_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070087
88#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburnc7d3e732016-03-08 09:30:30 -070089 ptr_instance->wsi_win32_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070090#endif // VK_USE_PLATFORM_WIN32_KHR
91#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060092 ptr_instance->wsi_mir_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070093#endif // VK_USE_PLATFORM_MIR_KHR
94#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060095 ptr_instance->wsi_wayland_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070096#endif // VK_USE_PLATFORM_WAYLAND_KHR
97#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -060098 ptr_instance->wsi_xcb_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070099#endif // VK_USE_PLATFORM_XCB_KHR
100#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600101 ptr_instance->wsi_xlib_surface_enabled = false;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700102#endif // VK_USE_PLATFORM_XLIB_KHR
103#ifdef VK_USE_PLATFORM_ANDROID_KHR
104 ptr_instance->wsi_android_surface_enabled = false;
105#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600106
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700107 ptr_instance->wsi_display_enabled = false;
108
Jon Ashburnf19916e2016-01-11 13:12:43 -0700109 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Jon Ashburn23d36b12016-02-02 17:47:28 -0700110 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
111 VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -0600112 ptr_instance->wsi_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -0700113 continue;
Ian Elliott954fa342015-10-30 15:28:23 -0600114 }
Ian Elliottc2e9aee2015-11-19 11:58:08 -0700115#ifdef VK_USE_PLATFORM_WIN32_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700116 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
117 VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliottdb4300a2015-11-23 10:17:23 -0700118 ptr_instance->wsi_win32_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -0700119 continue;
Ian Elliott954fa342015-10-30 15:28:23 -0600120 }
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700121#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliottaf7d6362015-10-30 17:45:05 -0600122#ifdef VK_USE_PLATFORM_MIR_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700123 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
124 VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -0600125 ptr_instance->wsi_mir_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -0700126 continue;
Ian Elliott954fa342015-10-30 15:28:23 -0600127 }
Ian Elliottaf7d6362015-10-30 17:45:05 -0600128#endif // VK_USE_PLATFORM_MIR_KHR
129#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700130 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
131 VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -0600132 ptr_instance->wsi_wayland_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -0700133 continue;
Ian Elliott954fa342015-10-30 15:28:23 -0600134 }
Ian Elliottaf7d6362015-10-30 17:45:05 -0600135#endif // VK_USE_PLATFORM_WAYLAND_KHR
136#ifdef VK_USE_PLATFORM_XCB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700137 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
138 VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -0600139 ptr_instance->wsi_xcb_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -0700140 continue;
Ian Elliott954fa342015-10-30 15:28:23 -0600141 }
Ian Elliottaf7d6362015-10-30 17:45:05 -0600142#endif // VK_USE_PLATFORM_XCB_KHR
143#ifdef VK_USE_PLATFORM_XLIB_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700144 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
145 VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott954fa342015-10-30 15:28:23 -0600146 ptr_instance->wsi_xlib_surface_enabled = true;
Ian Elliottc2e9aee2015-11-19 11:58:08 -0700147 continue;
Ian Elliott954fa342015-10-30 15:28:23 -0600148 }
Ian Elliottaf7d6362015-10-30 17:45:05 -0600149#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700150#ifdef VK_USE_PLATFORM_ANDROID_KHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700151 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
152 VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700153 ptr_instance->wsi_android_surface_enabled = true;
154 continue;
155 }
156#endif // VK_USE_PLATFORM_ANDROID_KHR
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700157 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
158 VK_KHR_DISPLAY_EXTENSION_NAME) == 0) {
159 ptr_instance->wsi_display_enabled = true;
160 continue;
161 }
Ian Elliott954fa342015-10-30 15:28:23 -0600162 }
163}
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600164
165// Linux WSI surface extensions are not always compiled into the loader. (Assume
166// for Windows the KHR_win32_surface is always compiled into loader). A given
167// Linux build environment might not have the headers required for building one
168// of the four extensions (Xlib, Xcb, Mir, Wayland). Thus, need to check if
169// the built loader actually supports the particular Linux surface extension.
170// If not supported by the built loader it will not be included in the list of
171// enumerated instance extensions. This solves the issue where an ICD or layer
172// advertises support for a given Linux surface extension but the loader was not
173// built to support the extension.
Jon Ashburn6fa520f2016-03-25 12:49:35 -0600174bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop) {
175#ifndef VK_USE_PLATFORM_MIR_KHR
176 if (!strcmp(ext_prop->extensionName, "VK_KHR_mir_surface"))
177 return true;
178#endif // VK_USE_PLATFORM_MIR_KHR
179#ifndef VK_USE_PLATFORM_WAYLAND_KHR
180 if (!strcmp(ext_prop->extensionName, "VK_KHR_wayland_surface"))
181 return true;
182#endif // VK_USE_PLATFORM_WAYLAND_KHR
183#ifndef VK_USE_PLATFORM_XCB_KHR
184 if (!strcmp(ext_prop->extensionName, "VK_KHR_xcb_surface"))
185 return true;
186#endif // VK_USE_PLATFORM_XCB_KHR
187#ifndef VK_USE_PLATFORM_XLIB_KHR
188 if (!strcmp(ext_prop->extensionName, "VK_KHR_xlib_surface"))
189 return true;
190#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott954fa342015-10-30 15:28:23 -0600191
Jon Ashburn6fa520f2016-03-25 12:49:35 -0600192 return false;
193}
Ian Elliott2c05e222015-11-19 13:14:05 -0700194
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600195// Functions for the VK_KHR_surface extension:
196
197// This is the trampoline entrypoint for DestroySurfaceKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700198LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL
199vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
200 const VkAllocationCallbacks *pAllocator) {
Ian Elliottfb42cd72015-11-25 14:43:02 -0700201 const VkLayerInstanceDispatchTable *disp;
202 disp = loader_get_instance_dispatch(instance);
203 disp->DestroySurfaceKHR(instance, surface, pAllocator);
204}
205
Jon Ashburnc7d3e732016-03-08 09:30:30 -0700206// TODO probably need to lock around all the loader_get_instance() calls.
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600207
208// This is the instance chain terminator function for DestroySurfaceKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700209VKAPI_ATTR void VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -0700210terminator_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
211 const VkAllocationCallbacks *pAllocator) {
Ian Elliottdb4300a2015-11-23 10:17:23 -0700212 struct loader_instance *ptr_instance = loader_get_instance(instance);
213
Mark Young16573c72016-06-28 10:52:43 -0600214// Android doesn't have to worry about multiple ICD scenario, but the rest do.
215#ifndef VK_USE_PLATFORM_ANDROID_KHR
216 VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);
217 if (NULL != icd_surface->real_icd_surfaces) {
218 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
219 if (ptr_instance->icd_libs.list[i].interface_version >=
220 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
221 struct loader_icd *icd = &ptr_instance->icds[i];
222 if (NULL != icd->DestroySurfaceKHR &&
223 NULL != (void *)icd_surface->real_icd_surfaces[i]) {
224 icd->DestroySurfaceKHR(instance,
225 icd_surface->real_icd_surfaces[i],
226 pAllocator);
227 icd_surface->real_icd_surfaces[i] = (VkSurfaceKHR)NULL;
228 }
229 } else {
230 // The real_icd_surface for any ICD not supporting the proper
231 // interface version should be NULL. If not, then we have a
232 // problem.
233 assert(NULL == icd_surface->real_icd_surfaces[i]);
234 }
235 }
236 loader_instance_heap_free(ptr_instance, icd_surface->real_icd_surfaces);
237 }
238#endif // !VK_USE_PLATFORM_XLIB_KHR
239
Mark Young0ad83132016-06-30 13:02:42 -0600240 loader_instance_heap_free(ptr_instance, (void *)surface);
Ian Elliott2c05e222015-11-19 13:14:05 -0700241}
242
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600243// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700244LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
245vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
246 uint32_t queueFamilyIndex,
247 VkSurfaceKHR surface,
248 VkBool32 *pSupported) {
Ian Elliott954fa342015-10-30 15:28:23 -0600249 const VkLayerInstanceDispatchTable *disp;
Jon Ashburn014438f2016-03-01 19:51:07 -0700250 VkPhysicalDevice unwrapped_phys_dev =
251 loader_unwrap_physical_device(physicalDevice);
Ian Elliott954fa342015-10-30 15:28:23 -0600252 disp = loader_get_instance_dispatch(physicalDevice);
253 VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700254 unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott954fa342015-10-30 15:28:23 -0600255 return res;
256}
257
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600258// This is the instance chain terminator function for
259// GetPhysicalDeviceSurfaceSupportKHR
260VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceSupportKHR(
261 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
262 VkSurfaceKHR surface, VkBool32 *pSupported) {
Ian Elliott2b8965a2016-03-24 13:59:22 -0600263 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700264 struct loader_physical_device *phys_dev =
265 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600266 struct loader_instance *ptr_instance =
267 (struct loader_instance *)phys_dev->this_icd->this_instance;
268 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600269 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
270 "VK_KHR_VK_KHR_surface extension not enabled. "
271 "vkGetPhysicalDeviceSurfaceSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600272 return VK_SUCCESS;
273 }
274
275 // Next, if so, proceed with the implementation of this function:
Ian Elliott954fa342015-10-30 15:28:23 -0600276 struct loader_icd *icd = phys_dev->this_icd;
277
Jon Ashburn23d36b12016-02-02 17:47:28 -0700278 assert(pSupported &&
279 "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
Ian Elliott954fa342015-10-30 15:28:23 -0600280 *pSupported = false;
281
Jon Ashburn23d36b12016-02-02 17:47:28 -0700282 assert(icd->GetPhysicalDeviceSurfaceSupportKHR &&
283 "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
Ian Elliott954fa342015-10-30 15:28:23 -0600284
Mark Young16573c72016-06-28 10:52:43 -0600285// Android doesn't have to worry about multiple ICD scenario, but the rest do.
286#ifndef VK_USE_PLATFORM_ANDROID_KHR
287 VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);
288 if (NULL != icd_surface->real_icd_surfaces &&
289 NULL != (void *)icd_surface->real_icd_surfaces[phys_dev->icd_index]) {
290 return icd->GetPhysicalDeviceSurfaceSupportKHR(
291 phys_dev->phys_dev, queueFamilyIndex,
292 icd_surface->real_icd_surfaces[phys_dev->icd_index], pSupported);
293 }
294#endif
295
Jon Ashburn23d36b12016-02-02 17:47:28 -0700296 return icd->GetPhysicalDeviceSurfaceSupportKHR(
297 phys_dev->phys_dev, queueFamilyIndex, surface, pSupported);
Ian Elliott954fa342015-10-30 15:28:23 -0600298}
299
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600300// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceCapabilitiesKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700301LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
302vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
303 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
304 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700305
Ian Elliott486c5502015-11-19 16:05:09 -0700306 const VkLayerInstanceDispatchTable *disp;
Jon Ashburn014438f2016-03-01 19:51:07 -0700307 VkPhysicalDevice unwrapped_phys_dev =
308 loader_unwrap_physical_device(physicalDevice);
Ian Elliott486c5502015-11-19 16:05:09 -0700309 disp = loader_get_instance_dispatch(physicalDevice);
310 VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700311 unwrapped_phys_dev, surface, pSurfaceCapabilities);
Ian Elliott486c5502015-11-19 16:05:09 -0700312 return res;
313}
314
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600315// This is the instance chain terminator function for
316// GetPhysicalDeviceSurfaceCapabilitiesKHR
Jon Ashburn1530c342016-02-26 13:14:27 -0700317VKAPI_ATTR VkResult VKAPI_CALL
318terminator_GetPhysicalDeviceSurfaceCapabilitiesKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700319 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
320 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {
Ian Elliott2b8965a2016-03-24 13:59:22 -0600321 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700322 struct loader_physical_device *phys_dev =
323 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600324 struct loader_instance *ptr_instance =
325 (struct loader_instance *)phys_dev->this_icd->this_instance;
326 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600327 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
328 "VK_KHR_surface extension not enabled. "
329 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600330 return VK_SUCCESS;
331 }
332
333 // Next, if so, proceed with the implementation of this function:
Ian Elliott486c5502015-11-19 16:05:09 -0700334 struct loader_icd *icd = phys_dev->this_icd;
335
Jon Ashburn23d36b12016-02-02 17:47:28 -0700336 assert(pSurfaceCapabilities && "GetPhysicalDeviceSurfaceCapabilitiesKHR: "
337 "Error, null pSurfaceCapabilities");
Ian Elliott486c5502015-11-19 16:05:09 -0700338
Jon Ashburn23d36b12016-02-02 17:47:28 -0700339 assert(icd->GetPhysicalDeviceSurfaceCapabilitiesKHR &&
340 "loader: null GetPhysicalDeviceSurfaceCapabilitiesKHR ICD pointer");
Ian Elliott486c5502015-11-19 16:05:09 -0700341
Mark Young16573c72016-06-28 10:52:43 -0600342// Android doesn't have to worry about multiple ICD scenario, but the rest do.
343#ifndef VK_USE_PLATFORM_ANDROID_KHR
344 VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);
345 if (NULL != icd_surface->real_icd_surfaces &&
346 NULL != (void *)icd_surface->real_icd_surfaces[phys_dev->icd_index]) {
347 return icd->GetPhysicalDeviceSurfaceCapabilitiesKHR(
348 phys_dev->phys_dev,
349 icd_surface->real_icd_surfaces[phys_dev->icd_index],
350 pSurfaceCapabilities);
351 }
352#endif
353
Jon Ashburn23d36b12016-02-02 17:47:28 -0700354 return icd->GetPhysicalDeviceSurfaceCapabilitiesKHR(
355 phys_dev->phys_dev, surface, pSurfaceCapabilities);
Ian Elliott486c5502015-11-19 16:05:09 -0700356}
357
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600358
359// This is the trampoline entrypoint for GetPhysicalDeviceSurfaceFormatsKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700360LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
361vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
362 VkSurfaceKHR surface,
363 uint32_t *pSurfaceFormatCount,
364 VkSurfaceFormatKHR *pSurfaceFormats) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700365 VkPhysicalDevice unwrapped_phys_dev =
366 loader_unwrap_physical_device(physicalDevice);
Ian Elliott486c5502015-11-19 16:05:09 -0700367 const VkLayerInstanceDispatchTable *disp;
368 disp = loader_get_instance_dispatch(physicalDevice);
369 VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700370 unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliott486c5502015-11-19 16:05:09 -0700371 return res;
372}
373
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600374
375// This is the instance chain terminator function for GetPhysicalDeviceSurfaceFormatsKHR
Jon Ashburn1530c342016-02-26 13:14:27 -0700376VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceFormatsKHR(
377 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
378 uint32_t *pSurfaceFormatCount, VkSurfaceFormatKHR *pSurfaceFormats) {
Ian Elliott2b8965a2016-03-24 13:59:22 -0600379 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700380 struct loader_physical_device *phys_dev =
381 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600382 struct loader_instance *ptr_instance =
383 (struct loader_instance *)phys_dev->this_icd->this_instance;
384 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600385 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
386 "VK_KHR_surface extension not enabled. "
387 "vkGetPhysicalDeviceSurfaceFormatsKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600388 return VK_SUCCESS;
389 }
390
391 // Next, if so, proceed with the implementation of this function:
Ian Elliott486c5502015-11-19 16:05:09 -0700392 struct loader_icd *icd = phys_dev->this_icd;
393
Jon Ashburn23d36b12016-02-02 17:47:28 -0700394 assert(
395 pSurfaceFormatCount &&
396 "GetPhysicalDeviceSurfaceFormatsKHR: Error, null pSurfaceFormatCount");
Ian Elliott486c5502015-11-19 16:05:09 -0700397
Jon Ashburn23d36b12016-02-02 17:47:28 -0700398 assert(icd->GetPhysicalDeviceSurfaceFormatsKHR &&
399 "loader: null GetPhysicalDeviceSurfaceFormatsKHR ICD pointer");
Ian Elliott486c5502015-11-19 16:05:09 -0700400
Mark Young16573c72016-06-28 10:52:43 -0600401// Android doesn't have to worry about multiple ICD scenario, but the rest do.
402#ifndef VK_USE_PLATFORM_ANDROID_KHR
403 VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);
404 if (NULL != icd_surface->real_icd_surfaces &&
405 NULL != (void *)icd_surface->real_icd_surfaces[phys_dev->icd_index]) {
406 return icd->GetPhysicalDeviceSurfaceFormatsKHR(
407 phys_dev->phys_dev,
408 icd_surface->real_icd_surfaces[phys_dev->icd_index],
409 pSurfaceFormatCount, pSurfaceFormats);
410 }
411#endif
412
Jon Ashburn23d36b12016-02-02 17:47:28 -0700413 return icd->GetPhysicalDeviceSurfaceFormatsKHR(
414 phys_dev->phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliott486c5502015-11-19 16:05:09 -0700415}
416
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600417// This is the trampoline entrypoint for GetPhysicalDeviceSurfacePresentModesKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700418LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
419vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
420 VkSurfaceKHR surface,
421 uint32_t *pPresentModeCount,
422 VkPresentModeKHR *pPresentModes) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700423 VkPhysicalDevice unwrapped_phys_dev =
424 loader_unwrap_physical_device(physicalDevice);
Ian Elliott486c5502015-11-19 16:05:09 -0700425 const VkLayerInstanceDispatchTable *disp;
426 disp = loader_get_instance_dispatch(physicalDevice);
427 VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700428 unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliott486c5502015-11-19 16:05:09 -0700429 return res;
430}
431
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600432// This is the instance chain terminator function for
433// GetPhysicalDeviceSurfacePresentModesKHR
Jon Ashburn1530c342016-02-26 13:14:27 -0700434VKAPI_ATTR VkResult VKAPI_CALL
435terminator_GetPhysicalDeviceSurfacePresentModesKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700436 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
437 uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes) {
Ian Elliott2b8965a2016-03-24 13:59:22 -0600438 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700439 struct loader_physical_device *phys_dev =
440 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600441 struct loader_instance *ptr_instance =
442 (struct loader_instance *)phys_dev->this_icd->this_instance;
443 if (!ptr_instance->wsi_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600444 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
445 "VK_KHR_surface extension not enabled. "
446 "vkGetPhysicalDeviceSurfacePresentModesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600447 return VK_SUCCESS;
448 }
449
450 // Next, if so, proceed with the implementation of this function:
Ian Elliott486c5502015-11-19 16:05:09 -0700451 struct loader_icd *icd = phys_dev->this_icd;
452
Jon Ashburn23d36b12016-02-02 17:47:28 -0700453 assert(pPresentModeCount && "GetPhysicalDeviceSurfacePresentModesKHR: "
454 "Error, null pPresentModeCount");
Ian Elliott486c5502015-11-19 16:05:09 -0700455
Jon Ashburn23d36b12016-02-02 17:47:28 -0700456 assert(icd->GetPhysicalDeviceSurfacePresentModesKHR &&
457 "loader: null GetPhysicalDeviceSurfacePresentModesKHR ICD pointer");
Ian Elliott486c5502015-11-19 16:05:09 -0700458
Mark Young16573c72016-06-28 10:52:43 -0600459// Android doesn't have to worry about multiple ICD scenario, but the rest do.
460#ifndef VK_USE_PLATFORM_ANDROID_KHR
461 VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);
462 if (NULL != icd_surface->real_icd_surfaces &&
463 NULL != (void *)icd_surface->real_icd_surfaces[phys_dev->icd_index]) {
464 return icd->GetPhysicalDeviceSurfacePresentModesKHR(
465 phys_dev->phys_dev,
466 icd_surface->real_icd_surfaces[phys_dev->icd_index],
467 pPresentModeCount, pPresentModes);
468 }
469#endif
470
Jon Ashburn23d36b12016-02-02 17:47:28 -0700471 return icd->GetPhysicalDeviceSurfacePresentModesKHR(
472 phys_dev->phys_dev, surface, pPresentModeCount, pPresentModes);
Ian Elliott486c5502015-11-19 16:05:09 -0700473}
474
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600475// Functions for the VK_KHR_swapchain extension:
Ian Elliott2c05e222015-11-19 13:14:05 -0700476
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600477// This is the trampoline entrypoint for CreateSwapchainKHR
Mark Young0ad83132016-06-30 13:02:42 -0600478LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
479 VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
480 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {
Ian Elliott934d0d52015-11-19 16:39:21 -0700481 const VkLayerDispatchTable *disp;
482 disp = loader_get_dispatch(device);
Mark Youngead9b932016-09-08 12:28:38 -0600483 return disp->CreateSwapchainKHR(device, pCreateInfo, pAllocator,
484 pSwapchain);
Ian Elliott934d0d52015-11-19 16:39:21 -0700485}
Ian Elliott2c05e222015-11-19 13:14:05 -0700486
Mark Young16573c72016-06-28 10:52:43 -0600487VKAPI_ATTR VkResult VKAPI_CALL terminator_vkCreateSwapchainKHR(
488 VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
489 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {
490 uint32_t icd_index = 0;
491 struct loader_device *dev;
492 struct loader_icd *icd = loader_get_icd_and_device(device, &dev, &icd_index);
493 PFN_vkCreateSwapchainKHR CreateSwapchainKHR;
494 if (NULL != icd &&
495 NULL != icd->CreateSwapchainKHR) {
496 // Android doesn't have to worry about multiple ICD scenario, but the rest do.
497#ifndef VK_USE_PLATFORM_ANDROID_KHR
498 VkIcdSurface *icd_surface = (VkIcdSurface *)(pCreateInfo->surface);
499 if (NULL != icd_surface->real_icd_surfaces) {
500 if (NULL != (void *)icd_surface->real_icd_surfaces[icd_index]) {
501 // We found the ICD, and there is an ICD KHR surface
502 // associated with it, so copy the CreateInfo struct
503 // and point it at the ICD's surface.
504 VkSwapchainCreateInfoKHR *pCreateCopy =
505 loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR));
506 if (NULL == pCreateCopy) {
507 return VK_ERROR_OUT_OF_HOST_MEMORY;
508 }
509 memcpy(pCreateCopy, pCreateInfo, sizeof(VkIcdSurface));
510 pCreateCopy->surface =
511 icd_surface->real_icd_surfaces[icd_index];
512 return icd->CreateSwapchainKHR(device, pCreateCopy, pAllocator, pSwapchain);
513 }
514 }
515#endif
516 return icd->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
517 }
518 return VK_SUCCESS;
519}
520
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600521// This is the trampoline entrypoint for DestroySwapchainKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700522LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL
523vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
524 const VkAllocationCallbacks *pAllocator) {
Ian Elliott934d0d52015-11-19 16:39:21 -0700525 const VkLayerDispatchTable *disp;
526 disp = loader_get_dispatch(device);
527 disp->DestroySwapchainKHR(device, swapchain, pAllocator);
528}
Ian Elliott2c05e222015-11-19 13:14:05 -0700529
Mark Young16573c72016-06-28 10:52:43 -0600530/*
531 * This is the trampoline entrypoint
532 * for GetSwapchainImagesKHR
533 */
534LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
535 VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
536 VkImage *pSwapchainImages) {
Ian Elliott934d0d52015-11-19 16:39:21 -0700537 const VkLayerDispatchTable *disp;
538 disp = loader_get_dispatch(device);
Mark Youngead9b932016-09-08 12:28:38 -0600539 return disp->GetSwapchainImagesKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700540 device, swapchain, pSwapchainImageCount, pSwapchainImages);
Ian Elliott934d0d52015-11-19 16:39:21 -0700541}
542
Mark Young16573c72016-06-28 10:52:43 -0600543/*
544 * This is the trampoline entrypoint
545 * for AcquireNextImageKHR
546 */
547LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
548 VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
549 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Ian Elliott934d0d52015-11-19 16:39:21 -0700550 const VkLayerDispatchTable *disp;
551 disp = loader_get_dispatch(device);
Mark Youngead9b932016-09-08 12:28:38 -0600552 return disp->AcquireNextImageKHR(device, swapchain, timeout,
553 semaphore, fence, pImageIndex);
Ian Elliott934d0d52015-11-19 16:39:21 -0700554}
555
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600556// This is the trampoline entrypoint for QueuePresentKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700557LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
558vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
Ian Elliott934d0d52015-11-19 16:39:21 -0700559 const VkLayerDispatchTable *disp;
560 disp = loader_get_dispatch(queue);
Mark Youngead9b932016-09-08 12:28:38 -0600561 return disp->QueuePresentKHR(queue, pPresentInfo);
Ian Elliott934d0d52015-11-19 16:39:21 -0700562}
Ian Elliott2c05e222015-11-19 13:14:05 -0700563
Ian Elliott2c05e222015-11-19 13:14:05 -0700564#ifdef VK_USE_PLATFORM_WIN32_KHR
565
Ian Elliott2c05e222015-11-19 13:14:05 -0700566
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600567// Functions for the VK_KHR_win32_surface extension:
568
569// This is the trampoline entrypoint for CreateWin32SurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600570LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
571 VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
572 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700573 const VkLayerInstanceDispatchTable *disp;
574 disp = loader_get_instance_dispatch(instance);
575 VkResult res;
576
Jon Ashburn23d36b12016-02-02 17:47:28 -0700577 res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator,
578 pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700579 return res;
580}
581
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600582// This is the instance chain terminator function for CreateWin32SurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600583VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWin32SurfaceKHR(
584 VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
585 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -0600586 VkResult vkRes = VK_SUCCESS;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600587 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -0700588 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -0600589 if (!ptr_instance->wsi_win32_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600590 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
591 "VK_KHR_win32_surface extension not enabled. "
592 "vkCreateWin32SurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -0600593 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
594 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600595 }
596
597 // Next, if so, proceed with the implementation of this function:
Mark Young16573c72016-06-28 10:52:43 -0600598 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(
599 ptr_instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Ian Elliott2c05e222015-11-19 13:14:05 -0700600 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -0600601 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
602 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -0700603 }
604
Mark Young16573c72016-06-28 10:52:43 -0600605 pIcdSurface->win_surf.base.platform = VK_ICD_WSI_PLATFORM_WIN32;
606 pIcdSurface->win_surf.hinstance = pCreateInfo->hinstance;
607 pIcdSurface->win_surf.hwnd = pCreateInfo->hwnd;
Ian Elliott2c05e222015-11-19 13:14:05 -0700608
Mark Young16573c72016-06-28 10:52:43 -0600609 // Setup the new sizes and offsets so we can grow the structures in the
610 // future withouth having problems
611 pIcdSurface->base_size = sizeof(pIcdSurface->win_surf.base);
612 pIcdSurface->platform_size = sizeof(pIcdSurface->win_surf);
613 pIcdSurface->non_platform_offset = (uint32_t)(
614 (uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
615 pIcdSurface->entire_size = sizeof(VkIcdSurface);
Ian Elliott2c05e222015-11-19 13:14:05 -0700616
Mark Young16573c72016-06-28 10:52:43 -0600617 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(
618 ptr_instance, sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count,
619 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
620 if (pIcdSurface == NULL) {
621 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
622 goto out;
623 }
624 memset(pIcdSurface->real_icd_surfaces, 0,
625 sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count);
626
627 // Loop through each ICD and determine if they need to create a surface
628 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
629 if (ptr_instance->icd_libs.list[i].interface_version >=
630 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
631 struct loader_icd *icd = &ptr_instance->icds[i];
632 if (NULL != icd->CreateWin32SurfaceKHR) {
633 vkRes = icd->CreateWin32SurfaceKHR(
634 instance, pCreateInfo, pAllocator,
635 &pIcdSurface->real_icd_surfaces[i]);
636 if (VK_SUCCESS != vkRes) {
637 goto out;
638 }
639 }
640 }
641 }
642
643 *pSurface = (VkSurfaceKHR)(pIcdSurface);
644
645out:
646
647 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
648 if (NULL != pIcdSurface->real_icd_surfaces) {
649 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
650 struct loader_icd *icd = &ptr_instance->icds[i];
651 if (NULL != pIcdSurface->real_icd_surfaces[i] &&
652 NULL != icd->DestroySurfaceKHR) {
653 icd->DestroySurfaceKHR(
654 instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
655 }
656 }
657 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
658 }
659 loader_instance_heap_free(ptr_instance, pIcdSurface);
660 }
661
662 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -0700663}
Ian Elliott919fa302015-11-24 15:39:10 -0700664
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600665// This is the trampoline entrypoint for
666// GetPhysicalDeviceWin32PresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700667LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
668vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
669 uint32_t queueFamilyIndex) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700670 VkPhysicalDevice unwrapped_phys_dev =
671 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -0700672 const VkLayerInstanceDispatchTable *disp;
673 disp = loader_get_instance_dispatch(physicalDevice);
674 VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700675 unwrapped_phys_dev, queueFamilyIndex);
Ian Elliott919fa302015-11-24 15:39:10 -0700676 return res;
677}
678
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600679// This is the instance chain terminator function for
680// GetPhysicalDeviceWin32PresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700681VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -0700682terminator_GetPhysicalDeviceWin32PresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700683 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex) {
Ian Elliott2b8965a2016-03-24 13:59:22 -0600684 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700685 struct loader_physical_device *phys_dev =
686 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600687 struct loader_instance *ptr_instance =
688 (struct loader_instance *)phys_dev->this_icd->this_instance;
689 if (!ptr_instance->wsi_win32_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -0600690 loader_log(
691 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
692 "VK_KHR_win32_surface extension not enabled. "
693 "vkGetPhysicalDeviceWin32PresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600694 return VK_SUCCESS;
695 }
696
697 // Next, if so, proceed with the implementation of this function:
Ian Elliott919fa302015-11-24 15:39:10 -0700698 struct loader_icd *icd = phys_dev->this_icd;
699
Jon Ashburn23d36b12016-02-02 17:47:28 -0700700 assert(icd->GetPhysicalDeviceWin32PresentationSupportKHR &&
701 "loader: null GetPhysicalDeviceWin32PresentationSupportKHR ICD "
702 "pointer");
Ian Elliott919fa302015-11-24 15:39:10 -0700703
704 return icd->GetPhysicalDeviceWin32PresentationSupportKHR(phys_dev->phys_dev,
Jon Ashburn23d36b12016-02-02 17:47:28 -0700705 queueFamilyIndex);
Ian Elliott919fa302015-11-24 15:39:10 -0700706}
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700707#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -0700708
709#ifdef VK_USE_PLATFORM_MIR_KHR
710
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600711// Functions for the VK_KHR_mir_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -0700712
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600713// This is the trampoline entrypoint for CreateMirSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600714LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(
715 VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
716 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700717 const VkLayerInstanceDispatchTable *disp;
718 disp = loader_get_instance_dispatch(instance);
719 VkResult res;
720
Jon Ashburn23d36b12016-02-02 17:47:28 -0700721 res =
722 disp->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700723 return res;
724}
725
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600726// This is the instance chain terminator function for CreateMirSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600727VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMirSurfaceKHR(
728 VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
729 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -0600730 VkResult vkRes = VK_SUCCESS;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600731 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -0700732 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -0600733 if (!ptr_instance->wsi_mir_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600734 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
735 "VK_KHR_mir_surface extension not enabled. "
736 "vkCreateMirSurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -0600737 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
738 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600739 }
740
741 // Next, if so, proceed with the implementation of this function:
Mark Young16573c72016-06-28 10:52:43 -0600742 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(
743 ptr_instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Ian Elliott2c05e222015-11-19 13:14:05 -0700744 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -0600745 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
746 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -0700747 }
748
Mark Young16573c72016-06-28 10:52:43 -0600749 pIcdSurface->mir_surf.base.platform = VK_ICD_WSI_PLATFORM_MIR;
750 pIcdSurface->mir_surf.connection = pCreateInfo->connection;
751 pIcdSurface->mir_surf.mirSurface = pCreateInfo->mirSurface;
752
753 // Setup the new sizes and offsets so we can grow the structures in the
754 // future withouth having problems
755 pIcdSurface->base_size = sizeof(pIcdSurface->mir_surf.base);
756 pIcdSurface->platform_size = sizeof(pIcdSurface->mir_surf);
757 pIcdSurface->non_platform_offset = (uint32_t)(
758 (uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
759 pIcdSurface->entire_size = sizeof(VkIcdSurface);
760
761 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(
762 ptr_instance, sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count,
763 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
764 if (pIcdSurface == NULL) {
765 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
766 goto out;
767 }
768 memset(pIcdSurface->real_icd_surfaces, 0,
769 sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count);
770
771 // Loop through each ICD and determine if they need to create a surface
772 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
773 if (ptr_instance->icd_libs.list[i].interface_version >=
774 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
775 struct loader_icd *icd = &ptr_instance->icds[i];
776 if (NULL != icd->CreateMirSurfaceKHR) {
777 vkRes = icd->CreateMirSurfaceKHR(
778 instance, pCreateInfo, pAllocator,
779 &pIcdSurface->real_icd_surfaces[i]);
780 if (VK_SUCCESS != vkRes) {
781 goto out;
782 }
783 }
784 }
785 }
Ian Elliott2c05e222015-11-19 13:14:05 -0700786
Jon Ashburn23d36b12016-02-02 17:47:28 -0700787 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott2c05e222015-11-19 13:14:05 -0700788
Mark Young16573c72016-06-28 10:52:43 -0600789out:
790
791 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
792 if (NULL != pIcdSurface->real_icd_surfaces) {
793 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
794 struct loader_icd *icd = &ptr_instance->icds[i];
795 if (NULL != pIcdSurface->real_icd_surfaces[i] &&
796 NULL != icd->DestroySurfaceKHR) {
797 icd->DestroySurfaceKHR(
798 instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
799 }
800 }
801 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
802 }
803 loader_instance_heap_free(ptr_instance, pIcdSurface);
804 }
805
806 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -0700807}
Ian Elliott919fa302015-11-24 15:39:10 -0700808
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600809// This is the trampoline entrypoint for
810// GetPhysicalDeviceMirPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700811LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
812vkGetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice,
813 uint32_t queueFamilyIndex,
814 MirConnection *connection) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700815 VkPhysicalDevice unwrapped_phys_dev =
816 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -0700817 const VkLayerInstanceDispatchTable *disp;
818 disp = loader_get_instance_dispatch(physicalDevice);
819 VkBool32 res = disp->GetPhysicalDeviceMirPresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700820 unwrapped_phys_dev, queueFamilyIndex, connection);
Ian Elliott919fa302015-11-24 15:39:10 -0700821 return res;
822}
823
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600824// This is the instance chain terminator function for
825// GetPhysicalDeviceMirPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700826VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -0700827terminator_GetPhysicalDeviceMirPresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700828 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
829 MirConnection *connection) {
Ian Elliott2b8965a2016-03-24 13:59:22 -0600830 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700831 struct loader_physical_device *phys_dev =
832 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600833 struct loader_instance *ptr_instance =
834 (struct loader_instance *)phys_dev->this_icd->this_instance;
835 if (!ptr_instance->wsi_mir_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -0600836 loader_log(
837 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
838 "VK_KHR_mir_surface extension not enabled. "
839 "vkGetPhysicalDeviceMirPresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600840 return VK_SUCCESS;
841 }
842
843 // Next, if so, proceed with the implementation of this function:
Ian Elliott919fa302015-11-24 15:39:10 -0700844 struct loader_icd *icd = phys_dev->this_icd;
845
Jon Ashburn23d36b12016-02-02 17:47:28 -0700846 assert(
847 icd->GetPhysicalDeviceMirPresentationSupportKHR &&
848 "loader: null GetPhysicalDeviceMirPresentationSupportKHR ICD pointer");
Ian Elliott919fa302015-11-24 15:39:10 -0700849
Jon Ashburn23d36b12016-02-02 17:47:28 -0700850 return icd->GetPhysicalDeviceMirPresentationSupportKHR(
851 phys_dev->phys_dev, queueFamilyIndex, connection);
Ian Elliott919fa302015-11-24 15:39:10 -0700852}
Ian Elliott2c05e222015-11-19 13:14:05 -0700853#endif // VK_USE_PLATFORM_MIR_KHR
854
855#ifdef VK_USE_PLATFORM_WAYLAND_KHR
856
Mark Young16573c72016-06-28 10:52:43 -0600857/*
858 * This is the trampoline entrypoint
859 * for CreateWaylandSurfaceKHR
860 */
861LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
862 VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
863 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700864 const VkLayerInstanceDispatchTable *disp;
865 disp = loader_get_instance_dispatch(instance);
866 VkResult res;
867
Jon Ashburn23d36b12016-02-02 17:47:28 -0700868 res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator,
869 pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -0700870 return res;
871}
872
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600873// This is the instance chain terminator function for CreateWaylandSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -0600874VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(
Jon Ashburn1530c342016-02-26 13:14:27 -0700875 VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
876 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -0600877 VkResult vkRes = VK_SUCCESS;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600878 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -0700879 struct loader_instance *ptr_instance = loader_get_instance(instance);
Jon Ashburnd76b51c2016-03-24 17:26:59 -0600880 if (!ptr_instance->wsi_wayland_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -0600881 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
882 "VK_KHR_wayland_surface extension not enabled. "
883 "vkCreateWaylandSurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -0600884 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
885 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600886 }
887
888 // Next, if so, proceed with the implementation of this function:
Mark Young16573c72016-06-28 10:52:43 -0600889 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(
890 ptr_instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Ian Elliott2c05e222015-11-19 13:14:05 -0700891 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -0600892 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
893 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -0700894 }
895
Mark Young16573c72016-06-28 10:52:43 -0600896 pIcdSurface->wayland_surf.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
897 pIcdSurface->wayland_surf.display = pCreateInfo->display;
898 pIcdSurface->wayland_surf.surface = pCreateInfo->surface;
899
900 // Setup the new sizes and offsets so we can grow the structures in the
901 // future withouth having problems
902 pIcdSurface->base_size = sizeof(pIcdSurface->wayland_surf.base);
903 pIcdSurface->platform_size = sizeof(pIcdSurface->wayland_surf);
904 pIcdSurface->non_platform_offset = (uint32_t)(
905 (uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
906 pIcdSurface->entire_size = sizeof(VkIcdSurface);
907
908 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(
909 ptr_instance, sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count,
910 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
911 if (pIcdSurface == NULL) {
912 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
913 goto out;
914 }
915 memset(pIcdSurface->real_icd_surfaces, 0,
916 sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count);
917
918 // Loop through each ICD and determine if they need to create a surface
919 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
920 if (ptr_instance->icd_libs.list[i].interface_version >=
921 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
922 struct loader_icd *icd = &ptr_instance->icds[i];
923 if (NULL != icd->CreateWaylandSurfaceKHR) {
924 vkRes = icd->CreateWaylandSurfaceKHR(
925 instance, pCreateInfo, pAllocator,
926 &pIcdSurface->real_icd_surfaces[i]);
927 if (VK_SUCCESS != vkRes) {
928 goto out;
929 }
930 }
931 }
932 }
Ian Elliott2c05e222015-11-19 13:14:05 -0700933
Jon Ashburn23d36b12016-02-02 17:47:28 -0700934 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott2c05e222015-11-19 13:14:05 -0700935
Mark Young16573c72016-06-28 10:52:43 -0600936out:
937
938 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
939 if (NULL != pIcdSurface->real_icd_surfaces) {
940 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
941 struct loader_icd *icd = &ptr_instance->icds[i];
942 if (NULL != pIcdSurface->real_icd_surfaces[i] &&
943 NULL != icd->DestroySurfaceKHR) {
944 icd->DestroySurfaceKHR(
945 instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
946 }
947 }
948 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
949 }
950 loader_instance_heap_free(ptr_instance, pIcdSurface);
951 }
952
953 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -0700954}
Ian Elliott919fa302015-11-24 15:39:10 -0700955
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600956
957// This is the trampoline entrypoint for
958// GetPhysicalDeviceWaylandPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700959LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
960vkGetPhysicalDeviceWaylandPresentationSupportKHR(
961 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
962 struct wl_display *display) {
Jon Ashburn014438f2016-03-01 19:51:07 -0700963 VkPhysicalDevice unwrapped_phys_dev =
964 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -0700965 const VkLayerInstanceDispatchTable *disp;
966 disp = loader_get_instance_dispatch(physicalDevice);
967 VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -0700968 unwrapped_phys_dev, queueFamilyIndex, display);
Ian Elliott919fa302015-11-24 15:39:10 -0700969 return res;
970}
971
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -0600972// This is the instance chain terminator function for
973// GetPhysicalDeviceWaylandPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -0700974VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -0700975terminator_GetPhysicalDeviceWaylandPresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -0700976 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
977 struct wl_display *display) {
Ian Elliott2b8965a2016-03-24 13:59:22 -0600978 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -0700979 struct loader_physical_device *phys_dev =
980 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -0600981 struct loader_instance *ptr_instance =
982 (struct loader_instance *)phys_dev->this_icd->this_instance;
Jon Ashburnd76b51c2016-03-24 17:26:59 -0600983 if (!ptr_instance->wsi_wayland_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -0600984 loader_log(
985 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
986 "VK_KHR_wayland_surface extension not enabled. "
987 "vkGetPhysicalDeviceWaylandPresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -0600988 return VK_SUCCESS;
989 }
990
991 // Next, if so, proceed with the implementation of this function:
Ian Elliott919fa302015-11-24 15:39:10 -0700992 struct loader_icd *icd = phys_dev->this_icd;
993
Jon Ashburn23d36b12016-02-02 17:47:28 -0700994 assert(icd->GetPhysicalDeviceWaylandPresentationSupportKHR &&
995 "loader: null GetPhysicalDeviceWaylandPresentationSupportKHR ICD "
996 "pointer");
Ian Elliott919fa302015-11-24 15:39:10 -0700997
Jon Ashburn23d36b12016-02-02 17:47:28 -0700998 return icd->GetPhysicalDeviceWaylandPresentationSupportKHR(
999 phys_dev->phys_dev, queueFamilyIndex, display);
Ian Elliott919fa302015-11-24 15:39:10 -07001000}
Ian Elliott2c05e222015-11-19 13:14:05 -07001001#endif // VK_USE_PLATFORM_WAYLAND_KHR
1002
1003#ifdef VK_USE_PLATFORM_XCB_KHR
1004
Ian Elliott2c05e222015-11-19 13:14:05 -07001005
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001006// Functions for the VK_KHR_xcb_surface extension:
1007
1008// This is the trampoline entrypoint for CreateXcbSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001009LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
1010 VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
1011 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -07001012 const VkLayerInstanceDispatchTable *disp;
1013 disp = loader_get_instance_dispatch(instance);
1014 VkResult res;
1015
Jon Ashburn23d36b12016-02-02 17:47:28 -07001016 res =
1017 disp->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -07001018 return res;
1019}
1020
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001021// This is the instance chain terminator function for CreateXcbSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001022VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXcbSurfaceKHR(
1023 VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
1024 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -06001025 VkResult vkRes = VK_SUCCESS;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001026 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -07001027 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -06001028 if (!ptr_instance->wsi_xcb_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001029 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1030 "VK_KHR_xcb_surface extension not enabled. "
1031 "vkCreateXcbSurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -06001032 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1033 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001034 }
1035
1036 // Next, if so, proceed with the implementation of this function:
Mark Young16573c72016-06-28 10:52:43 -06001037 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(
1038 ptr_instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Ian Elliott2c05e222015-11-19 13:14:05 -07001039 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -06001040 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1041 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -07001042 }
1043
Mark Young16573c72016-06-28 10:52:43 -06001044 pIcdSurface->xcb_surf.base.platform = VK_ICD_WSI_PLATFORM_XCB;
1045 pIcdSurface->xcb_surf.connection = pCreateInfo->connection;
1046 pIcdSurface->xcb_surf.window = pCreateInfo->window;
1047
1048 // Setup the new sizes and offsets so we can grow the structures in the
1049 // future withouth having problems
1050 pIcdSurface->base_size = sizeof(pIcdSurface->xcb_surf.base);
1051 pIcdSurface->platform_size = sizeof(pIcdSurface->xcb_surf);
1052 pIcdSurface->non_platform_offset = (uint32_t)(
1053 (uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
1054 pIcdSurface->entire_size = sizeof(VkIcdSurface);
1055
1056 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(
1057 ptr_instance, sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count,
1058 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
1059 if (pIcdSurface == NULL) {
1060 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1061 goto out;
1062 }
1063 memset(pIcdSurface->real_icd_surfaces, 0,
1064 sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count);
1065
1066 // Loop through each ICD and determine if they need to create a surface
1067 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
1068 if (ptr_instance->icd_libs.list[i].interface_version >=
1069 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1070 struct loader_icd *icd = &ptr_instance->icds[i];
1071 if (NULL != icd->CreateXcbSurfaceKHR) {
1072 vkRes = icd->CreateXcbSurfaceKHR(
1073 instance, pCreateInfo, pAllocator,
1074 &pIcdSurface->real_icd_surfaces[i]);
1075 if (VK_SUCCESS != vkRes) {
1076 goto out;
1077 }
1078 }
1079 }
1080 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001081
Jon Ashburn23d36b12016-02-02 17:47:28 -07001082 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott2c05e222015-11-19 13:14:05 -07001083
Mark Young16573c72016-06-28 10:52:43 -06001084out:
1085
1086 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1087 if (NULL != pIcdSurface->real_icd_surfaces) {
1088 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
1089 struct loader_icd *icd = &ptr_instance->icds[i];
1090 if (NULL != pIcdSurface->real_icd_surfaces[i] &&
1091 NULL != icd->DestroySurfaceKHR) {
1092 icd->DestroySurfaceKHR(
1093 instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1094 }
1095 }
1096 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
1097 }
1098 loader_instance_heap_free(ptr_instance, pIcdSurface);
1099 }
1100
1101 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -07001102}
Ian Elliott919fa302015-11-24 15:39:10 -07001103
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001104// This is the trampoline entrypoint for
1105// GetPhysicalDeviceXcbPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -07001106LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
1107vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
1108 uint32_t queueFamilyIndex,
1109 xcb_connection_t *connection,
1110 xcb_visualid_t visual_id) {
Jon Ashburn014438f2016-03-01 19:51:07 -07001111 VkPhysicalDevice unwrapped_phys_dev =
1112 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -07001113 const VkLayerInstanceDispatchTable *disp;
1114 disp = loader_get_instance_dispatch(physicalDevice);
1115 VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -07001116 unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliott919fa302015-11-24 15:39:10 -07001117 return res;
1118}
1119
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001120// This is the instance chain terminator function for
1121// GetPhysicalDeviceXcbPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -07001122VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -07001123terminator_GetPhysicalDeviceXcbPresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -07001124 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
1125 xcb_connection_t *connection, xcb_visualid_t visual_id) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001126 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -07001127 struct loader_physical_device *phys_dev =
1128 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001129 struct loader_instance *ptr_instance =
1130 (struct loader_instance *)phys_dev->this_icd->this_instance;
1131 if (!ptr_instance->wsi_xcb_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -06001132 loader_log(
1133 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1134 "VK_KHR_xcb_surface extension not enabled. "
1135 "vkGetPhysicalDeviceXcbPresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001136 return VK_SUCCESS;
1137 }
1138
1139 // Next, if so, proceed with the implementation of this function:
Ian Elliott919fa302015-11-24 15:39:10 -07001140 struct loader_icd *icd = phys_dev->this_icd;
1141
Jon Ashburn23d36b12016-02-02 17:47:28 -07001142 assert(
1143 icd->GetPhysicalDeviceXcbPresentationSupportKHR &&
1144 "loader: null GetPhysicalDeviceXcbPresentationSupportKHR ICD pointer");
Ian Elliott919fa302015-11-24 15:39:10 -07001145
Jon Ashburn23d36b12016-02-02 17:47:28 -07001146 return icd->GetPhysicalDeviceXcbPresentationSupportKHR(
1147 phys_dev->phys_dev, queueFamilyIndex, connection, visual_id);
Ian Elliott919fa302015-11-24 15:39:10 -07001148}
Ian Elliott2c05e222015-11-19 13:14:05 -07001149#endif // VK_USE_PLATFORM_XCB_KHR
1150
1151#ifdef VK_USE_PLATFORM_XLIB_KHR
1152
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001153// Functions for the VK_KHR_xlib_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -07001154
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001155// This is the trampoline entrypoint for CreateXlibSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001156LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
1157 VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
1158 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnf72a04b2015-11-25 17:55:49 -07001159 const VkLayerInstanceDispatchTable *disp;
1160 disp = loader_get_instance_dispatch(instance);
1161 VkResult res;
1162
Jon Ashburn23d36b12016-02-02 17:47:28 -07001163 res =
1164 disp->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
Jon Ashburnf72a04b2015-11-25 17:55:49 -07001165 return res;
1166}
1167
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001168// This is the instance chain terminator function for CreateXlibSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001169VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXlibSurfaceKHR(
1170 VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
1171 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Young16573c72016-06-28 10:52:43 -06001172 VkResult vkRes = VK_SUCCESS;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001173 // First, check to ensure the appropriate extension was enabled:
Ian Elliottdb4300a2015-11-23 10:17:23 -07001174 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -06001175 if (!ptr_instance->wsi_xlib_surface_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001176 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1177 "VK_KHR_xlib_surface extension not enabled. "
1178 "vkCreateXlibSurfaceKHR not executed!\n");
Mark Young16573c72016-06-28 10:52:43 -06001179 vkRes = VK_ERROR_EXTENSION_NOT_PRESENT;
1180 goto out;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001181 }
1182
1183 // Next, if so, proceed with the implementation of this function:
Mark Young16573c72016-06-28 10:52:43 -06001184 VkIcdSurface *pIcdSurface = loader_instance_heap_alloc(
1185 ptr_instance, sizeof(VkIcdSurface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Ian Elliott2c05e222015-11-19 13:14:05 -07001186 if (pIcdSurface == NULL) {
Mark Young16573c72016-06-28 10:52:43 -06001187 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1188 goto out;
Ian Elliott2c05e222015-11-19 13:14:05 -07001189 }
1190
Mark Young16573c72016-06-28 10:52:43 -06001191 pIcdSurface->xlib_surf.base.platform = VK_ICD_WSI_PLATFORM_XLIB;
1192 pIcdSurface->xlib_surf.dpy = pCreateInfo->dpy;
1193 pIcdSurface->xlib_surf.window = pCreateInfo->window;
1194
1195 // Setup the new sizes and offsets so we can grow the structures in the
1196 // future withouth having problems
1197 pIcdSurface->base_size = sizeof(pIcdSurface->xlib_surf.base);
1198 pIcdSurface->platform_size = sizeof(pIcdSurface->xlib_surf);
1199 pIcdSurface->non_platform_offset = (uint32_t)(
1200 (uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
1201 pIcdSurface->entire_size = sizeof(VkIcdSurface);
1202
1203 pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(
1204 ptr_instance, sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count,
1205 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
1206 if (pIcdSurface == NULL) {
1207 vkRes = VK_ERROR_OUT_OF_HOST_MEMORY;
1208 goto out;
1209 }
1210 memset(pIcdSurface->real_icd_surfaces, 0,
1211 sizeof(VkSurfaceKHR) * ptr_instance->total_icd_count);
1212
1213 // Loop through each ICD and determine if they need to create a surface
1214 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
1215 if (ptr_instance->icd_libs.list[i].interface_version >=
1216 ICD_VER_SUPPORTS_ICD_SURFACE_KHR) {
1217 struct loader_icd *icd = &ptr_instance->icds[i];
1218 if (NULL != icd->CreateXlibSurfaceKHR) {
1219 vkRes = icd->CreateXlibSurfaceKHR(
1220 instance, pCreateInfo, pAllocator,
1221 &pIcdSurface->real_icd_surfaces[i]);
1222 if (VK_SUCCESS != vkRes) {
1223 goto out;
1224 }
1225 }
1226 }
1227 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001228
Jon Ashburn23d36b12016-02-02 17:47:28 -07001229 *pSurface = (VkSurfaceKHR)pIcdSurface;
Ian Elliott2c05e222015-11-19 13:14:05 -07001230
Mark Young16573c72016-06-28 10:52:43 -06001231out:
1232
1233 if (VK_SUCCESS != vkRes && NULL != pIcdSurface) {
1234 if (NULL != pIcdSurface->real_icd_surfaces) {
1235 for (uint32_t i = 0; i < ptr_instance->total_icd_count; i++) {
1236 struct loader_icd *icd = &ptr_instance->icds[i];
1237 if (NULL != pIcdSurface->real_icd_surfaces[i] &&
1238 NULL != icd->DestroySurfaceKHR) {
1239 icd->DestroySurfaceKHR(
1240 instance, pIcdSurface->real_icd_surfaces[i], pAllocator);
1241 }
1242 }
1243 loader_instance_heap_free(ptr_instance, pIcdSurface->real_icd_surfaces);
1244 }
1245 loader_instance_heap_free(ptr_instance, pIcdSurface);
1246 }
1247
1248 return vkRes;
Ian Elliott2c05e222015-11-19 13:14:05 -07001249}
Ian Elliott919fa302015-11-24 15:39:10 -07001250
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001251// This is the trampoline entrypoint for GetPhysicalDeviceXlibPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -07001252LOADER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL
1253vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
1254 uint32_t queueFamilyIndex,
1255 Display *dpy, VisualID visualID) {
Jon Ashburn014438f2016-03-01 19:51:07 -07001256 VkPhysicalDevice unwrapped_phys_dev =
1257 loader_unwrap_physical_device(physicalDevice);
Ian Elliott919fa302015-11-24 15:39:10 -07001258 const VkLayerInstanceDispatchTable *disp;
1259 disp = loader_get_instance_dispatch(physicalDevice);
1260 VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(
Jon Ashburn014438f2016-03-01 19:51:07 -07001261 unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliott919fa302015-11-24 15:39:10 -07001262 return res;
1263}
1264
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001265// This is the instance chain terminator function for
1266// GetPhysicalDeviceXlibPresentationSupportKHR
Jon Ashburn23d36b12016-02-02 17:47:28 -07001267VKAPI_ATTR VkBool32 VKAPI_CALL
Jon Ashburn1530c342016-02-26 13:14:27 -07001268terminator_GetPhysicalDeviceXlibPresentationSupportKHR(
Jon Ashburn23d36b12016-02-02 17:47:28 -07001269 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display *dpy,
1270 VisualID visualID) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001271 // First, check to ensure the appropriate extension was enabled:
Jon Ashburn23d36b12016-02-02 17:47:28 -07001272 struct loader_physical_device *phys_dev =
1273 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001274 struct loader_instance *ptr_instance =
1275 (struct loader_instance *)phys_dev->this_icd->this_instance;
1276 if (!ptr_instance->wsi_xlib_surface_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -06001277 loader_log(
1278 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1279 "VK_KHR_xlib_surface extension not enabled. "
1280 "vkGetPhysicalDeviceXlibPresentationSupportKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001281 return VK_SUCCESS;
1282 }
1283
1284 // Next, if so, proceed with the implementation of this function:
Ian Elliott919fa302015-11-24 15:39:10 -07001285 struct loader_icd *icd = phys_dev->this_icd;
1286
Jon Ashburn23d36b12016-02-02 17:47:28 -07001287 assert(
1288 icd->GetPhysicalDeviceXlibPresentationSupportKHR &&
1289 "loader: null GetPhysicalDeviceXlibPresentationSupportKHR ICD pointer");
Ian Elliott919fa302015-11-24 15:39:10 -07001290
Jon Ashburn23d36b12016-02-02 17:47:28 -07001291 return icd->GetPhysicalDeviceXlibPresentationSupportKHR(
1292 phys_dev->phys_dev, queueFamilyIndex, dpy, visualID);
Ian Elliott919fa302015-11-24 15:39:10 -07001293}
Ian Elliott2c05e222015-11-19 13:14:05 -07001294#endif // VK_USE_PLATFORM_XLIB_KHR
1295
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001296#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -07001297
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001298
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001299// Functions for the VK_KHR_android_surface extension:
1300
1301// This is the trampoline entrypoint for CreateAndroidSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001302LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
1303 VkInstance instance, ANativeWindow *window,
1304 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001305 const VkLayerInstanceDispatchTable *disp;
1306 disp = loader_get_instance_dispatch(instance);
1307 VkResult res;
1308
1309 res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
1310 return res;
1311}
1312
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001313// This is the instance chain terminator function for CreateAndroidSurfaceKHR
Mark Young0ad83132016-06-30 13:02:42 -06001314VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(
1315 VkInstance instance, Window window, const VkAllocationCallbacks *pAllocator,
1316 VkSurfaceKHR *pSurface) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001317 // First, check to ensure the appropriate extension was enabled:
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001318 struct loader_instance *ptr_instance = loader_get_instance(instance);
Ian Elliott2b8965a2016-03-24 13:59:22 -06001319 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001320 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1321 "VK_KHR_display extension not enabled. "
1322 "vkCreateAndroidSurfaceKHR not executed!\n");
Jeremy Hayes9f1d0b62016-06-14 11:50:02 -06001323 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001324 }
1325
1326 // Next, if so, proceed with the implementation of this function:
Mark Young16573c72016-06-28 10:52:43 -06001327 VkIcdSurfaceAndroid *pIcdSurface =
Mark Young0ad83132016-06-30 13:02:42 -06001328 loader_instance_heap_alloc(ptr_instance, sizeof(VkIcdSurfaceAndroid),
Mark Young16573c72016-06-28 10:52:43 -06001329 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001330 if (pIcdSurface == NULL) {
1331 return VK_ERROR_OUT_OF_HOST_MEMORY;
1332 }
1333
1334 pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_ANDROID;
1335 pIcdSurface->dpy = dpy;
1336 pIcdSurface->window = window;
1337
Jon Ashburn23d36b12016-02-02 17:47:28 -07001338 *pSurface = (VkSurfaceKHR)pIcdSurface;
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001339
1340 return VK_SUCCESS;
1341}
1342
1343#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -07001344
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001345
1346// Functions for the VK_KHR_display instance extension:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001347LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
Jon Ashburncc407a22016-04-15 09:25:03 -06001348vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
1349 uint32_t *pPropertyCount,
1350 VkDisplayPropertiesKHR *pProperties) {
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->GetPhysicalDeviceDisplayPropertiesKHR(
1356 unwrapped_phys_dev, pPropertyCount, pProperties);
1357 return res;
1358}
1359
Jon Ashburncc407a22016-04-15 09:25:03 -06001360VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceDisplayPropertiesKHR(
1361 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1362 VkDisplayPropertiesKHR *pProperties) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001363 // First, check to ensure the appropriate extension was enabled:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001364 struct loader_physical_device *phys_dev =
1365 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001366 struct loader_instance *ptr_instance =
1367 (struct loader_instance *)phys_dev->this_icd->this_instance;
1368 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001369 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1370 "VK_KHR_display extension not enabled. "
1371 "vkGetPhysicalDeviceDisplayPropertiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001372 return VK_SUCCESS;
1373 }
1374
1375 // Next, if so, proceed with the implementation of this function:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001376 struct loader_icd *icd = phys_dev->this_icd;
1377
Jon Ashburncc407a22016-04-15 09:25:03 -06001378 assert(icd->GetPhysicalDeviceDisplayPropertiesKHR &&
1379 "loader: null GetPhysicalDeviceDisplayPropertiesKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001380
1381 return icd->GetPhysicalDeviceDisplayPropertiesKHR(
1382 phys_dev->phys_dev, pPropertyCount, pProperties);
1383}
1384
1385LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
1386vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
Jon Ashburncc407a22016-04-15 09:25:03 -06001387 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1388 VkDisplayPlanePropertiesKHR *pProperties) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001389 VkPhysicalDevice unwrapped_phys_dev =
1390 loader_unwrap_physical_device(physicalDevice);
1391 const VkLayerInstanceDispatchTable *disp;
1392 disp = loader_get_instance_dispatch(physicalDevice);
1393 VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(
1394 unwrapped_phys_dev, pPropertyCount, pProperties);
1395 return res;
1396}
1397
1398VKAPI_ATTR VkResult VKAPI_CALL
1399terminator_GetPhysicalDeviceDisplayPlanePropertiesKHR(
Jon Ashburncc407a22016-04-15 09:25:03 -06001400 VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
1401 VkDisplayPlanePropertiesKHR *pProperties) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001402 // First, check to ensure the appropriate extension was enabled:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001403 struct loader_physical_device *phys_dev =
1404 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001405 struct loader_instance *ptr_instance =
1406 (struct loader_instance *)phys_dev->this_icd->this_instance;
1407 if (!ptr_instance->wsi_display_enabled) {
Jon Ashburncc407a22016-04-15 09:25:03 -06001408 loader_log(
1409 ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1410 "VK_KHR_display extension not enabled. "
1411 "vkGetPhysicalDeviceDisplayPlanePropertiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001412 return VK_SUCCESS;
1413 }
1414
1415 // Next, if so, proceed with the implementation of this function:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001416 struct loader_icd *icd = phys_dev->this_icd;
1417
1418 assert(
1419 icd->GetPhysicalDeviceDisplayPlanePropertiesKHR &&
1420 "loader: null GetPhysicalDeviceDisplayPlanePropertiesKHR ICD pointer");
1421
1422 return icd->GetPhysicalDeviceDisplayPlanePropertiesKHR(
1423 phys_dev->phys_dev, pPropertyCount, pProperties);
1424}
1425
1426LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
Jon Ashburncc407a22016-04-15 09:25:03 -06001427vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
1428 uint32_t planeIndex,
1429 uint32_t *pDisplayCount,
1430 VkDisplayKHR *pDisplays) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001431 VkPhysicalDevice unwrapped_phys_dev =
1432 loader_unwrap_physical_device(physicalDevice);
1433 const VkLayerInstanceDispatchTable *disp;
1434 disp = loader_get_instance_dispatch(physicalDevice);
1435 VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(
1436 unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
1437 return res;
1438}
1439
Mark Young16573c72016-06-28 10:52:43 -06001440VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneSupportedDisplaysKHR(
1441 VkPhysicalDevice physicalDevice, uint32_t planeIndex,
1442 uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001443 // First, check to ensure the appropriate extension was enabled:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001444 struct loader_physical_device *phys_dev =
1445 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001446 struct loader_instance *ptr_instance =
1447 (struct loader_instance *)phys_dev->this_icd->this_instance;
1448 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001449 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1450 "VK_KHR_display extension not enabled. "
1451 "vkGetDisplayPlaneSupportedDisplaysKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001452 return VK_SUCCESS;
1453 }
1454
1455 // Next, if so, proceed with the implementation of this function:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001456 struct loader_icd *icd = phys_dev->this_icd;
1457
Jon Ashburncc407a22016-04-15 09:25:03 -06001458 assert(icd->GetDisplayPlaneSupportedDisplaysKHR &&
1459 "loader: null GetDisplayPlaneSupportedDisplaysKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001460
1461 return icd->GetDisplayPlaneSupportedDisplaysKHR(
1462 phys_dev->phys_dev, planeIndex, pDisplayCount, pDisplays);
1463}
1464
Mark Young16573c72016-06-28 10:52:43 -06001465LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(
1466 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1467 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001468 VkPhysicalDevice unwrapped_phys_dev =
1469 loader_unwrap_physical_device(physicalDevice);
1470 const VkLayerInstanceDispatchTable *disp;
1471 disp = loader_get_instance_dispatch(physicalDevice);
1472 VkResult res = disp->GetDisplayModePropertiesKHR(
1473 unwrapped_phys_dev, display, pPropertyCount, pProperties);
1474 return res;
1475}
1476
Jon Ashburncc407a22016-04-15 09:25:03 -06001477VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayModePropertiesKHR(
1478 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1479 uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001480 // First, check to ensure the appropriate extension was enabled:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001481 struct loader_physical_device *phys_dev =
1482 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001483 struct loader_instance *ptr_instance =
1484 (struct loader_instance *)phys_dev->this_icd->this_instance;
1485 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001486 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1487 "VK_KHR_display extension not enabled. "
1488 "vkGetDisplayModePropertiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001489 return VK_SUCCESS;
1490 }
1491
1492 // Next, if so, proceed with the implementation of this function:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001493 struct loader_icd *icd = phys_dev->this_icd;
1494
Jon Ashburncc407a22016-04-15 09:25:03 -06001495 assert(icd->GetDisplayModePropertiesKHR &&
1496 "loader: null GetDisplayModePropertiesKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001497
Jon Ashburncc407a22016-04-15 09:25:03 -06001498 return icd->GetDisplayModePropertiesKHR(phys_dev->phys_dev, display,
1499 pPropertyCount, pProperties);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001500}
1501
Mark Young0ad83132016-06-30 13:02:42 -06001502LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR(
1503 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1504 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1505 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001506 VkPhysicalDevice unwrapped_phys_dev =
1507 loader_unwrap_physical_device(physicalDevice);
1508 const VkLayerInstanceDispatchTable *disp;
1509 disp = loader_get_instance_dispatch(physicalDevice);
Jon Ashburncc407a22016-04-15 09:25:03 -06001510 VkResult res = disp->CreateDisplayModeKHR(unwrapped_phys_dev, display,
1511 pCreateInfo, pAllocator, pMode);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001512 return res;
1513}
1514
Mark Young0ad83132016-06-30 13:02:42 -06001515VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayModeKHR(
1516 VkPhysicalDevice physicalDevice, VkDisplayKHR display,
1517 const VkDisplayModeCreateInfoKHR *pCreateInfo,
1518 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001519 // First, check to ensure the appropriate extension was enabled:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001520 struct loader_physical_device *phys_dev =
1521 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001522 struct loader_instance *ptr_instance =
1523 (struct loader_instance *)phys_dev->this_icd->this_instance;
1524 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001525 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1526 "VK_KHR_display extension not enabled. "
1527 "vkCreateDisplayModeKHR not executed!\n");
Jeremy Hayes9f1d0b62016-06-14 11:50:02 -06001528 return VK_ERROR_EXTENSION_NOT_PRESENT;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001529 }
1530
1531 // Next, if so, proceed with the implementation of this function:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001532 struct loader_icd *icd = phys_dev->this_icd;
1533
Jon Ashburncc407a22016-04-15 09:25:03 -06001534 assert(icd->CreateDisplayModeKHR &&
1535 "loader: null CreateDisplayModeKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001536
Jon Ashburncc407a22016-04-15 09:25:03 -06001537 return icd->CreateDisplayModeKHR(phys_dev->phys_dev, display, pCreateInfo,
1538 pAllocator, pMode);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001539}
1540
Mark Young16573c72016-06-28 10:52:43 -06001541LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(
1542 VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex,
1543 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001544 VkPhysicalDevice unwrapped_phys_dev =
1545 loader_unwrap_physical_device(physicalDevice);
1546 const VkLayerInstanceDispatchTable *disp;
1547 disp = loader_get_instance_dispatch(physicalDevice);
1548 VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(
1549 unwrapped_phys_dev, mode, planeIndex, pCapabilities);
1550 return res;
1551}
1552
Jon Ashburncc407a22016-04-15 09:25:03 -06001553VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDisplayPlaneCapabilitiesKHR(
1554 VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex,
1555 VkDisplayPlaneCapabilitiesKHR *pCapabilities) {
Ian Elliott2b8965a2016-03-24 13:59:22 -06001556 // First, check to ensure the appropriate extension was enabled:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001557 struct loader_physical_device *phys_dev =
1558 (struct loader_physical_device *)physicalDevice;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001559 struct loader_instance *ptr_instance =
1560 (struct loader_instance *)phys_dev->this_icd->this_instance;
1561 if (!ptr_instance->wsi_display_enabled) {
Ian Elliott31f72842016-03-24 15:49:02 -06001562 loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1563 "VK_KHR_display extension not enabled. "
1564 "vkGetDisplayPlaneCapabilitiesKHR not executed!\n");
Ian Elliott2b8965a2016-03-24 13:59:22 -06001565 return VK_SUCCESS;
1566 }
1567
1568 // Next, if so, proceed with the implementation of this function:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001569 struct loader_icd *icd = phys_dev->this_icd;
1570
Jon Ashburncc407a22016-04-15 09:25:03 -06001571 assert(icd->GetDisplayPlaneCapabilitiesKHR &&
1572 "loader: null GetDisplayPlaneCapabilitiesKHR ICD pointer");
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001573
Jon Ashburncc407a22016-04-15 09:25:03 -06001574 return icd->GetDisplayPlaneCapabilitiesKHR(phys_dev->phys_dev, mode,
1575 planeIndex, pCapabilities);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001576}
1577
Mark Young0ad83132016-06-30 13:02:42 -06001578LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(
1579 VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1580 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001581 const VkLayerInstanceDispatchTable *disp;
1582 disp = loader_get_instance_dispatch(instance);
1583 VkResult res;
1584
1585 res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator,
1586 pSurface);
1587 return res;
1588}
1589
Jon Ashburncc407a22016-04-15 09:25:03 -06001590VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayPlaneSurfaceKHR(
1591 VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
1592 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001593 struct loader_instance *inst = loader_get_instance(instance);
Mark Young16573c72016-06-28 10:52:43 -06001594 VkIcdSurface *pIcdSurface = NULL;
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001595
Petros Bantolas25d27fe2016-04-14 12:50:42 +01001596 if (!inst->wsi_surface_enabled) {
1597 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
1598 "VK_KHR_surface extension not enabled. "
1599 "vkCreateDisplayPlaneSurfaceKHR not executed!\n");
Jeremy Hayes9f1d0b62016-06-14 11:50:02 -06001600 return VK_ERROR_EXTENSION_NOT_PRESENT;
Petros Bantolas25d27fe2016-04-14 12:50:42 +01001601 }
1602
Mark Young16573c72016-06-28 10:52:43 -06001603 pIcdSurface = loader_instance_heap_alloc(inst, sizeof(VkIcdSurface),
1604 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001605 if (pIcdSurface == NULL) {
1606 return VK_ERROR_OUT_OF_HOST_MEMORY;
1607 }
1608
Mark Young16573c72016-06-28 10:52:43 -06001609 pIcdSurface->display_surf.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
1610 pIcdSurface->display_surf.displayMode = pCreateInfo->displayMode;
1611 pIcdSurface->display_surf.planeIndex = pCreateInfo->planeIndex;
1612 pIcdSurface->display_surf.planeStackIndex = pCreateInfo->planeStackIndex;
1613 pIcdSurface->display_surf.transform = pCreateInfo->transform;
1614 pIcdSurface->display_surf.globalAlpha = pCreateInfo->globalAlpha;
1615 pIcdSurface->display_surf.alphaMode = pCreateInfo->alphaMode;
1616 pIcdSurface->display_surf.imageExtent = pCreateInfo->imageExtent;
1617
1618 // Setup the new sizes and offsets so we can grow the structures in the
1619 // future withouth having problems
1620 pIcdSurface->real_icd_surfaces = NULL;
1621 pIcdSurface->base_size = sizeof(pIcdSurface->display_surf.base);
1622 pIcdSurface->platform_size = sizeof(pIcdSurface->display_surf);
1623 pIcdSurface->non_platform_offset = (uint32_t)(
1624 (uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
1625 pIcdSurface->entire_size = sizeof(VkIcdSurface);
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001626
1627 *pSurface = (VkSurfaceKHR)pIcdSurface;
1628
1629 return VK_SUCCESS;
1630}
1631
Mark Young1a867442016-07-01 15:18:27 -06001632// This is the trampoline entrypoint
1633// for CreateSharedSwapchainsKHR
1634LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(
1635 VkDevice device, uint32_t swapchainCount,
1636 const VkSwapchainCreateInfoKHR *pCreateInfos,
1637 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchains) {
Mark Young5210abc2016-09-08 18:36:32 -06001638 const VkLayerDispatchTable *disp;
1639 disp = loader_get_dispatch(device);
1640 return disp->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
Mark Young1a867442016-07-01 15:18:27 -06001641}
1642
Ian Elliott954fa342015-10-30 15:28:23 -06001643bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance,
Jon Ashburn23d36b12016-02-02 17:47:28 -07001644 const char *name, void **addr) {
Ian Elliott954fa342015-10-30 15:28:23 -06001645 *addr = NULL;
1646
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001647 // Functions for the VK_KHR_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -07001648 if (!strcmp("vkDestroySurfaceKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001649 *addr = ptr_instance->wsi_surface_enabled ? (void *)vkDestroySurfaceKHR
1650 : NULL;
Ian Elliott2c05e222015-11-19 13:14:05 -07001651 return true;
1652 }
Ian Elliott954fa342015-10-30 15:28:23 -06001653 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001654 *addr = ptr_instance->wsi_surface_enabled
1655 ? (void *)vkGetPhysicalDeviceSurfaceSupportKHR
1656 : NULL;
Ian Elliott954fa342015-10-30 15:28:23 -06001657 return true;
1658 }
Ian Elliott486c5502015-11-19 16:05:09 -07001659 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001660 *addr = ptr_instance->wsi_surface_enabled
1661 ? (void *)vkGetPhysicalDeviceSurfaceCapabilitiesKHR
1662 : NULL;
Ian Elliott486c5502015-11-19 16:05:09 -07001663 return true;
1664 }
1665 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001666 *addr = ptr_instance->wsi_surface_enabled
1667 ? (void *)vkGetPhysicalDeviceSurfaceFormatsKHR
1668 : NULL;
Ian Elliott486c5502015-11-19 16:05:09 -07001669 return true;
1670 }
1671 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001672 *addr = ptr_instance->wsi_surface_enabled
1673 ? (void *)vkGetPhysicalDeviceSurfacePresentModesKHR
1674 : NULL;
Ian Elliott486c5502015-11-19 16:05:09 -07001675 return true;
1676 }
Ian Elliott934d0d52015-11-19 16:39:21 -07001677
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001678 // Functions for the VK_KHR_swapchain extension:
1679
1680 // Note: This is a device extension, and its functions are statically
1681 // exported from the loader. Per Khronos decisions, the loader's GIPA
1682 // function will return the trampoline function for such device-extension
1683 // functions, regardless of whether the extension has been enabled.
Ian Elliott934d0d52015-11-19 16:39:21 -07001684 if (!strcmp("vkCreateSwapchainKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001685 *addr = (void *)vkCreateSwapchainKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001686 return true;
1687 }
1688 if (!strcmp("vkDestroySwapchainKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001689 *addr = (void *)vkDestroySwapchainKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001690 return true;
1691 }
1692 if (!strcmp("vkGetSwapchainImagesKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001693 *addr = (void *)vkGetSwapchainImagesKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001694 return true;
1695 }
1696 if (!strcmp("vkAcquireNextImageKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001697 *addr = (void *)vkAcquireNextImageKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001698 return true;
1699 }
1700 if (!strcmp("vkQueuePresentKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001701 *addr = (void *)vkQueuePresentKHR;
Ian Elliott934d0d52015-11-19 16:39:21 -07001702 return true;
1703 }
1704
Ian Elliott2c05e222015-11-19 13:14:05 -07001705#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001706
1707 // Functions for the VK_KHR_win32_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -07001708 if (!strcmp("vkCreateWin32SurfaceKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001709 *addr = ptr_instance->wsi_win32_surface_enabled
1710 ? (void *)vkCreateWin32SurfaceKHR
1711 : NULL;
Ian Elliott2c05e222015-11-19 13:14:05 -07001712 return true;
1713 }
Ian Elliott919fa302015-11-24 15:39:10 -07001714 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001715 *addr = ptr_instance->wsi_win32_surface_enabled
1716 ? (void *)vkGetPhysicalDeviceWin32PresentationSupportKHR
1717 : NULL;
Ian Elliott919fa302015-11-24 15:39:10 -07001718 return true;
1719 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001720#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -07001721#ifdef VK_USE_PLATFORM_MIR_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001722
1723 // Functions for the VK_KHR_mir_surface extension:
Ian Elliott2c05e222015-11-19 13:14:05 -07001724 if (!strcmp("vkCreateMirSurfaceKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001725 *addr = ptr_instance->wsi_mir_surface_enabled
1726 ? (void *)vkCreateMirSurfaceKHR
1727 : NULL;
Ian Elliott2c05e222015-11-19 13:14:05 -07001728 return true;
1729 }
Ian Elliott919fa302015-11-24 15:39:10 -07001730 if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", name)) {
Jon Ashburn23d36b12016-02-02 17:47:28 -07001731 *addr = ptr_instance->wsi_mir_surface_enabled
1732 ? (void *)vkGetPhysicalDeviceMirPresentationSupportKHR
1733 : NULL;
Ian Elliott919fa302015-11-24 15:39:10 -07001734 return true;
Jason Ekstranda5ebe8a2016-02-12 17:25:03 -08001735 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001736#endif // VK_USE_PLATFORM_MIR_KHR
1737#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001738
1739 // Functions for the VK_KHR_wayland_surface extension:
Jon Ashburn1530c342016-02-26 13:14:27 -07001740 if (!strcmp("vkCreateWaylandSurfaceKHR", name)) {
1741 *addr = ptr_instance->wsi_wayland_surface_enabled
1742 ? (void *)vkCreateWaylandSurfaceKHR
1743 : NULL;
1744 return true;
1745 }
1746 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", name)) {
1747 *addr = ptr_instance->wsi_wayland_surface_enabled
Jon Ashburn23d36b12016-02-02 17:47:28 -07001748 ? (void *)vkGetPhysicalDeviceWaylandPresentationSupportKHR
1749 : NULL;
Jon Ashburn1530c342016-02-26 13:14:27 -07001750 return true;
1751 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001752#endif // VK_USE_PLATFORM_WAYLAND_KHR
1753#ifdef VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001754
1755 // Functions for the VK_KHR_xcb_surface extension:
Jon Ashburn1530c342016-02-26 13:14:27 -07001756 if (!strcmp("vkCreateXcbSurfaceKHR", name)) {
1757 *addr = ptr_instance->wsi_xcb_surface_enabled
1758 ? (void *)vkCreateXcbSurfaceKHR
1759 : NULL;
1760 return true;
1761 }
1762 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", name)) {
1763 *addr = ptr_instance->wsi_xcb_surface_enabled
1764 ? (void *)vkGetPhysicalDeviceXcbPresentationSupportKHR
1765 : NULL;
1766 return true;
1767 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001768#endif // VK_USE_PLATFORM_XCB_KHR
1769#ifdef VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001770
1771 // Functions for the VK_KHR_xlib_surface extension:
Jon Ashburn1530c342016-02-26 13:14:27 -07001772 if (!strcmp("vkCreateXlibSurfaceKHR", name)) {
1773 *addr = ptr_instance->wsi_xlib_surface_enabled
1774 ? (void *)vkCreateXlibSurfaceKHR
1775 : NULL;
1776 return true;
1777 }
1778 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", name)) {
1779 *addr = ptr_instance->wsi_xlib_surface_enabled
1780 ? (void *)vkGetPhysicalDeviceXlibPresentationSupportKHR
1781 : NULL;
1782 return true;
1783 }
Ian Elliott2c05e222015-11-19 13:14:05 -07001784#endif // VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001785#ifdef VK_USE_PLATFORM_ANDROID_KHR
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001786
1787 // Functions for the VK_KHR_android_surface extension:
Jon Ashburn1530c342016-02-26 13:14:27 -07001788 if (!strcmp("vkCreateAndroidSurfaceKHR", name)) {
1789 *addr = ptr_instance->wsi_xlib_surface_enabled
1790 ? (void *)vkCreateAndroidSurfaceKHR
1791 : NULL;
1792 return true;
1793 }
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001794#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c05e222015-11-19 13:14:05 -07001795
Mark Lobodzinski6e45fe72016-08-31 09:31:29 -06001796 // Functions for VK_KHR_display extension:
Jon Ashburnc7d3e732016-03-08 09:30:30 -07001797 if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) {
1798 *addr = ptr_instance->wsi_display_enabled
1799 ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR
1800 : NULL;
1801 return true;
1802 }
1803 if (!strcmp("vkGetPhysicalDeviceDisplayPlanePropertiesKHR", name)) {
1804 *addr = ptr_instance->wsi_display_enabled
1805 ? (void *)vkGetPhysicalDeviceDisplayPlanePropertiesKHR
1806 : NULL;
1807 return true;
1808 }
1809 if (!strcmp("vkGetDisplayPlaneSupportedDisplaysKHR", name)) {
1810 *addr = ptr_instance->wsi_display_enabled
1811 ? (void *)vkGetDisplayPlaneSupportedDisplaysKHR
1812 : NULL;
1813 return true;
1814 }
1815 if (!strcmp("vkGetDisplayModePropertiesKHR", name)) {
1816 *addr = ptr_instance->wsi_display_enabled
1817 ? (void *)vkGetDisplayModePropertiesKHR
1818 : NULL;
1819 return true;
1820 }
1821 if (!strcmp("vkCreateDisplayModeKHR", name)) {
1822 *addr = ptr_instance->wsi_display_enabled
1823 ? (void *)vkCreateDisplayModeKHR
1824 : NULL;
1825 return true;
1826 }
1827 if (!strcmp("vkGetDisplayPlaneCapabilitiesKHR", name)) {
1828 *addr = ptr_instance->wsi_display_enabled
1829 ? (void *)vkGetDisplayPlaneCapabilitiesKHR
1830 : NULL;
1831 return true;
1832 }
1833 if (!strcmp("vkCreateDisplayPlaneSurfaceKHR", name)) {
1834 *addr = ptr_instance->wsi_display_enabled
1835 ? (void *)vkCreateDisplayPlaneSurfaceKHR
1836 : NULL;
1837 return true;
1838 }
Mark Young1a867442016-07-01 15:18:27 -06001839
1840 // Functions for KHR_display_swapchain extension:
1841 if (!strcmp("vkCreateSharedSwapchainsKHR", name)) {
1842 *addr = (void *)vkCreateSharedSwapchainsKHR;
1843 return true;
1844 }
1845
Jon Ashburn1530c342016-02-26 13:14:27 -07001846 return false;
Ian Elliott2b8965a2016-03-24 13:59:22 -06001847}