blob: ff7681673c8ccd8d2fcafb918acb723ca7287c8a [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>
24 *
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 Elliotta983e9a2015-12-22 12:18:12 -070078// This function validates a VkSurfaceKHR object:
79static VkBool32 validateSurface(layer_data *my_data, VkSurfaceKHR surface, char *fn)
80{
81 VkBool32 skipCall = VK_FALSE;
82 bool found_error = false;
83
84 SwpSurface *pSurface = &my_data->surfaceMap[surface];
85 if ((pSurface == NULL) || (pSurface->surface != surface)) {
86 found_error = true;
87 } else {
88#if !defined(__ANDROID__)
89 VkIcdSurfaceBase *pIcdSurface = (VkIcdSurfaceBase *) surface;
90 if (pSurface->platform != pIcdSurface->platform) {
91 found_error = true;
92 }
93#else // !defined(__ANDROID__)
94 if (pSurface->platform != VK_ICD_WSI_PLATFORM_ANDROID) {
95 found_error = true;
96 }
97#endif // !defined(__ANDROID__)
98 }
99 if (found_error) {
Ian Elliott1bf155f2015-12-29 17:35:46 -0700100 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, surface, "VkSurfaceKHR",
Ian Elliotta983e9a2015-12-22 12:18:12 -0700101 SWAPCHAIN_INVALID_HANDLE,
102 "%s() called with an invalid surface object.",
103 fn);
104 }
105 return skipCall;
106}
Ian Elliott0b4d6242015-09-22 10:51:24 -0600107
Ian Elliott0b4d6242015-09-22 10:51:24 -0600108static void createDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
109{
110 uint32_t i;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700111 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
112 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600113
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700114 VkLayerDispatchTable *pDisp = my_device_data->device_dispatch_table;
115 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
116
117 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
118 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
119 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
120 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
121 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
122
123 SwpPhysicalDevice *pPhysicalDevice = &my_instance_data->physicalDeviceMap[physicalDevice];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600124 if (pPhysicalDevice) {
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700125 my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice;
126 pPhysicalDevice->pDevice = &my_device_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600127 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700128 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 -0700129 (uint64_t)physicalDevice , __LINE__, SWAPCHAIN_INVALID_HANDLE, "Swapchain",
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700130 "vkCreateDevice() called with a non-valid VkPhysicalDevice.");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600131 }
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700132 my_device_data->deviceMap[device].device = device;
Ian Elliott427058f2015-12-29 16:45:49 -0700133 my_device_data->deviceMap[device].swapchainExtensionEnabled = false;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600134
135 // Record whether the WSI device extension was enabled for this VkDevice.
136 // No need to check if the extension was advertised by
137 // vkEnumerateDeviceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800138 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700139 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600140
Ian Elliott427058f2015-12-29 16:45:49 -0700141 my_device_data->deviceMap[device].swapchainExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600142 }
143 }
144}
145
146static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)
147{
148 uint32_t i;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600149 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
150 VkLayerInstanceDispatchTable *pDisp = my_data->instance_dispatch_table;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600151 PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700152#ifdef VK_USE_PLATFORM_ANDROID_KHR
153 pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR) gpa(instance, "vkCreateAndroidSurfaceKHR");
154#endif // VK_USE_PLATFORM_ANDROID_KHR
155#ifdef VK_USE_PLATFORM_MIR_KHR
156 pDisp->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR) gpa(instance, "vkCreateMirSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700157 pDisp->GetPhysicalDeviceMirPresentationSupportKHR = (PFN_vkGetPhysicalDeviceMirPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700158#endif // VK_USE_PLATFORM_MIR_KHR
159#ifdef VK_USE_PLATFORM_WAYLAND_KHR
160 pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR) gpa(instance, "vkCreateWaylandSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700161 pDisp->GetPhysicalDeviceWaylandPresentationSupportKHR = (PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWaylandPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700162#endif // VK_USE_PLATFORM_WAYLAND_KHR
163#ifdef VK_USE_PLATFORM_WIN32_KHR
164 pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) gpa(instance, "vkCreateWin32SurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700165 pDisp->GetPhysicalDeviceWin32PresentationSupportKHR = (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700166#endif // VK_USE_PLATFORM_WIN32_KHR
167#ifdef VK_USE_PLATFORM_XCB_KHR
168 pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) gpa(instance, "vkCreateXcbSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700169 pDisp->GetPhysicalDeviceXcbPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700170#endif // VK_USE_PLATFORM_XCB_KHR
171#ifdef VK_USE_PLATFORM_XLIB_KHR
172 pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR) gpa(instance, "vkCreateXlibSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700173 pDisp->GetPhysicalDeviceXlibPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700174#endif // VK_USE_PLATFORM_XLIB_KHR
175 pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR) gpa(instance, "vkDestroySurfaceKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600176 pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
Ian Elliott27d39c72015-11-20 16:39:34 -0700177 pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
178 pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
179 pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600180
Ian Elliott1dcd1092015-11-17 17:29:40 -0700181 // Remember this instance, and whether the VK_KHR_surface extension
Ian Elliott0b4d6242015-09-22 10:51:24 -0600182 // was enabled for it:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600183 my_data->instanceMap[instance].instance = instance;
Ian Elliott1cb77a62015-12-29 16:44:39 -0700184 my_data->instanceMap[instance].surfaceExtensionEnabled = false;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600185
186 // Record whether the WSI instance extension was enabled for this
187 // VkInstance. No need to check if the extension was advertised by
188 // vkEnumerateInstanceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800189 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700190 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600191
Ian Elliott1cb77a62015-12-29 16:44:39 -0700192 my_data->instanceMap[instance].surfaceExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600193 }
194 }
195}
196
197
198#include "vk_dispatch_table_helper.h"
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700199static void initSwapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600200{
201 uint32_t report_flags = 0;
202 uint32_t debug_action = 0;
203 FILE *log_output = NULL;
204 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700205 VkDebugReportCallbackEXT callback;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600206
207 // Initialize Swapchain options:
208 report_flags = getLayerOptionFlags("SwapchainReportFlags", 0);
209 getLayerOptionEnum("SwapchainDebugAction", (uint32_t *) &debug_action);
210
211 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
212 {
213 // Turn on logging, since it was requested:
214 option_str = getLayerOption("SwapchainLogFilename");
215 log_output = getLayerLogOutput(option_str, "Swapchain");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700216 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700217 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700218 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700219 dbgInfo.pfnCallback = log_callback;
220 dbgInfo.pUserData = log_output;
221 dbgInfo.flags = report_flags;
222 layer_create_msg_callback(my_data->report_data,
223 &dbgInfo,
224 pAllocator,
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600225 &callback);
226 my_data->logging_callback.push_back(callback);
227 }
228 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700229 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700230 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700231 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700232 dbgInfo.pfnCallback = win32_debug_output_msg;
233 dbgInfo.pUserData = log_output;
234 dbgInfo.flags = report_flags;
235 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600236 my_data->logging_callback.push_back(callback);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600237 }
238}
239
Ian Elliott27d39c72015-11-20 16:39:34 -0700240static const char *surfaceTransformStr(VkSurfaceTransformFlagBitsKHR value)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600241{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600242 // Return a string corresponding to the value:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700243 return string_VkSurfaceTransformFlagBitsKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600244}
245
Ian Elliotta2a89c52015-12-28 15:23:57 -0700246static const char *surfaceCompositeAlphaStr(VkCompositeAlphaFlagBitsKHR value)
247{
248 // Return a string corresponding to the value:
249 return string_VkCompositeAlphaFlagBitsKHR(value);
250}
251
Ian Elliott0b4d6242015-09-22 10:51:24 -0600252static const char *presentModeStr(VkPresentModeKHR value)
253{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600254 // Return a string corresponding to the value:
Ian Elliott24491af2015-12-28 15:04:49 -0700255 return string_VkPresentModeKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600256}
257
Ian Elliotta2a89c52015-12-28 15:23:57 -0700258static const char *sharingModeStr(VkSharingMode value)
259{
260 // Return a string corresponding to the value:
261 return string_VkSharingMode(value);
262}
263
Ian Elliott0b4d6242015-09-22 10:51:24 -0600264
Chia-I Wu9ab61502015-11-06 06:42:02 +0800265VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600266{
Tobin Ehlis711ff312015-10-29 12:58:13 -0600267 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600268 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600269 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800270 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600271 if (result == VK_SUCCESS) {
272 // Since it succeeded, do layer-specific work:
Ian Elliott68124ac2015-10-07 16:18:35 -0600273 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
274 my_data->report_data = debug_report_create_instance(
Tobin Ehlis711ff312015-10-29 12:58:13 -0600275 pTable,
Ian Elliott68124ac2015-10-07 16:18:35 -0600276 *pInstance,
Chia-I Wud50a7d72015-10-26 20:48:51 +0800277 pCreateInfo->enabledExtensionNameCount,
Ian Elliott68124ac2015-10-07 16:18:35 -0600278 pCreateInfo->ppEnabledExtensionNames);
279 // Call the following function after my_data is initialized:
Ian Elliott0b4d6242015-09-22 10:51:24 -0600280 createInstanceRegisterExtensions(pCreateInfo, *pInstance);
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700281 initSwapchain(my_data, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600282 }
283 return result;
284}
285
Chia-I Wu9ab61502015-11-06 06:42:02 +0800286VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600287{
288 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600289 dispatch_key key = get_dispatch_key(instance);
290 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600291 // Validate that a valid VkInstance was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600292 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600293 if (!pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700294 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600295 instance,
296 "VkInstance");
297 }
298
299 if (VK_FALSE == skipCall) {
300 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800301 my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator);
Ian Elliott68124ac2015-10-07 16:18:35 -0600302
303 // Clean up logging callback, if any
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600304 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700305 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700306 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600307 my_data->logging_callback.pop_back();
Ian Elliott68124ac2015-10-07 16:18:35 -0600308 }
309 layer_debug_report_destroy_instance(my_data->report_data);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600310 }
311
312 // Regardless of skipCall value, do some internal cleanup:
313 if (pInstance) {
314 // Delete all of the SwpPhysicalDevice's and the SwpInstance associated
315 // with this instance:
316 for (auto it = pInstance->physicalDevices.begin() ;
317 it != pInstance->physicalDevices.end() ; it++) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700318
319 // Free memory that was allocated for/by this SwpPhysicalDevice:
320 SwpPhysicalDevice *pPhysicalDevice = it->second;
321 free(pPhysicalDevice->pSurfaceFormats);
322 free(pPhysicalDevice->pPresentModes);
323
Tobin Ehlis711ff312015-10-29 12:58:13 -0600324 // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which
Ian Elliott0b4d6242015-09-22 10:51:24 -0600325 // are simply pointed to by the SwpInstance):
Tobin Ehlis711ff312015-10-29 12:58:13 -0600326 my_data->physicalDeviceMap.erase(it->second->physicalDevice);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600327 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600328 my_data->instanceMap.erase(instance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600329 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600330 delete my_data->instance_dispatch_table;
331 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600332}
333
Ian Elliotta983e9a2015-12-22 12:18:12 -0700334#ifdef VK_USE_PLATFORM_ANDROID_KHR
335VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
336 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700337 const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700338 const VkAllocationCallbacks* pAllocator,
339 VkSurfaceKHR* pSurface)
340{
341 VkResult result = VK_SUCCESS;
342 VkBool32 skipCall = VK_FALSE;
343 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
344
345 // Validate that a valid VkInstance was used:
346 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
347 if (!pInstance) {
Ian Elliott1bf155f2015-12-29 17:35:46 -0700348 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700349 instance,
350 "VkInstance");
351 }
352
353 if (VK_FALSE == skipCall) {
354 // Call down the call chain:
355 result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700356 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700357
358 if ((result == VK_SUCCESS) && pInstance && pSurface) {
359 // Record the VkSurfaceKHR returned by the ICD:
360 my_data->surfaceMap[*pSurface].surface = *pSurface;
361 my_data->surfaceMap[*pSurface].pInstance = pInstance;
362 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_ANDROID;
363 // Point to the associated SwpInstance:
364 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
365 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
366 }
367 return result;
368 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700369 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700370}
371#endif // VK_USE_PLATFORM_ANDROID_KHR
372
373#ifdef VK_USE_PLATFORM_MIR_KHR
374VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(
375 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700376 const VkMirSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700377 const VkAllocationCallbacks* pAllocator,
378 VkSurfaceKHR* pSurface)
379{
380 VkResult result = VK_SUCCESS;
381 VkBool32 skipCall = VK_FALSE;
382 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
383
384 // Validate that a valid VkInstance was used:
385 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
386 if (!pInstance) {
Ian Elliott1bf155f2015-12-29 17:35:46 -0700387 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700388 instance,
389 "VkInstance");
390 }
391
392 if (VK_FALSE == skipCall) {
393 // Call down the call chain:
394 result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700395 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700396
397 if ((result == VK_SUCCESS) && pInstance && pSurface) {
398 // Record the VkSurfaceKHR returned by the ICD:
399 my_data->surfaceMap[*pSurface].surface = *pSurface;
400 my_data->surfaceMap[*pSurface].pInstance = pInstance;
401 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_MIR;
402 // Point to the associated SwpInstance:
403 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
404 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
405 }
406 return result;
407 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700408 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700409}
Ian Elliott55ff7962015-12-30 10:18:47 -0700410
411VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceMirPresentationSupportKHR(
412 VkPhysicalDevice physicalDevice,
413 uint32_t queueFamilyIndex,
414 MirConnection* connection)
415{
416 VkBool32 result = VK_FALSE;
417 VkBool32 skipCall = VK_FALSE;
418 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
419
420 // Validate that a valid VkPhysicalDevice was used, and that the instance
421 // extension was enabled:
422 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
423 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
424 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
425 physicalDevice,
426 "VkPhysicalDevice");
427 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
428 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
429 pPhysicalDevice->pInstance,
430 "VkInstance",
431 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
432 "%s() called even though the %s extension was not enabled for this VkInstance.",
433 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
434 }
435
436 if (VK_FALSE == skipCall) {
437 // Call down the call chain:
438 result = my_data->instance_dispatch_table->GetPhysicalDeviceMirPresentationSupportKHR(
439 physicalDevice, queueFamilyIndex, connection);
440
441 if (pPhysicalDevice) {
442 // Record the result of this query:
443 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
444 }
445 }
446 return result;
447}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700448#endif // VK_USE_PLATFORM_MIR_KHR
449
450#ifdef VK_USE_PLATFORM_WAYLAND_KHR
451VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
452 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700453 const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700454 const VkAllocationCallbacks* pAllocator,
455 VkSurfaceKHR* pSurface)
456{
457 VkResult result = VK_SUCCESS;
458 VkBool32 skipCall = VK_FALSE;
459 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
460
461 // Validate that a valid VkInstance was used:
462 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
463 if (!pInstance) {
Ian Elliott1bf155f2015-12-29 17:35:46 -0700464 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700465 instance,
466 "VkInstance");
467 }
468
469 if (VK_FALSE == skipCall) {
470 // Call down the call chain:
471 result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700472 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700473
474 if ((result == VK_SUCCESS) && pInstance && pSurface) {
475 // Record the VkSurfaceKHR returned by the ICD:
476 my_data->surfaceMap[*pSurface].surface = *pSurface;
477 my_data->surfaceMap[*pSurface].pInstance = pInstance;
478 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_WAYLAND;
479 // Point to the associated SwpInstance:
480 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
481 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
482 }
483 return result;
484 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700485 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700486}
Ian Elliott55ff7962015-12-30 10:18:47 -0700487
488VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(
489 VkPhysicalDevice physicalDevice,
490 uint32_t queueFamilyIndex,
491 struct wl_display* display)
492{
493 VkBool32 result = VK_FALSE;
494 VkBool32 skipCall = VK_FALSE;
495 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
496
497 // Validate that a valid VkPhysicalDevice was used, and that the instance
498 // extension was enabled:
499 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
500 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
501 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
502 physicalDevice,
503 "VkPhysicalDevice");
504 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
505 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
506 pPhysicalDevice->pInstance,
507 "VkInstance",
508 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
509 "%s() called even though the %s extension was not enabled for this VkInstance.",
510 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
511 }
512
513 if (VK_FALSE == skipCall) {
514 // Call down the call chain:
515 result = my_data->instance_dispatch_table->GetPhysicalDeviceWaylandPresentationSupportKHR(
516 physicalDevice, queueFamilyIndex, display);
517
518 if (pPhysicalDevice) {
519 // Record the result of this query:
520 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
521 }
522 }
523 return result;
524}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700525#endif // VK_USE_PLATFORM_WAYLAND_KHR
526
527#ifdef VK_USE_PLATFORM_WIN32_KHR
528VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
529 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700530 const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700531 const VkAllocationCallbacks* pAllocator,
532 VkSurfaceKHR* pSurface)
533{
534 VkResult result = VK_SUCCESS;
535 VkBool32 skipCall = VK_FALSE;
536 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
537
538 // Validate that a valid VkInstance was used:
539 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
540 if (!pInstance) {
Ian Elliott1bf155f2015-12-29 17:35:46 -0700541 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700542 instance,
543 "VkInstance");
544 }
545
546 if (VK_FALSE == skipCall) {
547 // Call down the call chain:
548 result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700549 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700550
551 if ((result == VK_SUCCESS) && pInstance && pSurface) {
552 // Record the VkSurfaceKHR returned by the ICD:
553 my_data->surfaceMap[*pSurface].surface = *pSurface;
554 my_data->surfaceMap[*pSurface].pInstance = pInstance;
555 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_WIN32;
556 // Point to the associated SwpInstance:
557 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
558 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
559 }
560 return result;
561 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700562 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700563}
Ian Elliott55ff7962015-12-30 10:18:47 -0700564
565VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(
566 VkPhysicalDevice physicalDevice,
567 uint32_t queueFamilyIndex)
568{
569 VkBool32 result = VK_FALSE;
570 VkBool32 skipCall = VK_FALSE;
571 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
572
573 // Validate that a valid VkPhysicalDevice was used, and that the instance
574 // extension was enabled:
575 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
576 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
577 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
578 physicalDevice,
579 "VkPhysicalDevice");
580 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
581 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
582 pPhysicalDevice->pInstance,
583 "VkInstance",
584 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
585 "%s() called even though the %s extension was not enabled for this VkInstance.",
586 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
587 }
588
589 if (VK_FALSE == skipCall) {
590 // Call down the call chain:
591 result = my_data->instance_dispatch_table->GetPhysicalDeviceWin32PresentationSupportKHR(
592 physicalDevice, queueFamilyIndex);
593
594 if (pPhysicalDevice) {
595 // Record the result of this query:
596 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
597 }
598 }
599 return result;
600}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700601#endif // VK_USE_PLATFORM_WIN32_KHR
602
603#ifdef VK_USE_PLATFORM_XCB_KHR
604VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
605 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700606 const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700607 const VkAllocationCallbacks* pAllocator,
608 VkSurfaceKHR* pSurface)
609{
610 VkResult result = VK_SUCCESS;
611 VkBool32 skipCall = VK_FALSE;
612 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
613
614 // Validate that a valid VkInstance was used:
615 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
616 if (!pInstance) {
Ian Elliott1bf155f2015-12-29 17:35:46 -0700617 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700618 instance,
619 "VkInstance");
620 }
621
622 if (VK_FALSE == skipCall) {
623 // Call down the call chain:
624 result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700625 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700626
627 if ((result == VK_SUCCESS) && pInstance && pSurface) {
628 // Record the VkSurfaceKHR returned by the ICD:
629 my_data->surfaceMap[*pSurface].surface = *pSurface;
630 my_data->surfaceMap[*pSurface].pInstance = pInstance;
631 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_XCB;
632 // Point to the associated SwpInstance:
633 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
634 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
635 }
636 return result;
637 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700638 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700639}
Ian Elliott55ff7962015-12-30 10:18:47 -0700640
641VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(
642 VkPhysicalDevice physicalDevice,
643 uint32_t queueFamilyIndex,
644 xcb_connection_t* connection,
645 xcb_visualid_t visual_id)
646{
647 VkBool32 result = VK_FALSE;
648 VkBool32 skipCall = VK_FALSE;
649 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
650
651 // Validate that a valid VkPhysicalDevice was used, and that the instance
652 // extension was enabled:
653 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
654 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
655 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
656 physicalDevice,
657 "VkPhysicalDevice");
658 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
659 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
660 pPhysicalDevice->pInstance,
661 "VkInstance",
662 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
663 "%s() called even though the %s extension was not enabled for this VkInstance.",
664 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
665 }
666
667 if (VK_FALSE == skipCall) {
668 // Call down the call chain:
669 result = my_data->instance_dispatch_table->GetPhysicalDeviceXcbPresentationSupportKHR(
670 physicalDevice, queueFamilyIndex, connection, visual_id);
671
672 if (pPhysicalDevice) {
673 // Record the result of this query:
674 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
675 }
676 }
677 return result;
678}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700679#endif // VK_USE_PLATFORM_XCB_KHR
680
681#ifdef VK_USE_PLATFORM_XLIB_KHR
682VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
683 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700684 const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700685 const VkAllocationCallbacks* pAllocator,
686 VkSurfaceKHR* pSurface)
687{
688 VkResult result = VK_SUCCESS;
689 VkBool32 skipCall = VK_FALSE;
690 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
691
692 // Validate that a valid VkInstance was used:
693 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
694 if (!pInstance) {
Ian Elliott1bf155f2015-12-29 17:35:46 -0700695 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700696 instance,
697 "VkInstance");
698 }
699
700 if (VK_FALSE == skipCall) {
701 // Call down the call chain:
702 result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700703 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700704
705 if ((result == VK_SUCCESS) && pInstance && pSurface) {
706 // Record the VkSurfaceKHR returned by the ICD:
707 my_data->surfaceMap[*pSurface].surface = *pSurface;
708 my_data->surfaceMap[*pSurface].pInstance = pInstance;
709 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_XLIB;
710 // Point to the associated SwpInstance:
711 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
712 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
713 }
714 return result;
715 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700716 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700717}
Ian Elliott55ff7962015-12-30 10:18:47 -0700718
719VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(
720 VkPhysicalDevice physicalDevice,
721 uint32_t queueFamilyIndex,
722 Display* dpy,
723 VisualID visualID)
724{
725 VkBool32 result = VK_FALSE;
726 VkBool32 skipCall = VK_FALSE;
727 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
728
729 // Validate that a valid VkPhysicalDevice was used, and that the instance
730 // extension was enabled:
731 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
732 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
733 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
734 physicalDevice,
735 "VkPhysicalDevice");
736 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
737 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
738 pPhysicalDevice->pInstance,
739 "VkInstance",
740 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
741 "%s() called even though the %s extension was not enabled for this VkInstance.",
742 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
743 }
744
745 if (VK_FALSE == skipCall) {
746 // Call down the call chain:
747 result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR(
748 physicalDevice, queueFamilyIndex, dpy, visualID);
749
750 if (pPhysicalDevice) {
751 // Record the result of this query:
752 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
753 }
754 }
755 return result;
756}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700757#endif // VK_USE_PLATFORM_XLIB_KHR
758
759VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator)
760{
761 VkBool32 skipCall = VK_FALSE;
762 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
763
764 // Validate that a valid VkInstance was used:
765 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
766 if (!pInstance) {
Ian Elliott1bf155f2015-12-29 17:35:46 -0700767 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700768 instance,
769 "VkInstance");
770 }
771
772 if (VK_FALSE == skipCall) {
773 // Validate that a valid VkSurfaceKHR was used:
774 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
775 }
776
777 if (VK_FALSE == skipCall) {
778 // Call down the call chain:
779 my_data->instance_dispatch_table->DestroySurfaceKHR(
780 instance, surface, pAllocator);
781 }
782
783 // Regardless of skipCall value, do some internal cleanup:
784 SwpSurface *pSurface = &my_data->surfaceMap[surface];
785 if (pSurface && pSurface->pInstance) {
786 pSurface->pInstance->surfaces.erase(surface);
787 }
788 my_data->surfaceMap.erase(surface);
789}
790
Chia-I Wu9ab61502015-11-06 06:42:02 +0800791VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600792{
793 VkResult result = VK_SUCCESS;
794 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600795 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600796
797 // Validate that a valid VkInstance was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600798 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600799 if (!pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700800 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600801 instance,
802 "VkInstance");
803 }
804
805 if (VK_FALSE == skipCall) {
806 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600807 result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(
Ian Elliott0b4d6242015-09-22 10:51:24 -0600808 instance, pPhysicalDeviceCount, pPhysicalDevices);
809
810 if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices &&
811 (*pPhysicalDeviceCount > 0)) {
812 // Record the VkPhysicalDevices returned by the ICD:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600813 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600814 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis711ff312015-10-29 12:58:13 -0600815 my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice =
Ian Elliott0b4d6242015-09-22 10:51:24 -0600816 pPhysicalDevices[i];
Tobin Ehlis711ff312015-10-29 12:58:13 -0600817 my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance;
818 my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL;
Ian Elliott27d39c72015-11-20 16:39:34 -0700819 my_data->physicalDeviceMap[pPhysicalDevices[i]].gotSurfaceCapabilities = false;
820 my_data->physicalDeviceMap[pPhysicalDevices[i]].surfaceFormatCount = 0;
821 my_data->physicalDeviceMap[pPhysicalDevices[i]].pSurfaceFormats = NULL;
822 my_data->physicalDeviceMap[pPhysicalDevices[i]].presentModeCount = 0;
823 my_data->physicalDeviceMap[pPhysicalDevices[i]].pPresentModes = NULL;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600824 // Point to the associated SwpInstance:
825 pInstance->physicalDevices[pPhysicalDevices[i]] =
Tobin Ehlis711ff312015-10-29 12:58:13 -0600826 &my_data->physicalDeviceMap[pPhysicalDevices[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600827 }
828 }
829
830 return result;
831 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700832 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600833}
834
Chia-I Wu9ab61502015-11-06 06:42:02 +0800835VK_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 -0600836{
837 VkResult result = VK_SUCCESS;
838 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600839 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600840
841 // Validate that a valid VkPhysicalDevice was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600842 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600843 if (!pPhysicalDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700844 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Mark Lobodzinski6c1cb5a2015-11-05 15:27:03 -0700845 physicalDevice, "VkPhysicalDevice");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600846 }
847
Tobin Ehlis711ff312015-10-29 12:58:13 -0600848 if (VK_TRUE == skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700849 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600850
851 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
852 // Call down the call chain:
853 result = my_device_data->device_dispatch_table->CreateDevice(
Chia-I Wuf7458c52015-10-26 21:10:41 +0800854 physicalDevice, pCreateInfo, pAllocator, pDevice);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600855 if (result == VK_SUCCESS) {
856 // Since it succeeded, do layer-specific work:
Mark Lobodzinski6c1cb5a2015-11-05 15:27:03 -0700857 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
858 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
859 createDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600860 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600861 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600862}
863
Chia-I Wu9ab61502015-11-06 06:42:02 +0800864VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600865{
866 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600867 dispatch_key key = get_dispatch_key(device);
868 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600869 // Validate that a valid VkDevice was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600870 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600871 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700872 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600873 device,
874 "VkDevice");
875 }
876
877 if (VK_FALSE == skipCall) {
878 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800879 my_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600880 }
881
882 // Regardless of skipCall value, do some internal cleanup:
883 if (pDevice) {
884 // Delete the SwpDevice associated with this device:
885 if (pDevice->pPhysicalDevice) {
886 pDevice->pPhysicalDevice->pDevice = NULL;
887 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600888 if (!pDevice->swapchains.empty()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700889 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600890 SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600891 "%s() called before all of its associated "
892 "VkSwapchainKHRs were destroyed.",
893 __FUNCTION__);
894 // Empty and then delete all SwpSwapchain's
895 for (auto it = pDevice->swapchains.begin() ;
896 it != pDevice->swapchains.end() ; it++) {
897 // Delete all SwpImage's
898 it->second->images.clear();
899 }
900 pDevice->swapchains.clear();
901 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600902 my_data->deviceMap.erase(device);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600903 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600904 delete my_data->device_dispatch_table;
905 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600906}
907
Ian Elliott27d39c72015-11-20 16:39:34 -0700908VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
909 VkPhysicalDevice physicalDevice,
910 uint32_t queueFamilyIndex,
911 VkSurfaceKHR surface,
912 VkBool32* pSupported)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600913{
Ian Elliott320d0fc2015-12-30 12:04:43 -0700914// TODOs:
915//
916// - Ensure that queueFamilyIndex is a valid queue family index for
917// physicalDevice. How? Probably need to record data from another function
918// call(s).
Ian Elliott0b4d6242015-09-22 10:51:24 -0600919 VkResult result = VK_SUCCESS;
920 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600921 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600922
923 // Validate that a valid VkPhysicalDevice was used, and that the instance
924 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600925 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600926 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700927 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600928 physicalDevice,
929 "VkPhysicalDevice");
Ian Elliott1cb77a62015-12-29 16:44:39 -0700930 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700931 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600932 pPhysicalDevice->pInstance,
933 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600934 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -0800935 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott1dcd1092015-11-17 17:29:40 -0700936 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600937 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700938 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
Ian Elliottf955d682015-12-30 12:00:54 -0700939 if (!pSupported) {
940 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
941 physicalDevice,
942 "pSupported");
943 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600944
945 if (VK_FALSE == skipCall) {
946 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600947 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -0700948 physicalDevice, queueFamilyIndex, surface,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600949 pSupported);
950
951 if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) {
952 // Record the result of this query:
953 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] =
954 *pSupported;
955 // TODO: We need to compare this with the actual queue used for
956 // presentation, to ensure it was advertised to the application as
957 // supported for presentation.
958 }
959
960 return result;
961 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700962 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600963}
964
Ian Elliott27d39c72015-11-20 16:39:34 -0700965VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
966 VkPhysicalDevice physicalDevice,
967 VkSurfaceKHR surface,
968 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600969{
970 VkResult result = VK_SUCCESS;
971 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700972 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600973
Ian Elliott27d39c72015-11-20 16:39:34 -0700974 // Validate that a valid VkPhysicalDevice was used, and that the instance
Ian Elliott0b4d6242015-09-22 10:51:24 -0600975 // extension was enabled:
Ian Elliott27d39c72015-11-20 16:39:34 -0700976 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
977 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700978 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700979 physicalDevice,
980 "VkPhysicalDevice");
Ian Elliott1cb77a62015-12-29 16:44:39 -0700981 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700982 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700983 pPhysicalDevice->pInstance,
984 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600985 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700986 "%s() called even though the %s extension was not enabled for this VkInstance.",
987 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600988 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700989 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
Ian Elliottf955d682015-12-30 12:00:54 -0700990 if (!pSurfaceCapabilities) {
991 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
992 physicalDevice,
993 "pSurfaceCapabilities");
994 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600995
996 if (VK_FALSE == skipCall) {
997 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700998 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceCapabilitiesKHR(
999 physicalDevice, surface, pSurfaceCapabilities);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001000
Ian Elliott27d39c72015-11-20 16:39:34 -07001001 if ((result == VK_SUCCESS) && pPhysicalDevice) {
Ian Elliottf955d682015-12-30 12:00:54 -07001002 // Record the result of this query:
Ian Elliott27d39c72015-11-20 16:39:34 -07001003 pPhysicalDevice->gotSurfaceCapabilities = true;
1004// FIXME: NEED TO COPY THIS DATA, BECAUSE pSurfaceCapabilities POINTS TO APP-ALLOCATED DATA
1005 pPhysicalDevice->surfaceCapabilities = *pSurfaceCapabilities;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001006 }
1007
1008 return result;
1009 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001010 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001011}
1012
Ian Elliott27d39c72015-11-20 16:39:34 -07001013VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
1014 VkPhysicalDevice physicalDevice,
1015 VkSurfaceKHR surface,
Ian Elliottf955d682015-12-30 12:00:54 -07001016 uint32_t* pSurfaceFormatCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001017 VkSurfaceFormatKHR* pSurfaceFormats)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001018{
1019 VkResult result = VK_SUCCESS;
1020 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -07001021 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001022
Ian Elliott27d39c72015-11-20 16:39:34 -07001023 // Validate that a valid VkPhysicalDevice was used, and that the instance
Ian Elliott0b4d6242015-09-22 10:51:24 -06001024 // extension was enabled:
Ian Elliott27d39c72015-11-20 16:39:34 -07001025 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
1026 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001027 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001028 physicalDevice,
1029 "VkPhysicalDevice");
Ian Elliott1cb77a62015-12-29 16:44:39 -07001030 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001031 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001032 pPhysicalDevice->pInstance,
1033 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001034 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -07001035 "%s() called even though the %s extension was not enabled for this VkInstance.",
1036 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001037 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001038 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
Ian Elliottf955d682015-12-30 12:00:54 -07001039 if (!pSurfaceFormatCount) {
1040 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1041 physicalDevice,
1042 "pSurfaceFormatCount");
1043 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001044
1045 if (VK_FALSE == skipCall) {
1046 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001047 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceFormatsKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001048 physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001049
Ian Elliottf955d682015-12-30 12:00:54 -07001050 if ((result == VK_SUCCESS) && pPhysicalDevice && !pSurfaceFormats &&
1051 pSurfaceFormatCount) {
1052 // Record the result of this preliminary query:
1053 pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount;
1054 }
Ian Elliott9059b302015-12-30 13:14:36 -07001055 else if ((result == VK_SUCCESS) && pPhysicalDevice && pSurfaceFormats &&
1056 pSurfaceFormatCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001057 // Compare the preliminary value of *pSurfaceFormatCount with the
1058 // value this time:
1059 if (*pSurfaceFormatCount != pPhysicalDevice->surfaceFormatCount) {
1060 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1061 physicalDevice,
1062 "pSurfaceFormatCount",
1063 "pSurfaceFormats",
1064 pPhysicalDevice->surfaceFormatCount);
1065 }
Ian Elliott9059b302015-12-30 13:14:36 -07001066 else if (*pSurfaceFormatCount > 0) {
1067 // Record the result of this query:
1068 pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount;
1069 pPhysicalDevice->pSurfaceFormats = (VkSurfaceFormatKHR *)
1070 malloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR));
1071 if (pPhysicalDevice->pSurfaceFormats) {
1072 for (uint32_t i = 0 ; i < *pSurfaceFormatCount ; i++) {
1073 pPhysicalDevice->pSurfaceFormats[i] = pSurfaceFormats[i];
1074 }
1075 } else {
1076 pPhysicalDevice->surfaceFormatCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001077 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001078 }
1079 }
1080
1081 return result;
1082 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001083 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001084}
1085
Ian Elliott27d39c72015-11-20 16:39:34 -07001086VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
1087 VkPhysicalDevice physicalDevice,
1088 VkSurfaceKHR surface,
Ian Elliottf955d682015-12-30 12:00:54 -07001089 uint32_t* pPresentModeCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001090 VkPresentModeKHR* pPresentModes)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001091{
1092 VkResult result = VK_SUCCESS;
1093 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -07001094 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001095
Ian Elliott27d39c72015-11-20 16:39:34 -07001096 // Validate that a valid VkPhysicalDevice was used, and that the instance
Ian Elliott0b4d6242015-09-22 10:51:24 -06001097 // extension was enabled:
Ian Elliott27d39c72015-11-20 16:39:34 -07001098 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
1099 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001100 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001101 physicalDevice,
1102 "VkPhysicalDevice");
Ian Elliott1cb77a62015-12-29 16:44:39 -07001103 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001104 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001105 pPhysicalDevice->pInstance,
1106 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001107 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -07001108 "%s() called even though the %s extension was not enabled for this VkInstance.",
1109 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001110 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001111 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
Ian Elliottf955d682015-12-30 12:00:54 -07001112 if (!pPresentModeCount) {
1113 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1114 physicalDevice,
1115 "pPresentModeCount");
1116 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001117
1118 if (VK_FALSE == skipCall) {
1119 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001120 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfacePresentModesKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001121 physicalDevice, surface, pPresentModeCount, pPresentModes);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001122
Ian Elliottf955d682015-12-30 12:00:54 -07001123 if ((result == VK_SUCCESS) && pPhysicalDevice && !pPresentModes &&
1124 pPresentModeCount) {
1125 // Record the result of this preliminary query:
1126 pPhysicalDevice->presentModeCount = *pPresentModeCount;
1127 }
Ian Elliott9059b302015-12-30 13:14:36 -07001128 else if ((result == VK_SUCCESS) && pPhysicalDevice && pPresentModes &&
1129 pPresentModeCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001130 // Compare the preliminary value of *pPresentModeCount with the
1131 // value this time:
1132 if (*pPresentModeCount != pPhysicalDevice->presentModeCount) {
1133 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1134 physicalDevice,
1135 "pPresentModeCount",
1136 "pPresentModes",
1137 pPhysicalDevice->presentModeCount);
1138 }
Ian Elliott9059b302015-12-30 13:14:36 -07001139 else if (*pPresentModeCount > 0) {
1140 // Record the result of this query:
1141 pPhysicalDevice->presentModeCount = *pPresentModeCount;
1142 pPhysicalDevice->pPresentModes = (VkPresentModeKHR *)
1143 malloc(*pPresentModeCount * sizeof(VkPresentModeKHR));
1144 if (pPhysicalDevice->pSurfaceFormats) {
1145 for (uint32_t i = 0 ; i < *pPresentModeCount ; i++) {
1146 pPhysicalDevice->pPresentModes[i] = pPresentModes[i];
1147 }
1148 } else {
1149 pPhysicalDevice->presentModeCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001150 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001151 }
1152 }
1153
1154 return result;
1155 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001156 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001157}
1158
1159// This function does the up-front validation work for vkCreateSwapchainKHR(),
1160// and returns VK_TRUE if a logging callback indicates that the call down the
1161// chain should be skipped:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001162static VkBool32 validateCreateSwapchainKHR(
1163 VkDevice device,
1164 const VkSwapchainCreateInfoKHR* pCreateInfo,
1165 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001166{
1167// TODO: Validate cases of re-creating a swapchain (the current code
1168// assumes a new swapchain is being created).
1169 VkResult result = VK_SUCCESS;
1170 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001171 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001172 char fn[] = "vkCreateSwapchainKHR";
1173
1174 // Validate that a valid VkDevice was used, and that the device
1175 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001176 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001177 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001178 return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001179 SWAPCHAIN_INVALID_HANDLE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001180 "%s() called with a non-valid %s.",
1181 fn, "VkDevice");
1182
Ian Elliott427058f2015-12-29 16:45:49 -07001183 } else if (!pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001184 return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001185 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001186 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001187 fn, VK_KHR_SWAPCHAIN_EXTENSION_NAME );
Ian Elliott0b4d6242015-09-22 10:51:24 -06001188 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001189 if (!pCreateInfo) {
1190 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1191 device,
1192 "pCreateInfo");
1193 } else if (pCreateInfo->sType != VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR) {
1194 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1195 device,
1196 "pCreateInfo",
1197 "VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR");
1198 } else if (pCreateInfo->pNext != NULL) {
1199 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1200 device,
1201 "pCreateInfo");
1202 }
1203 if (!pSwapchain) {
1204 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1205 device,
1206 "pSwapchain");
1207 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001208
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001209 // Keep around a useful pointer to pPhysicalDevice:
1210 SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice;
1211
1212 // Validate pCreateInfo->surface:
1213 if (pPhysicalDevice) {
1214 // Note: in order to validate, we must lookup layer_data based on the
1215 // VkInstance associated with this VkDevice:
1216 SwpInstance *pInstance =
1217 (pPhysicalDevice) ? pPhysicalDevice->pInstance : NULL;
1218 layer_data *my_instance_data =
1219 (pInstance) ? get_my_data_ptr(get_dispatch_key(pInstance->instance), layer_data_map) : NULL;
1220 skipCall |= validateSurface(my_instance_data,
1221 pCreateInfo->surface,
1222 (char *) "vkCreateSwapchainKHR");
1223 }
1224
1225 // Validate pCreateInfo values with the results of
1226 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1227 if (!pPhysicalDevice || !pPhysicalDevice->gotSurfaceCapabilities) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001228 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001229 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001230 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001231 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001232 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001233 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001234 // Validate pCreateInfo->minImageCount against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001235 // VkSurfaceCapabilitiesKHR::{min|max}ImageCount:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001236 VkSurfaceCapabilitiesKHR *pCapabilities = &pPhysicalDevice->surfaceCapabilities;
Ian Elliott27d39c72015-11-20 16:39:34 -07001237 if ((pCreateInfo->minImageCount < pCapabilities->minImageCount) ||
1238 ((pCapabilities->maxImageCount > 0) &&
1239 (pCreateInfo->minImageCount > pCapabilities->maxImageCount))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001240 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001241 SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001242 "%s() called with pCreateInfo->minImageCount "
1243 "= %d, which is outside the bounds returned "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001244 "by vkGetPhysicalDeviceSurfaceCapabilitiesKHR() (i.e. "
Ian Elliott0b4d6242015-09-22 10:51:24 -06001245 "minImageCount = %d, maxImageCount = %d).",
1246 fn,
1247 pCreateInfo->minImageCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001248 pCapabilities->minImageCount,
1249 pCapabilities->maxImageCount);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001250 }
1251 // Validate pCreateInfo->imageExtent against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001252 // VkSurfaceCapabilitiesKHR::{current|min|max}ImageExtent:
Ian Elliott27d39c72015-11-20 16:39:34 -07001253 if ((pCapabilities->currentExtent.width == -1) &&
1254 ((pCreateInfo->imageExtent.width < pCapabilities->minImageExtent.width) ||
1255 (pCreateInfo->imageExtent.width > pCapabilities->maxImageExtent.width) ||
1256 (pCreateInfo->imageExtent.height < pCapabilities->minImageExtent.height) ||
1257 (pCreateInfo->imageExtent.height > pCapabilities->maxImageExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001258 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001259 SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001260 "%s() called with pCreateInfo->imageExtent = "
1261 "(%d,%d), which is outside the bounds "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001262 "returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): "
Ian Elliott0b4d6242015-09-22 10:51:24 -06001263 "currentExtent = (%d,%d), minImageExtent = "
1264 "(%d,%d), maxImageExtent = (%d,%d).",
1265 fn,
1266 pCreateInfo->imageExtent.width,
1267 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001268 pCapabilities->currentExtent.width,
1269 pCapabilities->currentExtent.height,
1270 pCapabilities->minImageExtent.width,
1271 pCapabilities->minImageExtent.height,
1272 pCapabilities->maxImageExtent.width,
1273 pCapabilities->maxImageExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001274 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001275 if ((pCapabilities->currentExtent.width != -1) &&
1276 ((pCreateInfo->imageExtent.width != pCapabilities->currentExtent.width) ||
1277 (pCreateInfo->imageExtent.height != pCapabilities->currentExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001278 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001279 SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001280 "%s() called with pCreateInfo->imageExtent = "
1281 "(%d,%d), which is not equal to the "
1282 "currentExtent = (%d,%d) returned by "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001283 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001284 fn,
1285 pCreateInfo->imageExtent.width,
1286 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001287 pCapabilities->currentExtent.width,
1288 pCapabilities->currentExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001289 }
1290 // Validate pCreateInfo->preTransform against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001291 // VkSurfaceCapabilitiesKHR::supportedTransforms:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001292 if (!((pCreateInfo->preTransform) & pCapabilities->supportedTransforms)) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001293 // This is an error situation; one for which we'd like to give
1294 // the developer a helpful, multi-line error message. Build it
1295 // up a little at a time, and then log it:
1296 std::string errorString = "";
1297 char str[1024];
1298 // Here's the first part of the message:
1299 sprintf(str, "%s() called with a non-supported "
1300 "pCreateInfo->preTransform (i.e. %s). "
1301 "Supported values are:\n",
1302 fn,
1303 surfaceTransformStr(pCreateInfo->preTransform));
1304 errorString += str;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001305 for (int i = 0; i < 32; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001306 // Build up the rest of the message:
Ian Elliott27d39c72015-11-20 16:39:34 -07001307 if ((1 << i) & pCapabilities->supportedTransforms) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001308 const char *newStr =
Ian Elliott27d39c72015-11-20 16:39:34 -07001309 surfaceTransformStr((VkSurfaceTransformFlagBitsKHR) (1 << i));
Ian Elliott0b4d6242015-09-22 10:51:24 -06001310 sprintf(str, " %s\n", newStr);
1311 errorString += str;
1312 }
1313 }
1314 // Log the message that we've built up:
Ian Elliott68124ac2015-10-07 16:18:35 -06001315 skipCall |= debug_report_log_msg(my_data->report_data,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001316 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1317 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Mark Lobodzinski80e774f2016-01-04 15:54:59 -07001318 (uint64_t) device, __LINE__,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001319 SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM,
1320 LAYER_NAME,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001321 errorString.c_str());
1322 }
Ian Elliotta2a89c52015-12-28 15:23:57 -07001323 // Validate pCreateInfo->compositeAlpha against
1324 // VkSurfaceCapabilitiesKHR::supportedCompositeAlpha:
1325 if (!((pCreateInfo->compositeAlpha) & pCapabilities->supportedCompositeAlpha)) {
1326 // This is an error situation; one for which we'd like to give
1327 // the developer a helpful, multi-line error message. Build it
1328 // up a little at a time, and then log it:
1329 std::string errorString = "";
1330 char str[1024];
1331 // Here's the first part of the message:
1332 sprintf(str, "%s() called with a non-supported "
1333 "pCreateInfo->compositeAlpha (i.e. %s). "
1334 "Supported values are:\n",
1335 fn,
1336 surfaceCompositeAlphaStr(pCreateInfo->compositeAlpha));
1337 errorString += str;
1338 for (int i = 0; i < 32; i++) {
1339 // Build up the rest of the message:
1340 if ((1 << i) & pCapabilities->supportedCompositeAlpha) {
1341 const char *newStr =
1342 surfaceCompositeAlphaStr((VkCompositeAlphaFlagBitsKHR) (1 << i));
1343 sprintf(str, " %s\n", newStr);
1344 errorString += str;
1345 }
1346 }
1347 // Log the message that we've built up:
1348 skipCall |= debug_report_log_msg(my_data->report_data,
Ian Elliott1bf155f2015-12-29 17:35:46 -07001349 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1350 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliotta2a89c52015-12-28 15:23:57 -07001351 (uint64_t) device, 0,
1352 SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA,
1353 LAYER_NAME,
1354 errorString.c_str());
1355 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001356 // Validate pCreateInfo->imageArraySize against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001357 // VkSurfaceCapabilitiesKHR::maxImageArraySize:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001358 if ((pCreateInfo->imageArrayLayers > 0) &&
1359 (pCreateInfo->imageArrayLayers > pCapabilities->maxImageArrayLayers)) {
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_ARRAY_SIZE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001362 "%s() called with a non-supported "
1363 "pCreateInfo->imageArraySize (i.e. %d). "
1364 "Maximum value is %d.",
1365 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001366 pCreateInfo->imageArrayLayers,
1367 pCapabilities->maxImageArrayLayers);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001368 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001369 // Validate pCreateInfo->imageUsage against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001370 // VkSurfaceCapabilitiesKHR::supportedUsageFlags:
Ian Elliott27d39c72015-11-20 16:39:34 -07001371 if (pCreateInfo->imageUsage &&
1372 (pCreateInfo->imageUsage !=
1373 (pCreateInfo->imageUsage & pCapabilities->supportedUsageFlags))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001374 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001375 SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001376 "%s() called with a non-supported "
Ian Elliott27d39c72015-11-20 16:39:34 -07001377 "pCreateInfo->imageUsage (i.e. 0x%08x)."
Ian Elliott0b4d6242015-09-22 10:51:24 -06001378 " Supported flag bits are 0x%08x.",
1379 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001380 pCreateInfo->imageUsage,
1381 pCapabilities->supportedUsageFlags);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001382 }
1383 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001384
1385 // Validate pCreateInfo values with the results of
1386 // vkGetPhysicalDeviceSurfaceFormatsKHR():
1387 if (!pPhysicalDevice || !pPhysicalDevice->surfaceFormatCount) {
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_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001390 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001391 "vkGetPhysicalDeviceSurfaceFormatsKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001392 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001393 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001394 // Validate pCreateInfo->imageFormat against
1395 // VkSurfaceFormatKHR::format:
1396 bool foundFormat = false;
1397 bool foundColorSpace = false;
1398 bool foundMatch = false;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001399 for (uint32_t i = 0 ; i < pPhysicalDevice->surfaceFormatCount ; i++) {
1400 if (pCreateInfo->imageFormat == pPhysicalDevice->pSurfaceFormats[i].format) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001401 // Validate pCreateInfo->imageColorSpace against
1402 // VkSurfaceFormatKHR::colorSpace:
1403 foundFormat = true;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001404 if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001405 foundMatch = true;
1406 break;
1407 }
1408 } else {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001409 if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001410 foundColorSpace = true;
1411 }
1412 }
1413 }
1414 if (!foundMatch) {
1415 if (!foundFormat) {
1416 if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001417 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001418 "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001419 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001420 "%s() called with neither a "
1421 "supported pCreateInfo->imageFormat "
1422 "(i.e. %d) nor a supported "
1423 "pCreateInfo->imageColorSpace "
1424 "(i.e. %d).",
1425 fn,
1426 pCreateInfo->imageFormat,
1427 pCreateInfo->imageColorSpace);
1428 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001429 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001430 "VkDevice",
1431 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001432 "%s() called with a non-supported "
1433 "pCreateInfo->imageFormat (i.e. %d).",
1434 fn, pCreateInfo->imageFormat);
1435 }
1436 } else if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001437 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001438 SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001439 "%s() called with a non-supported "
1440 "pCreateInfo->imageColorSpace (i.e. %d).",
1441 fn, pCreateInfo->imageColorSpace);
1442 }
1443 }
1444 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001445
1446 // Validate pCreateInfo values with the results of
1447 // vkGetPhysicalDeviceSurfacePresentModesKHR():
1448 if (!pPhysicalDevice || !pPhysicalDevice->presentModeCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001449 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001450 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001451 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001452 "vkGetPhysicalDeviceSurfacePresentModesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001453 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001454 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001455 // Validate pCreateInfo->presentMode against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001456 // vkGetPhysicalDeviceSurfacePresentModesKHR():
Ian Elliott0b4d6242015-09-22 10:51:24 -06001457 bool foundMatch = false;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001458 for (uint32_t i = 0 ; i < pPhysicalDevice->presentModeCount ; i++) {
1459 if (pPhysicalDevice->pPresentModes[i] == pCreateInfo->presentMode) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001460 foundMatch = true;
1461 break;
1462 }
1463 }
1464 if (!foundMatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001465 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001466 SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001467 "%s() called with a non-supported "
1468 "pCreateInfo->presentMode (i.e. %s).",
1469 fn,
1470 presentModeStr(pCreateInfo->presentMode));
1471 }
1472 }
1473
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001474 // Validate pCreateInfo->imageSharingMode and related values:
Ian Elliotta2a89c52015-12-28 15:23:57 -07001475 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
1476 if ((pCreateInfo->queueFamilyIndexCount <= 1) ||
1477 !pCreateInfo->pQueueFamilyIndices) {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001478 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001479 SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES,
1480 "%s() called with a supported "
1481 "pCreateInfo->sharingMode of (i.e. %s),"
1482 "but with a bad value(s) for "
1483 "pCreateInfo->queueFamilyIndexCount or "
1484 "pCreateInfo->pQueueFamilyIndices).",
1485 fn,
1486 sharingModeStr(pCreateInfo->imageSharingMode));
1487 }
1488 } else if (pCreateInfo->imageSharingMode != VK_SHARING_MODE_EXCLUSIVE) {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001489 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001490 SWAPCHAIN_CREATE_SWAP_BAD_SHARING_MODE,
1491 "%s() called with a non-supported "
1492 "pCreateInfo->imageSharingMode (i.e. %s).",
1493 fn,
1494 sharingModeStr(pCreateInfo->imageSharingMode));
1495 }
1496
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001497 // Validate pCreateInfo->clipped:
1498 if (pCreateInfo &&
1499 (pCreateInfo->clipped != VK_FALSE) &&
Ian Elliotta2a89c52015-12-28 15:23:57 -07001500 (pCreateInfo->clipped != VK_TRUE)) {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001501 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1502 device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001503 SWAPCHAIN_BAD_BOOL,
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001504 "%s() called with a VkBool32 value that is "
1505 "neither VK_TRUE nor VK_FALSE, but has the "
1506 "numeric value of %d.",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001507 fn,
1508 pCreateInfo->clipped);
1509 }
1510
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001511 // Validate pCreateInfo->oldSwapchain:
1512 if (pCreateInfo && pCreateInfo->oldSwapchain) {
1513 SwpSwapchain *pOldSwapchain = &my_data->swapchainMap[pCreateInfo->oldSwapchain];
1514 if (pOldSwapchain) {
1515 if (device != pOldSwapchain->pDevice->device) {
1516 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1517 device, "VkDevice",
1518 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
1519 "%s() called with a different VkDevice "
1520 "than the VkSwapchainKHR was created with.",
1521 __FUNCTION__);
1522 }
1523 if (pCreateInfo->surface != pOldSwapchain->surface) {
1524 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1525 device, "VkDevice",
1526 SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE,
1527 "%s() called with pCreateInfo->oldSwapchain "
1528 "that has a different VkSurfaceKHR than "
1529 "pCreateInfo->surface.",
1530 fn);
Ian Elliotta2a89c52015-12-28 15:23:57 -07001531 }
1532 } else {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001533 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliotta2a89c52015-12-28 15:23:57 -07001534 pCreateInfo->oldSwapchain,
1535 "VkSwapchainKHR");
1536 }
1537 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001538
1539 return skipCall;
1540}
1541
Ian Elliott27d39c72015-11-20 16:39:34 -07001542VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
1543 VkDevice device,
1544 const VkSwapchainCreateInfoKHR* pCreateInfo,
1545 const VkAllocationCallbacks* pAllocator,
1546 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001547{
1548 VkResult result = VK_SUCCESS;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001549 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001550 VkBool32 skipCall = validateCreateSwapchainKHR(device, pCreateInfo,
1551 pSwapchain);
1552
1553 if (VK_FALSE == skipCall) {
1554 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001555 result = my_data->device_dispatch_table->CreateSwapchainKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001556 device, pCreateInfo, pAllocator, pSwapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001557
1558 if (result == VK_SUCCESS) {
1559 // Remember the swapchain's handle, and link it to the device:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001560 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001561
Tobin Ehlis711ff312015-10-29 12:58:13 -06001562 my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001563 pDevice->swapchains[*pSwapchain] =
Tobin Ehlis711ff312015-10-29 12:58:13 -06001564 &my_data->swapchainMap[*pSwapchain];
1565 my_data->swapchainMap[*pSwapchain].pDevice = pDevice;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001566 my_data->swapchainMap[*pSwapchain].surface =
1567 (pCreateInfo) ? pCreateInfo->surface : 0;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001568 my_data->swapchainMap[*pSwapchain].imageCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001569 }
1570
1571 return result;
1572 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001573 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001574}
1575
Ian Elliott27d39c72015-11-20 16:39:34 -07001576VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
1577 VkDevice device,
1578 VkSwapchainKHR swapchain,
1579 const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001580{
1581 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001582 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001583
1584 // Validate that a valid VkDevice was used, and that the device
1585 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001586 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001587 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001588 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001589 device,
1590 "VkDevice");
Ian Elliott427058f2015-12-29 16:45:49 -07001591 } else if (!pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001592 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001593 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001594 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001595 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001596 }
1597
1598 // Regardless of skipCall value, do some internal cleanup:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001599 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001600 if (pSwapchain) {
1601 // Delete the SwpSwapchain associated with this swapchain:
1602 if (pSwapchain->pDevice) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08001603 pSwapchain->pDevice->swapchains.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001604 if (device != pSwapchain->pDevice->device) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001605 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001606 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001607 "%s() called with a different VkDevice than the "
1608 "VkSwapchainKHR was created with.",
1609 __FUNCTION__);
1610 }
1611 }
1612 if (pSwapchain->imageCount) {
1613 pSwapchain->images.clear();
1614 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001615 my_data->swapchainMap.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001616 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001617 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Chia-I Wue2fc5522015-10-26 20:04:44 +08001618 swapchain,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001619 "VkSwapchainKHR");
1620 }
1621
1622 if (VK_FALSE == skipCall) {
1623 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001624 my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001625 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001626}
1627
Ian Elliottf955d682015-12-30 12:00:54 -07001628VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
1629 VkDevice device,
1630 VkSwapchainKHR swapchain,
1631 uint32_t* pSwapchainImageCount,
1632 VkImage* pSwapchainImages)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001633{
1634 VkResult result = VK_SUCCESS;
1635 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001636 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001637
1638 // Validate that a valid VkDevice was used, and that the device
1639 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001640 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001641 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001642 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001643 device,
1644 "VkDevice");
Ian Elliott427058f2015-12-29 16:45:49 -07001645 } else if (!pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001646 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001647 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001648 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001649 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001650 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001651 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001652 if (!pSwapchain) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001653 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001654 swapchain.handle,
1655 "VkSwapchainKHR");
1656 }
Ian Elliottf955d682015-12-30 12:00:54 -07001657 if (!pSwapchainImageCount) {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001658 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1659 device,
Ian Elliottf955d682015-12-30 12:00:54 -07001660 "pSwapchainImageCount");
1661 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001662
1663 if (VK_FALSE == skipCall) {
1664 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001665 result = my_data->device_dispatch_table->GetSwapchainImagesKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001666 device, swapchain, pSwapchainImageCount, pSwapchainImages);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001667
Ian Elliottf955d682015-12-30 12:00:54 -07001668 if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages &&
1669 pSwapchainImageCount) {
1670 // Record the result of this preliminary query:
1671 pSwapchain->imageCount = *pSwapchainImageCount;
1672 }
Ian Elliott9059b302015-12-30 13:14:36 -07001673 else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages &&
1674 pSwapchainImageCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001675 // Compare the preliminary value of *pSwapchainImageCount with the
1676 // value this time:
1677 if (*pSwapchainImageCount != pSwapchain->imageCount) {
1678 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1679 device,
1680 "pSwapchainImageCount",
1681 "pSwapchainImages",
1682 pSwapchain->imageCount);
1683 }
Ian Elliott9059b302015-12-30 13:14:36 -07001684 else if (*pSwapchainImageCount > 0) {
1685 // Record the images and their state:
1686 pSwapchain->imageCount = *pSwapchainImageCount;
1687 for (uint32_t i = 0 ; i < *pSwapchainImageCount ; i++) {
1688 pSwapchain->images[i].image = pSwapchainImages[i];
1689 pSwapchain->images[i].pSwapchain = pSwapchain;
1690 pSwapchain->images[i].ownedByApp = false;
1691 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001692 }
1693 }
1694
1695 return result;
1696 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001697 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001698}
1699
Ian Elliott27d39c72015-11-20 16:39:34 -07001700VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
1701 VkDevice device,
1702 VkSwapchainKHR swapchain,
1703 uint64_t timeout,
1704 VkSemaphore semaphore,
1705 VkFence fence,
1706 uint32_t* pImageIndex)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001707{
1708// TODO: Record/update the state of the swapchain, in case an error occurs
1709// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
1710 VkResult result = VK_SUCCESS;
1711 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001712 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001713
1714 // Validate that a valid VkDevice was used, and that the device
1715 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001716 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001717 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001718 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001719 device,
1720 "VkDevice");
Ian Elliott427058f2015-12-29 16:45:49 -07001721 } else if (!pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001722 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001723 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001724 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001725 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001726 }
1727 // Validate that a valid VkSwapchainKHR was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001728 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001729 if (!pSwapchain) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001730 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Chia-I Wue2fc5522015-10-26 20:04:44 +08001731 swapchain,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001732 "VkSwapchainKHR");
1733 } else {
1734 // Look to see if the application is trying to own too many images at
1735 // the same time (i.e. not leave any to display):
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001736 uint32_t imagesOwnedByApp = 0;
1737 for (uint32_t i = 0 ; i < pSwapchain->imageCount ; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001738 if (pSwapchain->images[i].ownedByApp) {
1739 imagesOwnedByApp++;
1740 }
1741 }
1742 if (imagesOwnedByApp >= (pSwapchain->imageCount - 1)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001743 skipCall |= LOG_PERF_WARNING(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott4a994452015-09-24 18:33:16 -06001744 swapchain,
1745 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001746 SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES,
Ian Elliott4a994452015-09-24 18:33:16 -06001747 "%s() called when the application "
1748 "already owns all presentable images "
1749 "in this swapchain except for the "
1750 "image currently being displayed. "
1751 "This call to %s() cannot succeed "
1752 "unless another thread calls the "
1753 "vkQueuePresentKHR() function in "
1754 "order to release ownership of one of "
1755 "the presentable images of this "
1756 "swapchain.",
1757 __FUNCTION__, __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001758 }
1759 }
1760
1761 if (VK_FALSE == skipCall) {
1762 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001763 result = my_data->device_dispatch_table->AcquireNextImageKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001764 device, swapchain, timeout, semaphore, fence, pImageIndex);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001765
1766 if (((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)) &&
1767 pSwapchain) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001768 // Change the state of the image (now owned by the application):
1769 pSwapchain->images[*pImageIndex].ownedByApp = true;
1770 }
1771
1772 return result;
1773 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001774 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001775}
1776
Ian Elliott27d39c72015-11-20 16:39:34 -07001777VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(
1778 VkQueue queue,
1779 const VkPresentInfoKHR* pPresentInfo)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001780{
1781// TODOs:
1782//
1783// - Ensure that the queue is active, and is one of the queueFamilyIndex's
1784// that was returned by a previuos query.
1785// - Record/update the state of the swapchain, in case an error occurs
1786// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
1787 VkResult result = VK_SUCCESS;
1788 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001789 layer_data *my_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001790
Ian Elliott046ed2c2015-12-30 17:07:17 -07001791 if (!pPresentInfo) {
1792 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1793 device,
1794 "pPresentInfo");
1795 } else {
1796 if (pPresentInfo->sType != VK_STRUCTURE_TYPE_PRESENT_INFO_KHR) {
1797 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1798 device,
1799 "pPresentInfo",
1800 "VK_STRUCTURE_TYPE_PRESENT_INFO_KHR");
1801 }
1802 if (pPresentInfo->pNext != NULL) {
1803 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1804 device,
1805 "pPresentInfo");
1806 }
1807 if (!pPresentInfo->waitSemaphoreCount) {
1808 skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1809 device,
1810 "pPresentInfo->waitSemaphoreCount");
1811 }
1812 if (!pPresentInfo->pWaitSemaphores) {
1813 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1814 device,
1815 "pPresentInfo->pWaitSemaphores");
1816 }
1817 if (!pPresentInfo->swapchainCount) {
1818 skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1819 device,
1820 "pPresentInfo->swapchainCount");
1821 }
1822 if (!pPresentInfo->pSwapchains) {
1823 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1824 device,
1825 "pPresentInfo->pSwapchains");
1826 }
1827 if (!pPresentInfo->pImageIndices) {
1828 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1829 device,
1830 "pPresentInfo->pImageIndices");
1831 }
1832 // Note: pPresentInfo->pResults is allowed to be NULL
1833 }
1834
1835 for (uint32_t i = 0;
1836 pPresentInfo && (i < pPresentInfo->swapchainCount);
1837 i++) {
1838 uint32_t swapchainCount = pPresentInfo->swapchainCount;
Ian Elliott27d39c72015-11-20 16:39:34 -07001839 uint32_t index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001840 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001841 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001842 if (pSwapchain) {
Ian Elliott427058f2015-12-29 16:45:49 -07001843 if (!pSwapchain->pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001844 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001845 pSwapchain->pDevice, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001846 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001847 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001848 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001849 }
1850 if (index >= pSwapchain->imageCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001851 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001852 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001853 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001854 SWAPCHAIN_INDEX_TOO_LARGE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001855 "%s() called for an index that is too "
1856 "large (i.e. %d). There are only %d "
1857 "images in this VkSwapchainKHR.\n",
1858 __FUNCTION__, index,
1859 pSwapchain->imageCount);
1860 } else {
1861 if (!pSwapchain->images[index].ownedByApp) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001862 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001863 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001864 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001865 SWAPCHAIN_INDEX_NOT_IN_USE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001866 "%s() returned an index (i.e. %d) "
1867 "for an image that is not owned by "
1868 "the application.",
1869 __FUNCTION__, index);
1870 }
1871 }
1872 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001873 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001874 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001875 "VkSwapchainKHR");
1876 }
1877 }
1878
1879 if (VK_FALSE == skipCall) {
1880 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001881 result = my_data->device_dispatch_table->QueuePresentKHR(queue,
Ian Elliott046ed2c2015-12-30 17:07:17 -07001882 pPresentInfo);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001883
Ian Elliott046ed2c2015-12-30 17:07:17 -07001884 if (pPresentInfo &&
1885 ((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR))) {
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001886 for (uint32_t i = 0; i < pPresentInfo->swapchainCount ; i++) {
Ian Elliott27d39c72015-11-20 16:39:34 -07001887 int index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001888 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001889 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001890 if (pSwapchain) {
1891 // Change the state of the image (no longer owned by the
1892 // application):
1893 pSwapchain->images[index].ownedByApp = false;
1894 }
1895 }
1896 }
1897
1898 return result;
1899 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001900 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001901}
1902
1903static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)
1904{
1905 if (!name || name[0] != 'v' || name[1] != 'k')
1906 return NULL;
1907
1908 name += 2;
1909 if (!strcmp(name, "CreateInstance"))
1910 return (PFN_vkVoidFunction) vkCreateInstance;
1911 if (!strcmp(name, "DestroyInstance"))
1912 return (PFN_vkVoidFunction) vkDestroyInstance;
1913 if (!strcmp(name, "EnumeratePhysicalDevices"))
1914 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1915 if (!strcmp(name, "CreateDevice"))
1916 return (PFN_vkVoidFunction) vkCreateDevice;
1917 if (!strcmp(name, "DestroyDevice"))
1918 return (PFN_vkVoidFunction) vkDestroyDevice;
1919
1920 return NULL;
1921}
1922static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)
1923{
1924 if (!name || name[0] != 'v' || name[1] != 'k')
1925 return NULL;
1926
1927 name += 2;
1928 if (!strcmp(name, "CreateInstance"))
1929 return (PFN_vkVoidFunction) vkCreateInstance;
1930 if (!strcmp(name, "DestroyInstance"))
1931 return (PFN_vkVoidFunction) vkDestroyInstance;
1932 if (!strcmp(name, "EnumeratePhysicalDevices"))
1933 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1934
1935 return NULL;
1936}
1937
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001938VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
1939 VkInstance instance,
1940 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
1941 const VkAllocationCallbacks* pAllocator,
1942 VkDebugReportCallbackEXT* pMsgCallback)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001943{
Tobin Ehlis711ff312015-10-29 12:58:13 -06001944 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001945 VkResult result = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001946 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001947 result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001948 }
1949 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001950}
1951
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001952VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001953{
Ian Elliott68124ac2015-10-07 16:18:35 -06001954 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001955 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001956 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001957}
1958
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001959VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001960 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001961 VkDebugReportFlagsEXT flags,
1962 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001963 uint64_t object,
1964 size_t location,
1965 int32_t msgCode,
1966 const char* pLayerPrefix,
1967 const char* pMsg)
1968{
1969 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001970 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001971}
1972
Chia-I Wu9ab61502015-11-06 06:42:02 +08001973VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001974{
1975 PFN_vkVoidFunction addr;
1976 if (device == VK_NULL_HANDLE) {
1977 return NULL;
1978 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001979
Tobin Ehlis711ff312015-10-29 12:58:13 -06001980 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001981 /* loader uses this to force layer initialization; device object is wrapped */
1982 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001983 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) device;
1984 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
1985 my_data->device_dispatch_table = new VkLayerDispatchTable;
1986 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001987 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
1988 }
1989
1990 addr = layer_intercept_proc(funcName);
1991 if (addr)
1992 return addr;
1993
Tobin Ehlis711ff312015-10-29 12:58:13 -06001994 my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
1995 VkLayerDispatchTable *pDisp = my_data->device_dispatch_table;
1996 if (my_data->deviceMap.size() != 0 &&
Ian Elliott427058f2015-12-29 16:45:49 -07001997 my_data->deviceMap[device].swapchainExtensionEnabled)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001998 {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001999 if (!strcmp("vkCreateSwapchainKHR", funcName))
2000 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR);
2001 if (!strcmp("vkDestroySwapchainKHR", funcName))
2002 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR);
2003 if (!strcmp("vkGetSwapchainImagesKHR", funcName))
2004 return reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR);
2005 if (!strcmp("vkAcquireNextImageKHR", funcName))
2006 return reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR);
2007 if (!strcmp("vkQueuePresentKHR", funcName))
2008 return reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR);
2009 }
2010 {
2011 if (pDisp->GetDeviceProcAddr == NULL)
2012 return NULL;
2013 return pDisp->GetDeviceProcAddr(device, funcName);
2014 }
2015}
2016
Chia-I Wu9ab61502015-11-06 06:42:02 +08002017VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06002018{
2019 PFN_vkVoidFunction addr;
2020 if (instance == VK_NULL_HANDLE) {
2021 return NULL;
2022 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06002023
Tobin Ehlis711ff312015-10-29 12:58:13 -06002024 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06002025 /* loader uses this to force layer initialization; instance object is wrapped */
2026 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06002027 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
2028 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
2029 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
2030 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002031 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
2032 }
2033
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002034 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
2035 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
2036 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
2037 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
2038
Ian Elliott0b4d6242015-09-22 10:51:24 -06002039 addr = layer_intercept_instance_proc(funcName);
2040 if (addr)
2041 return addr;
2042
Tobin Ehlis711ff312015-10-29 12:58:13 -06002043 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2044 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Ian Elliott68124ac2015-10-07 16:18:35 -06002045 addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
2046 if (addr) {
2047 return addr;
2048 }
2049
Tobin Ehlis711ff312015-10-29 12:58:13 -06002050 if (my_data->instanceMap.size() != 0 &&
Ian Elliott1cb77a62015-12-29 16:44:39 -07002051 my_data->instanceMap[instance].surfaceExtensionEnabled)
Ian Elliott0b4d6242015-09-22 10:51:24 -06002052 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002053#ifdef VK_USE_PLATFORM_ANDROID_KHR
2054 if (!strcmp("vkCreateAndroidSurfaceKHR", funcName))
2055 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateAndroidSurfaceKHR);
2056#endif // VK_USE_PLATFORM_ANDROID_KHR
2057#ifdef VK_USE_PLATFORM_MIR_KHR
2058 if (!strcmp("vkCreateMirSurfaceKHR", funcName))
2059 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateMirSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002060 if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", funcName))
2061 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceMirPresentationSupportKHR);
Ian Elliotta983e9a2015-12-22 12:18:12 -07002062#endif // VK_USE_PLATFORM_MIR_KHR
2063#ifdef VK_USE_PLATFORM_WAYLAND_KHR
2064 if (!strcmp("vkCreateWaylandSurfaceKHR", funcName))
2065 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWaylandSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002066 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", funcName))
2067 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
Ian Elliotta983e9a2015-12-22 12:18:12 -07002068#endif // VK_USE_PLATFORM_WAYLAND_KHR
2069#ifdef VK_USE_PLATFORM_WIN32_KHR
2070 if (!strcmp("vkCreateWin32SurfaceKHR", funcName))
2071 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWin32SurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002072 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", funcName))
2073 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWin32PresentationSupportKHR);
Ian Elliotta983e9a2015-12-22 12:18:12 -07002074#endif // VK_USE_PLATFORM_WIN32_KHR
2075#ifdef VK_USE_PLATFORM_XCB_KHR
2076 if (!strcmp("vkCreateXcbSurfaceKHR", funcName))
2077 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXcbSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002078 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", funcName))
2079 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXcbPresentationSupportKHR);
Ian Elliotta983e9a2015-12-22 12:18:12 -07002080#endif // VK_USE_PLATFORM_XCB_KHR
2081#ifdef VK_USE_PLATFORM_XLIB_KHR
2082 if (!strcmp("vkCreateXlibSurfaceKHR", funcName))
2083 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXlibSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002084 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", funcName))
2085 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXlibPresentationSupportKHR);
Ian Elliotta983e9a2015-12-22 12:18:12 -07002086#endif // VK_USE_PLATFORM_XLIB_KHR
2087 if (!strcmp("vkDestroySurfaceKHR", funcName))
2088 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySurfaceKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002089 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", funcName))
2090 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceSupportKHR);
Ian Elliott27d39c72015-11-20 16:39:34 -07002091 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", funcName))
2092 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
2093 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", funcName))
2094 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceFormatsKHR);
2095 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", funcName))
2096 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfacePresentModesKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002097 }
2098
2099 if (pTable->GetInstanceProcAddr == NULL)
2100 return NULL;
2101 return pTable->GetInstanceProcAddr(instance, funcName);
2102}
2103