blob: 5d4dfda020e05e33a4dc6f7411e17f109c04972f [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) {
100 skipCall |= LOG_ERROR(VK_OBJECT_TYPE_SURFACE_KHR, surface, "VkSurfaceKHR",
101 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;
133 my_device_data->deviceMap[device].deviceSwapchainExtensionEnabled = 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
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700141 my_device_data->deviceMap[device].deviceSwapchainExtensionEnabled = 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");
157#endif // VK_USE_PLATFORM_MIR_KHR
158#ifdef VK_USE_PLATFORM_WAYLAND_KHR
159 pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR) gpa(instance, "vkCreateWaylandSurfaceKHR");
160#endif // VK_USE_PLATFORM_WAYLAND_KHR
161#ifdef VK_USE_PLATFORM_WIN32_KHR
162 pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) gpa(instance, "vkCreateWin32SurfaceKHR");
163#endif // VK_USE_PLATFORM_WIN32_KHR
164#ifdef VK_USE_PLATFORM_XCB_KHR
165 pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) gpa(instance, "vkCreateXcbSurfaceKHR");
166#endif // VK_USE_PLATFORM_XCB_KHR
167#ifdef VK_USE_PLATFORM_XLIB_KHR
168 pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR) gpa(instance, "vkCreateXlibSurfaceKHR");
169#endif // VK_USE_PLATFORM_XLIB_KHR
170 pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR) gpa(instance, "vkDestroySurfaceKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600171 pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
Ian Elliott27d39c72015-11-20 16:39:34 -0700172 pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
173 pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
174 pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600175
Ian Elliott1dcd1092015-11-17 17:29:40 -0700176 // Remember this instance, and whether the VK_KHR_surface extension
Ian Elliott0b4d6242015-09-22 10:51:24 -0600177 // was enabled for it:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600178 my_data->instanceMap[instance].instance = instance;
Ian Elliott1cb77a62015-12-29 16:44:39 -0700179 my_data->instanceMap[instance].surfaceExtensionEnabled = false;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600180
181 // Record whether the WSI instance extension was enabled for this
182 // VkInstance. No need to check if the extension was advertised by
183 // vkEnumerateInstanceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800184 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700185 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600186
Ian Elliott1cb77a62015-12-29 16:44:39 -0700187 my_data->instanceMap[instance].surfaceExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600188 }
189 }
190}
191
192
193#include "vk_dispatch_table_helper.h"
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700194static void initSwapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600195{
196 uint32_t report_flags = 0;
197 uint32_t debug_action = 0;
198 FILE *log_output = NULL;
199 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700200 VkDebugReportCallbackEXT callback;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600201
202 // Initialize Swapchain options:
203 report_flags = getLayerOptionFlags("SwapchainReportFlags", 0);
204 getLayerOptionEnum("SwapchainDebugAction", (uint32_t *) &debug_action);
205
206 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
207 {
208 // Turn on logging, since it was requested:
209 option_str = getLayerOption("SwapchainLogFilename");
210 log_output = getLayerLogOutput(option_str, "Swapchain");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700211 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700212 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700213 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700214 dbgInfo.pfnCallback = log_callback;
215 dbgInfo.pUserData = log_output;
216 dbgInfo.flags = report_flags;
217 layer_create_msg_callback(my_data->report_data,
218 &dbgInfo,
219 pAllocator,
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600220 &callback);
221 my_data->logging_callback.push_back(callback);
222 }
223 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700224 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700225 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700226 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700227 dbgInfo.pfnCallback = win32_debug_output_msg;
228 dbgInfo.pUserData = log_output;
229 dbgInfo.flags = report_flags;
230 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600231 my_data->logging_callback.push_back(callback);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600232 }
233}
234
Ian Elliott27d39c72015-11-20 16:39:34 -0700235static const char *surfaceTransformStr(VkSurfaceTransformFlagBitsKHR value)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600236{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600237
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700238 // TODO: parse flags and print out one at a time
Ian Elliott0b4d6242015-09-22 10:51:24 -0600239 // Return a string corresponding to the value:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700240 return string_VkSurfaceTransformFlagBitsKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600241}
242
243static const char *presentModeStr(VkPresentModeKHR value)
244{
245 static std::string presentModeStrings[] = {
246 "VK_PRESENT_MODE_IMMEDIATE_KHR",
247 "VK_PRESENT_MODE_MAILBOX_KHR",
248 "VK_PRESENT_MODE_FIFO_KHR",
249 "Out-of-Range Value"};
250
251 // Deal with a out-of-range value:
252 switch (value) {
253 case VK_PRESENT_MODE_IMMEDIATE_KHR:
254 case VK_PRESENT_MODE_MAILBOX_KHR:
255 case VK_PRESENT_MODE_FIFO_KHR:
256 break;
257 default:
258 value = (VkPresentModeKHR) (VK_PRESENT_MODE_FIFO_KHR + 1);
259 break;
260 }
261
262 // Return a string corresponding to the value:
263 return presentModeStrings[value].c_str();
264}
265
266
Chia-I Wu9ab61502015-11-06 06:42:02 +0800267VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600268{
Tobin Ehlis711ff312015-10-29 12:58:13 -0600269 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600270 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600271 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800272 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600273 if (result == VK_SUCCESS) {
274 // Since it succeeded, do layer-specific work:
Ian Elliott68124ac2015-10-07 16:18:35 -0600275 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
276 my_data->report_data = debug_report_create_instance(
Tobin Ehlis711ff312015-10-29 12:58:13 -0600277 pTable,
Ian Elliott68124ac2015-10-07 16:18:35 -0600278 *pInstance,
Chia-I Wud50a7d72015-10-26 20:48:51 +0800279 pCreateInfo->enabledExtensionNameCount,
Ian Elliott68124ac2015-10-07 16:18:35 -0600280 pCreateInfo->ppEnabledExtensionNames);
281 // Call the following function after my_data is initialized:
Ian Elliott0b4d6242015-09-22 10:51:24 -0600282 createInstanceRegisterExtensions(pCreateInfo, *pInstance);
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700283 initSwapchain(my_data, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600284 }
285 return result;
286}
287
Chia-I Wu9ab61502015-11-06 06:42:02 +0800288VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600289{
290 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600291 dispatch_key key = get_dispatch_key(instance);
292 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600293 // Validate that a valid VkInstance was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600294 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600295 if (!pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700296 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600297 instance,
298 "VkInstance");
299 }
300
301 if (VK_FALSE == skipCall) {
302 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800303 my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator);
Ian Elliott68124ac2015-10-07 16:18:35 -0600304
305 // Clean up logging callback, if any
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600306 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700307 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700308 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600309 my_data->logging_callback.pop_back();
Ian Elliott68124ac2015-10-07 16:18:35 -0600310 }
311 layer_debug_report_destroy_instance(my_data->report_data);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600312 }
313
314 // Regardless of skipCall value, do some internal cleanup:
315 if (pInstance) {
316 // Delete all of the SwpPhysicalDevice's and the SwpInstance associated
317 // with this instance:
318 for (auto it = pInstance->physicalDevices.begin() ;
319 it != pInstance->physicalDevices.end() ; it++) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700320
321 // Free memory that was allocated for/by this SwpPhysicalDevice:
322 SwpPhysicalDevice *pPhysicalDevice = it->second;
323 free(pPhysicalDevice->pSurfaceFormats);
324 free(pPhysicalDevice->pPresentModes);
325
Tobin Ehlis711ff312015-10-29 12:58:13 -0600326 // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which
Ian Elliott0b4d6242015-09-22 10:51:24 -0600327 // are simply pointed to by the SwpInstance):
Tobin Ehlis711ff312015-10-29 12:58:13 -0600328 my_data->physicalDeviceMap.erase(it->second->physicalDevice);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600329 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600330 my_data->instanceMap.erase(instance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600331 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600332 delete my_data->instance_dispatch_table;
333 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600334}
335
Ian Elliotta983e9a2015-12-22 12:18:12 -0700336#ifdef VK_USE_PLATFORM_ANDROID_KHR
337VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
338 VkInstance instance,
339 ANativeWindow* window,
340 const VkAllocationCallbacks* pAllocator,
341 VkSurfaceKHR* pSurface)
342{
343 VkResult result = VK_SUCCESS;
344 VkBool32 skipCall = VK_FALSE;
345 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
346
347 // Validate that a valid VkInstance was used:
348 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
349 if (!pInstance) {
350 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_OBJECT_TYPE_INSTANCE,
351 instance,
352 "VkInstance");
353 }
354
355 if (VK_FALSE == skipCall) {
356 // Call down the call chain:
357 result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(
358 instance, window, pAllocator, pSurface);
359
360 if ((result == VK_SUCCESS) && pInstance && pSurface) {
361 // Record the VkSurfaceKHR returned by the ICD:
362 my_data->surfaceMap[*pSurface].surface = *pSurface;
363 my_data->surfaceMap[*pSurface].pInstance = pInstance;
364 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_ANDROID;
365 // Point to the associated SwpInstance:
366 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
367 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
368 }
369 return result;
370 }
371 return VK_ERROR_VALIDATION_FAILED;
372}
373#endif // VK_USE_PLATFORM_ANDROID_KHR
374
375#ifdef VK_USE_PLATFORM_MIR_KHR
376VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(
377 VkInstance instance,
378 MirConnection* connection,
379 MirSurface* mirSurface,
380 const VkAllocationCallbacks* pAllocator,
381 VkSurfaceKHR* pSurface)
382{
383 VkResult result = VK_SUCCESS;
384 VkBool32 skipCall = VK_FALSE;
385 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
386
387 // Validate that a valid VkInstance was used:
388 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
389 if (!pInstance) {
390 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_OBJECT_TYPE_INSTANCE,
391 instance,
392 "VkInstance");
393 }
394
395 if (VK_FALSE == skipCall) {
396 // Call down the call chain:
397 result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(
398 instance, connection, mirSurface, pAllocator, pSurface);
399
400 if ((result == VK_SUCCESS) && pInstance && pSurface) {
401 // Record the VkSurfaceKHR returned by the ICD:
402 my_data->surfaceMap[*pSurface].surface = *pSurface;
403 my_data->surfaceMap[*pSurface].pInstance = pInstance;
404 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_MIR;
405 // Point to the associated SwpInstance:
406 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
407 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
408 }
409 return result;
410 }
411 return VK_ERROR_VALIDATION_FAILED;
412}
413#endif // VK_USE_PLATFORM_MIR_KHR
414
415#ifdef VK_USE_PLATFORM_WAYLAND_KHR
416VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
417 VkInstance instance,
418 struct wl_display* display,
419 struct wl_surface* surface,
420 const VkAllocationCallbacks* pAllocator,
421 VkSurfaceKHR* pSurface)
422{
423 VkResult result = VK_SUCCESS;
424 VkBool32 skipCall = VK_FALSE;
425 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
426
427 // Validate that a valid VkInstance was used:
428 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
429 if (!pInstance) {
430 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_OBJECT_TYPE_INSTANCE,
431 instance,
432 "VkInstance");
433 }
434
435 if (VK_FALSE == skipCall) {
436 // Call down the call chain:
437 result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(
438 instance, display, surface, pAllocator, pSurface);
439
440 if ((result == VK_SUCCESS) && pInstance && pSurface) {
441 // Record the VkSurfaceKHR returned by the ICD:
442 my_data->surfaceMap[*pSurface].surface = *pSurface;
443 my_data->surfaceMap[*pSurface].pInstance = pInstance;
444 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_WAYLAND;
445 // Point to the associated SwpInstance:
446 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
447 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
448 }
449 return result;
450 }
451 return VK_ERROR_VALIDATION_FAILED;
452}
453#endif // VK_USE_PLATFORM_WAYLAND_KHR
454
455#ifdef VK_USE_PLATFORM_WIN32_KHR
456VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
457 VkInstance instance,
458 HINSTANCE hinstance,
459 HWND hwnd,
460 const VkAllocationCallbacks* pAllocator,
461 VkSurfaceKHR* pSurface)
462{
463 VkResult result = VK_SUCCESS;
464 VkBool32 skipCall = VK_FALSE;
465 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
466
467 // Validate that a valid VkInstance was used:
468 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
469 if (!pInstance) {
470 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_OBJECT_TYPE_INSTANCE,
471 instance,
472 "VkInstance");
473 }
474
475 if (VK_FALSE == skipCall) {
476 // Call down the call chain:
477 result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(
478 instance, hinstance, hwnd, pAllocator, pSurface);
479
480 if ((result == VK_SUCCESS) && pInstance && pSurface) {
481 // Record the VkSurfaceKHR returned by the ICD:
482 my_data->surfaceMap[*pSurface].surface = *pSurface;
483 my_data->surfaceMap[*pSurface].pInstance = pInstance;
484 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_WIN32;
485 // Point to the associated SwpInstance:
486 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
487 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
488 }
489 return result;
490 }
491 return VK_ERROR_VALIDATION_FAILED;
492}
493#endif // VK_USE_PLATFORM_WIN32_KHR
494
495#ifdef VK_USE_PLATFORM_XCB_KHR
496VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
497 VkInstance instance,
498 xcb_connection_t* connection,
499 xcb_window_t window,
500 const VkAllocationCallbacks* pAllocator,
501 VkSurfaceKHR* pSurface)
502{
503 VkResult result = VK_SUCCESS;
504 VkBool32 skipCall = VK_FALSE;
505 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
506
507 // Validate that a valid VkInstance was used:
508 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
509 if (!pInstance) {
510 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_OBJECT_TYPE_INSTANCE,
511 instance,
512 "VkInstance");
513 }
514
515 if (VK_FALSE == skipCall) {
516 // Call down the call chain:
517 result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(
518 instance, connection, window, pAllocator, pSurface);
519
520 if ((result == VK_SUCCESS) && pInstance && pSurface) {
521 // Record the VkSurfaceKHR returned by the ICD:
522 my_data->surfaceMap[*pSurface].surface = *pSurface;
523 my_data->surfaceMap[*pSurface].pInstance = pInstance;
524 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_XCB;
525 // Point to the associated SwpInstance:
526 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
527 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
528 }
529 return result;
530 }
531 return VK_ERROR_VALIDATION_FAILED;
532}
533#endif // VK_USE_PLATFORM_XCB_KHR
534
535#ifdef VK_USE_PLATFORM_XLIB_KHR
536VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
537 VkInstance instance,
538 Display* dpy,
539 Window window,
540 const VkAllocationCallbacks* pAllocator,
541 VkSurfaceKHR* pSurface)
542{
543 VkResult result = VK_SUCCESS;
544 VkBool32 skipCall = VK_FALSE;
545 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
546
547 // Validate that a valid VkInstance was used:
548 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
549 if (!pInstance) {
550 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_OBJECT_TYPE_INSTANCE,
551 instance,
552 "VkInstance");
553 }
554
555 if (VK_FALSE == skipCall) {
556 // Call down the call chain:
557 result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(
558 instance, dpy, window, pAllocator, pSurface);
559
560 if ((result == VK_SUCCESS) && pInstance && pSurface) {
561 // Record the VkSurfaceKHR returned by the ICD:
562 my_data->surfaceMap[*pSurface].surface = *pSurface;
563 my_data->surfaceMap[*pSurface].pInstance = pInstance;
564 my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_XLIB;
565 // Point to the associated SwpInstance:
566 pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
567 skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
568 }
569 return result;
570 }
571 return VK_ERROR_VALIDATION_FAILED;
572}
573#endif // VK_USE_PLATFORM_XLIB_KHR
574
575VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator)
576{
577 VkBool32 skipCall = VK_FALSE;
578 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
579
580 // Validate that a valid VkInstance was used:
581 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
582 if (!pInstance) {
583 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_OBJECT_TYPE_INSTANCE,
584 instance,
585 "VkInstance");
586 }
587
588 if (VK_FALSE == skipCall) {
589 // Validate that a valid VkSurfaceKHR was used:
590 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
591 }
592
593 if (VK_FALSE == skipCall) {
594 // Call down the call chain:
595 my_data->instance_dispatch_table->DestroySurfaceKHR(
596 instance, surface, pAllocator);
597 }
598
599 // Regardless of skipCall value, do some internal cleanup:
600 SwpSurface *pSurface = &my_data->surfaceMap[surface];
601 if (pSurface && pSurface->pInstance) {
602 pSurface->pInstance->surfaces.erase(surface);
603 }
604 my_data->surfaceMap.erase(surface);
605}
606
Chia-I Wu9ab61502015-11-06 06:42:02 +0800607VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600608{
609 VkResult result = VK_SUCCESS;
610 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600611 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600612
613 // Validate that a valid VkInstance was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600614 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600615 if (!pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700616 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600617 instance,
618 "VkInstance");
619 }
620
621 if (VK_FALSE == skipCall) {
622 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600623 result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(
Ian Elliott0b4d6242015-09-22 10:51:24 -0600624 instance, pPhysicalDeviceCount, pPhysicalDevices);
625
626 if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices &&
627 (*pPhysicalDeviceCount > 0)) {
628 // Record the VkPhysicalDevices returned by the ICD:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600629 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600630 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis711ff312015-10-29 12:58:13 -0600631 my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice =
Ian Elliott0b4d6242015-09-22 10:51:24 -0600632 pPhysicalDevices[i];
Tobin Ehlis711ff312015-10-29 12:58:13 -0600633 my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance;
634 my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL;
Ian Elliott27d39c72015-11-20 16:39:34 -0700635 my_data->physicalDeviceMap[pPhysicalDevices[i]].gotSurfaceCapabilities = false;
636 my_data->physicalDeviceMap[pPhysicalDevices[i]].surfaceFormatCount = 0;
637 my_data->physicalDeviceMap[pPhysicalDevices[i]].pSurfaceFormats = NULL;
638 my_data->physicalDeviceMap[pPhysicalDevices[i]].presentModeCount = 0;
639 my_data->physicalDeviceMap[pPhysicalDevices[i]].pPresentModes = NULL;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600640 // Point to the associated SwpInstance:
641 pInstance->physicalDevices[pPhysicalDevices[i]] =
Tobin Ehlis711ff312015-10-29 12:58:13 -0600642 &my_data->physicalDeviceMap[pPhysicalDevices[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600643 }
644 }
645
646 return result;
647 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700648 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600649}
650
Chia-I Wu9ab61502015-11-06 06:42:02 +0800651VK_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 -0600652{
653 VkResult result = VK_SUCCESS;
654 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600655 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600656
657 // Validate that a valid VkPhysicalDevice was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600658 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600659 if (!pPhysicalDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700660 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Mark Lobodzinski6c1cb5a2015-11-05 15:27:03 -0700661 physicalDevice, "VkPhysicalDevice");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600662 }
663
Tobin Ehlis711ff312015-10-29 12:58:13 -0600664 if (VK_TRUE == skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700665 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600666
667 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
668 // Call down the call chain:
669 result = my_device_data->device_dispatch_table->CreateDevice(
Chia-I Wuf7458c52015-10-26 21:10:41 +0800670 physicalDevice, pCreateInfo, pAllocator, pDevice);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600671 if (result == VK_SUCCESS) {
672 // Since it succeeded, do layer-specific work:
Mark Lobodzinski6c1cb5a2015-11-05 15:27:03 -0700673 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
674 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
675 createDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600676 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600677 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600678}
679
Chia-I Wu9ab61502015-11-06 06:42:02 +0800680VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600681{
682 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600683 dispatch_key key = get_dispatch_key(device);
684 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600685 // Validate that a valid VkDevice was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600686 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600687 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700688 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600689 device,
690 "VkDevice");
691 }
692
693 if (VK_FALSE == skipCall) {
694 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800695 my_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600696 }
697
698 // Regardless of skipCall value, do some internal cleanup:
699 if (pDevice) {
700 // Delete the SwpDevice associated with this device:
701 if (pDevice->pPhysicalDevice) {
702 pDevice->pPhysicalDevice->pDevice = NULL;
703 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600704 if (!pDevice->swapchains.empty()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700705 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600706 SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600707 "%s() called before all of its associated "
708 "VkSwapchainKHRs were destroyed.",
709 __FUNCTION__);
710 // Empty and then delete all SwpSwapchain's
711 for (auto it = pDevice->swapchains.begin() ;
712 it != pDevice->swapchains.end() ; it++) {
713 // Delete all SwpImage's
714 it->second->images.clear();
715 }
716 pDevice->swapchains.clear();
717 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600718 my_data->deviceMap.erase(device);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600719 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600720 delete my_data->device_dispatch_table;
721 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600722}
723
Ian Elliott27d39c72015-11-20 16:39:34 -0700724VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
725 VkPhysicalDevice physicalDevice,
726 uint32_t queueFamilyIndex,
727 VkSurfaceKHR surface,
728 VkBool32* pSupported)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600729{
730 VkResult result = VK_SUCCESS;
731 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600732 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600733
734 // Validate that a valid VkPhysicalDevice was used, and that the instance
735 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600736 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600737 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700738 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600739 physicalDevice,
740 "VkPhysicalDevice");
Ian Elliott1cb77a62015-12-29 16:44:39 -0700741 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700742 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600743 pPhysicalDevice->pInstance,
744 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600745 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -0800746 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott1dcd1092015-11-17 17:29:40 -0700747 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600748 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700749 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600750
751 if (VK_FALSE == skipCall) {
752 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600753 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -0700754 physicalDevice, queueFamilyIndex, surface,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600755 pSupported);
756
757 if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) {
758 // Record the result of this query:
759 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] =
760 *pSupported;
761 // TODO: We need to compare this with the actual queue used for
762 // presentation, to ensure it was advertised to the application as
763 // supported for presentation.
764 }
765
766 return result;
767 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700768 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600769}
770
Ian Elliott27d39c72015-11-20 16:39:34 -0700771VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
772 VkPhysicalDevice physicalDevice,
773 VkSurfaceKHR surface,
774 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600775{
776 VkResult result = VK_SUCCESS;
777 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700778 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600779
Ian Elliott27d39c72015-11-20 16:39:34 -0700780 // Validate that a valid VkPhysicalDevice was used, and that the instance
Ian Elliott0b4d6242015-09-22 10:51:24 -0600781 // extension was enabled:
Ian Elliott27d39c72015-11-20 16:39:34 -0700782 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
783 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700784 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700785 physicalDevice,
786 "VkPhysicalDevice");
Ian Elliott1cb77a62015-12-29 16:44:39 -0700787 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700788 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700789 pPhysicalDevice->pInstance,
790 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600791 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700792 "%s() called even though the %s extension was not enabled for this VkInstance.",
793 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600794 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700795 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600796
797 if (VK_FALSE == skipCall) {
798 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700799 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceCapabilitiesKHR(
800 physicalDevice, surface, pSurfaceCapabilities);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600801
Ian Elliott27d39c72015-11-20 16:39:34 -0700802 if ((result == VK_SUCCESS) && pPhysicalDevice) {
803 pPhysicalDevice->gotSurfaceCapabilities = true;
804// FIXME: NEED TO COPY THIS DATA, BECAUSE pSurfaceCapabilities POINTS TO APP-ALLOCATED DATA
805 pPhysicalDevice->surfaceCapabilities = *pSurfaceCapabilities;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600806 }
807
808 return result;
809 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700810 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600811}
812
Ian Elliott27d39c72015-11-20 16:39:34 -0700813VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
814 VkPhysicalDevice physicalDevice,
815 VkSurfaceKHR surface,
816 uint32_t* pCount,
817 VkSurfaceFormatKHR* pSurfaceFormats)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600818{
819 VkResult result = VK_SUCCESS;
820 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700821 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600822
Ian Elliott27d39c72015-11-20 16:39:34 -0700823 // Validate that a valid VkPhysicalDevice was used, and that the instance
Ian Elliott0b4d6242015-09-22 10:51:24 -0600824 // extension was enabled:
Ian Elliott27d39c72015-11-20 16:39:34 -0700825 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
826 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700827 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700828 physicalDevice,
829 "VkPhysicalDevice");
Ian Elliott1cb77a62015-12-29 16:44:39 -0700830 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700831 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700832 pPhysicalDevice->pInstance,
833 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600834 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700835 "%s() called even though the %s extension was not enabled for this VkInstance.",
836 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600837 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700838 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600839
840 if (VK_FALSE == skipCall) {
841 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700842 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceFormatsKHR(
843 physicalDevice, surface, pCount, pSurfaceFormats);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600844
Ian Elliott27d39c72015-11-20 16:39:34 -0700845 if ((result == VK_SUCCESS) && pPhysicalDevice && pSurfaceFormats && pCount &&
Ian Elliott0b4d6242015-09-22 10:51:24 -0600846 (*pCount > 0)) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700847 pPhysicalDevice->surfaceFormatCount = *pCount;
848 pPhysicalDevice->pSurfaceFormats = (VkSurfaceFormatKHR *)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600849 malloc(*pCount * sizeof(VkSurfaceFormatKHR));
Ian Elliott27d39c72015-11-20 16:39:34 -0700850 if (pPhysicalDevice->pSurfaceFormats) {
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600851 for (uint32_t i = 0 ; i < *pCount ; i++) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700852 pPhysicalDevice->pSurfaceFormats[i] = pSurfaceFormats[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600853 }
854 } else {
Ian Elliott27d39c72015-11-20 16:39:34 -0700855 pPhysicalDevice->surfaceFormatCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600856 }
857 }
858
859 return result;
860 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700861 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600862}
863
Ian Elliott27d39c72015-11-20 16:39:34 -0700864VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
865 VkPhysicalDevice physicalDevice,
866 VkSurfaceKHR surface,
867 uint32_t* pCount,
868 VkPresentModeKHR* pPresentModes)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600869{
870 VkResult result = VK_SUCCESS;
871 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700872 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600873
Ian Elliott27d39c72015-11-20 16:39:34 -0700874 // Validate that a valid VkPhysicalDevice was used, and that the instance
Ian Elliott0b4d6242015-09-22 10:51:24 -0600875 // extension was enabled:
Ian Elliott27d39c72015-11-20 16:39:34 -0700876 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
877 if (!pPhysicalDevice || !pPhysicalDevice->pInstance) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700878 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700879 physicalDevice,
880 "VkPhysicalDevice");
Ian Elliott1cb77a62015-12-29 16:44:39 -0700881 } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700882 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700883 pPhysicalDevice->pInstance,
884 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600885 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700886 "%s() called even though the %s extension was not enabled for this VkInstance.",
887 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600888 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700889 skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600890
891 if (VK_FALSE == skipCall) {
892 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700893 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfacePresentModesKHR(
894 physicalDevice, surface, pCount, pPresentModes);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600895
Ian Elliott27d39c72015-11-20 16:39:34 -0700896 if ((result == VK_SUCCESS) && pPhysicalDevice && pPresentModes && pCount &&
Ian Elliott0b4d6242015-09-22 10:51:24 -0600897 (*pCount > 0)) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700898 pPhysicalDevice->presentModeCount = *pCount;
899 pPhysicalDevice->pPresentModes = (VkPresentModeKHR *)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600900 malloc(*pCount * sizeof(VkPresentModeKHR));
Ian Elliott27d39c72015-11-20 16:39:34 -0700901 if (pPhysicalDevice->pSurfaceFormats) {
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600902 for (uint32_t i = 0 ; i < *pCount ; i++) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700903 pPhysicalDevice->pPresentModes[i] = pPresentModes[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600904 }
905 } else {
Ian Elliott27d39c72015-11-20 16:39:34 -0700906 pPhysicalDevice->presentModeCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600907 }
908 }
909
910 return result;
911 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700912 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600913}
914
915// This function does the up-front validation work for vkCreateSwapchainKHR(),
916// and returns VK_TRUE if a logging callback indicates that the call down the
917// chain should be skipped:
918static VkBool32 validateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, VkSwapchainKHR* pSwapchain)
919{
920// TODO: Validate cases of re-creating a swapchain (the current code
921// assumes a new swapchain is being created).
922 VkResult result = VK_SUCCESS;
923 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600924 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600925 char fn[] = "vkCreateSwapchainKHR";
926
927 // Validate that a valid VkDevice was used, and that the device
928 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600929 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600930 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700931 return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600932 SWAPCHAIN_INVALID_HANDLE,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600933 "%s() called with a non-valid %s.",
934 fn, "VkDevice");
935
936 } else if (!pDevice->deviceSwapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700937 return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600938 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -0800939 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -0700940 fn, VK_KHR_SWAPCHAIN_EXTENSION_NAME );
Ian Elliott0b4d6242015-09-22 10:51:24 -0600941 }
942
943 // Validate pCreateInfo with the results for previous queries:
Ian Elliott27d39c72015-11-20 16:39:34 -0700944 if (!pDevice->pPhysicalDevice && !pDevice->pPhysicalDevice->gotSurfaceCapabilities) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700945 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600946 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600947 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -0700948 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -0600949 fn);
950 } else {
Ian Elliotta983e9a2015-12-22 12:18:12 -0700951 // Validate pCreateInfo->surface, to ensure it is valid (Note: in order
952 // to validate, we must lookup layer_data based on the VkInstance
953 // associated with this VkDevice):
954 SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice;
955 SwpInstance *pInstance = pPhysicalDevice->pInstance;
956 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(pInstance->instance), layer_data_map);
957 skipCall |= validateSurface(my_instance_data,
958 pCreateInfo->surface,
959 (char *) "vkCreateSwapchainKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600960 // Validate pCreateInfo->minImageCount against
Ian Elliott1dcd1092015-11-17 17:29:40 -0700961 // VkSurfaceCapabilitiesKHR::{min|max}ImageCount:
Ian Elliott27d39c72015-11-20 16:39:34 -0700962 VkSurfaceCapabilitiesKHR *pCapabilities = &pDevice->pPhysicalDevice->surfaceCapabilities;
963 if ((pCreateInfo->minImageCount < pCapabilities->minImageCount) ||
964 ((pCapabilities->maxImageCount > 0) &&
965 (pCreateInfo->minImageCount > pCapabilities->maxImageCount))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700966 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600967 SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600968 "%s() called with pCreateInfo->minImageCount "
969 "= %d, which is outside the bounds returned "
Ian Elliott1dcd1092015-11-17 17:29:40 -0700970 "by vkGetPhysicalDeviceSurfaceCapabilitiesKHR() (i.e. "
Ian Elliott0b4d6242015-09-22 10:51:24 -0600971 "minImageCount = %d, maxImageCount = %d).",
972 fn,
973 pCreateInfo->minImageCount,
Ian Elliott27d39c72015-11-20 16:39:34 -0700974 pCapabilities->minImageCount,
975 pCapabilities->maxImageCount);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600976 }
977 // Validate pCreateInfo->imageExtent against
Ian Elliott1dcd1092015-11-17 17:29:40 -0700978 // VkSurfaceCapabilitiesKHR::{current|min|max}ImageExtent:
Ian Elliott27d39c72015-11-20 16:39:34 -0700979 if ((pCapabilities->currentExtent.width == -1) &&
980 ((pCreateInfo->imageExtent.width < pCapabilities->minImageExtent.width) ||
981 (pCreateInfo->imageExtent.width > pCapabilities->maxImageExtent.width) ||
982 (pCreateInfo->imageExtent.height < pCapabilities->minImageExtent.height) ||
983 (pCreateInfo->imageExtent.height > pCapabilities->maxImageExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700984 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600985 SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600986 "%s() called with pCreateInfo->imageExtent = "
987 "(%d,%d), which is outside the bounds "
Ian Elliott1dcd1092015-11-17 17:29:40 -0700988 "returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): "
Ian Elliott0b4d6242015-09-22 10:51:24 -0600989 "currentExtent = (%d,%d), minImageExtent = "
990 "(%d,%d), maxImageExtent = (%d,%d).",
991 fn,
992 pCreateInfo->imageExtent.width,
993 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -0700994 pCapabilities->currentExtent.width,
995 pCapabilities->currentExtent.height,
996 pCapabilities->minImageExtent.width,
997 pCapabilities->minImageExtent.height,
998 pCapabilities->maxImageExtent.width,
999 pCapabilities->maxImageExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001000 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001001 if ((pCapabilities->currentExtent.width != -1) &&
1002 ((pCreateInfo->imageExtent.width != pCapabilities->currentExtent.width) ||
1003 (pCreateInfo->imageExtent.height != pCapabilities->currentExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001004 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001005 SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001006 "%s() called with pCreateInfo->imageExtent = "
1007 "(%d,%d), which is not equal to the "
1008 "currentExtent = (%d,%d) returned by "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001009 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001010 fn,
1011 pCreateInfo->imageExtent.width,
1012 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001013 pCapabilities->currentExtent.width,
1014 pCapabilities->currentExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001015 }
1016 // Validate pCreateInfo->preTransform against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001017 // VkSurfaceCapabilitiesKHR::supportedTransforms:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001018 if (!((pCreateInfo->preTransform) & pCapabilities->supportedTransforms)) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001019 // This is an error situation; one for which we'd like to give
1020 // the developer a helpful, multi-line error message. Build it
1021 // up a little at a time, and then log it:
1022 std::string errorString = "";
1023 char str[1024];
1024 // Here's the first part of the message:
1025 sprintf(str, "%s() called with a non-supported "
1026 "pCreateInfo->preTransform (i.e. %s). "
1027 "Supported values are:\n",
1028 fn,
1029 surfaceTransformStr(pCreateInfo->preTransform));
1030 errorString += str;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001031 for (int i = 0; i < 32; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001032 // Build up the rest of the message:
Ian Elliott27d39c72015-11-20 16:39:34 -07001033 if ((1 << i) & pCapabilities->supportedTransforms) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001034 const char *newStr =
Ian Elliott27d39c72015-11-20 16:39:34 -07001035 surfaceTransformStr((VkSurfaceTransformFlagBitsKHR) (1 << i));
Ian Elliott0b4d6242015-09-22 10:51:24 -06001036 sprintf(str, " %s\n", newStr);
1037 errorString += str;
1038 }
1039 }
1040 // Log the message that we've built up:
Ian Elliott68124ac2015-10-07 16:18:35 -06001041 skipCall |= debug_report_log_msg(my_data->report_data,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001042 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1043 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Mark Lobodzinski80e774f2016-01-04 15:54:59 -07001044 (uint64_t) device, __LINE__,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001045 SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM,
1046 LAYER_NAME,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001047 errorString.c_str());
1048 }
1049 // Validate pCreateInfo->imageArraySize against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001050 // VkSurfaceCapabilitiesKHR::maxImageArraySize:
Mark Lobodzinskia3b44522015-12-11 11:05:33 -07001051 if (pCreateInfo->imageArrayLayers > pCapabilities->maxImageArrayLayers) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001052 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001053 SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_SIZE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001054 "%s() called with a non-supported "
1055 "pCreateInfo->imageArraySize (i.e. %d). "
1056 "Maximum value is %d.",
1057 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001058 pCreateInfo->imageArrayLayers,
1059 pCapabilities->maxImageArrayLayers);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001060 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001061 // Validate pCreateInfo->imageUsage against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001062 // VkSurfaceCapabilitiesKHR::supportedUsageFlags:
Ian Elliott27d39c72015-11-20 16:39:34 -07001063 if (pCreateInfo->imageUsage &&
1064 (pCreateInfo->imageUsage !=
1065 (pCreateInfo->imageUsage & pCapabilities->supportedUsageFlags))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001066 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001067 SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001068 "%s() called with a non-supported "
Ian Elliott27d39c72015-11-20 16:39:34 -07001069 "pCreateInfo->imageUsage (i.e. 0x%08x)."
Ian Elliott0b4d6242015-09-22 10:51:24 -06001070 " Supported flag bits are 0x%08x.",
1071 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001072 pCreateInfo->imageUsage,
1073 pCapabilities->supportedUsageFlags);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001074 }
1075 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001076 if (!pDevice->pPhysicalDevice && !pDevice->pPhysicalDevice->surfaceFormatCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001077 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001078 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001079 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001080 "vkGetPhysicalDeviceSurfaceFormatsKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001081 fn);
1082 } else {
1083 // Validate pCreateInfo->imageFormat against
1084 // VkSurfaceFormatKHR::format:
1085 bool foundFormat = false;
1086 bool foundColorSpace = false;
1087 bool foundMatch = false;
Ian Elliott27d39c72015-11-20 16:39:34 -07001088 for (uint32_t i = 0 ; i < pDevice->pPhysicalDevice->surfaceFormatCount ; i++) {
1089 if (pCreateInfo->imageFormat == pDevice->pPhysicalDevice->pSurfaceFormats[i].format) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001090 // Validate pCreateInfo->imageColorSpace against
1091 // VkSurfaceFormatKHR::colorSpace:
1092 foundFormat = true;
Ian Elliott27d39c72015-11-20 16:39:34 -07001093 if (pCreateInfo->imageColorSpace == pDevice->pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001094 foundMatch = true;
1095 break;
1096 }
1097 } else {
Ian Elliott27d39c72015-11-20 16:39:34 -07001098 if (pCreateInfo->imageColorSpace == pDevice->pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001099 foundColorSpace = true;
1100 }
1101 }
1102 }
1103 if (!foundMatch) {
1104 if (!foundFormat) {
1105 if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001106 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001107 "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001108 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001109 "%s() called with neither a "
1110 "supported pCreateInfo->imageFormat "
1111 "(i.e. %d) nor a supported "
1112 "pCreateInfo->imageColorSpace "
1113 "(i.e. %d).",
1114 fn,
1115 pCreateInfo->imageFormat,
1116 pCreateInfo->imageColorSpace);
1117 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001118 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001119 "VkDevice",
1120 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001121 "%s() called with a non-supported "
1122 "pCreateInfo->imageFormat (i.e. %d).",
1123 fn, pCreateInfo->imageFormat);
1124 }
1125 } else if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001126 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001127 SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001128 "%s() called with a non-supported "
1129 "pCreateInfo->imageColorSpace (i.e. %d).",
1130 fn, pCreateInfo->imageColorSpace);
1131 }
1132 }
1133 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001134 if (!pDevice->pPhysicalDevice && !pDevice->pPhysicalDevice->presentModeCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001135 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001136 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001137 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001138 "vkGetPhysicalDeviceSurfacePresentModesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001139 fn);
1140 } else {
1141 // Validate pCreateInfo->presentMode against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001142 // vkGetPhysicalDeviceSurfacePresentModesKHR():
Ian Elliott0b4d6242015-09-22 10:51:24 -06001143 bool foundMatch = false;
Ian Elliott27d39c72015-11-20 16:39:34 -07001144 for (uint32_t i = 0 ; i < pDevice->pPhysicalDevice->presentModeCount ; i++) {
1145 if (pDevice->pPhysicalDevice->pPresentModes[i] == pCreateInfo->presentMode) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001146 foundMatch = true;
1147 break;
1148 }
1149 }
1150 if (!foundMatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001151 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001152 SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001153 "%s() called with a non-supported "
1154 "pCreateInfo->presentMode (i.e. %s).",
1155 fn,
1156 presentModeStr(pCreateInfo->presentMode));
1157 }
1158 }
1159
1160 // TODO: Validate the following values:
1161 // - pCreateInfo->sharingMode
Chia-I Wud50a7d72015-10-26 20:48:51 +08001162 // - pCreateInfo->queueFamilyIndexCount
Ian Elliott0b4d6242015-09-22 10:51:24 -06001163 // - pCreateInfo->pQueueFamilyIndices
1164 // - pCreateInfo->oldSwapchain
1165
1166 return skipCall;
1167}
1168
Ian Elliott27d39c72015-11-20 16:39:34 -07001169VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
1170 VkDevice device,
1171 const VkSwapchainCreateInfoKHR* pCreateInfo,
1172 const VkAllocationCallbacks* pAllocator,
1173 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001174{
1175 VkResult result = VK_SUCCESS;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001176 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001177 VkBool32 skipCall = validateCreateSwapchainKHR(device, pCreateInfo,
1178 pSwapchain);
1179
1180 if (VK_FALSE == skipCall) {
1181 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001182 result = my_data->device_dispatch_table->CreateSwapchainKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001183 device, pCreateInfo, pAllocator, pSwapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001184
1185 if (result == VK_SUCCESS) {
1186 // Remember the swapchain's handle, and link it to the device:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001187 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001188
Tobin Ehlis711ff312015-10-29 12:58:13 -06001189 my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001190 pDevice->swapchains[*pSwapchain] =
Tobin Ehlis711ff312015-10-29 12:58:13 -06001191 &my_data->swapchainMap[*pSwapchain];
1192 my_data->swapchainMap[*pSwapchain].pDevice = pDevice;
1193 my_data->swapchainMap[*pSwapchain].imageCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001194 }
1195
1196 return result;
1197 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001198 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001199}
1200
Ian Elliott27d39c72015-11-20 16:39:34 -07001201VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
1202 VkDevice device,
1203 VkSwapchainKHR swapchain,
1204 const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001205{
1206 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001207 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001208
1209 // Validate that a valid VkDevice was used, and that the device
1210 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001211 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001212 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001213 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001214 device,
1215 "VkDevice");
1216 } else if (!pDevice->deviceSwapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001217 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001218 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001219 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001220 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001221 }
1222
1223 // Regardless of skipCall value, do some internal cleanup:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001224 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001225 if (pSwapchain) {
1226 // Delete the SwpSwapchain associated with this swapchain:
1227 if (pSwapchain->pDevice) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08001228 pSwapchain->pDevice->swapchains.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001229 if (device != pSwapchain->pDevice->device) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001230 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001231 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001232 "%s() called with a different VkDevice than the "
1233 "VkSwapchainKHR was created with.",
1234 __FUNCTION__);
1235 }
1236 }
1237 if (pSwapchain->imageCount) {
1238 pSwapchain->images.clear();
1239 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001240 my_data->swapchainMap.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001241 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001242 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Chia-I Wue2fc5522015-10-26 20:04:44 +08001243 swapchain,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001244 "VkSwapchainKHR");
1245 }
1246
1247 if (VK_FALSE == skipCall) {
1248 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001249 my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001250 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001251}
1252
Chia-I Wu9ab61502015-11-06 06:42:02 +08001253VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pCount, VkImage* pSwapchainImages)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001254{
1255 VkResult result = VK_SUCCESS;
1256 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001257 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001258
1259 // Validate that a valid VkDevice was used, and that the device
1260 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001261 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001262 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001263 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001264 device,
1265 "VkDevice");
1266 } else if (!pDevice->deviceSwapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001267 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001268 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001269 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001270 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001271 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001272 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001273 if (!pSwapchain) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001274 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001275 swapchain.handle,
1276 "VkSwapchainKHR");
1277 }
1278
1279 if (VK_FALSE == skipCall) {
1280 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001281 result = my_data->device_dispatch_table->GetSwapchainImagesKHR(
Ian Elliott0b4d6242015-09-22 10:51:24 -06001282 device, swapchain, pCount, pSwapchainImages);
1283
Ian Elliott66463852015-09-28 11:24:53 -06001284// TBD: Should we validate that this function was called once with
1285// pSwapchainImages set to NULL (and record pCount at that time), and then
1286// called again with a non-NULL pSwapchainImages?
Ian Elliott0b4d6242015-09-22 10:51:24 -06001287 if ((result == VK_SUCCESS) && pSwapchain &&pSwapchainImages &&
1288 pCount && (*pCount > 0)) {
1289 // Record the images and their state:
1290 if (pSwapchain) {
1291 pSwapchain->imageCount = *pCount;
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001292 for (uint32_t i = 0 ; i < *pCount ; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001293 pSwapchain->images[i].image = pSwapchainImages[i];
1294 pSwapchain->images[i].pSwapchain = pSwapchain;
1295 pSwapchain->images[i].ownedByApp = false;
1296 }
1297 }
1298 }
1299
1300 return result;
1301 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001302 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001303}
1304
Ian Elliott27d39c72015-11-20 16:39:34 -07001305VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
1306 VkDevice device,
1307 VkSwapchainKHR swapchain,
1308 uint64_t timeout,
1309 VkSemaphore semaphore,
1310 VkFence fence,
1311 uint32_t* pImageIndex)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001312{
1313// TODO: Record/update the state of the swapchain, in case an error occurs
1314// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
1315 VkResult result = VK_SUCCESS;
1316 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001317 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001318
1319 // Validate that a valid VkDevice was used, and that the device
1320 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001321 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001322 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001323 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001324 device,
1325 "VkDevice");
1326 } else if (!pDevice->deviceSwapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001327 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001328 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001329 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001330 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001331 }
1332 // Validate that a valid VkSwapchainKHR was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001333 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001334 if (!pSwapchain) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001335 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Chia-I Wue2fc5522015-10-26 20:04:44 +08001336 swapchain,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001337 "VkSwapchainKHR");
1338 } else {
1339 // Look to see if the application is trying to own too many images at
1340 // the same time (i.e. not leave any to display):
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001341 uint32_t imagesOwnedByApp = 0;
1342 for (uint32_t i = 0 ; i < pSwapchain->imageCount ; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001343 if (pSwapchain->images[i].ownedByApp) {
1344 imagesOwnedByApp++;
1345 }
1346 }
1347 if (imagesOwnedByApp >= (pSwapchain->imageCount - 1)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001348 skipCall |= LOG_PERF_WARNING(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott4a994452015-09-24 18:33:16 -06001349 swapchain,
1350 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001351 SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES,
Ian Elliott4a994452015-09-24 18:33:16 -06001352 "%s() called when the application "
1353 "already owns all presentable images "
1354 "in this swapchain except for the "
1355 "image currently being displayed. "
1356 "This call to %s() cannot succeed "
1357 "unless another thread calls the "
1358 "vkQueuePresentKHR() function in "
1359 "order to release ownership of one of "
1360 "the presentable images of this "
1361 "swapchain.",
1362 __FUNCTION__, __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001363 }
1364 }
1365
1366 if (VK_FALSE == skipCall) {
1367 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001368 result = my_data->device_dispatch_table->AcquireNextImageKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001369 device, swapchain, timeout, semaphore, fence, pImageIndex);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001370
1371 if (((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)) &&
1372 pSwapchain) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001373 // Change the state of the image (now owned by the application):
1374 pSwapchain->images[*pImageIndex].ownedByApp = true;
1375 }
1376
1377 return result;
1378 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001379 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001380}
1381
Ian Elliott27d39c72015-11-20 16:39:34 -07001382VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(
1383 VkQueue queue,
1384 const VkPresentInfoKHR* pPresentInfo)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001385{
1386// TODOs:
1387//
1388// - Ensure that the queue is active, and is one of the queueFamilyIndex's
1389// that was returned by a previuos query.
1390// - Record/update the state of the swapchain, in case an error occurs
1391// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
1392 VkResult result = VK_SUCCESS;
1393 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001394 layer_data *my_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001395
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001396 for (uint32_t i = 0; i < pPresentInfo->swapchainCount ; i++) {
Ian Elliott27d39c72015-11-20 16:39:34 -07001397 uint32_t index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001398 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001399 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001400 if (pSwapchain) {
1401 if (!pSwapchain->pDevice->deviceSwapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001402 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001403 pSwapchain->pDevice, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001404 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001405 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001406 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001407 }
1408 if (index >= pSwapchain->imageCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001409 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001410 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001411 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001412 SWAPCHAIN_INDEX_TOO_LARGE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001413 "%s() called for an index that is too "
1414 "large (i.e. %d). There are only %d "
1415 "images in this VkSwapchainKHR.\n",
1416 __FUNCTION__, index,
1417 pSwapchain->imageCount);
1418 } else {
1419 if (!pSwapchain->images[index].ownedByApp) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001420 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001421 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001422 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001423 SWAPCHAIN_INDEX_NOT_IN_USE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001424 "%s() returned an index (i.e. %d) "
1425 "for an image that is not owned by "
1426 "the application.",
1427 __FUNCTION__, index);
1428 }
1429 }
1430 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001431 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001432 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001433 "VkSwapchainKHR");
1434 }
1435 }
1436
1437 if (VK_FALSE == skipCall) {
1438 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001439 result = my_data->device_dispatch_table->QueuePresentKHR(queue,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001440 pPresentInfo);
1441
1442 if ((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)) {
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001443 for (uint32_t i = 0; i < pPresentInfo->swapchainCount ; i++) {
Ian Elliott27d39c72015-11-20 16:39:34 -07001444 int index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001445 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001446 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001447 if (pSwapchain) {
1448 // Change the state of the image (no longer owned by the
1449 // application):
1450 pSwapchain->images[index].ownedByApp = false;
1451 }
1452 }
1453 }
1454
1455 return result;
1456 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001457 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001458}
1459
1460static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)
1461{
1462 if (!name || name[0] != 'v' || name[1] != 'k')
1463 return NULL;
1464
1465 name += 2;
1466 if (!strcmp(name, "CreateInstance"))
1467 return (PFN_vkVoidFunction) vkCreateInstance;
1468 if (!strcmp(name, "DestroyInstance"))
1469 return (PFN_vkVoidFunction) vkDestroyInstance;
1470 if (!strcmp(name, "EnumeratePhysicalDevices"))
1471 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1472 if (!strcmp(name, "CreateDevice"))
1473 return (PFN_vkVoidFunction) vkCreateDevice;
1474 if (!strcmp(name, "DestroyDevice"))
1475 return (PFN_vkVoidFunction) vkDestroyDevice;
1476
1477 return NULL;
1478}
1479static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)
1480{
1481 if (!name || name[0] != 'v' || name[1] != 'k')
1482 return NULL;
1483
1484 name += 2;
1485 if (!strcmp(name, "CreateInstance"))
1486 return (PFN_vkVoidFunction) vkCreateInstance;
1487 if (!strcmp(name, "DestroyInstance"))
1488 return (PFN_vkVoidFunction) vkDestroyInstance;
1489 if (!strcmp(name, "EnumeratePhysicalDevices"))
1490 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1491
1492 return NULL;
1493}
1494
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001495VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
1496 VkInstance instance,
1497 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
1498 const VkAllocationCallbacks* pAllocator,
1499 VkDebugReportCallbackEXT* pMsgCallback)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001500{
Tobin Ehlis711ff312015-10-29 12:58:13 -06001501 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001502 VkResult result = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001503 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001504 result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001505 }
1506 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001507}
1508
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001509VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001510{
Ian Elliott68124ac2015-10-07 16:18:35 -06001511 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001512 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001513 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001514}
1515
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001516VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001517 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001518 VkDebugReportFlagsEXT flags,
1519 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001520 uint64_t object,
1521 size_t location,
1522 int32_t msgCode,
1523 const char* pLayerPrefix,
1524 const char* pMsg)
1525{
1526 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001527 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001528}
1529
Chia-I Wu9ab61502015-11-06 06:42:02 +08001530VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001531{
1532 PFN_vkVoidFunction addr;
1533 if (device == VK_NULL_HANDLE) {
1534 return NULL;
1535 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001536
Tobin Ehlis711ff312015-10-29 12:58:13 -06001537 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001538 /* loader uses this to force layer initialization; device object is wrapped */
1539 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001540 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) device;
1541 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
1542 my_data->device_dispatch_table = new VkLayerDispatchTable;
1543 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001544 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
1545 }
1546
1547 addr = layer_intercept_proc(funcName);
1548 if (addr)
1549 return addr;
1550
Tobin Ehlis711ff312015-10-29 12:58:13 -06001551 my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
1552 VkLayerDispatchTable *pDisp = my_data->device_dispatch_table;
1553 if (my_data->deviceMap.size() != 0 &&
Mark Lobodzinski6c1cb5a2015-11-05 15:27:03 -07001554 my_data->deviceMap[device].deviceSwapchainExtensionEnabled)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001555 {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001556 if (!strcmp("vkCreateSwapchainKHR", funcName))
1557 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR);
1558 if (!strcmp("vkDestroySwapchainKHR", funcName))
1559 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR);
1560 if (!strcmp("vkGetSwapchainImagesKHR", funcName))
1561 return reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR);
1562 if (!strcmp("vkAcquireNextImageKHR", funcName))
1563 return reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR);
1564 if (!strcmp("vkQueuePresentKHR", funcName))
1565 return reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR);
1566 }
1567 {
1568 if (pDisp->GetDeviceProcAddr == NULL)
1569 return NULL;
1570 return pDisp->GetDeviceProcAddr(device, funcName);
1571 }
1572}
1573
Chia-I Wu9ab61502015-11-06 06:42:02 +08001574VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001575{
1576 PFN_vkVoidFunction addr;
1577 if (instance == VK_NULL_HANDLE) {
1578 return NULL;
1579 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001580
Tobin Ehlis711ff312015-10-29 12:58:13 -06001581 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001582 /* loader uses this to force layer initialization; instance object is wrapped */
1583 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001584 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
1585 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
1586 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
1587 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001588 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
1589 }
1590
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07001591 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
1592 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
1593 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
1594 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
1595
Ian Elliott0b4d6242015-09-22 10:51:24 -06001596 addr = layer_intercept_instance_proc(funcName);
1597 if (addr)
1598 return addr;
1599
Tobin Ehlis711ff312015-10-29 12:58:13 -06001600 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1601 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Ian Elliott68124ac2015-10-07 16:18:35 -06001602 addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
1603 if (addr) {
1604 return addr;
1605 }
1606
Tobin Ehlis711ff312015-10-29 12:58:13 -06001607 if (my_data->instanceMap.size() != 0 &&
Ian Elliott1cb77a62015-12-29 16:44:39 -07001608 my_data->instanceMap[instance].surfaceExtensionEnabled)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001609 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001610#ifdef VK_USE_PLATFORM_ANDROID_KHR
1611 if (!strcmp("vkCreateAndroidSurfaceKHR", funcName))
1612 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateAndroidSurfaceKHR);
1613#endif // VK_USE_PLATFORM_ANDROID_KHR
1614#ifdef VK_USE_PLATFORM_MIR_KHR
1615 if (!strcmp("vkCreateMirSurfaceKHR", funcName))
1616 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateMirSurfaceKHR);
1617#endif // VK_USE_PLATFORM_MIR_KHR
1618#ifdef VK_USE_PLATFORM_WAYLAND_KHR
1619 if (!strcmp("vkCreateWaylandSurfaceKHR", funcName))
1620 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWaylandSurfaceKHR);
1621#endif // VK_USE_PLATFORM_WAYLAND_KHR
1622#ifdef VK_USE_PLATFORM_WIN32_KHR
1623 if (!strcmp("vkCreateWin32SurfaceKHR", funcName))
1624 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWin32SurfaceKHR);
1625#endif // VK_USE_PLATFORM_WIN32_KHR
1626#ifdef VK_USE_PLATFORM_XCB_KHR
1627 if (!strcmp("vkCreateXcbSurfaceKHR", funcName))
1628 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXcbSurfaceKHR);
1629#endif // VK_USE_PLATFORM_XCB_KHR
1630#ifdef VK_USE_PLATFORM_XLIB_KHR
1631 if (!strcmp("vkCreateXlibSurfaceKHR", funcName))
1632 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXlibSurfaceKHR);
1633#endif // VK_USE_PLATFORM_XLIB_KHR
1634 if (!strcmp("vkDestroySurfaceKHR", funcName))
1635 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySurfaceKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001636 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", funcName))
1637 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceSupportKHR);
Ian Elliott27d39c72015-11-20 16:39:34 -07001638 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", funcName))
1639 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
1640 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", funcName))
1641 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceFormatsKHR);
1642 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", funcName))
1643 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfacePresentModesKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001644 }
1645
1646 if (pTable->GetInstanceProcAddr == NULL)
1647 return NULL;
1648 return pTable->GetInstanceProcAddr(instance, funcName);
1649}
1650