blob: 9b53ea4f11cf78d6e1bcd3629e1e75851f500149 [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 Elliott0b4d6242015-09-22 10:51:24 -060078static void createDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
79{
80 uint32_t i;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070081 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
82 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -060083
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070084 VkLayerDispatchTable *pDisp = my_device_data->device_dispatch_table;
85 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
86
87 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
88 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
89 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
90 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
91 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
92
93 SwpPhysicalDevice *pPhysicalDevice = &my_instance_data->physicalDeviceMap[physicalDevice];
Ian Elliott0b4d6242015-09-22 10:51:24 -060094 if (pPhysicalDevice) {
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070095 my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice;
96 pPhysicalDevice->pDevice = &my_device_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -060097 } else {
Ian Elliott07adb112016-01-05 12:51:03 -070098 // TBD: Should we leave error in (since Swapchain really needs this
99 // link)?
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700100 log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Mark Lobodzinski80e774f2016-01-04 15:54:59 -0700101 (uint64_t)physicalDevice , __LINE__, SWAPCHAIN_INVALID_HANDLE, "Swapchain",
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700102 "vkCreateDevice() called with a non-valid VkPhysicalDevice.");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600103 }
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700104 my_device_data->deviceMap[device].device = device;
Ian Elliott427058f2015-12-29 16:45:49 -0700105 my_device_data->deviceMap[device].swapchainExtensionEnabled = false;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600106
107 // Record whether the WSI device extension was enabled for this VkDevice.
108 // No need to check if the extension was advertised by
109 // vkEnumerateDeviceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800110 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700111 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600112
Ian Elliott427058f2015-12-29 16:45:49 -0700113 my_device_data->deviceMap[device].swapchainExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600114 }
115 }
116}
117
118static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)
119{
120 uint32_t i;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600121 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
122 VkLayerInstanceDispatchTable *pDisp = my_data->instance_dispatch_table;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600123 PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700124#ifdef VK_USE_PLATFORM_ANDROID_KHR
125 pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR) gpa(instance, "vkCreateAndroidSurfaceKHR");
126#endif // VK_USE_PLATFORM_ANDROID_KHR
127#ifdef VK_USE_PLATFORM_MIR_KHR
128 pDisp->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR) gpa(instance, "vkCreateMirSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700129 pDisp->GetPhysicalDeviceMirPresentationSupportKHR = (PFN_vkGetPhysicalDeviceMirPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700130#endif // VK_USE_PLATFORM_MIR_KHR
131#ifdef VK_USE_PLATFORM_WAYLAND_KHR
132 pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR) gpa(instance, "vkCreateWaylandSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700133 pDisp->GetPhysicalDeviceWaylandPresentationSupportKHR = (PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWaylandPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700134#endif // VK_USE_PLATFORM_WAYLAND_KHR
135#ifdef VK_USE_PLATFORM_WIN32_KHR
136 pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) gpa(instance, "vkCreateWin32SurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700137 pDisp->GetPhysicalDeviceWin32PresentationSupportKHR = (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700138#endif // VK_USE_PLATFORM_WIN32_KHR
139#ifdef VK_USE_PLATFORM_XCB_KHR
140 pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) gpa(instance, "vkCreateXcbSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700141 pDisp->GetPhysicalDeviceXcbPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700142#endif // VK_USE_PLATFORM_XCB_KHR
143#ifdef VK_USE_PLATFORM_XLIB_KHR
144 pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR) gpa(instance, "vkCreateXlibSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700145 pDisp->GetPhysicalDeviceXlibPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700146#endif // VK_USE_PLATFORM_XLIB_KHR
147 pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR) gpa(instance, "vkDestroySurfaceKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600148 pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
Ian Elliott27d39c72015-11-20 16:39:34 -0700149 pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
150 pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
151 pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600152
Ian Elliott1dcd1092015-11-17 17:29:40 -0700153 // Remember this instance, and whether the VK_KHR_surface extension
Ian Elliott0b4d6242015-09-22 10:51:24 -0600154 // was enabled for it:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600155 my_data->instanceMap[instance].instance = instance;
Ian Elliott1cb77a62015-12-29 16:44:39 -0700156 my_data->instanceMap[instance].surfaceExtensionEnabled = false;
Ian Elliott8dffaf32016-01-04 14:10:30 -0700157#ifdef VK_USE_PLATFORM_ANDROID_KHR
158 my_data->instanceMap[instance].androidSurfaceExtensionEnabled = false;
159#endif // VK_USE_PLATFORM_ANDROID_KHR
160#ifdef VK_USE_PLATFORM_MIR_KHR
161 my_data->instanceMap[instance].mirSurfaceExtensionEnabled = false;
162#endif // VK_USE_PLATFORM_MIR_KHR
163#ifdef VK_USE_PLATFORM_WAYLAND_KHR
164 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = false;
165#endif // VK_USE_PLATFORM_WAYLAND_KHR
166#ifdef VK_USE_PLATFORM_WIN32_KHR
167 my_data->instanceMap[instance].win32SurfaceExtensionEnabled = false;
168#endif // VK_USE_PLATFORM_WIN32_KHR
169#ifdef VK_USE_PLATFORM_XCB_KHR
170 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = false;
171#endif // VK_USE_PLATFORM_XCB_KHR
172#ifdef VK_USE_PLATFORM_XLIB_KHR
173 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = false;
174#endif // VK_USE_PLATFORM_XLIB_KHR
175
Ian Elliott0b4d6242015-09-22 10:51:24 -0600176
177 // Record whether the WSI instance extension was enabled for this
178 // VkInstance. No need to check if the extension was advertised by
179 // vkEnumerateInstanceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800180 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700181 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600182
Ian Elliott1cb77a62015-12-29 16:44:39 -0700183 my_data->instanceMap[instance].surfaceExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600184 }
Ian Elliott8dffaf32016-01-04 14:10:30 -0700185#ifdef VK_USE_PLATFORM_ANDROID_KHR
186 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
187
188 my_data->instanceMap[instance].androidSurfaceExtensionEnabled = true;
189#endif // VK_USE_PLATFORM_ANDROID_KHR
190#ifdef VK_USE_PLATFORM_MIR_KHR
191 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
192
193 my_data->instanceMap[instance].mirSurfaceExtensionEnabled = true;
194#endif // VK_USE_PLATFORM_MIR_KHR
195#ifdef VK_USE_PLATFORM_WAYLAND_KHR
196 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
197
198 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = true;
199#endif // VK_USE_PLATFORM_WAYLAND_KHR
200#ifdef VK_USE_PLATFORM_WIN32_KHR
201 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
202
203 my_data->instanceMap[instance].win32SurfaceExtensionEnabled = true;
204#endif // VK_USE_PLATFORM_WIN32_KHR
205#ifdef VK_USE_PLATFORM_XCB_KHR
206 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
207
208 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = true;
209#endif // VK_USE_PLATFORM_XCB_KHR
210#ifdef VK_USE_PLATFORM_XLIB_KHR
211 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
212
213 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = true;
214#endif // VK_USE_PLATFORM_XLIB_KHR
215 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600216 }
217}
218
219
220#include "vk_dispatch_table_helper.h"
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700221static void initSwapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600222{
223 uint32_t report_flags = 0;
224 uint32_t debug_action = 0;
225 FILE *log_output = NULL;
226 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700227 VkDebugReportCallbackEXT callback;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600228
229 // Initialize Swapchain options:
230 report_flags = getLayerOptionFlags("SwapchainReportFlags", 0);
231 getLayerOptionEnum("SwapchainDebugAction", (uint32_t *) &debug_action);
232
233 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
234 {
235 // Turn on logging, since it was requested:
236 option_str = getLayerOption("SwapchainLogFilename");
237 log_output = getLayerLogOutput(option_str, "Swapchain");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700238 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700239 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700240 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700241 dbgInfo.pfnCallback = log_callback;
242 dbgInfo.pUserData = log_output;
243 dbgInfo.flags = report_flags;
244 layer_create_msg_callback(my_data->report_data,
245 &dbgInfo,
246 pAllocator,
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600247 &callback);
248 my_data->logging_callback.push_back(callback);
249 }
250 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700251 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700252 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700253 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700254 dbgInfo.pfnCallback = win32_debug_output_msg;
255 dbgInfo.pUserData = log_output;
256 dbgInfo.flags = report_flags;
257 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600258 my_data->logging_callback.push_back(callback);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600259 }
260}
261
Ian Elliott27d39c72015-11-20 16:39:34 -0700262static const char *surfaceTransformStr(VkSurfaceTransformFlagBitsKHR value)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600263{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600264 // Return a string corresponding to the value:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700265 return string_VkSurfaceTransformFlagBitsKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600266}
267
Ian Elliotta2a89c52015-12-28 15:23:57 -0700268static const char *surfaceCompositeAlphaStr(VkCompositeAlphaFlagBitsKHR value)
269{
270 // Return a string corresponding to the value:
271 return string_VkCompositeAlphaFlagBitsKHR(value);
272}
273
Ian Elliott0b4d6242015-09-22 10:51:24 -0600274static const char *presentModeStr(VkPresentModeKHR value)
275{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600276 // Return a string corresponding to the value:
Ian Elliott24491af2015-12-28 15:04:49 -0700277 return string_VkPresentModeKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600278}
279
Ian Elliotta2a89c52015-12-28 15:23:57 -0700280static const char *sharingModeStr(VkSharingMode value)
281{
282 // Return a string corresponding to the value:
283 return string_VkSharingMode(value);
284}
285
Ian Elliott0b4d6242015-09-22 10:51:24 -0600286
Chia-I Wu9ab61502015-11-06 06:42:02 +0800287VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600288{
Tobin Ehlis711ff312015-10-29 12:58:13 -0600289 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600290 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600291 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800292 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600293 if (result == VK_SUCCESS) {
294 // Since it succeeded, do layer-specific work:
Ian Elliott68124ac2015-10-07 16:18:35 -0600295 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
296 my_data->report_data = debug_report_create_instance(
Tobin Ehlis711ff312015-10-29 12:58:13 -0600297 pTable,
Ian Elliott68124ac2015-10-07 16:18:35 -0600298 *pInstance,
Chia-I Wud50a7d72015-10-26 20:48:51 +0800299 pCreateInfo->enabledExtensionNameCount,
Ian Elliott68124ac2015-10-07 16:18:35 -0600300 pCreateInfo->ppEnabledExtensionNames);
301 // Call the following function after my_data is initialized:
Ian Elliott0b4d6242015-09-22 10:51:24 -0600302 createInstanceRegisterExtensions(pCreateInfo, *pInstance);
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700303 initSwapchain(my_data, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600304 }
305 return result;
306}
307
Chia-I Wu9ab61502015-11-06 06:42:02 +0800308VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600309{
310 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600311 dispatch_key key = get_dispatch_key(instance);
312 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600313 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600314
315 if (VK_FALSE == skipCall) {
316 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800317 my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator);
Ian Elliott68124ac2015-10-07 16:18:35 -0600318
319 // Clean up logging callback, if any
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600320 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700321 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700322 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600323 my_data->logging_callback.pop_back();
Ian Elliott68124ac2015-10-07 16:18:35 -0600324 }
325 layer_debug_report_destroy_instance(my_data->report_data);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600326 }
327
328 // Regardless of skipCall value, do some internal cleanup:
329 if (pInstance) {
330 // Delete all of the SwpPhysicalDevice's and the SwpInstance associated
331 // with this instance:
332 for (auto it = pInstance->physicalDevices.begin() ;
333 it != pInstance->physicalDevices.end() ; it++) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700334
335 // Free memory that was allocated for/by this SwpPhysicalDevice:
336 SwpPhysicalDevice *pPhysicalDevice = it->second;
Ian Elliott07adb112016-01-05 12:51:03 -0700337 if (pPhysicalDevice) {
338 free(pPhysicalDevice->pSurfaceFormats);
339 free(pPhysicalDevice->pPresentModes);
340 }
Ian Elliott27d39c72015-11-20 16:39:34 -0700341
Tobin Ehlis711ff312015-10-29 12:58:13 -0600342 // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which
Ian Elliott0b4d6242015-09-22 10:51:24 -0600343 // are simply pointed to by the SwpInstance):
Tobin Ehlis711ff312015-10-29 12:58:13 -0600344 my_data->physicalDeviceMap.erase(it->second->physicalDevice);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600345 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600346 my_data->instanceMap.erase(instance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600347 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600348 delete my_data->instance_dispatch_table;
349 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600350}
351
Ian Elliotta983e9a2015-12-22 12:18:12 -0700352#ifdef VK_USE_PLATFORM_ANDROID_KHR
353VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
354 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700355 const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700356 const VkAllocationCallbacks* pAllocator,
357 VkSurfaceKHR* pSurface)
358{
359 VkResult result = VK_SUCCESS;
360 VkBool32 skipCall = VK_FALSE;
361 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
362
Ian Elliottf5758292015-12-30 17:39:02 -0700363 if (!pCreateInfo) {
364 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
365 device,
366 "pCreateInfo");
367 } else {
368 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR) {
369 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
370 device,
371 "pCreateInfo",
372 "VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR");
373 }
374 if (pCreateInfo->pNext != NULL) {
375 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
376 device,
377 "pCreateInfo");
378 }
379 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700380
381 if (VK_FALSE == skipCall) {
382 // Call down the call chain:
383 result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700384 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700385 return result;
386 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700387 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700388}
389#endif // VK_USE_PLATFORM_ANDROID_KHR
390
391#ifdef VK_USE_PLATFORM_MIR_KHR
392VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(
393 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700394 const VkMirSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700395 const VkAllocationCallbacks* pAllocator,
396 VkSurfaceKHR* pSurface)
397{
398 VkResult result = VK_SUCCESS;
399 VkBool32 skipCall = VK_FALSE;
400 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
401
Ian Elliottf5758292015-12-30 17:39:02 -0700402 if (!pCreateInfo) {
403 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
404 device,
405 "pCreateInfo");
406 } else {
407 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR) {
408 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
409 device,
410 "pCreateInfo",
411 "VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR");
412 }
413 if (pCreateInfo->pNext != NULL) {
414 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
415 device,
416 "pCreateInfo");
417 }
418 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700419
420 if (VK_FALSE == skipCall) {
421 // Call down the call chain:
422 result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700423 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700424 return result;
425 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700426 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700427}
Ian Elliott55ff7962015-12-30 10:18:47 -0700428
429VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceMirPresentationSupportKHR(
430 VkPhysicalDevice physicalDevice,
431 uint32_t queueFamilyIndex,
432 MirConnection* connection)
433{
434 VkBool32 result = VK_FALSE;
435 VkBool32 skipCall = VK_FALSE;
436 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700437 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700438
439 // Validate that the platform extension was enabled:
440 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
441 !pPhysicalDevice->pInstance->mirSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700442 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
443 pPhysicalDevice->pInstance,
444 "VkInstance",
445 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
446 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700447 __FUNCTION__, VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700448 }
449
450 if (VK_FALSE == skipCall) {
451 // Call down the call chain:
452 result = my_data->instance_dispatch_table->GetPhysicalDeviceMirPresentationSupportKHR(
453 physicalDevice, queueFamilyIndex, connection);
454
455 if (pPhysicalDevice) {
456 // Record the result of this query:
457 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
458 }
459 }
460 return result;
461}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700462#endif // VK_USE_PLATFORM_MIR_KHR
463
464#ifdef VK_USE_PLATFORM_WAYLAND_KHR
465VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
466 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700467 const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700468 const VkAllocationCallbacks* pAllocator,
469 VkSurfaceKHR* pSurface)
470{
471 VkResult result = VK_SUCCESS;
472 VkBool32 skipCall = VK_FALSE;
473 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
474
Ian Elliottf5758292015-12-30 17:39:02 -0700475 if (!pCreateInfo) {
476 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
477 device,
478 "pCreateInfo");
479 } else {
480 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR) {
481 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
482 device,
483 "pCreateInfo",
484 "VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR");
485 }
486 if (pCreateInfo->pNext != NULL) {
487 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
488 device,
489 "pCreateInfo");
490 }
491 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700492
493 if (VK_FALSE == skipCall) {
494 // Call down the call chain:
495 result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700496 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700497 return result;
498 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700499 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700500}
Ian Elliott55ff7962015-12-30 10:18:47 -0700501
502VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(
503 VkPhysicalDevice physicalDevice,
504 uint32_t queueFamilyIndex,
505 struct wl_display* display)
506{
507 VkBool32 result = VK_FALSE;
508 VkBool32 skipCall = VK_FALSE;
509 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700510 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700511
512 // Validate that the platform extension was enabled:
513 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
514 !pPhysicalDevice->pInstance->waylandSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700515 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
516 pPhysicalDevice->pInstance,
517 "VkInstance",
518 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
519 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700520 __FUNCTION__, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700521 }
522
523 if (VK_FALSE == skipCall) {
524 // Call down the call chain:
525 result = my_data->instance_dispatch_table->GetPhysicalDeviceWaylandPresentationSupportKHR(
526 physicalDevice, queueFamilyIndex, display);
527
528 if (pPhysicalDevice) {
529 // Record the result of this query:
530 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
531 }
532 }
533 return result;
534}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700535#endif // VK_USE_PLATFORM_WAYLAND_KHR
536
537#ifdef VK_USE_PLATFORM_WIN32_KHR
538VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
539 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700540 const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700541 const VkAllocationCallbacks* pAllocator,
542 VkSurfaceKHR* pSurface)
543{
544 VkResult result = VK_SUCCESS;
545 VkBool32 skipCall = VK_FALSE;
546 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
547
Ian Elliottf5758292015-12-30 17:39:02 -0700548 if (!pCreateInfo) {
549 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
550 device,
551 "pCreateInfo");
552 } else {
553 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR) {
554 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
555 device,
556 "pCreateInfo",
557 "VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR");
558 }
559 if (pCreateInfo->pNext != NULL) {
560 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
561 device,
562 "pCreateInfo");
563 }
564 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700565
566 if (VK_FALSE == skipCall) {
567 // Call down the call chain:
568 result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700569 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700570 return result;
571 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700572 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700573}
Ian Elliott55ff7962015-12-30 10:18:47 -0700574
575VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(
576 VkPhysicalDevice physicalDevice,
577 uint32_t queueFamilyIndex)
578{
579 VkBool32 result = VK_FALSE;
580 VkBool32 skipCall = VK_FALSE;
581 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700582 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700583
584 // Validate that the platform extension was enabled:
585 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
586 !pPhysicalDevice->pInstance->win32SurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700587 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
588 pPhysicalDevice->pInstance,
589 "VkInstance",
590 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
591 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700592 __FUNCTION__, VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700593 }
594
595 if (VK_FALSE == skipCall) {
596 // Call down the call chain:
597 result = my_data->instance_dispatch_table->GetPhysicalDeviceWin32PresentationSupportKHR(
598 physicalDevice, queueFamilyIndex);
599
600 if (pPhysicalDevice) {
601 // Record the result of this query:
602 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
603 }
604 }
605 return result;
606}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700607#endif // VK_USE_PLATFORM_WIN32_KHR
608
609#ifdef VK_USE_PLATFORM_XCB_KHR
610VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
611 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700612 const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700613 const VkAllocationCallbacks* pAllocator,
614 VkSurfaceKHR* pSurface)
615{
616 VkResult result = VK_SUCCESS;
617 VkBool32 skipCall = VK_FALSE;
618 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
619
Ian Elliottf5758292015-12-30 17:39:02 -0700620 if (!pCreateInfo) {
621 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
622 device,
623 "pCreateInfo");
624 } else {
625 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR) {
626 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
627 device,
628 "pCreateInfo",
629 "VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR");
630 }
631 if (pCreateInfo->pNext != NULL) {
632 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
633 device,
634 "pCreateInfo");
635 }
636 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700637
638 if (VK_FALSE == skipCall) {
639 // Call down the call chain:
640 result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700641 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700642 return result;
643 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700644 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700645}
Ian Elliott55ff7962015-12-30 10:18:47 -0700646
647VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(
648 VkPhysicalDevice physicalDevice,
649 uint32_t queueFamilyIndex,
650 xcb_connection_t* connection,
651 xcb_visualid_t visual_id)
652{
653 VkBool32 result = VK_FALSE;
654 VkBool32 skipCall = VK_FALSE;
655 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700656 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700657
658 // Validate that the platform extension was enabled:
659 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
660 !pPhysicalDevice->pInstance->xcbSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700661 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
662 pPhysicalDevice->pInstance,
663 "VkInstance",
664 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
665 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700666 __FUNCTION__, VK_KHR_XCB_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700667 }
668
669 if (VK_FALSE == skipCall) {
670 // Call down the call chain:
671 result = my_data->instance_dispatch_table->GetPhysicalDeviceXcbPresentationSupportKHR(
672 physicalDevice, queueFamilyIndex, connection, visual_id);
673
674 if (pPhysicalDevice) {
675 // Record the result of this query:
676 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
677 }
678 }
679 return result;
680}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700681#endif // VK_USE_PLATFORM_XCB_KHR
682
683#ifdef VK_USE_PLATFORM_XLIB_KHR
684VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
685 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700686 const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700687 const VkAllocationCallbacks* pAllocator,
688 VkSurfaceKHR* pSurface)
689{
690 VkResult result = VK_SUCCESS;
691 VkBool32 skipCall = VK_FALSE;
692 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
693
Ian Elliottf5758292015-12-30 17:39:02 -0700694 if (!pCreateInfo) {
695 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
696 device,
697 "pCreateInfo");
698 } else {
699 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR) {
700 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
701 device,
702 "pCreateInfo",
703 "VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR");
704 }
705 if (pCreateInfo->pNext != NULL) {
706 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
707 device,
708 "pCreateInfo");
709 }
710 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700711
712 if (VK_FALSE == skipCall) {
713 // Call down the call chain:
714 result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700715 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700716 return result;
717 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700718 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700719}
Ian Elliott55ff7962015-12-30 10:18:47 -0700720
721VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(
722 VkPhysicalDevice physicalDevice,
723 uint32_t queueFamilyIndex,
724 Display* dpy,
725 VisualID visualID)
726{
727 VkBool32 result = VK_FALSE;
728 VkBool32 skipCall = VK_FALSE;
729 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700730 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700731
732 // Validate that the platform extension was enabled:
733 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
734 !pPhysicalDevice->pInstance->xlibSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700735 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
736 pPhysicalDevice->pInstance,
737 "VkInstance",
738 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
739 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700740 __FUNCTION__, VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700741 }
742
743 if (VK_FALSE == skipCall) {
744 // Call down the call chain:
745 result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR(
746 physicalDevice, queueFamilyIndex, dpy, visualID);
747
748 if (pPhysicalDevice) {
749 // Record the result of this query:
750 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
751 }
752 }
753 return result;
754}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700755#endif // VK_USE_PLATFORM_XLIB_KHR
756
757VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator)
758{
759 VkBool32 skipCall = VK_FALSE;
760 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
761
Ian Elliotta983e9a2015-12-22 12:18:12 -0700762 if (VK_FALSE == skipCall) {
Ian Elliotta983e9a2015-12-22 12:18:12 -0700763 // Call down the call chain:
764 my_data->instance_dispatch_table->DestroySurfaceKHR(
765 instance, surface, pAllocator);
766 }
767
Ian Elliott6b9941a2016-01-05 12:03:06 -0700768 // No need to do any cleanup--rely on object_tracker to track VkSurfaceKHR
Ian Elliotta983e9a2015-12-22 12:18:12 -0700769}
770
Chia-I Wu9ab61502015-11-06 06:42:02 +0800771VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600772{
773 VkResult result = VK_SUCCESS;
774 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600775 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600776 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600777
778 if (VK_FALSE == skipCall) {
779 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600780 result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(
Ian Elliott0b4d6242015-09-22 10:51:24 -0600781 instance, pPhysicalDeviceCount, pPhysicalDevices);
782
783 if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices &&
784 (*pPhysicalDeviceCount > 0)) {
785 // Record the VkPhysicalDevices returned by the ICD:
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600786 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis711ff312015-10-29 12:58:13 -0600787 my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice =
Ian Elliott0b4d6242015-09-22 10:51:24 -0600788 pPhysicalDevices[i];
Tobin Ehlis711ff312015-10-29 12:58:13 -0600789 my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance;
790 my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL;
Ian Elliott27d39c72015-11-20 16:39:34 -0700791 my_data->physicalDeviceMap[pPhysicalDevices[i]].gotSurfaceCapabilities = false;
792 my_data->physicalDeviceMap[pPhysicalDevices[i]].surfaceFormatCount = 0;
793 my_data->physicalDeviceMap[pPhysicalDevices[i]].pSurfaceFormats = NULL;
794 my_data->physicalDeviceMap[pPhysicalDevices[i]].presentModeCount = 0;
795 my_data->physicalDeviceMap[pPhysicalDevices[i]].pPresentModes = NULL;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600796 // Point to the associated SwpInstance:
Ian Elliott4f07d082016-01-05 12:18:50 -0700797 if (pInstance) {
798 pInstance->physicalDevices[pPhysicalDevices[i]] =
799 &my_data->physicalDeviceMap[pPhysicalDevices[i]];
800 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600801 }
802 }
803
804 return result;
805 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700806 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600807}
808
Chia-I Wu9ab61502015-11-06 06:42:02 +0800809VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600810{
811 VkResult result = VK_SUCCESS;
812 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600813 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600814
Ian Elliott07adb112016-01-05 12:51:03 -0700815 if (VK_FALSE == skipCall) {
816 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
817 // Call down the call chain:
818 result = my_device_data->device_dispatch_table->CreateDevice(
819 physicalDevice, pCreateInfo, pAllocator, pDevice);
820 if (result == VK_SUCCESS) {
821 // Since it succeeded, do layer-specific work:
822 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
823 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
824 createDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice);
825 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600826 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600827 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600828}
829
Chia-I Wu9ab61502015-11-06 06:42:02 +0800830VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600831{
832 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600833 dispatch_key key = get_dispatch_key(device);
834 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600835 // Validate that a valid VkDevice was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600836 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600837 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700838 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600839 device,
840 "VkDevice");
841 }
842
843 if (VK_FALSE == skipCall) {
844 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800845 my_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600846 }
847
848 // Regardless of skipCall value, do some internal cleanup:
849 if (pDevice) {
850 // Delete the SwpDevice associated with this device:
851 if (pDevice->pPhysicalDevice) {
852 pDevice->pPhysicalDevice->pDevice = NULL;
853 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600854 if (!pDevice->swapchains.empty()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700855 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600856 SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600857 "%s() called before all of its associated "
858 "VkSwapchainKHRs were destroyed.",
859 __FUNCTION__);
860 // Empty and then delete all SwpSwapchain's
861 for (auto it = pDevice->swapchains.begin() ;
862 it != pDevice->swapchains.end() ; it++) {
863 // Delete all SwpImage's
864 it->second->images.clear();
865 }
866 pDevice->swapchains.clear();
867 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600868 my_data->deviceMap.erase(device);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600869 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600870 delete my_data->device_dispatch_table;
871 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600872}
873
Ian Elliott27d39c72015-11-20 16:39:34 -0700874VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
875 VkPhysicalDevice physicalDevice,
876 uint32_t queueFamilyIndex,
877 VkSurfaceKHR surface,
878 VkBool32* pSupported)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600879{
Ian Elliott320d0fc2015-12-30 12:04:43 -0700880// TODOs:
881//
882// - Ensure that queueFamilyIndex is a valid queue family index for
883// physicalDevice. How? Probably need to record data from another function
884// call(s).
Ian Elliott0b4d6242015-09-22 10:51:24 -0600885 VkResult result = VK_SUCCESS;
886 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600887 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600888 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700889
890 // Validate that the surface extension was enabled:
891 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
892 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700893 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600894 pPhysicalDevice->pInstance,
895 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600896 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -0800897 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott1dcd1092015-11-17 17:29:40 -0700898 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600899 }
Ian Elliottf955d682015-12-30 12:00:54 -0700900 if (!pSupported) {
901 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
902 physicalDevice,
903 "pSupported");
904 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600905
906 if (VK_FALSE == skipCall) {
907 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600908 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -0700909 physicalDevice, queueFamilyIndex, surface,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600910 pSupported);
911
912 if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) {
913 // Record the result of this query:
914 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] =
915 *pSupported;
916 // TODO: We need to compare this with the actual queue used for
917 // presentation, to ensure it was advertised to the application as
918 // supported for presentation.
919 }
920
921 return result;
922 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700923 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600924}
925
Ian Elliott27d39c72015-11-20 16:39:34 -0700926VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
927 VkPhysicalDevice physicalDevice,
928 VkSurfaceKHR surface,
929 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600930{
931 VkResult result = VK_SUCCESS;
932 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700933 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -0700934 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700935
936 // Validate that the surface extension was enabled:
937 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
938 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700939 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700940 pPhysicalDevice->pInstance,
941 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600942 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700943 "%s() called even though the %s extension was not enabled for this VkInstance.",
944 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600945 }
Ian Elliottf955d682015-12-30 12:00:54 -0700946 if (!pSurfaceCapabilities) {
947 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
948 physicalDevice,
949 "pSurfaceCapabilities");
950 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600951
952 if (VK_FALSE == skipCall) {
953 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700954 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceCapabilitiesKHR(
955 physicalDevice, surface, pSurfaceCapabilities);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600956
Ian Elliott27d39c72015-11-20 16:39:34 -0700957 if ((result == VK_SUCCESS) && pPhysicalDevice) {
Ian Elliottf955d682015-12-30 12:00:54 -0700958 // Record the result of this query:
Ian Elliott27d39c72015-11-20 16:39:34 -0700959 pPhysicalDevice->gotSurfaceCapabilities = true;
960// FIXME: NEED TO COPY THIS DATA, BECAUSE pSurfaceCapabilities POINTS TO APP-ALLOCATED DATA
961 pPhysicalDevice->surfaceCapabilities = *pSurfaceCapabilities;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600962 }
963
964 return result;
965 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700966 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600967}
968
Ian Elliott27d39c72015-11-20 16:39:34 -0700969VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
970 VkPhysicalDevice physicalDevice,
971 VkSurfaceKHR surface,
Ian Elliottf955d682015-12-30 12:00:54 -0700972 uint32_t* pSurfaceFormatCount,
Ian Elliott27d39c72015-11-20 16:39:34 -0700973 VkSurfaceFormatKHR* pSurfaceFormats)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600974{
975 VkResult result = VK_SUCCESS;
976 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700977 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -0700978 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700979
980 // Validate that the surface extension was enabled:
981 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
982 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700983 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700984 pPhysicalDevice->pInstance,
985 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600986 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700987 "%s() called even though the %s extension was not enabled for this VkInstance.",
988 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600989 }
Ian Elliottf955d682015-12-30 12:00:54 -0700990 if (!pSurfaceFormatCount) {
991 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
992 physicalDevice,
993 "pSurfaceFormatCount");
994 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600995
996 if (VK_FALSE == skipCall) {
997 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700998 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceFormatsKHR(
Ian Elliottf955d682015-12-30 12:00:54 -0700999 physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001000
Ian Elliottf955d682015-12-30 12:00:54 -07001001 if ((result == VK_SUCCESS) && pPhysicalDevice && !pSurfaceFormats &&
1002 pSurfaceFormatCount) {
1003 // Record the result of this preliminary query:
1004 pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount;
1005 }
Ian Elliott9059b302015-12-30 13:14:36 -07001006 else if ((result == VK_SUCCESS) && pPhysicalDevice && pSurfaceFormats &&
1007 pSurfaceFormatCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001008 // Compare the preliminary value of *pSurfaceFormatCount with the
1009 // value this time:
1010 if (*pSurfaceFormatCount != pPhysicalDevice->surfaceFormatCount) {
1011 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1012 physicalDevice,
1013 "pSurfaceFormatCount",
1014 "pSurfaceFormats",
1015 pPhysicalDevice->surfaceFormatCount);
1016 }
Ian Elliott9059b302015-12-30 13:14:36 -07001017 else if (*pSurfaceFormatCount > 0) {
1018 // Record the result of this query:
1019 pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount;
1020 pPhysicalDevice->pSurfaceFormats = (VkSurfaceFormatKHR *)
1021 malloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR));
1022 if (pPhysicalDevice->pSurfaceFormats) {
1023 for (uint32_t i = 0 ; i < *pSurfaceFormatCount ; i++) {
1024 pPhysicalDevice->pSurfaceFormats[i] = pSurfaceFormats[i];
1025 }
1026 } else {
1027 pPhysicalDevice->surfaceFormatCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001028 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001029 }
1030 }
1031
1032 return result;
1033 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001034 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001035}
1036
Ian Elliott27d39c72015-11-20 16:39:34 -07001037VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
1038 VkPhysicalDevice physicalDevice,
1039 VkSurfaceKHR surface,
Ian Elliottf955d682015-12-30 12:00:54 -07001040 uint32_t* pPresentModeCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001041 VkPresentModeKHR* pPresentModes)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001042{
1043 VkResult result = VK_SUCCESS;
1044 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -07001045 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -07001046 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -07001047
1048 // Validate that the surface extension was enabled:
1049 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
1050 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001051 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001052 pPhysicalDevice->pInstance,
1053 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001054 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -07001055 "%s() called even though the %s extension was not enabled for this VkInstance.",
1056 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001057 }
Ian Elliottf955d682015-12-30 12:00:54 -07001058 if (!pPresentModeCount) {
1059 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1060 physicalDevice,
1061 "pPresentModeCount");
1062 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001063
1064 if (VK_FALSE == skipCall) {
1065 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001066 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfacePresentModesKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001067 physicalDevice, surface, pPresentModeCount, pPresentModes);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001068
Ian Elliottf955d682015-12-30 12:00:54 -07001069 if ((result == VK_SUCCESS) && pPhysicalDevice && !pPresentModes &&
1070 pPresentModeCount) {
1071 // Record the result of this preliminary query:
1072 pPhysicalDevice->presentModeCount = *pPresentModeCount;
1073 }
Ian Elliott9059b302015-12-30 13:14:36 -07001074 else if ((result == VK_SUCCESS) && pPhysicalDevice && pPresentModes &&
1075 pPresentModeCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001076 // Compare the preliminary value of *pPresentModeCount with the
1077 // value this time:
1078 if (*pPresentModeCount != pPhysicalDevice->presentModeCount) {
1079 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1080 physicalDevice,
1081 "pPresentModeCount",
1082 "pPresentModes",
1083 pPhysicalDevice->presentModeCount);
1084 }
Ian Elliott9059b302015-12-30 13:14:36 -07001085 else if (*pPresentModeCount > 0) {
1086 // Record the result of this query:
1087 pPhysicalDevice->presentModeCount = *pPresentModeCount;
1088 pPhysicalDevice->pPresentModes = (VkPresentModeKHR *)
1089 malloc(*pPresentModeCount * sizeof(VkPresentModeKHR));
1090 if (pPhysicalDevice->pSurfaceFormats) {
1091 for (uint32_t i = 0 ; i < *pPresentModeCount ; i++) {
1092 pPhysicalDevice->pPresentModes[i] = pPresentModes[i];
1093 }
1094 } else {
1095 pPhysicalDevice->presentModeCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001096 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001097 }
1098 }
1099
1100 return result;
1101 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001102 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001103}
1104
1105// This function does the up-front validation work for vkCreateSwapchainKHR(),
1106// and returns VK_TRUE if a logging callback indicates that the call down the
1107// chain should be skipped:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001108static VkBool32 validateCreateSwapchainKHR(
1109 VkDevice device,
1110 const VkSwapchainCreateInfoKHR* pCreateInfo,
1111 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001112{
1113// TODO: Validate cases of re-creating a swapchain (the current code
1114// assumes a new swapchain is being created).
1115 VkResult result = VK_SUCCESS;
1116 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001117 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001118 char fn[] = "vkCreateSwapchainKHR";
1119
1120 // Validate that a valid VkDevice was used, and that the device
1121 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001122 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001123 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001124 return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001125 SWAPCHAIN_INVALID_HANDLE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001126 "%s() called with a non-valid %s.",
1127 fn, "VkDevice");
1128
Ian Elliott427058f2015-12-29 16:45:49 -07001129 } else if (!pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001130 return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001131 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001132 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001133 fn, VK_KHR_SWAPCHAIN_EXTENSION_NAME );
Ian Elliott0b4d6242015-09-22 10:51:24 -06001134 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001135 if (!pCreateInfo) {
1136 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1137 device,
1138 "pCreateInfo");
Ian Elliottf5758292015-12-30 17:39:02 -07001139 } else {
1140 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR) {
1141 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1142 device,
1143 "pCreateInfo",
1144 "VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR");
1145 }
1146 if (pCreateInfo->pNext != NULL) {
1147 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1148 device,
1149 "pCreateInfo");
1150 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001151 }
1152 if (!pSwapchain) {
1153 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1154 device,
1155 "pSwapchain");
1156 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001157
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001158 // Keep around a useful pointer to pPhysicalDevice:
1159 SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice;
1160
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001161 // Validate pCreateInfo values with the results of
1162 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1163 if (!pPhysicalDevice || !pPhysicalDevice->gotSurfaceCapabilities) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001164 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001165 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001166 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001167 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001168 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001169 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001170 // Validate pCreateInfo->minImageCount against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001171 // VkSurfaceCapabilitiesKHR::{min|max}ImageCount:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001172 VkSurfaceCapabilitiesKHR *pCapabilities = &pPhysicalDevice->surfaceCapabilities;
Ian Elliott27d39c72015-11-20 16:39:34 -07001173 if ((pCreateInfo->minImageCount < pCapabilities->minImageCount) ||
1174 ((pCapabilities->maxImageCount > 0) &&
1175 (pCreateInfo->minImageCount > pCapabilities->maxImageCount))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001176 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001177 SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001178 "%s() called with pCreateInfo->minImageCount "
1179 "= %d, which is outside the bounds returned "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001180 "by vkGetPhysicalDeviceSurfaceCapabilitiesKHR() (i.e. "
Ian Elliott0b4d6242015-09-22 10:51:24 -06001181 "minImageCount = %d, maxImageCount = %d).",
1182 fn,
1183 pCreateInfo->minImageCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001184 pCapabilities->minImageCount,
1185 pCapabilities->maxImageCount);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001186 }
1187 // Validate pCreateInfo->imageExtent against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001188 // VkSurfaceCapabilitiesKHR::{current|min|max}ImageExtent:
Ian Elliott27d39c72015-11-20 16:39:34 -07001189 if ((pCapabilities->currentExtent.width == -1) &&
1190 ((pCreateInfo->imageExtent.width < pCapabilities->minImageExtent.width) ||
1191 (pCreateInfo->imageExtent.width > pCapabilities->maxImageExtent.width) ||
1192 (pCreateInfo->imageExtent.height < pCapabilities->minImageExtent.height) ||
1193 (pCreateInfo->imageExtent.height > pCapabilities->maxImageExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001194 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001195 SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001196 "%s() called with pCreateInfo->imageExtent = "
1197 "(%d,%d), which is outside the bounds "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001198 "returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): "
Ian Elliott0b4d6242015-09-22 10:51:24 -06001199 "currentExtent = (%d,%d), minImageExtent = "
1200 "(%d,%d), maxImageExtent = (%d,%d).",
1201 fn,
1202 pCreateInfo->imageExtent.width,
1203 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001204 pCapabilities->currentExtent.width,
1205 pCapabilities->currentExtent.height,
1206 pCapabilities->minImageExtent.width,
1207 pCapabilities->minImageExtent.height,
1208 pCapabilities->maxImageExtent.width,
1209 pCapabilities->maxImageExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001210 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001211 if ((pCapabilities->currentExtent.width != -1) &&
1212 ((pCreateInfo->imageExtent.width != pCapabilities->currentExtent.width) ||
1213 (pCreateInfo->imageExtent.height != pCapabilities->currentExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001214 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001215 SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001216 "%s() called with pCreateInfo->imageExtent = "
1217 "(%d,%d), which is not equal to the "
1218 "currentExtent = (%d,%d) returned by "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001219 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001220 fn,
1221 pCreateInfo->imageExtent.width,
1222 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001223 pCapabilities->currentExtent.width,
1224 pCapabilities->currentExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001225 }
1226 // Validate pCreateInfo->preTransform against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001227 // VkSurfaceCapabilitiesKHR::supportedTransforms:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001228 if (!((pCreateInfo->preTransform) & pCapabilities->supportedTransforms)) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001229 // This is an error situation; one for which we'd like to give
1230 // the developer a helpful, multi-line error message. Build it
1231 // up a little at a time, and then log it:
1232 std::string errorString = "";
1233 char str[1024];
1234 // Here's the first part of the message:
1235 sprintf(str, "%s() called with a non-supported "
1236 "pCreateInfo->preTransform (i.e. %s). "
1237 "Supported values are:\n",
1238 fn,
1239 surfaceTransformStr(pCreateInfo->preTransform));
1240 errorString += str;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001241 for (int i = 0; i < 32; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001242 // Build up the rest of the message:
Ian Elliott27d39c72015-11-20 16:39:34 -07001243 if ((1 << i) & pCapabilities->supportedTransforms) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001244 const char *newStr =
Ian Elliott27d39c72015-11-20 16:39:34 -07001245 surfaceTransformStr((VkSurfaceTransformFlagBitsKHR) (1 << i));
Ian Elliott0b4d6242015-09-22 10:51:24 -06001246 sprintf(str, " %s\n", newStr);
1247 errorString += str;
1248 }
1249 }
1250 // Log the message that we've built up:
Ian Elliott68124ac2015-10-07 16:18:35 -06001251 skipCall |= debug_report_log_msg(my_data->report_data,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001252 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1253 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Mark Lobodzinski80e774f2016-01-04 15:54:59 -07001254 (uint64_t) device, __LINE__,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001255 SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM,
1256 LAYER_NAME,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001257 errorString.c_str());
1258 }
Ian Elliotta2a89c52015-12-28 15:23:57 -07001259 // Validate pCreateInfo->compositeAlpha against
1260 // VkSurfaceCapabilitiesKHR::supportedCompositeAlpha:
1261 if (!((pCreateInfo->compositeAlpha) & pCapabilities->supportedCompositeAlpha)) {
1262 // This is an error situation; one for which we'd like to give
1263 // the developer a helpful, multi-line error message. Build it
1264 // up a little at a time, and then log it:
1265 std::string errorString = "";
1266 char str[1024];
1267 // Here's the first part of the message:
1268 sprintf(str, "%s() called with a non-supported "
1269 "pCreateInfo->compositeAlpha (i.e. %s). "
1270 "Supported values are:\n",
1271 fn,
1272 surfaceCompositeAlphaStr(pCreateInfo->compositeAlpha));
1273 errorString += str;
1274 for (int i = 0; i < 32; i++) {
1275 // Build up the rest of the message:
1276 if ((1 << i) & pCapabilities->supportedCompositeAlpha) {
1277 const char *newStr =
1278 surfaceCompositeAlphaStr((VkCompositeAlphaFlagBitsKHR) (1 << i));
1279 sprintf(str, " %s\n", newStr);
1280 errorString += str;
1281 }
1282 }
1283 // Log the message that we've built up:
1284 skipCall |= debug_report_log_msg(my_data->report_data,
Ian Elliott1bf155f2015-12-29 17:35:46 -07001285 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1286 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliotta2a89c52015-12-28 15:23:57 -07001287 (uint64_t) device, 0,
1288 SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA,
1289 LAYER_NAME,
1290 errorString.c_str());
1291 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001292 // Validate pCreateInfo->imageArraySize against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001293 // VkSurfaceCapabilitiesKHR::maxImageArraySize:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001294 if ((pCreateInfo->imageArrayLayers > 0) &&
1295 (pCreateInfo->imageArrayLayers > pCapabilities->maxImageArrayLayers)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001296 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001297 SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_SIZE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001298 "%s() called with a non-supported "
1299 "pCreateInfo->imageArraySize (i.e. %d). "
1300 "Maximum value is %d.",
1301 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001302 pCreateInfo->imageArrayLayers,
1303 pCapabilities->maxImageArrayLayers);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001304 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001305 // Validate pCreateInfo->imageUsage against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001306 // VkSurfaceCapabilitiesKHR::supportedUsageFlags:
Ian Elliott27d39c72015-11-20 16:39:34 -07001307 if (pCreateInfo->imageUsage &&
1308 (pCreateInfo->imageUsage !=
1309 (pCreateInfo->imageUsage & pCapabilities->supportedUsageFlags))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001310 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001311 SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001312 "%s() called with a non-supported "
Ian Elliott27d39c72015-11-20 16:39:34 -07001313 "pCreateInfo->imageUsage (i.e. 0x%08x)."
Ian Elliott0b4d6242015-09-22 10:51:24 -06001314 " Supported flag bits are 0x%08x.",
1315 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001316 pCreateInfo->imageUsage,
1317 pCapabilities->supportedUsageFlags);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001318 }
1319 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001320
1321 // Validate pCreateInfo values with the results of
1322 // vkGetPhysicalDeviceSurfaceFormatsKHR():
1323 if (!pPhysicalDevice || !pPhysicalDevice->surfaceFormatCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001324 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001325 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001326 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001327 "vkGetPhysicalDeviceSurfaceFormatsKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001328 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001329 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001330 // Validate pCreateInfo->imageFormat against
1331 // VkSurfaceFormatKHR::format:
1332 bool foundFormat = false;
1333 bool foundColorSpace = false;
1334 bool foundMatch = false;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001335 for (uint32_t i = 0 ; i < pPhysicalDevice->surfaceFormatCount ; i++) {
1336 if (pCreateInfo->imageFormat == pPhysicalDevice->pSurfaceFormats[i].format) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001337 // Validate pCreateInfo->imageColorSpace against
1338 // VkSurfaceFormatKHR::colorSpace:
1339 foundFormat = true;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001340 if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001341 foundMatch = true;
1342 break;
1343 }
1344 } else {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001345 if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001346 foundColorSpace = true;
1347 }
1348 }
1349 }
1350 if (!foundMatch) {
1351 if (!foundFormat) {
1352 if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001353 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001354 "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001355 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001356 "%s() called with neither a "
1357 "supported pCreateInfo->imageFormat "
1358 "(i.e. %d) nor a supported "
1359 "pCreateInfo->imageColorSpace "
1360 "(i.e. %d).",
1361 fn,
1362 pCreateInfo->imageFormat,
1363 pCreateInfo->imageColorSpace);
1364 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001365 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001366 "VkDevice",
1367 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001368 "%s() called with a non-supported "
1369 "pCreateInfo->imageFormat (i.e. %d).",
1370 fn, pCreateInfo->imageFormat);
1371 }
1372 } else if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001373 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001374 SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001375 "%s() called with a non-supported "
1376 "pCreateInfo->imageColorSpace (i.e. %d).",
1377 fn, pCreateInfo->imageColorSpace);
1378 }
1379 }
1380 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001381
1382 // Validate pCreateInfo values with the results of
1383 // vkGetPhysicalDeviceSurfacePresentModesKHR():
1384 if (!pPhysicalDevice || !pPhysicalDevice->presentModeCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001385 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001386 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001387 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001388 "vkGetPhysicalDeviceSurfacePresentModesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001389 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001390 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001391 // Validate pCreateInfo->presentMode against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001392 // vkGetPhysicalDeviceSurfacePresentModesKHR():
Ian Elliott0b4d6242015-09-22 10:51:24 -06001393 bool foundMatch = false;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001394 for (uint32_t i = 0 ; i < pPhysicalDevice->presentModeCount ; i++) {
1395 if (pPhysicalDevice->pPresentModes[i] == pCreateInfo->presentMode) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001396 foundMatch = true;
1397 break;
1398 }
1399 }
1400 if (!foundMatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001401 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001402 SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001403 "%s() called with a non-supported "
1404 "pCreateInfo->presentMode (i.e. %s).",
1405 fn,
1406 presentModeStr(pCreateInfo->presentMode));
1407 }
1408 }
1409
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001410 // Validate pCreateInfo->imageSharingMode and related values:
Ian Elliotta2a89c52015-12-28 15:23:57 -07001411 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
1412 if ((pCreateInfo->queueFamilyIndexCount <= 1) ||
1413 !pCreateInfo->pQueueFamilyIndices) {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001414 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001415 SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES,
1416 "%s() called with a supported "
1417 "pCreateInfo->sharingMode of (i.e. %s),"
1418 "but with a bad value(s) for "
1419 "pCreateInfo->queueFamilyIndexCount or "
1420 "pCreateInfo->pQueueFamilyIndices).",
1421 fn,
1422 sharingModeStr(pCreateInfo->imageSharingMode));
1423 }
1424 } else if (pCreateInfo->imageSharingMode != VK_SHARING_MODE_EXCLUSIVE) {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001425 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001426 SWAPCHAIN_CREATE_SWAP_BAD_SHARING_MODE,
1427 "%s() called with a non-supported "
1428 "pCreateInfo->imageSharingMode (i.e. %s).",
1429 fn,
1430 sharingModeStr(pCreateInfo->imageSharingMode));
1431 }
1432
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001433 // Validate pCreateInfo->clipped:
1434 if (pCreateInfo &&
1435 (pCreateInfo->clipped != VK_FALSE) &&
Ian Elliotta2a89c52015-12-28 15:23:57 -07001436 (pCreateInfo->clipped != VK_TRUE)) {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001437 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1438 device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001439 SWAPCHAIN_BAD_BOOL,
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001440 "%s() called with a VkBool32 value that is "
1441 "neither VK_TRUE nor VK_FALSE, but has the "
1442 "numeric value of %d.",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001443 fn,
1444 pCreateInfo->clipped);
1445 }
1446
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001447 // Validate pCreateInfo->oldSwapchain:
1448 if (pCreateInfo && pCreateInfo->oldSwapchain) {
1449 SwpSwapchain *pOldSwapchain = &my_data->swapchainMap[pCreateInfo->oldSwapchain];
1450 if (pOldSwapchain) {
1451 if (device != pOldSwapchain->pDevice->device) {
1452 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1453 device, "VkDevice",
1454 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
1455 "%s() called with a different VkDevice "
1456 "than the VkSwapchainKHR was created with.",
1457 __FUNCTION__);
1458 }
1459 if (pCreateInfo->surface != pOldSwapchain->surface) {
1460 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1461 device, "VkDevice",
1462 SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE,
1463 "%s() called with pCreateInfo->oldSwapchain "
1464 "that has a different VkSurfaceKHR than "
1465 "pCreateInfo->surface.",
1466 fn);
Ian Elliotta2a89c52015-12-28 15:23:57 -07001467 }
1468 } else {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001469 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliotta2a89c52015-12-28 15:23:57 -07001470 pCreateInfo->oldSwapchain,
1471 "VkSwapchainKHR");
1472 }
1473 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001474
1475 return skipCall;
1476}
1477
Ian Elliott27d39c72015-11-20 16:39:34 -07001478VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
1479 VkDevice device,
1480 const VkSwapchainCreateInfoKHR* pCreateInfo,
1481 const VkAllocationCallbacks* pAllocator,
1482 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001483{
1484 VkResult result = VK_SUCCESS;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001485 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001486 VkBool32 skipCall = validateCreateSwapchainKHR(device, pCreateInfo,
1487 pSwapchain);
1488
1489 if (VK_FALSE == skipCall) {
1490 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001491 result = my_data->device_dispatch_table->CreateSwapchainKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001492 device, pCreateInfo, pAllocator, pSwapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001493
1494 if (result == VK_SUCCESS) {
1495 // Remember the swapchain's handle, and link it to the device:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001496 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001497
Tobin Ehlis711ff312015-10-29 12:58:13 -06001498 my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001499 pDevice->swapchains[*pSwapchain] =
Tobin Ehlis711ff312015-10-29 12:58:13 -06001500 &my_data->swapchainMap[*pSwapchain];
1501 my_data->swapchainMap[*pSwapchain].pDevice = pDevice;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001502 my_data->swapchainMap[*pSwapchain].surface =
1503 (pCreateInfo) ? pCreateInfo->surface : 0;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001504 my_data->swapchainMap[*pSwapchain].imageCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001505 }
1506
1507 return result;
1508 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001509 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001510}
1511
Ian Elliott27d39c72015-11-20 16:39:34 -07001512VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
1513 VkDevice device,
1514 VkSwapchainKHR swapchain,
1515 const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001516{
1517 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001518 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001519
1520 // Validate that a valid VkDevice was used, and that the device
1521 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001522 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001523 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001524 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001525 device,
1526 "VkDevice");
Ian Elliott427058f2015-12-29 16:45:49 -07001527 } else if (!pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001528 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001529 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001530 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001531 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001532 }
1533
1534 // Regardless of skipCall value, do some internal cleanup:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001535 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001536 if (pSwapchain) {
1537 // Delete the SwpSwapchain associated with this swapchain:
1538 if (pSwapchain->pDevice) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08001539 pSwapchain->pDevice->swapchains.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001540 if (device != pSwapchain->pDevice->device) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001541 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001542 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001543 "%s() called with a different VkDevice than the "
1544 "VkSwapchainKHR was created with.",
1545 __FUNCTION__);
1546 }
1547 }
1548 if (pSwapchain->imageCount) {
1549 pSwapchain->images.clear();
1550 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001551 my_data->swapchainMap.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001552 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001553 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Chia-I Wue2fc5522015-10-26 20:04:44 +08001554 swapchain,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001555 "VkSwapchainKHR");
1556 }
1557
1558 if (VK_FALSE == skipCall) {
1559 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001560 my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001561 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001562}
1563
Ian Elliottf955d682015-12-30 12:00:54 -07001564VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
1565 VkDevice device,
1566 VkSwapchainKHR swapchain,
1567 uint32_t* pSwapchainImageCount,
1568 VkImage* pSwapchainImages)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001569{
1570 VkResult result = VK_SUCCESS;
1571 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001572 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001573
1574 // Validate that a valid VkDevice was used, and that the device
1575 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001576 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001577 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001578 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001579 device,
1580 "VkDevice");
Ian Elliott427058f2015-12-29 16:45:49 -07001581 } else if (!pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001582 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001583 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001584 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001585 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001586 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001587 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001588 if (!pSwapchain) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001589 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001590 swapchain.handle,
1591 "VkSwapchainKHR");
1592 }
Ian Elliottf955d682015-12-30 12:00:54 -07001593 if (!pSwapchainImageCount) {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001594 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1595 device,
Ian Elliottf955d682015-12-30 12:00:54 -07001596 "pSwapchainImageCount");
1597 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001598
1599 if (VK_FALSE == skipCall) {
1600 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001601 result = my_data->device_dispatch_table->GetSwapchainImagesKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001602 device, swapchain, pSwapchainImageCount, pSwapchainImages);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001603
Ian Elliottf955d682015-12-30 12:00:54 -07001604 if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages &&
1605 pSwapchainImageCount) {
1606 // Record the result of this preliminary query:
1607 pSwapchain->imageCount = *pSwapchainImageCount;
1608 }
Ian Elliott9059b302015-12-30 13:14:36 -07001609 else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages &&
1610 pSwapchainImageCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001611 // Compare the preliminary value of *pSwapchainImageCount with the
1612 // value this time:
1613 if (*pSwapchainImageCount != pSwapchain->imageCount) {
1614 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1615 device,
1616 "pSwapchainImageCount",
1617 "pSwapchainImages",
1618 pSwapchain->imageCount);
1619 }
Ian Elliott9059b302015-12-30 13:14:36 -07001620 else if (*pSwapchainImageCount > 0) {
1621 // Record the images and their state:
1622 pSwapchain->imageCount = *pSwapchainImageCount;
1623 for (uint32_t i = 0 ; i < *pSwapchainImageCount ; i++) {
1624 pSwapchain->images[i].image = pSwapchainImages[i];
1625 pSwapchain->images[i].pSwapchain = pSwapchain;
1626 pSwapchain->images[i].ownedByApp = false;
1627 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001628 }
1629 }
1630
1631 return result;
1632 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001633 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001634}
1635
Ian Elliott27d39c72015-11-20 16:39:34 -07001636VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
1637 VkDevice device,
1638 VkSwapchainKHR swapchain,
1639 uint64_t timeout,
1640 VkSemaphore semaphore,
1641 VkFence fence,
1642 uint32_t* pImageIndex)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001643{
Ian Elliottdd45e462015-12-29 17:52:10 -07001644// TODOs:
1645//
1646// - Address the timeout. Possibilities include looking at the state of the
1647// swapchain's images, depending on the timeout value.
1648// - Validate that semaphore and fence are either VK_NULL_HANDLE or valid
1649// handles.
1650// - Record/update the state of the swapchain, in case an error occurs
1651// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
Ian Elliott0b4d6242015-09-22 10:51:24 -06001652 VkResult result = VK_SUCCESS;
1653 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001654 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001655
1656 // Validate that a valid VkDevice was used, and that the device
1657 // extension was enabled:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001658 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001659 if (!pDevice) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001660 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001661 device,
1662 "VkDevice");
Ian Elliott427058f2015-12-29 16:45:49 -07001663 } else if (!pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001664 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001665 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001666 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001667 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001668 }
1669 // Validate that a valid VkSwapchainKHR was used:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001670 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001671 if (!pSwapchain) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001672 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Chia-I Wue2fc5522015-10-26 20:04:44 +08001673 swapchain,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001674 "VkSwapchainKHR");
1675 } else {
1676 // Look to see if the application is trying to own too many images at
1677 // the same time (i.e. not leave any to display):
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001678 uint32_t imagesOwnedByApp = 0;
1679 for (uint32_t i = 0 ; i < pSwapchain->imageCount ; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001680 if (pSwapchain->images[i].ownedByApp) {
1681 imagesOwnedByApp++;
1682 }
1683 }
1684 if (imagesOwnedByApp >= (pSwapchain->imageCount - 1)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001685 skipCall |= LOG_PERF_WARNING(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott4a994452015-09-24 18:33:16 -06001686 swapchain,
1687 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001688 SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES,
Ian Elliott4a994452015-09-24 18:33:16 -06001689 "%s() called when the application "
1690 "already owns all presentable images "
1691 "in this swapchain except for the "
1692 "image currently being displayed. "
1693 "This call to %s() cannot succeed "
1694 "unless another thread calls the "
1695 "vkQueuePresentKHR() function in "
1696 "order to release ownership of one of "
1697 "the presentable images of this "
1698 "swapchain.",
1699 __FUNCTION__, __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001700 }
1701 }
Ian Elliottdd45e462015-12-29 17:52:10 -07001702 if (!pImageIndex) {
1703 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1704 device,
1705 "pImageIndex");
1706 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001707
1708 if (VK_FALSE == skipCall) {
1709 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001710 result = my_data->device_dispatch_table->AcquireNextImageKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001711 device, swapchain, timeout, semaphore, fence, pImageIndex);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001712
1713 if (((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)) &&
1714 pSwapchain) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001715 // Change the state of the image (now owned by the application):
1716 pSwapchain->images[*pImageIndex].ownedByApp = true;
1717 }
1718
1719 return result;
1720 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001721 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001722}
1723
Ian Elliott27d39c72015-11-20 16:39:34 -07001724VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(
1725 VkQueue queue,
1726 const VkPresentInfoKHR* pPresentInfo)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001727{
1728// TODOs:
1729//
1730// - Ensure that the queue is active, and is one of the queueFamilyIndex's
1731// that was returned by a previuos query.
1732// - Record/update the state of the swapchain, in case an error occurs
1733// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
1734 VkResult result = VK_SUCCESS;
1735 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001736 layer_data *my_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001737
Ian Elliott046ed2c2015-12-30 17:07:17 -07001738 if (!pPresentInfo) {
1739 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1740 device,
1741 "pPresentInfo");
1742 } else {
1743 if (pPresentInfo->sType != VK_STRUCTURE_TYPE_PRESENT_INFO_KHR) {
1744 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1745 device,
1746 "pPresentInfo",
1747 "VK_STRUCTURE_TYPE_PRESENT_INFO_KHR");
1748 }
1749 if (pPresentInfo->pNext != NULL) {
1750 skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1751 device,
1752 "pPresentInfo");
1753 }
1754 if (!pPresentInfo->waitSemaphoreCount) {
1755 skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1756 device,
1757 "pPresentInfo->waitSemaphoreCount");
1758 }
1759 if (!pPresentInfo->pWaitSemaphores) {
1760 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1761 device,
1762 "pPresentInfo->pWaitSemaphores");
1763 }
1764 if (!pPresentInfo->swapchainCount) {
1765 skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1766 device,
1767 "pPresentInfo->swapchainCount");
1768 }
1769 if (!pPresentInfo->pSwapchains) {
1770 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1771 device,
1772 "pPresentInfo->pSwapchains");
1773 }
1774 if (!pPresentInfo->pImageIndices) {
1775 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1776 device,
1777 "pPresentInfo->pImageIndices");
1778 }
1779 // Note: pPresentInfo->pResults is allowed to be NULL
1780 }
1781
1782 for (uint32_t i = 0;
1783 pPresentInfo && (i < pPresentInfo->swapchainCount);
1784 i++) {
1785 uint32_t swapchainCount = pPresentInfo->swapchainCount;
Ian Elliott27d39c72015-11-20 16:39:34 -07001786 uint32_t index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001787 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001788 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001789 if (pSwapchain) {
Ian Elliott427058f2015-12-29 16:45:49 -07001790 if (!pSwapchain->pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001791 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001792 pSwapchain->pDevice, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001793 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001794 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001795 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001796 }
1797 if (index >= pSwapchain->imageCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001798 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001799 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001800 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001801 SWAPCHAIN_INDEX_TOO_LARGE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001802 "%s() called for an index that is too "
1803 "large (i.e. %d). There are only %d "
1804 "images in this VkSwapchainKHR.\n",
1805 __FUNCTION__, index,
1806 pSwapchain->imageCount);
1807 } else {
1808 if (!pSwapchain->images[index].ownedByApp) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001809 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001810 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001811 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001812 SWAPCHAIN_INDEX_NOT_IN_USE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001813 "%s() returned an index (i.e. %d) "
1814 "for an image that is not owned by "
1815 "the application.",
1816 __FUNCTION__, index);
1817 }
1818 }
1819 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001820 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001821 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001822 "VkSwapchainKHR");
1823 }
1824 }
1825
1826 if (VK_FALSE == skipCall) {
1827 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001828 result = my_data->device_dispatch_table->QueuePresentKHR(queue,
Ian Elliott046ed2c2015-12-30 17:07:17 -07001829 pPresentInfo);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001830
Ian Elliott046ed2c2015-12-30 17:07:17 -07001831 if (pPresentInfo &&
1832 ((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR))) {
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001833 for (uint32_t i = 0; i < pPresentInfo->swapchainCount ; i++) {
Ian Elliott27d39c72015-11-20 16:39:34 -07001834 int index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001835 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001836 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001837 if (pSwapchain) {
1838 // Change the state of the image (no longer owned by the
1839 // application):
1840 pSwapchain->images[index].ownedByApp = false;
1841 }
1842 }
1843 }
1844
1845 return result;
1846 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001847 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001848}
1849
1850static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)
1851{
1852 if (!name || name[0] != 'v' || name[1] != 'k')
1853 return NULL;
1854
1855 name += 2;
1856 if (!strcmp(name, "CreateInstance"))
1857 return (PFN_vkVoidFunction) vkCreateInstance;
1858 if (!strcmp(name, "DestroyInstance"))
1859 return (PFN_vkVoidFunction) vkDestroyInstance;
1860 if (!strcmp(name, "EnumeratePhysicalDevices"))
1861 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1862 if (!strcmp(name, "CreateDevice"))
1863 return (PFN_vkVoidFunction) vkCreateDevice;
1864 if (!strcmp(name, "DestroyDevice"))
1865 return (PFN_vkVoidFunction) vkDestroyDevice;
1866
1867 return NULL;
1868}
1869static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)
1870{
1871 if (!name || name[0] != 'v' || name[1] != 'k')
1872 return NULL;
1873
1874 name += 2;
1875 if (!strcmp(name, "CreateInstance"))
1876 return (PFN_vkVoidFunction) vkCreateInstance;
1877 if (!strcmp(name, "DestroyInstance"))
1878 return (PFN_vkVoidFunction) vkDestroyInstance;
1879 if (!strcmp(name, "EnumeratePhysicalDevices"))
1880 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1881
1882 return NULL;
1883}
1884
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001885VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
1886 VkInstance instance,
1887 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
1888 const VkAllocationCallbacks* pAllocator,
1889 VkDebugReportCallbackEXT* pMsgCallback)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001890{
Tobin Ehlis711ff312015-10-29 12:58:13 -06001891 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001892 VkResult result = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001893 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001894 result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001895 }
1896 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001897}
1898
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001899VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001900{
Ian Elliott68124ac2015-10-07 16:18:35 -06001901 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001902 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001903 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001904}
1905
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001906VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001907 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001908 VkDebugReportFlagsEXT flags,
1909 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001910 uint64_t object,
1911 size_t location,
1912 int32_t msgCode,
1913 const char* pLayerPrefix,
1914 const char* pMsg)
1915{
1916 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001917 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001918}
1919
Chia-I Wu9ab61502015-11-06 06:42:02 +08001920VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001921{
1922 PFN_vkVoidFunction addr;
1923 if (device == VK_NULL_HANDLE) {
1924 return NULL;
1925 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001926
Tobin Ehlis711ff312015-10-29 12:58:13 -06001927 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001928 /* loader uses this to force layer initialization; device object is wrapped */
1929 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001930 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) device;
1931 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
1932 my_data->device_dispatch_table = new VkLayerDispatchTable;
1933 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001934 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
1935 }
1936
1937 addr = layer_intercept_proc(funcName);
1938 if (addr)
1939 return addr;
1940
Tobin Ehlis711ff312015-10-29 12:58:13 -06001941 my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
1942 VkLayerDispatchTable *pDisp = my_data->device_dispatch_table;
1943 if (my_data->deviceMap.size() != 0 &&
Ian Elliott427058f2015-12-29 16:45:49 -07001944 my_data->deviceMap[device].swapchainExtensionEnabled)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001945 {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001946 if (!strcmp("vkCreateSwapchainKHR", funcName))
1947 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR);
1948 if (!strcmp("vkDestroySwapchainKHR", funcName))
1949 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR);
1950 if (!strcmp("vkGetSwapchainImagesKHR", funcName))
1951 return reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR);
1952 if (!strcmp("vkAcquireNextImageKHR", funcName))
1953 return reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR);
1954 if (!strcmp("vkQueuePresentKHR", funcName))
1955 return reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR);
1956 }
1957 {
1958 if (pDisp->GetDeviceProcAddr == NULL)
1959 return NULL;
1960 return pDisp->GetDeviceProcAddr(device, funcName);
1961 }
1962}
1963
Chia-I Wu9ab61502015-11-06 06:42:02 +08001964VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001965{
1966 PFN_vkVoidFunction addr;
1967 if (instance == VK_NULL_HANDLE) {
1968 return NULL;
1969 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001970
Tobin Ehlis711ff312015-10-29 12:58:13 -06001971 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001972 /* loader uses this to force layer initialization; instance object is wrapped */
1973 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001974 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
1975 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
1976 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
1977 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001978 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
1979 }
1980
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07001981 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
1982 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
1983 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
1984 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
1985
Ian Elliott0b4d6242015-09-22 10:51:24 -06001986 addr = layer_intercept_instance_proc(funcName);
1987 if (addr)
1988 return addr;
1989
Tobin Ehlis711ff312015-10-29 12:58:13 -06001990 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1991 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Ian Elliott68124ac2015-10-07 16:18:35 -06001992 addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
1993 if (addr) {
1994 return addr;
1995 }
1996
Ian Elliotta983e9a2015-12-22 12:18:12 -07001997#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001998 if (my_data->instanceMap.size() != 0 &&
1999 my_data->instanceMap[instance].androidSurfaceExtensionEnabled)
2000 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002001 if (!strcmp("vkCreateAndroidSurfaceKHR", funcName))
2002 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateAndroidSurfaceKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07002003 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07002004#endif // VK_USE_PLATFORM_ANDROID_KHR
2005#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002006 if (my_data->instanceMap.size() != 0 &&
2007 my_data->instanceMap[instance].mirSurfaceExtensionEnabled)
2008 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002009 if (!strcmp("vkCreateMirSurfaceKHR", funcName))
2010 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateMirSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002011 if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", funcName))
2012 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceMirPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07002013 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07002014#endif // VK_USE_PLATFORM_MIR_KHR
2015#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002016 if (my_data->instanceMap.size() != 0 &&
2017 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled)
2018 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002019 if (!strcmp("vkCreateWaylandSurfaceKHR", funcName))
2020 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWaylandSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002021 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", funcName))
2022 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07002023 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07002024#endif // VK_USE_PLATFORM_WAYLAND_KHR
2025#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002026 if (my_data->instanceMap.size() != 0 &&
2027 my_data->instanceMap[instance].win32SurfaceExtensionEnabled)
2028 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002029 if (!strcmp("vkCreateWin32SurfaceKHR", funcName))
2030 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWin32SurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002031 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", funcName))
2032 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWin32PresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07002033 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07002034#endif // VK_USE_PLATFORM_WIN32_KHR
2035#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002036 if (my_data->instanceMap.size() != 0 &&
2037 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled)
2038 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002039 if (!strcmp("vkCreateXcbSurfaceKHR", funcName))
2040 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXcbSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002041 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", funcName))
2042 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXcbPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07002043 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07002044#endif // VK_USE_PLATFORM_XCB_KHR
2045#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002046 if (my_data->instanceMap.size() != 0 &&
2047 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled)
2048 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002049 if (!strcmp("vkCreateXlibSurfaceKHR", funcName))
2050 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXlibSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07002051 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", funcName))
2052 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXlibPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07002053 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07002054#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002055 if (my_data->instanceMap.size() != 0 &&
2056 my_data->instanceMap[instance].surfaceExtensionEnabled)
2057 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002058 if (!strcmp("vkDestroySurfaceKHR", funcName))
2059 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySurfaceKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002060 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", funcName))
2061 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceSupportKHR);
Ian Elliott27d39c72015-11-20 16:39:34 -07002062 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", funcName))
2063 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
2064 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", funcName))
2065 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceFormatsKHR);
2066 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", funcName))
2067 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfacePresentModesKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002068 }
2069
2070 if (pTable->GetInstanceProcAddr == NULL)
2071 return NULL;
2072 return pTable->GetInstanceProcAddr(instance, funcName);
2073}
2074