blob: 7c19c272d438d9c2688a68c6a925c0dc6a59ac14 [file] [log] [blame]
Ian Elliott0b4d6242015-09-22 10:51:24 -06001/*
Ian Elliott0b4d6242015-09-22 10:51:24 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Ian Elliott0b4d6242015-09-22 10:51:24 -06004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 * Author: Ian Elliott <ian@lunarg.com>
Ian Elliott578e7e22016-01-05 14:03:16 -070024 * Author: Ian Elliott <ianelliott@google.com>
Ian Elliott0b4d6242015-09-22 10:51:24 -060025 */
26
Ian Elliottd8c5db12015-10-07 11:32:31 -060027#include <stdio.h>
28#include <string.h>
Mark Lobodzinskib49b6e52015-11-26 10:59:58 -070029#include <vk_loader_platform.h>
Ian Elliotta983e9a2015-12-22 12:18:12 -070030#include <vk_icd.h>
Ian Elliott0b4d6242015-09-22 10:51:24 -060031#include "swapchain.h"
Tobin Ehlis711ff312015-10-29 12:58:13 -060032#include "vk_layer_extension_utils.h"
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070033#include "vk_enum_string_helper.h"
Ian Elliott68124ac2015-10-07 16:18:35 -060034
Ian Elliott0b4d6242015-09-22 10:51:24 -060035// FIXME/TODO: Make sure this layer is thread-safe!
36
Ian Elliott68124ac2015-10-07 16:18:35 -060037
Ian Elliott0b4d6242015-09-22 10:51:24 -060038// The following is for logging error messages:
Ian Elliott68124ac2015-10-07 16:18:35 -060039static std::unordered_map<void *, layer_data *> layer_data_map;
Ian Elliott0b4d6242015-09-22 10:51:24 -060040
Ian Elliott68124ac2015-10-07 16:18:35 -060041template layer_data *get_my_data_ptr<layer_data>(
42 void *data_key,
43 std::unordered_map<void *, layer_data *> &data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -060044
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -070045static const VkExtensionProperties instance_extensions[] = {
46 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070047 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
48 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -070049 }
50};
51
52VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
53 const char *pLayerName,
54 uint32_t *pCount,
55 VkExtensionProperties* pProperties)
56{
57 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
58}
59
60static const VkLayerProperties swapchain_global_layers[] = {
61 {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070062 "swapchain",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -070063 VK_API_VERSION,
64 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070065 "Validation layer: swapchain",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -070066 }
67};
68
69VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
70 uint32_t *pCount,
71 VkLayerProperties* pProperties)
72{
73 return util_GetLayerProperties(ARRAY_SIZE(swapchain_global_layers),
74 swapchain_global_layers,
75 pCount, pProperties);
76}
77
Ian Elliott0b4d6242015-09-22 10:51:24 -060078static void createDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
79{
80 uint32_t i;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070081 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
82 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -060083
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070084 VkLayerDispatchTable *pDisp = my_device_data->device_dispatch_table;
85 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
86
87 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
88 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
89 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
90 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
91 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
92
93 SwpPhysicalDevice *pPhysicalDevice = &my_instance_data->physicalDeviceMap[physicalDevice];
Ian Elliott0b4d6242015-09-22 10:51:24 -060094 if (pPhysicalDevice) {
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070095 my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice;
96 pPhysicalDevice->pDevice = &my_device_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -060097 } else {
Ian Elliott07adb112016-01-05 12:51:03 -070098 // TBD: Should we leave error in (since Swapchain really needs this
99 // link)?
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700100 log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Mark Lobodzinski80e774f2016-01-04 15:54:59 -0700101 (uint64_t)physicalDevice , __LINE__, SWAPCHAIN_INVALID_HANDLE, "Swapchain",
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700102 "vkCreateDevice() called with a non-valid VkPhysicalDevice.");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600103 }
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700104 my_device_data->deviceMap[device].device = device;
Ian Elliott427058f2015-12-29 16:45:49 -0700105 my_device_data->deviceMap[device].swapchainExtensionEnabled = false;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600106
107 // Record whether the WSI device extension was enabled for this VkDevice.
108 // No need to check if the extension was advertised by
109 // vkEnumerateDeviceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800110 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700111 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600112
Ian Elliott427058f2015-12-29 16:45:49 -0700113 my_device_data->deviceMap[device].swapchainExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600114 }
115 }
116}
117
118static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)
119{
120 uint32_t i;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600121 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
122 VkLayerInstanceDispatchTable *pDisp = my_data->instance_dispatch_table;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600123 PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700124#ifdef VK_USE_PLATFORM_ANDROID_KHR
125 pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR) gpa(instance, "vkCreateAndroidSurfaceKHR");
126#endif // VK_USE_PLATFORM_ANDROID_KHR
127#ifdef VK_USE_PLATFORM_MIR_KHR
128 pDisp->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR) gpa(instance, "vkCreateMirSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700129 pDisp->GetPhysicalDeviceMirPresentationSupportKHR = (PFN_vkGetPhysicalDeviceMirPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700130#endif // VK_USE_PLATFORM_MIR_KHR
131#ifdef VK_USE_PLATFORM_WAYLAND_KHR
132 pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR) gpa(instance, "vkCreateWaylandSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700133 pDisp->GetPhysicalDeviceWaylandPresentationSupportKHR = (PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWaylandPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700134#endif // VK_USE_PLATFORM_WAYLAND_KHR
135#ifdef VK_USE_PLATFORM_WIN32_KHR
136 pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) gpa(instance, "vkCreateWin32SurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700137 pDisp->GetPhysicalDeviceWin32PresentationSupportKHR = (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700138#endif // VK_USE_PLATFORM_WIN32_KHR
139#ifdef VK_USE_PLATFORM_XCB_KHR
140 pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) gpa(instance, "vkCreateXcbSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700141 pDisp->GetPhysicalDeviceXcbPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700142#endif // VK_USE_PLATFORM_XCB_KHR
143#ifdef VK_USE_PLATFORM_XLIB_KHR
144 pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR) gpa(instance, "vkCreateXlibSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700145 pDisp->GetPhysicalDeviceXlibPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700146#endif // VK_USE_PLATFORM_XLIB_KHR
147 pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR) gpa(instance, "vkDestroySurfaceKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600148 pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
Ian Elliott27d39c72015-11-20 16:39:34 -0700149 pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
150 pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
151 pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600152
Ian Elliott1dcd1092015-11-17 17:29:40 -0700153 // Remember this instance, and whether the VK_KHR_surface extension
Ian Elliott0b4d6242015-09-22 10:51:24 -0600154 // was enabled for it:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600155 my_data->instanceMap[instance].instance = instance;
Ian Elliott1cb77a62015-12-29 16:44:39 -0700156 my_data->instanceMap[instance].surfaceExtensionEnabled = false;
Ian Elliott8dffaf32016-01-04 14:10:30 -0700157#ifdef VK_USE_PLATFORM_ANDROID_KHR
158 my_data->instanceMap[instance].androidSurfaceExtensionEnabled = false;
159#endif // VK_USE_PLATFORM_ANDROID_KHR
160#ifdef VK_USE_PLATFORM_MIR_KHR
161 my_data->instanceMap[instance].mirSurfaceExtensionEnabled = false;
162#endif // VK_USE_PLATFORM_MIR_KHR
163#ifdef VK_USE_PLATFORM_WAYLAND_KHR
164 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = false;
165#endif // VK_USE_PLATFORM_WAYLAND_KHR
166#ifdef VK_USE_PLATFORM_WIN32_KHR
167 my_data->instanceMap[instance].win32SurfaceExtensionEnabled = false;
168#endif // VK_USE_PLATFORM_WIN32_KHR
169#ifdef VK_USE_PLATFORM_XCB_KHR
170 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = false;
171#endif // VK_USE_PLATFORM_XCB_KHR
172#ifdef VK_USE_PLATFORM_XLIB_KHR
173 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = false;
174#endif // VK_USE_PLATFORM_XLIB_KHR
175
Ian Elliott0b4d6242015-09-22 10:51:24 -0600176
177 // Record whether the WSI instance extension was enabled for this
178 // VkInstance. No need to check if the extension was advertised by
179 // vkEnumerateInstanceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800180 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700181 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600182
Ian Elliott1cb77a62015-12-29 16:44:39 -0700183 my_data->instanceMap[instance].surfaceExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600184 }
Ian Elliott8dffaf32016-01-04 14:10:30 -0700185#ifdef VK_USE_PLATFORM_ANDROID_KHR
186 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
187
188 my_data->instanceMap[instance].androidSurfaceExtensionEnabled = true;
189#endif // VK_USE_PLATFORM_ANDROID_KHR
190#ifdef VK_USE_PLATFORM_MIR_KHR
191 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
192
193 my_data->instanceMap[instance].mirSurfaceExtensionEnabled = true;
194#endif // VK_USE_PLATFORM_MIR_KHR
195#ifdef VK_USE_PLATFORM_WAYLAND_KHR
196 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
197
198 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = true;
199#endif // VK_USE_PLATFORM_WAYLAND_KHR
200#ifdef VK_USE_PLATFORM_WIN32_KHR
201 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
202
203 my_data->instanceMap[instance].win32SurfaceExtensionEnabled = true;
204#endif // VK_USE_PLATFORM_WIN32_KHR
205#ifdef VK_USE_PLATFORM_XCB_KHR
206 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
207
208 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = true;
209#endif // VK_USE_PLATFORM_XCB_KHR
210#ifdef VK_USE_PLATFORM_XLIB_KHR
211 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
212
213 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = true;
214#endif // VK_USE_PLATFORM_XLIB_KHR
215 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600216 }
217}
218
219
220#include "vk_dispatch_table_helper.h"
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700221static void initSwapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600222{
223 uint32_t report_flags = 0;
224 uint32_t debug_action = 0;
225 FILE *log_output = NULL;
226 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700227 VkDebugReportCallbackEXT callback;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600228
229 // Initialize Swapchain options:
230 report_flags = getLayerOptionFlags("SwapchainReportFlags", 0);
231 getLayerOptionEnum("SwapchainDebugAction", (uint32_t *) &debug_action);
232
233 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
234 {
235 // Turn on logging, since it was requested:
236 option_str = getLayerOption("SwapchainLogFilename");
237 log_output = getLayerLogOutput(option_str, "Swapchain");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700238 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700239 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700240 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700241 dbgInfo.pfnCallback = log_callback;
242 dbgInfo.pUserData = log_output;
243 dbgInfo.flags = report_flags;
244 layer_create_msg_callback(my_data->report_data,
245 &dbgInfo,
246 pAllocator,
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600247 &callback);
248 my_data->logging_callback.push_back(callback);
249 }
250 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700251 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700252 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700253 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700254 dbgInfo.pfnCallback = win32_debug_output_msg;
255 dbgInfo.pUserData = log_output;
256 dbgInfo.flags = report_flags;
257 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600258 my_data->logging_callback.push_back(callback);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600259 }
260}
261
Ian Elliott27d39c72015-11-20 16:39:34 -0700262static const char *surfaceTransformStr(VkSurfaceTransformFlagBitsKHR value)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600263{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600264 // Return a string corresponding to the value:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700265 return string_VkSurfaceTransformFlagBitsKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600266}
267
Ian Elliotta2a89c52015-12-28 15:23:57 -0700268static const char *surfaceCompositeAlphaStr(VkCompositeAlphaFlagBitsKHR value)
269{
270 // Return a string corresponding to the value:
271 return string_VkCompositeAlphaFlagBitsKHR(value);
272}
273
Ian Elliott0b4d6242015-09-22 10:51:24 -0600274static const char *presentModeStr(VkPresentModeKHR value)
275{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600276 // Return a string corresponding to the value:
Ian Elliott24491af2015-12-28 15:04:49 -0700277 return string_VkPresentModeKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600278}
279
Ian Elliotta2a89c52015-12-28 15:23:57 -0700280static const char *sharingModeStr(VkSharingMode value)
281{
282 // Return a string corresponding to the value:
283 return string_VkSharingMode(value);
284}
285
Ian Elliott0b4d6242015-09-22 10:51:24 -0600286
Chia-I Wu9ab61502015-11-06 06:42:02 +0800287VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600288{
Tobin Ehlis711ff312015-10-29 12:58:13 -0600289 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600290 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600291 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800292 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600293 if (result == VK_SUCCESS) {
294 // Since it succeeded, do layer-specific work:
Ian Elliott68124ac2015-10-07 16:18:35 -0600295 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
296 my_data->report_data = debug_report_create_instance(
Tobin Ehlis711ff312015-10-29 12:58:13 -0600297 pTable,
Ian Elliott68124ac2015-10-07 16:18:35 -0600298 *pInstance,
Chia-I Wud50a7d72015-10-26 20:48:51 +0800299 pCreateInfo->enabledExtensionNameCount,
Ian Elliott68124ac2015-10-07 16:18:35 -0600300 pCreateInfo->ppEnabledExtensionNames);
301 // Call the following function after my_data is initialized:
Ian Elliott0b4d6242015-09-22 10:51:24 -0600302 createInstanceRegisterExtensions(pCreateInfo, *pInstance);
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700303 initSwapchain(my_data, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600304 }
305 return result;
306}
307
Chia-I Wu9ab61502015-11-06 06:42:02 +0800308VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600309{
310 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600311 dispatch_key key = get_dispatch_key(instance);
312 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600313 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600314
315 if (VK_FALSE == skipCall) {
316 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800317 my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator);
Ian Elliott68124ac2015-10-07 16:18:35 -0600318
319 // Clean up logging callback, if any
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600320 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700321 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700322 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600323 my_data->logging_callback.pop_back();
Ian Elliott68124ac2015-10-07 16:18:35 -0600324 }
325 layer_debug_report_destroy_instance(my_data->report_data);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600326 }
327
328 // Regardless of skipCall value, do some internal cleanup:
329 if (pInstance) {
330 // Delete all of the SwpPhysicalDevice's and the SwpInstance associated
331 // with this instance:
332 for (auto it = pInstance->physicalDevices.begin() ;
333 it != pInstance->physicalDevices.end() ; it++) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700334
335 // Free memory that was allocated for/by this SwpPhysicalDevice:
336 SwpPhysicalDevice *pPhysicalDevice = it->second;
Ian Elliott07adb112016-01-05 12:51:03 -0700337 if (pPhysicalDevice) {
338 free(pPhysicalDevice->pSurfaceFormats);
339 free(pPhysicalDevice->pPresentModes);
340 }
Ian Elliott27d39c72015-11-20 16:39:34 -0700341
Tobin Ehlis711ff312015-10-29 12:58:13 -0600342 // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which
Ian Elliott0b4d6242015-09-22 10:51:24 -0600343 // are simply pointed to by the SwpInstance):
Tobin Ehlis711ff312015-10-29 12:58:13 -0600344 my_data->physicalDeviceMap.erase(it->second->physicalDevice);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600345 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600346 my_data->instanceMap.erase(instance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600347 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600348 delete my_data->instance_dispatch_table;
349 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600350}
351
Ian Elliotta983e9a2015-12-22 12:18:12 -0700352#ifdef VK_USE_PLATFORM_ANDROID_KHR
353VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
354 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700355 const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700356 const VkAllocationCallbacks* pAllocator,
357 VkSurfaceKHR* pSurface)
358{
359 VkResult result = VK_SUCCESS;
360 VkBool32 skipCall = VK_FALSE;
361 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
362
Ian Elliottf5758292015-12-30 17:39:02 -0700363 if (!pCreateInfo) {
364 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
365 device,
366 "pCreateInfo");
367 } else {
368 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR) {
369 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
370 device,
371 "pCreateInfo",
372 "VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR");
373 }
374 if (pCreateInfo->pNext != NULL) {
375 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
376 device,
377 "pCreateInfo");
378 }
379 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700380
381 if (VK_FALSE == skipCall) {
382 // Call down the call chain:
383 result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700384 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700385 return result;
386 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700387 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700388}
389#endif // VK_USE_PLATFORM_ANDROID_KHR
390
391#ifdef VK_USE_PLATFORM_MIR_KHR
392VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(
393 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700394 const VkMirSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700395 const VkAllocationCallbacks* pAllocator,
396 VkSurfaceKHR* pSurface)
397{
398 VkResult result = VK_SUCCESS;
399 VkBool32 skipCall = VK_FALSE;
400 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
401
Ian Elliottf5758292015-12-30 17:39:02 -0700402 if (!pCreateInfo) {
403 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
404 device,
405 "pCreateInfo");
406 } else {
407 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR) {
408 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
409 device,
410 "pCreateInfo",
411 "VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR");
412 }
413 if (pCreateInfo->pNext != NULL) {
414 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
415 device,
416 "pCreateInfo");
417 }
418 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700419
420 if (VK_FALSE == skipCall) {
421 // Call down the call chain:
422 result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700423 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700424 return result;
425 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700426 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700427}
Ian Elliott55ff7962015-12-30 10:18:47 -0700428
429VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceMirPresentationSupportKHR(
430 VkPhysicalDevice physicalDevice,
431 uint32_t queueFamilyIndex,
432 MirConnection* connection)
433{
434 VkBool32 result = VK_FALSE;
435 VkBool32 skipCall = VK_FALSE;
436 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700437 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700438
439 // Validate that the platform extension was enabled:
440 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
441 !pPhysicalDevice->pInstance->mirSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700442 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
443 pPhysicalDevice->pInstance,
444 "VkInstance",
445 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
446 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700447 __FUNCTION__, VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700448 }
449
450 if (VK_FALSE == skipCall) {
451 // Call down the call chain:
452 result = my_data->instance_dispatch_table->GetPhysicalDeviceMirPresentationSupportKHR(
453 physicalDevice, queueFamilyIndex, connection);
454
455 if (pPhysicalDevice) {
456 // Record the result of this query:
457 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
458 }
459 }
460 return result;
461}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700462#endif // VK_USE_PLATFORM_MIR_KHR
463
464#ifdef VK_USE_PLATFORM_WAYLAND_KHR
465VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
466 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700467 const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700468 const VkAllocationCallbacks* pAllocator,
469 VkSurfaceKHR* pSurface)
470{
471 VkResult result = VK_SUCCESS;
472 VkBool32 skipCall = VK_FALSE;
473 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
474
Ian Elliottf5758292015-12-30 17:39:02 -0700475 if (!pCreateInfo) {
476 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
477 device,
478 "pCreateInfo");
479 } else {
480 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR) {
481 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
482 device,
483 "pCreateInfo",
484 "VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR");
485 }
486 if (pCreateInfo->pNext != NULL) {
487 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
488 device,
489 "pCreateInfo");
490 }
491 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700492
493 if (VK_FALSE == skipCall) {
494 // Call down the call chain:
495 result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700496 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700497 return result;
498 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700499 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700500}
Ian Elliott55ff7962015-12-30 10:18:47 -0700501
502VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(
503 VkPhysicalDevice physicalDevice,
504 uint32_t queueFamilyIndex,
505 struct wl_display* display)
506{
507 VkBool32 result = VK_FALSE;
508 VkBool32 skipCall = VK_FALSE;
509 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700510 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700511
512 // Validate that the platform extension was enabled:
513 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
514 !pPhysicalDevice->pInstance->waylandSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700515 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
516 pPhysicalDevice->pInstance,
517 "VkInstance",
518 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
519 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700520 __FUNCTION__, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700521 }
522
523 if (VK_FALSE == skipCall) {
524 // Call down the call chain:
525 result = my_data->instance_dispatch_table->GetPhysicalDeviceWaylandPresentationSupportKHR(
526 physicalDevice, queueFamilyIndex, display);
527
528 if (pPhysicalDevice) {
529 // Record the result of this query:
530 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
531 }
532 }
533 return result;
534}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700535#endif // VK_USE_PLATFORM_WAYLAND_KHR
536
537#ifdef VK_USE_PLATFORM_WIN32_KHR
538VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
539 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700540 const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700541 const VkAllocationCallbacks* pAllocator,
542 VkSurfaceKHR* pSurface)
543{
544 VkResult result = VK_SUCCESS;
545 VkBool32 skipCall = VK_FALSE;
546 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
547
Ian Elliottf5758292015-12-30 17:39:02 -0700548 if (!pCreateInfo) {
549 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
550 device,
551 "pCreateInfo");
552 } else {
553 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR) {
554 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
555 device,
556 "pCreateInfo",
557 "VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR");
558 }
559 if (pCreateInfo->pNext != NULL) {
560 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
561 device,
562 "pCreateInfo");
563 }
564 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700565
566 if (VK_FALSE == skipCall) {
567 // Call down the call chain:
568 result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700569 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700570 return result;
571 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700572 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700573}
Ian Elliott55ff7962015-12-30 10:18:47 -0700574
575VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(
576 VkPhysicalDevice physicalDevice,
577 uint32_t queueFamilyIndex)
578{
579 VkBool32 result = VK_FALSE;
580 VkBool32 skipCall = VK_FALSE;
581 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700582 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700583
584 // Validate that the platform extension was enabled:
585 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
586 !pPhysicalDevice->pInstance->win32SurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700587 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
588 pPhysicalDevice->pInstance,
589 "VkInstance",
590 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
591 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700592 __FUNCTION__, VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700593 }
594
595 if (VK_FALSE == skipCall) {
596 // Call down the call chain:
597 result = my_data->instance_dispatch_table->GetPhysicalDeviceWin32PresentationSupportKHR(
598 physicalDevice, queueFamilyIndex);
599
600 if (pPhysicalDevice) {
601 // Record the result of this query:
602 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
603 }
604 }
605 return result;
606}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700607#endif // VK_USE_PLATFORM_WIN32_KHR
608
609#ifdef VK_USE_PLATFORM_XCB_KHR
610VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
611 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700612 const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700613 const VkAllocationCallbacks* pAllocator,
614 VkSurfaceKHR* pSurface)
615{
616 VkResult result = VK_SUCCESS;
617 VkBool32 skipCall = VK_FALSE;
618 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
619
Ian Elliottf5758292015-12-30 17:39:02 -0700620 if (!pCreateInfo) {
621 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
622 device,
623 "pCreateInfo");
624 } else {
625 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR) {
626 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
627 device,
628 "pCreateInfo",
629 "VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR");
630 }
631 if (pCreateInfo->pNext != NULL) {
632 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
633 device,
634 "pCreateInfo");
635 }
636 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700637
638 if (VK_FALSE == skipCall) {
639 // Call down the call chain:
640 result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700641 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700642 return result;
643 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700644 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700645}
Ian Elliott55ff7962015-12-30 10:18:47 -0700646
647VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(
648 VkPhysicalDevice physicalDevice,
649 uint32_t queueFamilyIndex,
650 xcb_connection_t* connection,
651 xcb_visualid_t visual_id)
652{
653 VkBool32 result = VK_FALSE;
654 VkBool32 skipCall = VK_FALSE;
655 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700656 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700657
658 // Validate that the platform extension was enabled:
659 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
660 !pPhysicalDevice->pInstance->xcbSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700661 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
662 pPhysicalDevice->pInstance,
663 "VkInstance",
664 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
665 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700666 __FUNCTION__, VK_KHR_XCB_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700667 }
668
669 if (VK_FALSE == skipCall) {
670 // Call down the call chain:
671 result = my_data->instance_dispatch_table->GetPhysicalDeviceXcbPresentationSupportKHR(
672 physicalDevice, queueFamilyIndex, connection, visual_id);
673
674 if (pPhysicalDevice) {
675 // Record the result of this query:
676 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
677 }
678 }
679 return result;
680}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700681#endif // VK_USE_PLATFORM_XCB_KHR
682
683#ifdef VK_USE_PLATFORM_XLIB_KHR
684VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
685 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700686 const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700687 const VkAllocationCallbacks* pAllocator,
688 VkSurfaceKHR* pSurface)
689{
690 VkResult result = VK_SUCCESS;
691 VkBool32 skipCall = VK_FALSE;
692 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
693
Ian Elliottf5758292015-12-30 17:39:02 -0700694 if (!pCreateInfo) {
695 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
696 device,
697 "pCreateInfo");
698 } else {
699 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR) {
700 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
701 device,
702 "pCreateInfo",
703 "VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR");
704 }
705 if (pCreateInfo->pNext != NULL) {
706 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
707 device,
708 "pCreateInfo");
709 }
710 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700711
712 if (VK_FALSE == skipCall) {
713 // Call down the call chain:
714 result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700715 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700716 return result;
717 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700718 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700719}
Ian Elliott55ff7962015-12-30 10:18:47 -0700720
721VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(
722 VkPhysicalDevice physicalDevice,
723 uint32_t queueFamilyIndex,
724 Display* dpy,
725 VisualID visualID)
726{
727 VkBool32 result = VK_FALSE;
728 VkBool32 skipCall = VK_FALSE;
729 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700730 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700731
732 // Validate that the platform extension was enabled:
733 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
734 !pPhysicalDevice->pInstance->xlibSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700735 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
736 pPhysicalDevice->pInstance,
737 "VkInstance",
738 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
739 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700740 __FUNCTION__, VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700741 }
742
743 if (VK_FALSE == skipCall) {
744 // Call down the call chain:
745 result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR(
746 physicalDevice, queueFamilyIndex, dpy, visualID);
747
748 if (pPhysicalDevice) {
749 // Record the result of this query:
750 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
751 }
752 }
753 return result;
754}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700755#endif // VK_USE_PLATFORM_XLIB_KHR
756
757VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator)
758{
759 VkBool32 skipCall = VK_FALSE;
760 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
761
Ian Elliotta983e9a2015-12-22 12:18:12 -0700762 if (VK_FALSE == skipCall) {
Ian Elliotta983e9a2015-12-22 12:18:12 -0700763 // Call down the call chain:
764 my_data->instance_dispatch_table->DestroySurfaceKHR(
765 instance, surface, pAllocator);
766 }
767
Ian Elliott6b9941a2016-01-05 12:03:06 -0700768 // No need to do any cleanup--rely on object_tracker to track VkSurfaceKHR
Ian Elliotta983e9a2015-12-22 12:18:12 -0700769}
770
Chia-I Wu9ab61502015-11-06 06:42:02 +0800771VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600772{
773 VkResult result = VK_SUCCESS;
774 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600775 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600776 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600777
778 if (VK_FALSE == skipCall) {
779 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600780 result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(
Ian Elliott0b4d6242015-09-22 10:51:24 -0600781 instance, pPhysicalDeviceCount, pPhysicalDevices);
782
783 if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices &&
784 (*pPhysicalDeviceCount > 0)) {
785 // Record the VkPhysicalDevices returned by the ICD:
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600786 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis711ff312015-10-29 12:58:13 -0600787 my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice =
Ian Elliott0b4d6242015-09-22 10:51:24 -0600788 pPhysicalDevices[i];
Tobin Ehlis711ff312015-10-29 12:58:13 -0600789 my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance;
790 my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL;
Ian Elliott27d39c72015-11-20 16:39:34 -0700791 my_data->physicalDeviceMap[pPhysicalDevices[i]].gotSurfaceCapabilities = false;
792 my_data->physicalDeviceMap[pPhysicalDevices[i]].surfaceFormatCount = 0;
793 my_data->physicalDeviceMap[pPhysicalDevices[i]].pSurfaceFormats = NULL;
794 my_data->physicalDeviceMap[pPhysicalDevices[i]].presentModeCount = 0;
795 my_data->physicalDeviceMap[pPhysicalDevices[i]].pPresentModes = NULL;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600796 // Point to the associated SwpInstance:
Ian Elliott4f07d082016-01-05 12:18:50 -0700797 if (pInstance) {
798 pInstance->physicalDevices[pPhysicalDevices[i]] =
799 &my_data->physicalDeviceMap[pPhysicalDevices[i]];
800 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600801 }
802 }
803
804 return result;
805 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700806 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600807}
808
Chia-I Wu9ab61502015-11-06 06:42:02 +0800809VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600810{
811 VkResult result = VK_SUCCESS;
812 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600813 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600814
Ian Elliott07adb112016-01-05 12:51:03 -0700815 if (VK_FALSE == skipCall) {
816 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
817 // Call down the call chain:
818 result = my_device_data->device_dispatch_table->CreateDevice(
819 physicalDevice, pCreateInfo, pAllocator, pDevice);
820 if (result == VK_SUCCESS) {
821 // Since it succeeded, do layer-specific work:
822 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
823 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
824 createDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice);
825 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600826 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600827 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600828}
829
Chia-I Wu9ab61502015-11-06 06:42:02 +0800830VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600831{
832 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600833 dispatch_key key = get_dispatch_key(device);
834 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600835 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600836
837 if (VK_FALSE == skipCall) {
838 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800839 my_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600840 }
841
842 // Regardless of skipCall value, do some internal cleanup:
843 if (pDevice) {
844 // Delete the SwpDevice associated with this device:
845 if (pDevice->pPhysicalDevice) {
846 pDevice->pPhysicalDevice->pDevice = NULL;
847 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600848 if (!pDevice->swapchains.empty()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700849 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600850 SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600851 "%s() called before all of its associated "
852 "VkSwapchainKHRs were destroyed.",
853 __FUNCTION__);
854 // Empty and then delete all SwpSwapchain's
855 for (auto it = pDevice->swapchains.begin() ;
856 it != pDevice->swapchains.end() ; it++) {
857 // Delete all SwpImage's
858 it->second->images.clear();
859 }
860 pDevice->swapchains.clear();
861 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600862 my_data->deviceMap.erase(device);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600863 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600864 delete my_data->device_dispatch_table;
865 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600866}
867
Ian Elliott27d39c72015-11-20 16:39:34 -0700868VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
869 VkPhysicalDevice physicalDevice,
870 uint32_t queueFamilyIndex,
871 VkSurfaceKHR surface,
872 VkBool32* pSupported)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600873{
Ian Elliott320d0fc2015-12-30 12:04:43 -0700874// TODOs:
875//
876// - Ensure that queueFamilyIndex is a valid queue family index for
877// physicalDevice. How? Probably need to record data from another function
878// call(s).
Ian Elliott0b4d6242015-09-22 10:51:24 -0600879 VkResult result = VK_SUCCESS;
880 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600881 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600882 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700883
884 // Validate that the surface extension was enabled:
885 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
886 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700887 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600888 pPhysicalDevice->pInstance,
889 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600890 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -0800891 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott1dcd1092015-11-17 17:29:40 -0700892 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600893 }
Ian Elliottf955d682015-12-30 12:00:54 -0700894 if (!pSupported) {
895 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
896 physicalDevice,
897 "pSupported");
898 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600899
900 if (VK_FALSE == skipCall) {
901 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600902 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -0700903 physicalDevice, queueFamilyIndex, surface,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600904 pSupported);
905
906 if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) {
907 // Record the result of this query:
908 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] =
909 *pSupported;
910 // TODO: We need to compare this with the actual queue used for
911 // presentation, to ensure it was advertised to the application as
912 // supported for presentation.
913 }
914
915 return result;
916 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700917 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600918}
919
Ian Elliott27d39c72015-11-20 16:39:34 -0700920VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
921 VkPhysicalDevice physicalDevice,
922 VkSurfaceKHR surface,
923 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600924{
925 VkResult result = VK_SUCCESS;
926 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700927 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -0700928 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700929
930 // Validate that the surface extension was enabled:
931 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
932 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700933 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700934 pPhysicalDevice->pInstance,
935 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600936 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700937 "%s() called even though the %s extension was not enabled for this VkInstance.",
938 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600939 }
Ian Elliottf955d682015-12-30 12:00:54 -0700940 if (!pSurfaceCapabilities) {
941 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
942 physicalDevice,
943 "pSurfaceCapabilities");
944 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600945
946 if (VK_FALSE == skipCall) {
947 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700948 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceCapabilitiesKHR(
949 physicalDevice, surface, pSurfaceCapabilities);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600950
Ian Elliott27d39c72015-11-20 16:39:34 -0700951 if ((result == VK_SUCCESS) && pPhysicalDevice) {
Ian Elliottf955d682015-12-30 12:00:54 -0700952 // Record the result of this query:
Ian Elliott27d39c72015-11-20 16:39:34 -0700953 pPhysicalDevice->gotSurfaceCapabilities = true;
954// FIXME: NEED TO COPY THIS DATA, BECAUSE pSurfaceCapabilities POINTS TO APP-ALLOCATED DATA
955 pPhysicalDevice->surfaceCapabilities = *pSurfaceCapabilities;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600956 }
957
958 return result;
959 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700960 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600961}
962
Ian Elliott27d39c72015-11-20 16:39:34 -0700963VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
964 VkPhysicalDevice physicalDevice,
965 VkSurfaceKHR surface,
Ian Elliottf955d682015-12-30 12:00:54 -0700966 uint32_t* pSurfaceFormatCount,
Ian Elliott27d39c72015-11-20 16:39:34 -0700967 VkSurfaceFormatKHR* pSurfaceFormats)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600968{
969 VkResult result = VK_SUCCESS;
970 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700971 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -0700972 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700973
974 // Validate that the surface extension was enabled:
975 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
976 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700977 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700978 pPhysicalDevice->pInstance,
979 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600980 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700981 "%s() called even though the %s extension was not enabled for this VkInstance.",
982 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600983 }
Ian Elliottf955d682015-12-30 12:00:54 -0700984 if (!pSurfaceFormatCount) {
985 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
986 physicalDevice,
987 "pSurfaceFormatCount");
988 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600989
990 if (VK_FALSE == skipCall) {
991 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700992 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceFormatsKHR(
Ian Elliottf955d682015-12-30 12:00:54 -0700993 physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600994
Ian Elliottf955d682015-12-30 12:00:54 -0700995 if ((result == VK_SUCCESS) && pPhysicalDevice && !pSurfaceFormats &&
996 pSurfaceFormatCount) {
997 // Record the result of this preliminary query:
998 pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount;
999 }
Ian Elliott9059b302015-12-30 13:14:36 -07001000 else if ((result == VK_SUCCESS) && pPhysicalDevice && pSurfaceFormats &&
1001 pSurfaceFormatCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001002 // Compare the preliminary value of *pSurfaceFormatCount with the
1003 // value this time:
1004 if (*pSurfaceFormatCount != pPhysicalDevice->surfaceFormatCount) {
1005 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1006 physicalDevice,
1007 "pSurfaceFormatCount",
1008 "pSurfaceFormats",
1009 pPhysicalDevice->surfaceFormatCount);
1010 }
Ian Elliott9059b302015-12-30 13:14:36 -07001011 else if (*pSurfaceFormatCount > 0) {
1012 // Record the result of this query:
1013 pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount;
1014 pPhysicalDevice->pSurfaceFormats = (VkSurfaceFormatKHR *)
1015 malloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR));
1016 if (pPhysicalDevice->pSurfaceFormats) {
1017 for (uint32_t i = 0 ; i < *pSurfaceFormatCount ; i++) {
1018 pPhysicalDevice->pSurfaceFormats[i] = pSurfaceFormats[i];
1019 }
1020 } else {
1021 pPhysicalDevice->surfaceFormatCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001022 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001023 }
1024 }
1025
1026 return result;
1027 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001028 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001029}
1030
Ian Elliott27d39c72015-11-20 16:39:34 -07001031VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
1032 VkPhysicalDevice physicalDevice,
1033 VkSurfaceKHR surface,
Ian Elliottf955d682015-12-30 12:00:54 -07001034 uint32_t* pPresentModeCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001035 VkPresentModeKHR* pPresentModes)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001036{
1037 VkResult result = VK_SUCCESS;
1038 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -07001039 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -07001040 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -07001041
1042 // Validate that the surface extension was enabled:
1043 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
1044 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001045 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001046 pPhysicalDevice->pInstance,
1047 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001048 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -07001049 "%s() called even though the %s extension was not enabled for this VkInstance.",
1050 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001051 }
Ian Elliottf955d682015-12-30 12:00:54 -07001052 if (!pPresentModeCount) {
1053 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1054 physicalDevice,
1055 "pPresentModeCount");
1056 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001057
1058 if (VK_FALSE == skipCall) {
1059 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001060 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfacePresentModesKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001061 physicalDevice, surface, pPresentModeCount, pPresentModes);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001062
Ian Elliottf955d682015-12-30 12:00:54 -07001063 if ((result == VK_SUCCESS) && pPhysicalDevice && !pPresentModes &&
1064 pPresentModeCount) {
1065 // Record the result of this preliminary query:
1066 pPhysicalDevice->presentModeCount = *pPresentModeCount;
1067 }
Ian Elliott9059b302015-12-30 13:14:36 -07001068 else if ((result == VK_SUCCESS) && pPhysicalDevice && pPresentModes &&
1069 pPresentModeCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001070 // Compare the preliminary value of *pPresentModeCount with the
1071 // value this time:
1072 if (*pPresentModeCount != pPhysicalDevice->presentModeCount) {
1073 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1074 physicalDevice,
1075 "pPresentModeCount",
1076 "pPresentModes",
1077 pPhysicalDevice->presentModeCount);
1078 }
Ian Elliott9059b302015-12-30 13:14:36 -07001079 else if (*pPresentModeCount > 0) {
1080 // Record the result of this query:
1081 pPhysicalDevice->presentModeCount = *pPresentModeCount;
1082 pPhysicalDevice->pPresentModes = (VkPresentModeKHR *)
1083 malloc(*pPresentModeCount * sizeof(VkPresentModeKHR));
1084 if (pPhysicalDevice->pSurfaceFormats) {
1085 for (uint32_t i = 0 ; i < *pPresentModeCount ; i++) {
1086 pPhysicalDevice->pPresentModes[i] = pPresentModes[i];
1087 }
1088 } else {
1089 pPhysicalDevice->presentModeCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001090 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001091 }
1092 }
1093
1094 return result;
1095 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001096 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001097}
1098
1099// This function does the up-front validation work for vkCreateSwapchainKHR(),
1100// and returns VK_TRUE if a logging callback indicates that the call down the
1101// chain should be skipped:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001102static VkBool32 validateCreateSwapchainKHR(
1103 VkDevice device,
1104 const VkSwapchainCreateInfoKHR* pCreateInfo,
1105 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001106{
1107// TODO: Validate cases of re-creating a swapchain (the current code
1108// assumes a new swapchain is being created).
1109 VkResult result = VK_SUCCESS;
1110 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001111 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001112 char fn[] = "vkCreateSwapchainKHR";
Tobin Ehlis711ff312015-10-29 12:58:13 -06001113 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001114
Ian Elliott8b9e2562016-01-05 13:00:50 -07001115 // Validate that the swapchain extension was enabled:
1116 if (pDevice && !pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001117 return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001118 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001119 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001120 fn, VK_KHR_SWAPCHAIN_EXTENSION_NAME );
Ian Elliott0b4d6242015-09-22 10:51:24 -06001121 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001122 if (!pCreateInfo) {
1123 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1124 device,
1125 "pCreateInfo");
Ian Elliottf5758292015-12-30 17:39:02 -07001126 } else {
1127 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR) {
1128 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1129 device,
1130 "pCreateInfo",
1131 "VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR");
1132 }
1133 if (pCreateInfo->pNext != NULL) {
1134 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1135 device,
1136 "pCreateInfo");
1137 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001138 }
1139 if (!pSwapchain) {
1140 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1141 device,
1142 "pSwapchain");
1143 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001144
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001145 // Keep around a useful pointer to pPhysicalDevice:
1146 SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice;
1147
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001148 // Validate pCreateInfo values with the results of
1149 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1150 if (!pPhysicalDevice || !pPhysicalDevice->gotSurfaceCapabilities) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001151 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001152 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001153 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001154 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001155 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001156 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001157 // Validate pCreateInfo->minImageCount against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001158 // VkSurfaceCapabilitiesKHR::{min|max}ImageCount:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001159 VkSurfaceCapabilitiesKHR *pCapabilities = &pPhysicalDevice->surfaceCapabilities;
Ian Elliott27d39c72015-11-20 16:39:34 -07001160 if ((pCreateInfo->minImageCount < pCapabilities->minImageCount) ||
1161 ((pCapabilities->maxImageCount > 0) &&
1162 (pCreateInfo->minImageCount > pCapabilities->maxImageCount))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001163 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001164 SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001165 "%s() called with pCreateInfo->minImageCount "
1166 "= %d, which is outside the bounds returned "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001167 "by vkGetPhysicalDeviceSurfaceCapabilitiesKHR() (i.e. "
Ian Elliott0b4d6242015-09-22 10:51:24 -06001168 "minImageCount = %d, maxImageCount = %d).",
1169 fn,
1170 pCreateInfo->minImageCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001171 pCapabilities->minImageCount,
1172 pCapabilities->maxImageCount);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001173 }
1174 // Validate pCreateInfo->imageExtent against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001175 // VkSurfaceCapabilitiesKHR::{current|min|max}ImageExtent:
Ian Elliott27d39c72015-11-20 16:39:34 -07001176 if ((pCapabilities->currentExtent.width == -1) &&
1177 ((pCreateInfo->imageExtent.width < pCapabilities->minImageExtent.width) ||
1178 (pCreateInfo->imageExtent.width > pCapabilities->maxImageExtent.width) ||
1179 (pCreateInfo->imageExtent.height < pCapabilities->minImageExtent.height) ||
1180 (pCreateInfo->imageExtent.height > pCapabilities->maxImageExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001181 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001182 SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001183 "%s() called with pCreateInfo->imageExtent = "
1184 "(%d,%d), which is outside the bounds "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001185 "returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): "
Ian Elliott0b4d6242015-09-22 10:51:24 -06001186 "currentExtent = (%d,%d), minImageExtent = "
1187 "(%d,%d), maxImageExtent = (%d,%d).",
1188 fn,
1189 pCreateInfo->imageExtent.width,
1190 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001191 pCapabilities->currentExtent.width,
1192 pCapabilities->currentExtent.height,
1193 pCapabilities->minImageExtent.width,
1194 pCapabilities->minImageExtent.height,
1195 pCapabilities->maxImageExtent.width,
1196 pCapabilities->maxImageExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001197 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001198 if ((pCapabilities->currentExtent.width != -1) &&
1199 ((pCreateInfo->imageExtent.width != pCapabilities->currentExtent.width) ||
1200 (pCreateInfo->imageExtent.height != pCapabilities->currentExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001201 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001202 SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001203 "%s() called with pCreateInfo->imageExtent = "
1204 "(%d,%d), which is not equal to the "
1205 "currentExtent = (%d,%d) returned by "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001206 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001207 fn,
1208 pCreateInfo->imageExtent.width,
1209 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001210 pCapabilities->currentExtent.width,
1211 pCapabilities->currentExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001212 }
1213 // Validate pCreateInfo->preTransform against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001214 // VkSurfaceCapabilitiesKHR::supportedTransforms:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001215 if (!((pCreateInfo->preTransform) & pCapabilities->supportedTransforms)) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001216 // This is an error situation; one for which we'd like to give
1217 // the developer a helpful, multi-line error message. Build it
1218 // up a little at a time, and then log it:
1219 std::string errorString = "";
1220 char str[1024];
1221 // Here's the first part of the message:
1222 sprintf(str, "%s() called with a non-supported "
1223 "pCreateInfo->preTransform (i.e. %s). "
1224 "Supported values are:\n",
1225 fn,
1226 surfaceTransformStr(pCreateInfo->preTransform));
1227 errorString += str;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001228 for (int i = 0; i < 32; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001229 // Build up the rest of the message:
Ian Elliott27d39c72015-11-20 16:39:34 -07001230 if ((1 << i) & pCapabilities->supportedTransforms) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001231 const char *newStr =
Ian Elliott27d39c72015-11-20 16:39:34 -07001232 surfaceTransformStr((VkSurfaceTransformFlagBitsKHR) (1 << i));
Ian Elliott0b4d6242015-09-22 10:51:24 -06001233 sprintf(str, " %s\n", newStr);
1234 errorString += str;
1235 }
1236 }
1237 // Log the message that we've built up:
Ian Elliott68124ac2015-10-07 16:18:35 -06001238 skipCall |= debug_report_log_msg(my_data->report_data,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001239 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1240 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Mark Lobodzinski80e774f2016-01-04 15:54:59 -07001241 (uint64_t) device, __LINE__,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001242 SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM,
1243 LAYER_NAME,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001244 errorString.c_str());
1245 }
Ian Elliotta2a89c52015-12-28 15:23:57 -07001246 // Validate pCreateInfo->compositeAlpha against
1247 // VkSurfaceCapabilitiesKHR::supportedCompositeAlpha:
1248 if (!((pCreateInfo->compositeAlpha) & pCapabilities->supportedCompositeAlpha)) {
1249 // This is an error situation; one for which we'd like to give
1250 // the developer a helpful, multi-line error message. Build it
1251 // up a little at a time, and then log it:
1252 std::string errorString = "";
1253 char str[1024];
1254 // Here's the first part of the message:
1255 sprintf(str, "%s() called with a non-supported "
1256 "pCreateInfo->compositeAlpha (i.e. %s). "
1257 "Supported values are:\n",
1258 fn,
1259 surfaceCompositeAlphaStr(pCreateInfo->compositeAlpha));
1260 errorString += str;
1261 for (int i = 0; i < 32; i++) {
1262 // Build up the rest of the message:
1263 if ((1 << i) & pCapabilities->supportedCompositeAlpha) {
1264 const char *newStr =
1265 surfaceCompositeAlphaStr((VkCompositeAlphaFlagBitsKHR) (1 << i));
1266 sprintf(str, " %s\n", newStr);
1267 errorString += str;
1268 }
1269 }
1270 // Log the message that we've built up:
1271 skipCall |= debug_report_log_msg(my_data->report_data,
Ian Elliott1bf155f2015-12-29 17:35:46 -07001272 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1273 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliotta2a89c52015-12-28 15:23:57 -07001274 (uint64_t) device, 0,
1275 SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA,
1276 LAYER_NAME,
1277 errorString.c_str());
1278 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001279 // Validate pCreateInfo->imageArraySize against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001280 // VkSurfaceCapabilitiesKHR::maxImageArraySize:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001281 if ((pCreateInfo->imageArrayLayers > 0) &&
1282 (pCreateInfo->imageArrayLayers > pCapabilities->maxImageArrayLayers)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001283 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001284 SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_SIZE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001285 "%s() called with a non-supported "
1286 "pCreateInfo->imageArraySize (i.e. %d). "
1287 "Maximum value is %d.",
1288 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001289 pCreateInfo->imageArrayLayers,
1290 pCapabilities->maxImageArrayLayers);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001291 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001292 // Validate pCreateInfo->imageUsage against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001293 // VkSurfaceCapabilitiesKHR::supportedUsageFlags:
Ian Elliott27d39c72015-11-20 16:39:34 -07001294 if (pCreateInfo->imageUsage &&
1295 (pCreateInfo->imageUsage !=
1296 (pCreateInfo->imageUsage & pCapabilities->supportedUsageFlags))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001297 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001298 SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001299 "%s() called with a non-supported "
Ian Elliott27d39c72015-11-20 16:39:34 -07001300 "pCreateInfo->imageUsage (i.e. 0x%08x)."
Ian Elliott0b4d6242015-09-22 10:51:24 -06001301 " Supported flag bits are 0x%08x.",
1302 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001303 pCreateInfo->imageUsage,
1304 pCapabilities->supportedUsageFlags);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001305 }
1306 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001307
1308 // Validate pCreateInfo values with the results of
1309 // vkGetPhysicalDeviceSurfaceFormatsKHR():
1310 if (!pPhysicalDevice || !pPhysicalDevice->surfaceFormatCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001311 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001312 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001313 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001314 "vkGetPhysicalDeviceSurfaceFormatsKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001315 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001316 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001317 // Validate pCreateInfo->imageFormat against
1318 // VkSurfaceFormatKHR::format:
1319 bool foundFormat = false;
1320 bool foundColorSpace = false;
1321 bool foundMatch = false;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001322 for (uint32_t i = 0 ; i < pPhysicalDevice->surfaceFormatCount ; i++) {
1323 if (pCreateInfo->imageFormat == pPhysicalDevice->pSurfaceFormats[i].format) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001324 // Validate pCreateInfo->imageColorSpace against
1325 // VkSurfaceFormatKHR::colorSpace:
1326 foundFormat = true;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001327 if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001328 foundMatch = true;
1329 break;
1330 }
1331 } else {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001332 if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001333 foundColorSpace = true;
1334 }
1335 }
1336 }
1337 if (!foundMatch) {
1338 if (!foundFormat) {
1339 if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001340 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001341 "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001342 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001343 "%s() called with neither a "
1344 "supported pCreateInfo->imageFormat "
1345 "(i.e. %d) nor a supported "
1346 "pCreateInfo->imageColorSpace "
1347 "(i.e. %d).",
1348 fn,
1349 pCreateInfo->imageFormat,
1350 pCreateInfo->imageColorSpace);
1351 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001352 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001353 "VkDevice",
1354 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001355 "%s() called with a non-supported "
1356 "pCreateInfo->imageFormat (i.e. %d).",
1357 fn, pCreateInfo->imageFormat);
1358 }
1359 } else if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001360 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001361 SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001362 "%s() called with a non-supported "
1363 "pCreateInfo->imageColorSpace (i.e. %d).",
1364 fn, pCreateInfo->imageColorSpace);
1365 }
1366 }
1367 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001368
1369 // Validate pCreateInfo values with the results of
1370 // vkGetPhysicalDeviceSurfacePresentModesKHR():
1371 if (!pPhysicalDevice || !pPhysicalDevice->presentModeCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001372 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001373 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001374 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001375 "vkGetPhysicalDeviceSurfacePresentModesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001376 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001377 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001378 // Validate pCreateInfo->presentMode against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001379 // vkGetPhysicalDeviceSurfacePresentModesKHR():
Ian Elliott0b4d6242015-09-22 10:51:24 -06001380 bool foundMatch = false;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001381 for (uint32_t i = 0 ; i < pPhysicalDevice->presentModeCount ; i++) {
1382 if (pPhysicalDevice->pPresentModes[i] == pCreateInfo->presentMode) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001383 foundMatch = true;
1384 break;
1385 }
1386 }
1387 if (!foundMatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001388 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001389 SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001390 "%s() called with a non-supported "
1391 "pCreateInfo->presentMode (i.e. %s).",
1392 fn,
1393 presentModeStr(pCreateInfo->presentMode));
1394 }
1395 }
1396
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001397 // Validate pCreateInfo->imageSharingMode and related values:
Ian Elliotta2a89c52015-12-28 15:23:57 -07001398 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
Ian Elliottafcb60c2016-01-05 14:11:03 -07001399 if ((pCreateInfo->queueFamilyIndexCount < 1) ||
Ian Elliotta2a89c52015-12-28 15:23:57 -07001400 !pCreateInfo->pQueueFamilyIndices) {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001401 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001402 SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES,
1403 "%s() called with a supported "
1404 "pCreateInfo->sharingMode of (i.e. %s),"
1405 "but with a bad value(s) for "
1406 "pCreateInfo->queueFamilyIndexCount or "
1407 "pCreateInfo->pQueueFamilyIndices).",
1408 fn,
1409 sharingModeStr(pCreateInfo->imageSharingMode));
1410 }
1411 } else if (pCreateInfo->imageSharingMode != VK_SHARING_MODE_EXCLUSIVE) {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001412 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001413 SWAPCHAIN_CREATE_SWAP_BAD_SHARING_MODE,
1414 "%s() called with a non-supported "
1415 "pCreateInfo->imageSharingMode (i.e. %s).",
1416 fn,
1417 sharingModeStr(pCreateInfo->imageSharingMode));
1418 }
1419
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001420 // Validate pCreateInfo->clipped:
1421 if (pCreateInfo &&
1422 (pCreateInfo->clipped != VK_FALSE) &&
Ian Elliotta2a89c52015-12-28 15:23:57 -07001423 (pCreateInfo->clipped != VK_TRUE)) {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001424 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1425 device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001426 SWAPCHAIN_BAD_BOOL,
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001427 "%s() called with a VkBool32 value that is "
1428 "neither VK_TRUE nor VK_FALSE, but has the "
1429 "numeric value of %d.",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001430 fn,
1431 pCreateInfo->clipped);
1432 }
1433
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001434 // Validate pCreateInfo->oldSwapchain:
1435 if (pCreateInfo && pCreateInfo->oldSwapchain) {
1436 SwpSwapchain *pOldSwapchain = &my_data->swapchainMap[pCreateInfo->oldSwapchain];
1437 if (pOldSwapchain) {
1438 if (device != pOldSwapchain->pDevice->device) {
1439 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1440 device, "VkDevice",
1441 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
1442 "%s() called with a different VkDevice "
1443 "than the VkSwapchainKHR was created with.",
1444 __FUNCTION__);
1445 }
1446 if (pCreateInfo->surface != pOldSwapchain->surface) {
1447 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1448 device, "VkDevice",
1449 SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE,
1450 "%s() called with pCreateInfo->oldSwapchain "
1451 "that has a different VkSurfaceKHR than "
1452 "pCreateInfo->surface.",
1453 fn);
Ian Elliotta2a89c52015-12-28 15:23:57 -07001454 }
1455 } else {
Ian Elliott6f3346b2016-01-05 13:06:48 -07001456 // TBD: Leave this in (not sure object_track will check this)?
Ian Elliott1bf155f2015-12-29 17:35:46 -07001457 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliotta2a89c52015-12-28 15:23:57 -07001458 pCreateInfo->oldSwapchain,
1459 "VkSwapchainKHR");
1460 }
1461 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001462
1463 return skipCall;
1464}
1465
Ian Elliott27d39c72015-11-20 16:39:34 -07001466VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
1467 VkDevice device,
1468 const VkSwapchainCreateInfoKHR* pCreateInfo,
1469 const VkAllocationCallbacks* pAllocator,
1470 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001471{
1472 VkResult result = VK_SUCCESS;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001473 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001474 VkBool32 skipCall = validateCreateSwapchainKHR(device, pCreateInfo,
1475 pSwapchain);
1476
1477 if (VK_FALSE == skipCall) {
1478 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001479 result = my_data->device_dispatch_table->CreateSwapchainKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001480 device, pCreateInfo, pAllocator, pSwapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001481
1482 if (result == VK_SUCCESS) {
1483 // Remember the swapchain's handle, and link it to the device:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001484 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001485
Tobin Ehlis711ff312015-10-29 12:58:13 -06001486 my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001487 pDevice->swapchains[*pSwapchain] =
Tobin Ehlis711ff312015-10-29 12:58:13 -06001488 &my_data->swapchainMap[*pSwapchain];
1489 my_data->swapchainMap[*pSwapchain].pDevice = pDevice;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001490 my_data->swapchainMap[*pSwapchain].surface =
1491 (pCreateInfo) ? pCreateInfo->surface : 0;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001492 my_data->swapchainMap[*pSwapchain].imageCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001493 }
1494
1495 return result;
1496 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001497 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001498}
1499
Ian Elliott27d39c72015-11-20 16:39:34 -07001500VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
1501 VkDevice device,
1502 VkSwapchainKHR swapchain,
1503 const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001504{
1505 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001506 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -06001507 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott8b9e2562016-01-05 13:00:50 -07001508
1509 // Validate that the swapchain extension was enabled:
1510 if (pDevice && !pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001511 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001512 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001513 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001514 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001515 }
1516
1517 // Regardless of skipCall value, do some internal cleanup:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001518 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001519 if (pSwapchain) {
1520 // Delete the SwpSwapchain associated with this swapchain:
1521 if (pSwapchain->pDevice) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08001522 pSwapchain->pDevice->swapchains.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001523 if (device != pSwapchain->pDevice->device) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001524 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001525 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001526 "%s() called with a different VkDevice than the "
1527 "VkSwapchainKHR was created with.",
1528 __FUNCTION__);
1529 }
1530 }
1531 if (pSwapchain->imageCount) {
1532 pSwapchain->images.clear();
1533 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001534 my_data->swapchainMap.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001535 }
1536
1537 if (VK_FALSE == skipCall) {
1538 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001539 my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001540 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001541}
1542
Ian Elliottf955d682015-12-30 12:00:54 -07001543VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
1544 VkDevice device,
1545 VkSwapchainKHR swapchain,
1546 uint32_t* pSwapchainImageCount,
1547 VkImage* pSwapchainImages)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001548{
1549 VkResult result = VK_SUCCESS;
1550 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001551 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -06001552 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott8b9e2562016-01-05 13:00:50 -07001553
1554 // Validate that the swapchain extension was enabled:
1555 if (pDevice && !pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001556 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001557 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001558 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001559 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001560 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001561 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliottf955d682015-12-30 12:00:54 -07001562 if (!pSwapchainImageCount) {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001563 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1564 device,
Ian Elliottf955d682015-12-30 12:00:54 -07001565 "pSwapchainImageCount");
1566 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001567
1568 if (VK_FALSE == skipCall) {
1569 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001570 result = my_data->device_dispatch_table->GetSwapchainImagesKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001571 device, swapchain, pSwapchainImageCount, pSwapchainImages);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001572
Ian Elliottf955d682015-12-30 12:00:54 -07001573 if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages &&
1574 pSwapchainImageCount) {
1575 // Record the result of this preliminary query:
1576 pSwapchain->imageCount = *pSwapchainImageCount;
1577 }
Ian Elliott9059b302015-12-30 13:14:36 -07001578 else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages &&
1579 pSwapchainImageCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001580 // Compare the preliminary value of *pSwapchainImageCount with the
1581 // value this time:
1582 if (*pSwapchainImageCount != pSwapchain->imageCount) {
1583 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1584 device,
1585 "pSwapchainImageCount",
1586 "pSwapchainImages",
1587 pSwapchain->imageCount);
1588 }
Ian Elliott9059b302015-12-30 13:14:36 -07001589 else if (*pSwapchainImageCount > 0) {
1590 // Record the images and their state:
1591 pSwapchain->imageCount = *pSwapchainImageCount;
1592 for (uint32_t i = 0 ; i < *pSwapchainImageCount ; i++) {
1593 pSwapchain->images[i].image = pSwapchainImages[i];
1594 pSwapchain->images[i].pSwapchain = pSwapchain;
1595 pSwapchain->images[i].ownedByApp = false;
1596 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001597 }
1598 }
1599
1600 return result;
1601 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001602 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001603}
1604
Ian Elliott27d39c72015-11-20 16:39:34 -07001605VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
1606 VkDevice device,
1607 VkSwapchainKHR swapchain,
1608 uint64_t timeout,
1609 VkSemaphore semaphore,
1610 VkFence fence,
1611 uint32_t* pImageIndex)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001612{
Ian Elliottdd45e462015-12-29 17:52:10 -07001613// TODOs:
1614//
1615// - Address the timeout. Possibilities include looking at the state of the
1616// swapchain's images, depending on the timeout value.
1617// - Validate that semaphore and fence are either VK_NULL_HANDLE or valid
1618// handles.
1619// - Record/update the state of the swapchain, in case an error occurs
1620// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
Ian Elliott0b4d6242015-09-22 10:51:24 -06001621 VkResult result = VK_SUCCESS;
1622 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001623 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -06001624 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott8b9e2562016-01-05 13:00:50 -07001625
1626 // Validate that the swapchain extension was enabled:
1627 if (pDevice && !pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001628 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001629 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001630 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001631 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001632 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001633 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott6f3346b2016-01-05 13:06:48 -07001634 if (pSwapchain) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001635 // Look to see if the application is trying to own too many images at
1636 // the same time (i.e. not leave any to display):
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001637 uint32_t imagesOwnedByApp = 0;
1638 for (uint32_t i = 0 ; i < pSwapchain->imageCount ; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001639 if (pSwapchain->images[i].ownedByApp) {
1640 imagesOwnedByApp++;
1641 }
1642 }
1643 if (imagesOwnedByApp >= (pSwapchain->imageCount - 1)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001644 skipCall |= LOG_PERF_WARNING(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott4a994452015-09-24 18:33:16 -06001645 swapchain,
1646 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001647 SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES,
Ian Elliott4a994452015-09-24 18:33:16 -06001648 "%s() called when the application "
1649 "already owns all presentable images "
1650 "in this swapchain except for the "
1651 "image currently being displayed. "
1652 "This call to %s() cannot succeed "
1653 "unless another thread calls the "
1654 "vkQueuePresentKHR() function in "
1655 "order to release ownership of one of "
1656 "the presentable images of this "
1657 "swapchain.",
1658 __FUNCTION__, __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001659 }
1660 }
Ian Elliottdd45e462015-12-29 17:52:10 -07001661 if (!pImageIndex) {
1662 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1663 device,
1664 "pImageIndex");
1665 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001666
1667 if (VK_FALSE == skipCall) {
1668 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001669 result = my_data->device_dispatch_table->AcquireNextImageKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001670 device, swapchain, timeout, semaphore, fence, pImageIndex);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001671
1672 if (((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)) &&
1673 pSwapchain) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001674 // Change the state of the image (now owned by the application):
1675 pSwapchain->images[*pImageIndex].ownedByApp = true;
1676 }
1677
1678 return result;
1679 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001680 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001681}
1682
Ian Elliott27d39c72015-11-20 16:39:34 -07001683VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(
1684 VkQueue queue,
1685 const VkPresentInfoKHR* pPresentInfo)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001686{
1687// TODOs:
1688//
1689// - Ensure that the queue is active, and is one of the queueFamilyIndex's
1690// that was returned by a previuos query.
1691// - Record/update the state of the swapchain, in case an error occurs
1692// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
1693 VkResult result = VK_SUCCESS;
1694 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001695 layer_data *my_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001696
Ian Elliott046ed2c2015-12-30 17:07:17 -07001697 if (!pPresentInfo) {
1698 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1699 device,
1700 "pPresentInfo");
1701 } else {
1702 if (pPresentInfo->sType != VK_STRUCTURE_TYPE_PRESENT_INFO_KHR) {
1703 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1704 device,
1705 "pPresentInfo",
1706 "VK_STRUCTURE_TYPE_PRESENT_INFO_KHR");
1707 }
1708 if (pPresentInfo->pNext != NULL) {
1709 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1710 device,
1711 "pPresentInfo");
1712 }
1713 if (!pPresentInfo->waitSemaphoreCount) {
1714 skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1715 device,
1716 "pPresentInfo->waitSemaphoreCount");
1717 }
1718 if (!pPresentInfo->pWaitSemaphores) {
1719 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1720 device,
1721 "pPresentInfo->pWaitSemaphores");
1722 }
1723 if (!pPresentInfo->swapchainCount) {
1724 skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1725 device,
1726 "pPresentInfo->swapchainCount");
1727 }
1728 if (!pPresentInfo->pSwapchains) {
1729 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1730 device,
1731 "pPresentInfo->pSwapchains");
1732 }
1733 if (!pPresentInfo->pImageIndices) {
1734 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1735 device,
1736 "pPresentInfo->pImageIndices");
1737 }
1738 // Note: pPresentInfo->pResults is allowed to be NULL
1739 }
1740
1741 for (uint32_t i = 0;
1742 pPresentInfo && (i < pPresentInfo->swapchainCount);
1743 i++) {
1744 uint32_t swapchainCount = pPresentInfo->swapchainCount;
Ian Elliott27d39c72015-11-20 16:39:34 -07001745 uint32_t index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001746 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001747 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001748 if (pSwapchain) {
Ian Elliott427058f2015-12-29 16:45:49 -07001749 if (!pSwapchain->pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001750 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001751 pSwapchain->pDevice, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001752 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001753 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001754 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001755 }
1756 if (index >= pSwapchain->imageCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001757 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001758 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001759 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001760 SWAPCHAIN_INDEX_TOO_LARGE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001761 "%s() called for an index that is too "
1762 "large (i.e. %d). There are only %d "
1763 "images in this VkSwapchainKHR.\n",
1764 __FUNCTION__, index,
1765 pSwapchain->imageCount);
1766 } else {
1767 if (!pSwapchain->images[index].ownedByApp) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001768 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001769 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001770 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001771 SWAPCHAIN_INDEX_NOT_IN_USE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001772 "%s() returned an index (i.e. %d) "
1773 "for an image that is not owned by "
1774 "the application.",
1775 __FUNCTION__, index);
1776 }
1777 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001778 }
1779 }
1780
1781 if (VK_FALSE == skipCall) {
1782 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001783 result = my_data->device_dispatch_table->QueuePresentKHR(queue,
Ian Elliott046ed2c2015-12-30 17:07:17 -07001784 pPresentInfo);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001785
Ian Elliott046ed2c2015-12-30 17:07:17 -07001786 if (pPresentInfo &&
1787 ((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR))) {
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001788 for (uint32_t i = 0; i < pPresentInfo->swapchainCount ; i++) {
Ian Elliott27d39c72015-11-20 16:39:34 -07001789 int index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001790 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001791 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001792 if (pSwapchain) {
1793 // Change the state of the image (no longer owned by the
1794 // application):
1795 pSwapchain->images[index].ownedByApp = false;
1796 }
1797 }
1798 }
1799
1800 return result;
1801 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001802 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001803}
1804
1805static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)
1806{
1807 if (!name || name[0] != 'v' || name[1] != 'k')
1808 return NULL;
1809
1810 name += 2;
1811 if (!strcmp(name, "CreateInstance"))
1812 return (PFN_vkVoidFunction) vkCreateInstance;
1813 if (!strcmp(name, "DestroyInstance"))
1814 return (PFN_vkVoidFunction) vkDestroyInstance;
1815 if (!strcmp(name, "EnumeratePhysicalDevices"))
1816 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1817 if (!strcmp(name, "CreateDevice"))
1818 return (PFN_vkVoidFunction) vkCreateDevice;
1819 if (!strcmp(name, "DestroyDevice"))
1820 return (PFN_vkVoidFunction) vkDestroyDevice;
1821
1822 return NULL;
1823}
1824static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)
1825{
1826 if (!name || name[0] != 'v' || name[1] != 'k')
1827 return NULL;
1828
1829 name += 2;
1830 if (!strcmp(name, "CreateInstance"))
1831 return (PFN_vkVoidFunction) vkCreateInstance;
1832 if (!strcmp(name, "DestroyInstance"))
1833 return (PFN_vkVoidFunction) vkDestroyInstance;
1834 if (!strcmp(name, "EnumeratePhysicalDevices"))
1835 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1836
1837 return NULL;
1838}
1839
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001840VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
1841 VkInstance instance,
1842 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
1843 const VkAllocationCallbacks* pAllocator,
1844 VkDebugReportCallbackEXT* pMsgCallback)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001845{
Tobin Ehlis711ff312015-10-29 12:58:13 -06001846 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001847 VkResult result = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001848 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001849 result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001850 }
1851 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001852}
1853
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001854VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001855{
Ian Elliott68124ac2015-10-07 16:18:35 -06001856 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001857 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001858 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001859}
1860
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001861VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001862 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001863 VkDebugReportFlagsEXT flags,
1864 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001865 uint64_t object,
1866 size_t location,
1867 int32_t msgCode,
1868 const char* pLayerPrefix,
1869 const char* pMsg)
1870{
1871 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001872 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001873}
1874
Chia-I Wu9ab61502015-11-06 06:42:02 +08001875VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001876{
1877 PFN_vkVoidFunction addr;
1878 if (device == VK_NULL_HANDLE) {
1879 return NULL;
1880 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001881
Tobin Ehlis711ff312015-10-29 12:58:13 -06001882 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001883 /* loader uses this to force layer initialization; device object is wrapped */
1884 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001885 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) device;
1886 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
1887 my_data->device_dispatch_table = new VkLayerDispatchTable;
1888 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001889 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
1890 }
1891
1892 addr = layer_intercept_proc(funcName);
1893 if (addr)
1894 return addr;
1895
Tobin Ehlis711ff312015-10-29 12:58:13 -06001896 my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
1897 VkLayerDispatchTable *pDisp = my_data->device_dispatch_table;
1898 if (my_data->deviceMap.size() != 0 &&
Ian Elliott427058f2015-12-29 16:45:49 -07001899 my_data->deviceMap[device].swapchainExtensionEnabled)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001900 {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001901 if (!strcmp("vkCreateSwapchainKHR", funcName))
1902 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR);
1903 if (!strcmp("vkDestroySwapchainKHR", funcName))
1904 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR);
1905 if (!strcmp("vkGetSwapchainImagesKHR", funcName))
1906 return reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR);
1907 if (!strcmp("vkAcquireNextImageKHR", funcName))
1908 return reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR);
1909 if (!strcmp("vkQueuePresentKHR", funcName))
1910 return reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR);
1911 }
1912 {
1913 if (pDisp->GetDeviceProcAddr == NULL)
1914 return NULL;
1915 return pDisp->GetDeviceProcAddr(device, funcName);
1916 }
1917}
1918
Chia-I Wu9ab61502015-11-06 06:42:02 +08001919VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001920{
1921 PFN_vkVoidFunction addr;
1922 if (instance == VK_NULL_HANDLE) {
1923 return NULL;
1924 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001925
Tobin Ehlis711ff312015-10-29 12:58:13 -06001926 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001927 /* loader uses this to force layer initialization; instance object is wrapped */
1928 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001929 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
1930 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
1931 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
1932 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001933 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
1934 }
1935
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07001936 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
1937 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
1938 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
1939 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
1940
Ian Elliott0b4d6242015-09-22 10:51:24 -06001941 addr = layer_intercept_instance_proc(funcName);
1942 if (addr)
1943 return addr;
1944
Tobin Ehlis711ff312015-10-29 12:58:13 -06001945 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1946 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Ian Elliott68124ac2015-10-07 16:18:35 -06001947 addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
1948 if (addr) {
1949 return addr;
1950 }
1951
Ian Elliotta983e9a2015-12-22 12:18:12 -07001952#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001953 if (my_data->instanceMap.size() != 0 &&
1954 my_data->instanceMap[instance].androidSurfaceExtensionEnabled)
1955 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001956 if (!strcmp("vkCreateAndroidSurfaceKHR", funcName))
1957 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateAndroidSurfaceKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001958 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001959#endif // VK_USE_PLATFORM_ANDROID_KHR
1960#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001961 if (my_data->instanceMap.size() != 0 &&
1962 my_data->instanceMap[instance].mirSurfaceExtensionEnabled)
1963 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001964 if (!strcmp("vkCreateMirSurfaceKHR", funcName))
1965 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateMirSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001966 if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", funcName))
1967 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceMirPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001968 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001969#endif // VK_USE_PLATFORM_MIR_KHR
1970#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001971 if (my_data->instanceMap.size() != 0 &&
1972 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled)
1973 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001974 if (!strcmp("vkCreateWaylandSurfaceKHR", funcName))
1975 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWaylandSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001976 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", funcName))
1977 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001978 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001979#endif // VK_USE_PLATFORM_WAYLAND_KHR
1980#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001981 if (my_data->instanceMap.size() != 0 &&
1982 my_data->instanceMap[instance].win32SurfaceExtensionEnabled)
1983 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001984 if (!strcmp("vkCreateWin32SurfaceKHR", funcName))
1985 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWin32SurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001986 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", funcName))
1987 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWin32PresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001988 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001989#endif // VK_USE_PLATFORM_WIN32_KHR
1990#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001991 if (my_data->instanceMap.size() != 0 &&
1992 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled)
1993 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001994 if (!strcmp("vkCreateXcbSurfaceKHR", funcName))
1995 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXcbSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001996 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", funcName))
1997 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXcbPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001998 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001999#endif // VK_USE_PLATFORM_XCB_KHR
2000#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002001 if (my_data->instanceMap.size() != 0 &&
2002 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled)
2003 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002004 if (!strcmp("vkCreateXlibSurfaceKHR", funcName))
2005 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXlibSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002006 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", funcName))
2007 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXlibPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07002008 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07002009#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002010 if (my_data->instanceMap.size() != 0 &&
2011 my_data->instanceMap[instance].surfaceExtensionEnabled)
2012 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002013 if (!strcmp("vkDestroySurfaceKHR", funcName))
2014 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySurfaceKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002015 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", funcName))
2016 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceSupportKHR);
Ian Elliott27d39c72015-11-20 16:39:34 -07002017 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", funcName))
2018 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
2019 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", funcName))
2020 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceFormatsKHR);
2021 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", funcName))
2022 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfacePresentModesKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002023 }
2024
2025 if (pTable->GetInstanceProcAddr == NULL)
2026 return NULL;
2027 return pTable->GetInstanceProcAddr(instance, funcName);
2028}
2029