blob: 857a17437d9408ed48be9a5dd1263b207d28800f [file] [log] [blame]
Ian Elliott0b4d6242015-09-22 10:51:24 -06001/*
Ian Elliott0b4d6242015-09-22 10:51:24 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Ian Elliott0b4d6242015-09-22 10:51:24 -06004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 * Author: Ian Elliott <ian@lunarg.com>
Ian Elliott578e7e22016-01-05 14:03:16 -070024 * Author: Ian Elliott <ianelliott@google.com>
Ian Elliott0b4d6242015-09-22 10:51:24 -060025 */
26
Ian Elliottd8c5db12015-10-07 11:32:31 -060027#include <stdio.h>
28#include <string.h>
Mark Lobodzinskib49b6e52015-11-26 10:59:58 -070029#include <vk_loader_platform.h>
Ian Elliotta983e9a2015-12-22 12:18:12 -070030#include <vk_icd.h>
Ian Elliott0b4d6242015-09-22 10:51:24 -060031#include "swapchain.h"
Tobin Ehlis711ff312015-10-29 12:58:13 -060032#include "vk_layer_extension_utils.h"
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070033#include "vk_enum_string_helper.h"
Ian Elliott68124ac2015-10-07 16:18:35 -060034
Ian Elliott0b4d6242015-09-22 10:51:24 -060035// FIXME/TODO: Make sure this layer is thread-safe!
36
Ian Elliott68124ac2015-10-07 16:18:35 -060037
Ian Elliott0b4d6242015-09-22 10:51:24 -060038// The following is for logging error messages:
Ian Elliott68124ac2015-10-07 16:18:35 -060039static std::unordered_map<void *, layer_data *> layer_data_map;
Ian Elliott0b4d6242015-09-22 10:51:24 -060040
Ian Elliott68124ac2015-10-07 16:18:35 -060041template layer_data *get_my_data_ptr<layer_data>(
42 void *data_key,
43 std::unordered_map<void *, layer_data *> &data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -060044
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -070045static const VkExtensionProperties instance_extensions[] = {
46 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070047 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
48 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -070049 }
50};
51
52VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
53 const char *pLayerName,
54 uint32_t *pCount,
55 VkExtensionProperties* pProperties)
56{
57 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
58}
59
60static const VkLayerProperties swapchain_global_layers[] = {
61 {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070062 "swapchain",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -070063 VK_API_VERSION,
64 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070065 "Validation layer: swapchain",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -070066 }
67};
68
69VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
70 uint32_t *pCount,
71 VkLayerProperties* pProperties)
72{
73 return util_GetLayerProperties(ARRAY_SIZE(swapchain_global_layers),
74 swapchain_global_layers,
75 pCount, pProperties);
76}
77
Ian Elliott0b4d6242015-09-22 10:51:24 -060078static void createDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
79{
80 uint32_t i;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070081 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
82 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -060083
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070084 VkLayerDispatchTable *pDisp = my_device_data->device_dispatch_table;
85 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
86
87 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
88 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
89 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
90 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
91 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
92
93 SwpPhysicalDevice *pPhysicalDevice = &my_instance_data->physicalDeviceMap[physicalDevice];
Ian Elliott0b4d6242015-09-22 10:51:24 -060094 if (pPhysicalDevice) {
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -070095 my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice;
96 pPhysicalDevice->pDevice = &my_device_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -060097 } else {
Ian Elliott07adb112016-01-05 12:51:03 -070098 // TBD: Should we leave error in (since Swapchain really needs this
99 // link)?
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700100 log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
Mark Lobodzinski80e774f2016-01-04 15:54:59 -0700101 (uint64_t)physicalDevice , __LINE__, SWAPCHAIN_INVALID_HANDLE, "Swapchain",
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700102 "vkCreateDevice() called with a non-valid VkPhysicalDevice.");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600103 }
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700104 my_device_data->deviceMap[device].device = device;
Ian Elliott427058f2015-12-29 16:45:49 -0700105 my_device_data->deviceMap[device].swapchainExtensionEnabled = false;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600106
107 // Record whether the WSI device extension was enabled for this VkDevice.
108 // No need to check if the extension was advertised by
109 // vkEnumerateDeviceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800110 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700111 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600112
Ian Elliott427058f2015-12-29 16:45:49 -0700113 my_device_data->deviceMap[device].swapchainExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600114 }
115 }
116}
117
118static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)
119{
120 uint32_t i;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600121 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
122 VkLayerInstanceDispatchTable *pDisp = my_data->instance_dispatch_table;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600123 PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700124#ifdef VK_USE_PLATFORM_ANDROID_KHR
125 pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR) gpa(instance, "vkCreateAndroidSurfaceKHR");
126#endif // VK_USE_PLATFORM_ANDROID_KHR
127#ifdef VK_USE_PLATFORM_MIR_KHR
128 pDisp->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR) gpa(instance, "vkCreateMirSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700129 pDisp->GetPhysicalDeviceMirPresentationSupportKHR = (PFN_vkGetPhysicalDeviceMirPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700130#endif // VK_USE_PLATFORM_MIR_KHR
131#ifdef VK_USE_PLATFORM_WAYLAND_KHR
132 pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR) gpa(instance, "vkCreateWaylandSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700133 pDisp->GetPhysicalDeviceWaylandPresentationSupportKHR = (PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWaylandPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700134#endif // VK_USE_PLATFORM_WAYLAND_KHR
135#ifdef VK_USE_PLATFORM_WIN32_KHR
136 pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) gpa(instance, "vkCreateWin32SurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700137 pDisp->GetPhysicalDeviceWin32PresentationSupportKHR = (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700138#endif // VK_USE_PLATFORM_WIN32_KHR
139#ifdef VK_USE_PLATFORM_XCB_KHR
140 pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) gpa(instance, "vkCreateXcbSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700141 pDisp->GetPhysicalDeviceXcbPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700142#endif // VK_USE_PLATFORM_XCB_KHR
143#ifdef VK_USE_PLATFORM_XLIB_KHR
144 pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR) gpa(instance, "vkCreateXlibSurfaceKHR");
Ian Elliott55ff7962015-12-30 10:18:47 -0700145 pDisp->GetPhysicalDeviceXlibPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
Ian Elliotta983e9a2015-12-22 12:18:12 -0700146#endif // VK_USE_PLATFORM_XLIB_KHR
147 pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR) gpa(instance, "vkDestroySurfaceKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600148 pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
Ian Elliott27d39c72015-11-20 16:39:34 -0700149 pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
150 pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
151 pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
Ian Elliott0b4d6242015-09-22 10:51:24 -0600152
Ian Elliott1dcd1092015-11-17 17:29:40 -0700153 // Remember this instance, and whether the VK_KHR_surface extension
Ian Elliott0b4d6242015-09-22 10:51:24 -0600154 // was enabled for it:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600155 my_data->instanceMap[instance].instance = instance;
Ian Elliott1cb77a62015-12-29 16:44:39 -0700156 my_data->instanceMap[instance].surfaceExtensionEnabled = false;
Ian Elliott8dffaf32016-01-04 14:10:30 -0700157#ifdef VK_USE_PLATFORM_ANDROID_KHR
158 my_data->instanceMap[instance].androidSurfaceExtensionEnabled = false;
159#endif // VK_USE_PLATFORM_ANDROID_KHR
160#ifdef VK_USE_PLATFORM_MIR_KHR
161 my_data->instanceMap[instance].mirSurfaceExtensionEnabled = false;
162#endif // VK_USE_PLATFORM_MIR_KHR
163#ifdef VK_USE_PLATFORM_WAYLAND_KHR
164 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = false;
165#endif // VK_USE_PLATFORM_WAYLAND_KHR
166#ifdef VK_USE_PLATFORM_WIN32_KHR
167 my_data->instanceMap[instance].win32SurfaceExtensionEnabled = false;
168#endif // VK_USE_PLATFORM_WIN32_KHR
169#ifdef VK_USE_PLATFORM_XCB_KHR
170 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = false;
171#endif // VK_USE_PLATFORM_XCB_KHR
172#ifdef VK_USE_PLATFORM_XLIB_KHR
173 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = false;
174#endif // VK_USE_PLATFORM_XLIB_KHR
175
Ian Elliott0b4d6242015-09-22 10:51:24 -0600176
177 // Record whether the WSI instance extension was enabled for this
178 // VkInstance. No need to check if the extension was advertised by
179 // vkEnumerateInstanceExtensionProperties(), since the loader handles that.
Chia-I Wud50a7d72015-10-26 20:48:51 +0800180 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott1dcd1092015-11-17 17:29:40 -0700181 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
Ian Elliott0b4d6242015-09-22 10:51:24 -0600182
Ian Elliott1cb77a62015-12-29 16:44:39 -0700183 my_data->instanceMap[instance].surfaceExtensionEnabled = true;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600184 }
Ian Elliott8dffaf32016-01-04 14:10:30 -0700185#ifdef VK_USE_PLATFORM_ANDROID_KHR
186 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) {
187
188 my_data->instanceMap[instance].androidSurfaceExtensionEnabled = true;
189#endif // VK_USE_PLATFORM_ANDROID_KHR
190#ifdef VK_USE_PLATFORM_MIR_KHR
191 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
192
193 my_data->instanceMap[instance].mirSurfaceExtensionEnabled = true;
194#endif // VK_USE_PLATFORM_MIR_KHR
195#ifdef VK_USE_PLATFORM_WAYLAND_KHR
196 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
197
198 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = true;
199#endif // VK_USE_PLATFORM_WAYLAND_KHR
200#ifdef VK_USE_PLATFORM_WIN32_KHR
201 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
202
203 my_data->instanceMap[instance].win32SurfaceExtensionEnabled = true;
204#endif // VK_USE_PLATFORM_WIN32_KHR
205#ifdef VK_USE_PLATFORM_XCB_KHR
206 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
207
208 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = true;
209#endif // VK_USE_PLATFORM_XCB_KHR
210#ifdef VK_USE_PLATFORM_XLIB_KHR
211 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
212
213 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = true;
214#endif // VK_USE_PLATFORM_XLIB_KHR
215 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600216 }
217}
218
219
220#include "vk_dispatch_table_helper.h"
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700221static void initSwapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600222{
223 uint32_t report_flags = 0;
224 uint32_t debug_action = 0;
225 FILE *log_output = NULL;
226 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700227 VkDebugReportCallbackEXT callback;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600228
229 // Initialize Swapchain options:
230 report_flags = getLayerOptionFlags("SwapchainReportFlags", 0);
231 getLayerOptionEnum("SwapchainDebugAction", (uint32_t *) &debug_action);
232
233 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
234 {
235 // Turn on logging, since it was requested:
236 option_str = getLayerOption("SwapchainLogFilename");
237 log_output = getLayerLogOutput(option_str, "Swapchain");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700238 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700239 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700240 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700241 dbgInfo.pfnCallback = log_callback;
242 dbgInfo.pUserData = log_output;
243 dbgInfo.flags = report_flags;
244 layer_create_msg_callback(my_data->report_data,
245 &dbgInfo,
246 pAllocator,
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600247 &callback);
248 my_data->logging_callback.push_back(callback);
249 }
250 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700251 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700252 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700253 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700254 dbgInfo.pfnCallback = win32_debug_output_msg;
255 dbgInfo.pUserData = log_output;
256 dbgInfo.flags = report_flags;
257 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600258 my_data->logging_callback.push_back(callback);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600259 }
260}
261
Ian Elliott27d39c72015-11-20 16:39:34 -0700262static const char *surfaceTransformStr(VkSurfaceTransformFlagBitsKHR value)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600263{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600264 // Return a string corresponding to the value:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -0700265 return string_VkSurfaceTransformFlagBitsKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600266}
267
Ian Elliotta2a89c52015-12-28 15:23:57 -0700268static const char *surfaceCompositeAlphaStr(VkCompositeAlphaFlagBitsKHR value)
269{
270 // Return a string corresponding to the value:
271 return string_VkCompositeAlphaFlagBitsKHR(value);
272}
273
Ian Elliott0b4d6242015-09-22 10:51:24 -0600274static const char *presentModeStr(VkPresentModeKHR value)
275{
Ian Elliott0b4d6242015-09-22 10:51:24 -0600276 // Return a string corresponding to the value:
Ian Elliott24491af2015-12-28 15:04:49 -0700277 return string_VkPresentModeKHR(value);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600278}
279
Ian Elliotta2a89c52015-12-28 15:23:57 -0700280static const char *sharingModeStr(VkSharingMode value)
281{
282 // Return a string corresponding to the value:
283 return string_VkSharingMode(value);
284}
285
Ian Elliott0b4d6242015-09-22 10:51:24 -0600286
Chia-I Wu9ab61502015-11-06 06:42:02 +0800287VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600288{
Tobin Ehlis711ff312015-10-29 12:58:13 -0600289 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600290 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600291 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800292 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600293 if (result == VK_SUCCESS) {
294 // Since it succeeded, do layer-specific work:
Ian Elliott68124ac2015-10-07 16:18:35 -0600295 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
296 my_data->report_data = debug_report_create_instance(
Tobin Ehlis711ff312015-10-29 12:58:13 -0600297 pTable,
Ian Elliott68124ac2015-10-07 16:18:35 -0600298 *pInstance,
Chia-I Wud50a7d72015-10-26 20:48:51 +0800299 pCreateInfo->enabledExtensionNameCount,
Ian Elliott68124ac2015-10-07 16:18:35 -0600300 pCreateInfo->ppEnabledExtensionNames);
301 // Call the following function after my_data is initialized:
Ian Elliott0b4d6242015-09-22 10:51:24 -0600302 createInstanceRegisterExtensions(pCreateInfo, *pInstance);
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700303 initSwapchain(my_data, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600304 }
305 return result;
306}
307
Chia-I Wu9ab61502015-11-06 06:42:02 +0800308VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600309{
310 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600311 dispatch_key key = get_dispatch_key(instance);
312 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600313 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600314
315 if (VK_FALSE == skipCall) {
316 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800317 my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator);
Ian Elliott68124ac2015-10-07 16:18:35 -0600318
319 // Clean up logging callback, if any
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600320 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700321 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700322 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -0600323 my_data->logging_callback.pop_back();
Ian Elliott68124ac2015-10-07 16:18:35 -0600324 }
325 layer_debug_report_destroy_instance(my_data->report_data);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600326 }
327
328 // Regardless of skipCall value, do some internal cleanup:
329 if (pInstance) {
330 // Delete all of the SwpPhysicalDevice's and the SwpInstance associated
331 // with this instance:
332 for (auto it = pInstance->physicalDevices.begin() ;
333 it != pInstance->physicalDevices.end() ; it++) {
Ian Elliott27d39c72015-11-20 16:39:34 -0700334
335 // Free memory that was allocated for/by this SwpPhysicalDevice:
336 SwpPhysicalDevice *pPhysicalDevice = it->second;
Ian Elliott07adb112016-01-05 12:51:03 -0700337 if (pPhysicalDevice) {
338 free(pPhysicalDevice->pSurfaceFormats);
339 free(pPhysicalDevice->pPresentModes);
340 }
Ian Elliott27d39c72015-11-20 16:39:34 -0700341
Tobin Ehlis711ff312015-10-29 12:58:13 -0600342 // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which
Ian Elliott0b4d6242015-09-22 10:51:24 -0600343 // are simply pointed to by the SwpInstance):
Tobin Ehlis711ff312015-10-29 12:58:13 -0600344 my_data->physicalDeviceMap.erase(it->second->physicalDevice);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600345 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600346 my_data->instanceMap.erase(instance);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600347 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600348 delete my_data->instance_dispatch_table;
349 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600350}
351
Ian Elliotta983e9a2015-12-22 12:18:12 -0700352#ifdef VK_USE_PLATFORM_ANDROID_KHR
353VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
354 VkInstance instance,
Ian Elliott1bf155f2015-12-29 17:35:46 -0700355 const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
Ian Elliotta983e9a2015-12-22 12:18:12 -0700356 const VkAllocationCallbacks* pAllocator,
357 VkSurfaceKHR* pSurface)
358{
359 VkResult result = VK_SUCCESS;
360 VkBool32 skipCall = VK_FALSE;
361 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
362
Ian Elliottf5758292015-12-30 17:39:02 -0700363 if (!pCreateInfo) {
364 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
365 device,
366 "pCreateInfo");
367 } else {
368 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR) {
369 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
370 device,
371 "pCreateInfo",
372 "VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR");
373 }
374 if (pCreateInfo->pNext != NULL) {
Ian Elliott31edb922016-01-05 14:41:45 -0700375 skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliottf5758292015-12-30 17:39:02 -0700376 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) {
Ian Elliott31edb922016-01-05 14:41:45 -0700414 skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliottf5758292015-12-30 17:39:02 -0700415 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) {
Ian Elliott31edb922016-01-05 14:41:45 -0700487 skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliottf5758292015-12-30 17:39:02 -0700488 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) {
Ian Elliott31edb922016-01-05 14:41:45 -0700560 skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliottf5758292015-12-30 17:39:02 -0700561 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) {
Ian Elliott31edb922016-01-05 14:41:45 -0700632 skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliottf5758292015-12-30 17:39:02 -0700633 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) {
Ian Elliott31edb922016-01-05 14:41:45 -0700706 skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliottf5758292015-12-30 17:39:02 -0700707 device,
708 "pCreateInfo");
709 }
710 }
Ian Elliotta983e9a2015-12-22 12:18:12 -0700711
712 if (VK_FALSE == skipCall) {
713 // Call down the call chain:
714 result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(
Ian Elliott1bf155f2015-12-29 17:35:46 -0700715 instance, pCreateInfo, pAllocator, pSurface);
Ian Elliotta983e9a2015-12-22 12:18:12 -0700716 return result;
717 }
Ian Elliott1bf155f2015-12-29 17:35:46 -0700718 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliotta983e9a2015-12-22 12:18:12 -0700719}
Ian Elliott55ff7962015-12-30 10:18:47 -0700720
721VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(
722 VkPhysicalDevice physicalDevice,
723 uint32_t queueFamilyIndex,
724 Display* dpy,
725 VisualID visualID)
726{
727 VkBool32 result = VK_FALSE;
728 VkBool32 skipCall = VK_FALSE;
729 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott55ff7962015-12-30 10:18:47 -0700730 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700731
732 // Validate that the platform extension was enabled:
733 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
734 !pPhysicalDevice->pInstance->xlibSurfaceExtensionEnabled) {
Ian Elliott55ff7962015-12-30 10:18:47 -0700735 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
736 pPhysicalDevice->pInstance,
737 "VkInstance",
738 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
739 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott8dffaf32016-01-04 14:10:30 -0700740 __FUNCTION__, VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Ian Elliott55ff7962015-12-30 10:18:47 -0700741 }
742
743 if (VK_FALSE == skipCall) {
744 // Call down the call chain:
745 result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR(
746 physicalDevice, queueFamilyIndex, dpy, visualID);
747
748 if (pPhysicalDevice) {
749 // Record the result of this query:
750 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
751 }
752 }
753 return result;
754}
Ian Elliotta983e9a2015-12-22 12:18:12 -0700755#endif // VK_USE_PLATFORM_XLIB_KHR
756
757VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator)
758{
759 VkBool32 skipCall = VK_FALSE;
760 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
761
Ian Elliotta983e9a2015-12-22 12:18:12 -0700762 if (VK_FALSE == skipCall) {
Ian Elliotta983e9a2015-12-22 12:18:12 -0700763 // Call down the call chain:
764 my_data->instance_dispatch_table->DestroySurfaceKHR(
765 instance, surface, pAllocator);
766 }
767
Ian Elliott6b9941a2016-01-05 12:03:06 -0700768 // No need to do any cleanup--rely on object_tracker to track VkSurfaceKHR
Ian Elliotta983e9a2015-12-22 12:18:12 -0700769}
770
Chia-I Wu9ab61502015-11-06 06:42:02 +0800771VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600772{
773 VkResult result = VK_SUCCESS;
774 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600775 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600776 SwpInstance *pInstance = &(my_data->instanceMap[instance]);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600777
778 if (VK_FALSE == skipCall) {
779 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600780 result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(
Ian Elliott0b4d6242015-09-22 10:51:24 -0600781 instance, pPhysicalDeviceCount, pPhysicalDevices);
782
783 if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices &&
784 (*pPhysicalDeviceCount > 0)) {
785 // Record the VkPhysicalDevices returned by the ICD:
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -0600786 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis711ff312015-10-29 12:58:13 -0600787 my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice =
Ian Elliott0b4d6242015-09-22 10:51:24 -0600788 pPhysicalDevices[i];
Tobin Ehlis711ff312015-10-29 12:58:13 -0600789 my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance;
790 my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL;
Ian Elliott27d39c72015-11-20 16:39:34 -0700791 my_data->physicalDeviceMap[pPhysicalDevices[i]].gotSurfaceCapabilities = false;
792 my_data->physicalDeviceMap[pPhysicalDevices[i]].surfaceFormatCount = 0;
793 my_data->physicalDeviceMap[pPhysicalDevices[i]].pSurfaceFormats = NULL;
794 my_data->physicalDeviceMap[pPhysicalDevices[i]].presentModeCount = 0;
795 my_data->physicalDeviceMap[pPhysicalDevices[i]].pPresentModes = NULL;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600796 // Point to the associated SwpInstance:
Ian Elliott4f07d082016-01-05 12:18:50 -0700797 if (pInstance) {
798 pInstance->physicalDevices[pPhysicalDevices[i]] =
799 &my_data->physicalDeviceMap[pPhysicalDevices[i]];
800 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600801 }
802 }
803
804 return result;
805 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700806 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600807}
808
Chia-I Wu9ab61502015-11-06 06:42:02 +0800809VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600810{
811 VkResult result = VK_SUCCESS;
812 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600813 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600814
Ian Elliott07adb112016-01-05 12:51:03 -0700815 if (VK_FALSE == skipCall) {
816 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
817 // Call down the call chain:
818 result = my_device_data->device_dispatch_table->CreateDevice(
819 physicalDevice, pCreateInfo, pAllocator, pDevice);
820 if (result == VK_SUCCESS) {
821 // Since it succeeded, do layer-specific work:
822 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
823 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
824 createDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice);
825 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600826 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600827 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600828}
829
Chia-I Wu9ab61502015-11-06 06:42:02 +0800830VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600831{
832 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600833 dispatch_key key = get_dispatch_key(device);
834 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600835 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -0600836
837 if (VK_FALSE == skipCall) {
838 // Call down the call chain:
Chia-I Wuf7458c52015-10-26 21:10:41 +0800839 my_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600840 }
841
842 // Regardless of skipCall value, do some internal cleanup:
843 if (pDevice) {
844 // Delete the SwpDevice associated with this device:
845 if (pDevice->pPhysicalDevice) {
846 pDevice->pPhysicalDevice->pDevice = NULL;
847 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600848 if (!pDevice->swapchains.empty()) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700849 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600850 SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600851 "%s() called before all of its associated "
852 "VkSwapchainKHRs were destroyed.",
853 __FUNCTION__);
854 // Empty and then delete all SwpSwapchain's
855 for (auto it = pDevice->swapchains.begin() ;
856 it != pDevice->swapchains.end() ; it++) {
857 // Delete all SwpImage's
858 it->second->images.clear();
859 }
860 pDevice->swapchains.clear();
861 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600862 my_data->deviceMap.erase(device);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600863 }
Tobin Ehlis711ff312015-10-29 12:58:13 -0600864 delete my_data->device_dispatch_table;
865 layer_data_map.erase(key);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600866}
867
Ian Elliott27d39c72015-11-20 16:39:34 -0700868VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
869 VkPhysicalDevice physicalDevice,
870 uint32_t queueFamilyIndex,
871 VkSurfaceKHR surface,
872 VkBool32* pSupported)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600873{
Ian Elliott320d0fc2015-12-30 12:04:43 -0700874// TODOs:
875//
876// - Ensure that queueFamilyIndex is a valid queue family index for
877// physicalDevice. How? Probably need to record data from another function
878// call(s).
Ian Elliott0b4d6242015-09-22 10:51:24 -0600879 VkResult result = VK_SUCCESS;
880 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -0600881 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -0600882 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700883
884 // Validate that the surface extension was enabled:
885 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
886 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700887 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600888 pPhysicalDevice->pInstance,
889 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600890 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -0800891 "%s() called even though the %s extension was not enabled for this VkInstance.",
Ian Elliott1dcd1092015-11-17 17:29:40 -0700892 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600893 }
Ian Elliottf955d682015-12-30 12:00:54 -0700894 if (!pSupported) {
895 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
896 physicalDevice,
897 "pSupported");
898 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600899
900 if (VK_FALSE == skipCall) {
901 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -0600902 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -0700903 physicalDevice, queueFamilyIndex, surface,
Ian Elliott0b4d6242015-09-22 10:51:24 -0600904 pSupported);
905
906 if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) {
907 // Record the result of this query:
908 pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] =
909 *pSupported;
910 // TODO: We need to compare this with the actual queue used for
911 // presentation, to ensure it was advertised to the application as
912 // supported for presentation.
913 }
914
915 return result;
916 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700917 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600918}
919
Ian Elliott27d39c72015-11-20 16:39:34 -0700920VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
921 VkPhysicalDevice physicalDevice,
922 VkSurfaceKHR surface,
923 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600924{
925 VkResult result = VK_SUCCESS;
926 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700927 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -0700928 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700929
930 // Validate that the surface extension was enabled:
931 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
932 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700933 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700934 pPhysicalDevice->pInstance,
935 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600936 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700937 "%s() called even though the %s extension was not enabled for this VkInstance.",
938 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600939 }
Ian Elliottf955d682015-12-30 12:00:54 -0700940 if (!pSurfaceCapabilities) {
941 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
942 physicalDevice,
943 "pSurfaceCapabilities");
944 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600945
946 if (VK_FALSE == skipCall) {
947 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700948 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceCapabilitiesKHR(
949 physicalDevice, surface, pSurfaceCapabilities);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600950
Ian Elliott27d39c72015-11-20 16:39:34 -0700951 if ((result == VK_SUCCESS) && pPhysicalDevice) {
Ian Elliottf955d682015-12-30 12:00:54 -0700952 // Record the result of this query:
Ian Elliott27d39c72015-11-20 16:39:34 -0700953 pPhysicalDevice->gotSurfaceCapabilities = true;
954// FIXME: NEED TO COPY THIS DATA, BECAUSE pSurfaceCapabilities POINTS TO APP-ALLOCATED DATA
955 pPhysicalDevice->surfaceCapabilities = *pSurfaceCapabilities;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600956 }
957
958 return result;
959 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700960 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600961}
962
Ian Elliott27d39c72015-11-20 16:39:34 -0700963VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
964 VkPhysicalDevice physicalDevice,
965 VkSurfaceKHR surface,
Ian Elliottf955d682015-12-30 12:00:54 -0700966 uint32_t* pSurfaceFormatCount,
Ian Elliott27d39c72015-11-20 16:39:34 -0700967 VkSurfaceFormatKHR* pSurfaceFormats)
Ian Elliott0b4d6242015-09-22 10:51:24 -0600968{
969 VkResult result = VK_SUCCESS;
970 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -0700971 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -0700972 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -0700973
974 // Validate that the surface extension was enabled:
975 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
976 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700977 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -0700978 pPhysicalDevice->pInstance,
979 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -0600980 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -0700981 "%s() called even though the %s extension was not enabled for this VkInstance.",
982 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600983 }
Ian Elliottf955d682015-12-30 12:00:54 -0700984 if (!pSurfaceFormatCount) {
985 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
986 physicalDevice,
987 "pSurfaceFormatCount");
988 }
Ian Elliott0b4d6242015-09-22 10:51:24 -0600989
990 if (VK_FALSE == skipCall) {
991 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -0700992 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceFormatsKHR(
Ian Elliottf955d682015-12-30 12:00:54 -0700993 physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
Ian Elliott0b4d6242015-09-22 10:51:24 -0600994
Ian Elliottf955d682015-12-30 12:00:54 -0700995 if ((result == VK_SUCCESS) && pPhysicalDevice && !pSurfaceFormats &&
996 pSurfaceFormatCount) {
997 // Record the result of this preliminary query:
998 pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount;
999 }
Ian Elliott9059b302015-12-30 13:14:36 -07001000 else if ((result == VK_SUCCESS) && pPhysicalDevice && pSurfaceFormats &&
1001 pSurfaceFormatCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001002 // Compare the preliminary value of *pSurfaceFormatCount with the
1003 // value this time:
Ian Elliottdcf8eca2016-01-05 14:28:32 -07001004 if (*pSurfaceFormatCount > pPhysicalDevice->surfaceFormatCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001005 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1006 physicalDevice,
1007 "pSurfaceFormatCount",
1008 "pSurfaceFormats",
Ian Elliottdcf8eca2016-01-05 14:28:32 -07001009 *pSurfaceFormatCount,
Ian Elliottf955d682015-12-30 12:00:54 -07001010 pPhysicalDevice->surfaceFormatCount);
1011 }
Ian Elliott9059b302015-12-30 13:14:36 -07001012 else if (*pSurfaceFormatCount > 0) {
1013 // Record the result of this query:
1014 pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount;
1015 pPhysicalDevice->pSurfaceFormats = (VkSurfaceFormatKHR *)
1016 malloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR));
1017 if (pPhysicalDevice->pSurfaceFormats) {
1018 for (uint32_t i = 0 ; i < *pSurfaceFormatCount ; i++) {
1019 pPhysicalDevice->pSurfaceFormats[i] = pSurfaceFormats[i];
1020 }
1021 } else {
1022 pPhysicalDevice->surfaceFormatCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001023 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001024 }
1025 }
1026
1027 return result;
1028 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001029 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001030}
1031
Ian Elliott27d39c72015-11-20 16:39:34 -07001032VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
1033 VkPhysicalDevice physicalDevice,
1034 VkSurfaceKHR surface,
Ian Elliottf955d682015-12-30 12:00:54 -07001035 uint32_t* pPresentModeCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001036 VkPresentModeKHR* pPresentModes)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001037{
1038 VkResult result = VK_SUCCESS;
1039 VkBool32 skipCall = VK_FALSE;
Ian Elliott27d39c72015-11-20 16:39:34 -07001040 layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Ian Elliott27d39c72015-11-20 16:39:34 -07001041 SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice];
Ian Elliott07adb112016-01-05 12:51:03 -07001042
1043 // Validate that the surface extension was enabled:
1044 if (pPhysicalDevice && pPhysicalDevice->pInstance &&
1045 !pPhysicalDevice->pInstance->surfaceExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001046 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001047 pPhysicalDevice->pInstance,
1048 "VkInstance",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001049 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Ian Elliott27d39c72015-11-20 16:39:34 -07001050 "%s() called even though the %s extension was not enabled for this VkInstance.",
1051 __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001052 }
Ian Elliottf955d682015-12-30 12:00:54 -07001053 if (!pPresentModeCount) {
1054 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1055 physicalDevice,
1056 "pPresentModeCount");
1057 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001058
1059 if (VK_FALSE == skipCall) {
1060 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001061 result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfacePresentModesKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001062 physicalDevice, surface, pPresentModeCount, pPresentModes);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001063
Ian Elliottf955d682015-12-30 12:00:54 -07001064 if ((result == VK_SUCCESS) && pPhysicalDevice && !pPresentModes &&
1065 pPresentModeCount) {
1066 // Record the result of this preliminary query:
1067 pPhysicalDevice->presentModeCount = *pPresentModeCount;
1068 }
Ian Elliott9059b302015-12-30 13:14:36 -07001069 else if ((result == VK_SUCCESS) && pPhysicalDevice && pPresentModes &&
1070 pPresentModeCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001071 // Compare the preliminary value of *pPresentModeCount with the
1072 // value this time:
Ian Elliottdcf8eca2016-01-05 14:28:32 -07001073 if (*pPresentModeCount > pPhysicalDevice->presentModeCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001074 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
1075 physicalDevice,
1076 "pPresentModeCount",
1077 "pPresentModes",
Ian Elliottdcf8eca2016-01-05 14:28:32 -07001078 *pPresentModeCount,
Ian Elliottf955d682015-12-30 12:00:54 -07001079 pPhysicalDevice->presentModeCount);
1080 }
Ian Elliott9059b302015-12-30 13:14:36 -07001081 else if (*pPresentModeCount > 0) {
1082 // Record the result of this query:
1083 pPhysicalDevice->presentModeCount = *pPresentModeCount;
1084 pPhysicalDevice->pPresentModes = (VkPresentModeKHR *)
1085 malloc(*pPresentModeCount * sizeof(VkPresentModeKHR));
1086 if (pPhysicalDevice->pSurfaceFormats) {
1087 for (uint32_t i = 0 ; i < *pPresentModeCount ; i++) {
1088 pPhysicalDevice->pPresentModes[i] = pPresentModes[i];
1089 }
1090 } else {
1091 pPhysicalDevice->presentModeCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001092 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001093 }
1094 }
1095
1096 return result;
1097 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001098 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001099}
1100
1101// This function does the up-front validation work for vkCreateSwapchainKHR(),
1102// and returns VK_TRUE if a logging callback indicates that the call down the
1103// chain should be skipped:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001104static VkBool32 validateCreateSwapchainKHR(
1105 VkDevice device,
1106 const VkSwapchainCreateInfoKHR* pCreateInfo,
1107 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001108{
1109// TODO: Validate cases of re-creating a swapchain (the current code
1110// assumes a new swapchain is being created).
1111 VkResult result = VK_SUCCESS;
1112 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001113 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001114 char fn[] = "vkCreateSwapchainKHR";
Tobin Ehlis711ff312015-10-29 12:58:13 -06001115 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001116
Ian Elliott8b9e2562016-01-05 13:00:50 -07001117 // Validate that the swapchain extension was enabled:
1118 if (pDevice && !pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001119 return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001120 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001121 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001122 fn, VK_KHR_SWAPCHAIN_EXTENSION_NAME );
Ian Elliott0b4d6242015-09-22 10:51:24 -06001123 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001124 if (!pCreateInfo) {
1125 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1126 device,
1127 "pCreateInfo");
Ian Elliottf5758292015-12-30 17:39:02 -07001128 } else {
1129 if (pCreateInfo->sType != VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR) {
1130 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1131 device,
1132 "pCreateInfo",
1133 "VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR");
1134 }
1135 if (pCreateInfo->pNext != NULL) {
Ian Elliott31edb922016-01-05 14:41:45 -07001136 skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliottf5758292015-12-30 17:39:02 -07001137 device,
1138 "pCreateInfo");
1139 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001140 }
1141 if (!pSwapchain) {
1142 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1143 device,
1144 "pSwapchain");
1145 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001146
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001147 // Keep around a useful pointer to pPhysicalDevice:
1148 SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice;
1149
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001150 // Validate pCreateInfo values with the results of
1151 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1152 if (!pPhysicalDevice || !pPhysicalDevice->gotSurfaceCapabilities) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001153 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001154 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001155 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001156 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001157 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001158 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001159 // Validate pCreateInfo->minImageCount against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001160 // VkSurfaceCapabilitiesKHR::{min|max}ImageCount:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001161 VkSurfaceCapabilitiesKHR *pCapabilities = &pPhysicalDevice->surfaceCapabilities;
Ian Elliott27d39c72015-11-20 16:39:34 -07001162 if ((pCreateInfo->minImageCount < pCapabilities->minImageCount) ||
1163 ((pCapabilities->maxImageCount > 0) &&
1164 (pCreateInfo->minImageCount > pCapabilities->maxImageCount))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001165 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001166 SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001167 "%s() called with pCreateInfo->minImageCount "
1168 "= %d, which is outside the bounds returned "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001169 "by vkGetPhysicalDeviceSurfaceCapabilitiesKHR() (i.e. "
Ian Elliott0b4d6242015-09-22 10:51:24 -06001170 "minImageCount = %d, maxImageCount = %d).",
1171 fn,
1172 pCreateInfo->minImageCount,
Ian Elliott27d39c72015-11-20 16:39:34 -07001173 pCapabilities->minImageCount,
1174 pCapabilities->maxImageCount);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001175 }
1176 // Validate pCreateInfo->imageExtent against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001177 // VkSurfaceCapabilitiesKHR::{current|min|max}ImageExtent:
Ian Elliott27d39c72015-11-20 16:39:34 -07001178 if ((pCapabilities->currentExtent.width == -1) &&
1179 ((pCreateInfo->imageExtent.width < pCapabilities->minImageExtent.width) ||
1180 (pCreateInfo->imageExtent.width > pCapabilities->maxImageExtent.width) ||
1181 (pCreateInfo->imageExtent.height < pCapabilities->minImageExtent.height) ||
1182 (pCreateInfo->imageExtent.height > pCapabilities->maxImageExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001183 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001184 SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001185 "%s() called with pCreateInfo->imageExtent = "
1186 "(%d,%d), which is outside the bounds "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001187 "returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): "
Ian Elliott0b4d6242015-09-22 10:51:24 -06001188 "currentExtent = (%d,%d), minImageExtent = "
1189 "(%d,%d), maxImageExtent = (%d,%d).",
1190 fn,
1191 pCreateInfo->imageExtent.width,
1192 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001193 pCapabilities->currentExtent.width,
1194 pCapabilities->currentExtent.height,
1195 pCapabilities->minImageExtent.width,
1196 pCapabilities->minImageExtent.height,
1197 pCapabilities->maxImageExtent.width,
1198 pCapabilities->maxImageExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001199 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001200 if ((pCapabilities->currentExtent.width != -1) &&
1201 ((pCreateInfo->imageExtent.width != pCapabilities->currentExtent.width) ||
1202 (pCreateInfo->imageExtent.height != pCapabilities->currentExtent.height))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001203 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001204 SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001205 "%s() called with pCreateInfo->imageExtent = "
1206 "(%d,%d), which is not equal to the "
1207 "currentExtent = (%d,%d) returned by "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001208 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001209 fn,
1210 pCreateInfo->imageExtent.width,
1211 pCreateInfo->imageExtent.height,
Ian Elliott27d39c72015-11-20 16:39:34 -07001212 pCapabilities->currentExtent.width,
1213 pCapabilities->currentExtent.height);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001214 }
1215 // Validate pCreateInfo->preTransform against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001216 // VkSurfaceCapabilitiesKHR::supportedTransforms:
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001217 if (!((pCreateInfo->preTransform) & pCapabilities->supportedTransforms)) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001218 // This is an error situation; one for which we'd like to give
1219 // the developer a helpful, multi-line error message. Build it
1220 // up a little at a time, and then log it:
1221 std::string errorString = "";
1222 char str[1024];
1223 // Here's the first part of the message:
1224 sprintf(str, "%s() called with a non-supported "
1225 "pCreateInfo->preTransform (i.e. %s). "
1226 "Supported values are:\n",
1227 fn,
1228 surfaceTransformStr(pCreateInfo->preTransform));
1229 errorString += str;
Mark Lobodzinski55cd49b2015-11-27 15:23:23 -07001230 for (int i = 0; i < 32; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001231 // Build up the rest of the message:
Ian Elliott27d39c72015-11-20 16:39:34 -07001232 if ((1 << i) & pCapabilities->supportedTransforms) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001233 const char *newStr =
Ian Elliott27d39c72015-11-20 16:39:34 -07001234 surfaceTransformStr((VkSurfaceTransformFlagBitsKHR) (1 << i));
Ian Elliott0b4d6242015-09-22 10:51:24 -06001235 sprintf(str, " %s\n", newStr);
1236 errorString += str;
1237 }
1238 }
1239 // Log the message that we've built up:
Ian Elliott68124ac2015-10-07 16:18:35 -06001240 skipCall |= debug_report_log_msg(my_data->report_data,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001241 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1242 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Mark Lobodzinski80e774f2016-01-04 15:54:59 -07001243 (uint64_t) device, __LINE__,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001244 SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM,
1245 LAYER_NAME,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001246 errorString.c_str());
1247 }
Ian Elliotta2a89c52015-12-28 15:23:57 -07001248 // Validate pCreateInfo->compositeAlpha against
1249 // VkSurfaceCapabilitiesKHR::supportedCompositeAlpha:
1250 if (!((pCreateInfo->compositeAlpha) & pCapabilities->supportedCompositeAlpha)) {
1251 // This is an error situation; one for which we'd like to give
1252 // the developer a helpful, multi-line error message. Build it
1253 // up a little at a time, and then log it:
1254 std::string errorString = "";
1255 char str[1024];
1256 // Here's the first part of the message:
1257 sprintf(str, "%s() called with a non-supported "
1258 "pCreateInfo->compositeAlpha (i.e. %s). "
1259 "Supported values are:\n",
1260 fn,
1261 surfaceCompositeAlphaStr(pCreateInfo->compositeAlpha));
1262 errorString += str;
1263 for (int i = 0; i < 32; i++) {
1264 // Build up the rest of the message:
1265 if ((1 << i) & pCapabilities->supportedCompositeAlpha) {
1266 const char *newStr =
1267 surfaceCompositeAlphaStr((VkCompositeAlphaFlagBitsKHR) (1 << i));
1268 sprintf(str, " %s\n", newStr);
1269 errorString += str;
1270 }
1271 }
1272 // Log the message that we've built up:
1273 skipCall |= debug_report_log_msg(my_data->report_data,
Ian Elliott1bf155f2015-12-29 17:35:46 -07001274 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1275 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliotta2a89c52015-12-28 15:23:57 -07001276 (uint64_t) device, 0,
1277 SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA,
1278 LAYER_NAME,
1279 errorString.c_str());
1280 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001281 // Validate pCreateInfo->imageArraySize against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001282 // VkSurfaceCapabilitiesKHR::maxImageArraySize:
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001283 if ((pCreateInfo->imageArrayLayers > 0) &&
1284 (pCreateInfo->imageArrayLayers > pCapabilities->maxImageArrayLayers)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001285 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001286 SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_SIZE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001287 "%s() called with a non-supported "
1288 "pCreateInfo->imageArraySize (i.e. %d). "
1289 "Maximum value is %d.",
1290 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001291 pCreateInfo->imageArrayLayers,
1292 pCapabilities->maxImageArrayLayers);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001293 }
Ian Elliott27d39c72015-11-20 16:39:34 -07001294 // Validate pCreateInfo->imageUsage against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001295 // VkSurfaceCapabilitiesKHR::supportedUsageFlags:
Ian Elliott27d39c72015-11-20 16:39:34 -07001296 if (pCreateInfo->imageUsage &&
1297 (pCreateInfo->imageUsage !=
1298 (pCreateInfo->imageUsage & pCapabilities->supportedUsageFlags))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001299 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001300 SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001301 "%s() called with a non-supported "
Ian Elliott27d39c72015-11-20 16:39:34 -07001302 "pCreateInfo->imageUsage (i.e. 0x%08x)."
Ian Elliott0b4d6242015-09-22 10:51:24 -06001303 " Supported flag bits are 0x%08x.",
1304 fn,
Ian Elliott27d39c72015-11-20 16:39:34 -07001305 pCreateInfo->imageUsage,
1306 pCapabilities->supportedUsageFlags);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001307 }
1308 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001309
1310 // Validate pCreateInfo values with the results of
1311 // vkGetPhysicalDeviceSurfaceFormatsKHR():
1312 if (!pPhysicalDevice || !pPhysicalDevice->surfaceFormatCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001313 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001314 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001315 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001316 "vkGetPhysicalDeviceSurfaceFormatsKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001317 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001318 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001319 // Validate pCreateInfo->imageFormat against
1320 // VkSurfaceFormatKHR::format:
1321 bool foundFormat = false;
1322 bool foundColorSpace = false;
1323 bool foundMatch = false;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001324 for (uint32_t i = 0 ; i < pPhysicalDevice->surfaceFormatCount ; i++) {
1325 if (pCreateInfo->imageFormat == pPhysicalDevice->pSurfaceFormats[i].format) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001326 // Validate pCreateInfo->imageColorSpace against
1327 // VkSurfaceFormatKHR::colorSpace:
1328 foundFormat = true;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001329 if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001330 foundMatch = true;
1331 break;
1332 }
1333 } else {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001334 if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001335 foundColorSpace = true;
1336 }
1337 }
1338 }
1339 if (!foundMatch) {
1340 if (!foundFormat) {
1341 if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001342 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001343 "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001344 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001345 "%s() called with neither a "
1346 "supported pCreateInfo->imageFormat "
1347 "(i.e. %d) nor a supported "
1348 "pCreateInfo->imageColorSpace "
1349 "(i.e. %d).",
1350 fn,
1351 pCreateInfo->imageFormat,
1352 pCreateInfo->imageColorSpace);
1353 } else {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001354 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device,
Ian Elliottb0f474c2015-09-25 15:50:55 -06001355 "VkDevice",
1356 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001357 "%s() called with a non-supported "
1358 "pCreateInfo->imageFormat (i.e. %d).",
1359 fn, pCreateInfo->imageFormat);
1360 }
1361 } else if (!foundColorSpace) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001362 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001363 SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001364 "%s() called with a non-supported "
1365 "pCreateInfo->imageColorSpace (i.e. %d).",
1366 fn, pCreateInfo->imageColorSpace);
1367 }
1368 }
1369 }
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001370
1371 // Validate pCreateInfo values with the results of
1372 // vkGetPhysicalDeviceSurfacePresentModesKHR():
1373 if (!pPhysicalDevice || !pPhysicalDevice->presentModeCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001374 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001375 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001376 "%s() called before calling "
Ian Elliott1dcd1092015-11-17 17:29:40 -07001377 "vkGetPhysicalDeviceSurfacePresentModesKHR().",
Ian Elliott0b4d6242015-09-22 10:51:24 -06001378 fn);
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001379 } else if (pCreateInfo) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001380 // Validate pCreateInfo->presentMode against
Ian Elliott1dcd1092015-11-17 17:29:40 -07001381 // vkGetPhysicalDeviceSurfacePresentModesKHR():
Ian Elliott0b4d6242015-09-22 10:51:24 -06001382 bool foundMatch = false;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001383 for (uint32_t i = 0 ; i < pPhysicalDevice->presentModeCount ; i++) {
1384 if (pPhysicalDevice->pPresentModes[i] == pCreateInfo->presentMode) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001385 foundMatch = true;
1386 break;
1387 }
1388 }
1389 if (!foundMatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001390 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001391 SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001392 "%s() called with a non-supported "
1393 "pCreateInfo->presentMode (i.e. %s).",
1394 fn,
1395 presentModeStr(pCreateInfo->presentMode));
1396 }
1397 }
1398
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001399 // Validate pCreateInfo->imageSharingMode and related values:
Ian Elliotta2a89c52015-12-28 15:23:57 -07001400 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
Ian Elliottafcb60c2016-01-05 14:11:03 -07001401 if ((pCreateInfo->queueFamilyIndexCount < 1) ||
Ian Elliotta2a89c52015-12-28 15:23:57 -07001402 !pCreateInfo->pQueueFamilyIndices) {
Ian Elliott1bf155f2015-12-29 17:35:46 -07001403 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001404 SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES,
1405 "%s() called with a supported "
1406 "pCreateInfo->sharingMode of (i.e. %s),"
1407 "but with a bad value(s) for "
1408 "pCreateInfo->queueFamilyIndexCount or "
1409 "pCreateInfo->pQueueFamilyIndices).",
1410 fn,
1411 sharingModeStr(pCreateInfo->imageSharingMode));
1412 }
1413 } else if (pCreateInfo->imageSharingMode != VK_SHARING_MODE_EXCLUSIVE) {
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_MODE,
1416 "%s() called with a non-supported "
1417 "pCreateInfo->imageSharingMode (i.e. %s).",
1418 fn,
1419 sharingModeStr(pCreateInfo->imageSharingMode));
1420 }
1421
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001422 // Validate pCreateInfo->clipped:
1423 if (pCreateInfo &&
1424 (pCreateInfo->clipped != VK_FALSE) &&
Ian Elliotta2a89c52015-12-28 15:23:57 -07001425 (pCreateInfo->clipped != VK_TRUE)) {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001426 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1427 device, "VkDevice",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001428 SWAPCHAIN_BAD_BOOL,
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001429 "%s() called with a VkBool32 value that is "
1430 "neither VK_TRUE nor VK_FALSE, but has the "
1431 "numeric value of %d.",
Ian Elliotta2a89c52015-12-28 15:23:57 -07001432 fn,
1433 pCreateInfo->clipped);
1434 }
1435
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001436 // Validate pCreateInfo->oldSwapchain:
1437 if (pCreateInfo && pCreateInfo->oldSwapchain) {
1438 SwpSwapchain *pOldSwapchain = &my_data->swapchainMap[pCreateInfo->oldSwapchain];
1439 if (pOldSwapchain) {
1440 if (device != pOldSwapchain->pDevice->device) {
1441 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1442 device, "VkDevice",
1443 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
1444 "%s() called with a different VkDevice "
1445 "than the VkSwapchainKHR was created with.",
1446 __FUNCTION__);
1447 }
1448 if (pCreateInfo->surface != pOldSwapchain->surface) {
1449 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1450 device, "VkDevice",
1451 SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE,
1452 "%s() called with pCreateInfo->oldSwapchain "
1453 "that has a different VkSurfaceKHR than "
1454 "pCreateInfo->surface.",
1455 fn);
Ian Elliotta2a89c52015-12-28 15:23:57 -07001456 }
1457 } else {
Ian Elliott6f3346b2016-01-05 13:06:48 -07001458 // TBD: Leave this in (not sure object_track will check this)?
Ian Elliott1bf155f2015-12-29 17:35:46 -07001459 skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliotta2a89c52015-12-28 15:23:57 -07001460 pCreateInfo->oldSwapchain,
1461 "VkSwapchainKHR");
1462 }
1463 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001464
1465 return skipCall;
1466}
1467
Ian Elliott27d39c72015-11-20 16:39:34 -07001468VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
1469 VkDevice device,
1470 const VkSwapchainCreateInfoKHR* pCreateInfo,
1471 const VkAllocationCallbacks* pAllocator,
1472 VkSwapchainKHR* pSwapchain)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001473{
1474 VkResult result = VK_SUCCESS;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001475 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001476 VkBool32 skipCall = validateCreateSwapchainKHR(device, pCreateInfo,
1477 pSwapchain);
1478
1479 if (VK_FALSE == skipCall) {
1480 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001481 result = my_data->device_dispatch_table->CreateSwapchainKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001482 device, pCreateInfo, pAllocator, pSwapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001483
1484 if (result == VK_SUCCESS) {
1485 // Remember the swapchain's handle, and link it to the device:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001486 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001487
Tobin Ehlis711ff312015-10-29 12:58:13 -06001488 my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain;
Chia-I Wue2fc5522015-10-26 20:04:44 +08001489 pDevice->swapchains[*pSwapchain] =
Tobin Ehlis711ff312015-10-29 12:58:13 -06001490 &my_data->swapchainMap[*pSwapchain];
1491 my_data->swapchainMap[*pSwapchain].pDevice = pDevice;
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001492 my_data->swapchainMap[*pSwapchain].surface =
1493 (pCreateInfo) ? pCreateInfo->surface : 0;
Tobin Ehlis711ff312015-10-29 12:58:13 -06001494 my_data->swapchainMap[*pSwapchain].imageCount = 0;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001495 }
1496
1497 return result;
1498 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001499 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001500}
1501
Ian Elliott27d39c72015-11-20 16:39:34 -07001502VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
1503 VkDevice device,
1504 VkSwapchainKHR swapchain,
1505 const VkAllocationCallbacks* pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001506{
1507 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001508 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -06001509 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott8b9e2562016-01-05 13:00:50 -07001510
1511 // Validate that the swapchain extension was enabled:
1512 if (pDevice && !pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001513 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001514 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001515 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001516 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001517 }
1518
1519 // Regardless of skipCall value, do some internal cleanup:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001520 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001521 if (pSwapchain) {
1522 // Delete the SwpSwapchain associated with this swapchain:
1523 if (pSwapchain->pDevice) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08001524 pSwapchain->pDevice->swapchains.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001525 if (device != pSwapchain->pDevice->device) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001526 LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001527 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001528 "%s() called with a different VkDevice than the "
1529 "VkSwapchainKHR was created with.",
1530 __FUNCTION__);
1531 }
1532 }
1533 if (pSwapchain->imageCount) {
1534 pSwapchain->images.clear();
1535 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001536 my_data->swapchainMap.erase(swapchain);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001537 }
1538
1539 if (VK_FALSE == skipCall) {
1540 // Call down the call chain:
Ian Elliott27d39c72015-11-20 16:39:34 -07001541 my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001542 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001543}
1544
Ian Elliottf955d682015-12-30 12:00:54 -07001545VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
1546 VkDevice device,
1547 VkSwapchainKHR swapchain,
1548 uint32_t* pSwapchainImageCount,
1549 VkImage* pSwapchainImages)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001550{
1551 VkResult result = VK_SUCCESS;
1552 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001553 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -06001554 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott8b9e2562016-01-05 13:00:50 -07001555
1556 // Validate that the swapchain extension was enabled:
1557 if (pDevice && !pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001558 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001559 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001560 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001561 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001562 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001563 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliottf955d682015-12-30 12:00:54 -07001564 if (!pSwapchainImageCount) {
Ian Elliottf7f8ff02015-12-30 14:55:41 -07001565 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1566 device,
Ian Elliottf955d682015-12-30 12:00:54 -07001567 "pSwapchainImageCount");
1568 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001569
1570 if (VK_FALSE == skipCall) {
1571 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001572 result = my_data->device_dispatch_table->GetSwapchainImagesKHR(
Ian Elliottf955d682015-12-30 12:00:54 -07001573 device, swapchain, pSwapchainImageCount, pSwapchainImages);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001574
Ian Elliottf955d682015-12-30 12:00:54 -07001575 if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages &&
1576 pSwapchainImageCount) {
1577 // Record the result of this preliminary query:
1578 pSwapchain->imageCount = *pSwapchainImageCount;
1579 }
Ian Elliott9059b302015-12-30 13:14:36 -07001580 else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages &&
1581 pSwapchainImageCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001582 // Compare the preliminary value of *pSwapchainImageCount with the
1583 // value this time:
Ian Elliottdcf8eca2016-01-05 14:28:32 -07001584 if (*pSwapchainImageCount > pSwapchain->imageCount) {
Ian Elliottf955d682015-12-30 12:00:54 -07001585 LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1586 device,
1587 "pSwapchainImageCount",
1588 "pSwapchainImages",
Ian Elliottdcf8eca2016-01-05 14:28:32 -07001589 *pSwapchainImageCount,
Ian Elliottf955d682015-12-30 12:00:54 -07001590 pSwapchain->imageCount);
1591 }
Ian Elliott9059b302015-12-30 13:14:36 -07001592 else if (*pSwapchainImageCount > 0) {
1593 // Record the images and their state:
1594 pSwapchain->imageCount = *pSwapchainImageCount;
1595 for (uint32_t i = 0 ; i < *pSwapchainImageCount ; i++) {
1596 pSwapchain->images[i].image = pSwapchainImages[i];
1597 pSwapchain->images[i].pSwapchain = pSwapchain;
1598 pSwapchain->images[i].ownedByApp = false;
1599 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001600 }
1601 }
1602
1603 return result;
1604 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001605 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001606}
1607
Ian Elliott27d39c72015-11-20 16:39:34 -07001608VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
1609 VkDevice device,
1610 VkSwapchainKHR swapchain,
1611 uint64_t timeout,
1612 VkSemaphore semaphore,
1613 VkFence fence,
1614 uint32_t* pImageIndex)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001615{
Ian Elliottdd45e462015-12-29 17:52:10 -07001616// TODOs:
1617//
1618// - Address the timeout. Possibilities include looking at the state of the
1619// swapchain's images, depending on the timeout value.
1620// - Validate that semaphore and fence are either VK_NULL_HANDLE or valid
1621// handles.
1622// - Record/update the state of the swapchain, in case an error occurs
1623// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
Ian Elliott0b4d6242015-09-22 10:51:24 -06001624 VkResult result = VK_SUCCESS;
1625 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001626 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis711ff312015-10-29 12:58:13 -06001627 SwpDevice *pDevice = &my_data->deviceMap[device];
Ian Elliott8b9e2562016-01-05 13:00:50 -07001628
1629 // Validate that the swapchain extension was enabled:
1630 if (pDevice && !pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001631 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001632 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001633 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001634 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001635 }
Tobin Ehlis711ff312015-10-29 12:58:13 -06001636 SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
Ian Elliott6f3346b2016-01-05 13:06:48 -07001637 if (pSwapchain) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001638 // Look to see if the application is trying to own too many images at
1639 // the same time (i.e. not leave any to display):
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001640 uint32_t imagesOwnedByApp = 0;
1641 for (uint32_t i = 0 ; i < pSwapchain->imageCount ; i++) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001642 if (pSwapchain->images[i].ownedByApp) {
1643 imagesOwnedByApp++;
1644 }
1645 }
1646 if (imagesOwnedByApp >= (pSwapchain->imageCount - 1)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001647 skipCall |= LOG_PERF_WARNING(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott4a994452015-09-24 18:33:16 -06001648 swapchain,
1649 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001650 SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES,
Ian Elliott4a994452015-09-24 18:33:16 -06001651 "%s() called when the application "
1652 "already owns all presentable images "
1653 "in this swapchain except for the "
1654 "image currently being displayed. "
1655 "This call to %s() cannot succeed "
1656 "unless another thread calls the "
1657 "vkQueuePresentKHR() function in "
1658 "order to release ownership of one of "
1659 "the presentable images of this "
1660 "swapchain.",
1661 __FUNCTION__, __FUNCTION__);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001662 }
1663 }
Ian Elliottdd45e462015-12-29 17:52:10 -07001664 if (!pImageIndex) {
1665 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1666 device,
1667 "pImageIndex");
1668 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001669
1670 if (VK_FALSE == skipCall) {
1671 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001672 result = my_data->device_dispatch_table->AcquireNextImageKHR(
Ian Elliott27d39c72015-11-20 16:39:34 -07001673 device, swapchain, timeout, semaphore, fence, pImageIndex);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001674
1675 if (((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)) &&
1676 pSwapchain) {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001677 // Change the state of the image (now owned by the application):
1678 pSwapchain->images[*pImageIndex].ownedByApp = true;
1679 }
1680
1681 return result;
1682 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001683 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001684}
1685
Ian Elliott27d39c72015-11-20 16:39:34 -07001686VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(
1687 VkQueue queue,
1688 const VkPresentInfoKHR* pPresentInfo)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001689{
1690// TODOs:
1691//
1692// - Ensure that the queue is active, and is one of the queueFamilyIndex's
1693// that was returned by a previuos query.
1694// - Record/update the state of the swapchain, in case an error occurs
1695// (e.g. VK_ERROR_OUT_OF_DATE_KHR).
1696 VkResult result = VK_SUCCESS;
1697 VkBool32 skipCall = VK_FALSE;
Ian Elliott68124ac2015-10-07 16:18:35 -06001698 layer_data *my_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001699
Ian Elliott046ed2c2015-12-30 17:07:17 -07001700 if (!pPresentInfo) {
1701 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1702 device,
1703 "pPresentInfo");
1704 } else {
1705 if (pPresentInfo->sType != VK_STRUCTURE_TYPE_PRESENT_INFO_KHR) {
1706 skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1707 device,
1708 "pPresentInfo",
1709 "VK_STRUCTURE_TYPE_PRESENT_INFO_KHR");
1710 }
1711 if (pPresentInfo->pNext != NULL) {
Ian Elliott31edb922016-01-05 14:41:45 -07001712 skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott046ed2c2015-12-30 17:07:17 -07001713 device,
1714 "pPresentInfo");
1715 }
Ian Elliott046ed2c2015-12-30 17:07:17 -07001716 if (!pPresentInfo->swapchainCount) {
1717 skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1718 device,
1719 "pPresentInfo->swapchainCount");
1720 }
1721 if (!pPresentInfo->pSwapchains) {
1722 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1723 device,
1724 "pPresentInfo->pSwapchains");
1725 }
1726 if (!pPresentInfo->pImageIndices) {
1727 skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
1728 device,
1729 "pPresentInfo->pImageIndices");
1730 }
1731 // Note: pPresentInfo->pResults is allowed to be NULL
1732 }
1733
1734 for (uint32_t i = 0;
1735 pPresentInfo && (i < pPresentInfo->swapchainCount);
1736 i++) {
1737 uint32_t swapchainCount = pPresentInfo->swapchainCount;
Ian Elliott27d39c72015-11-20 16:39:34 -07001738 uint32_t index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001739 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001740 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001741 if (pSwapchain) {
Ian Elliott427058f2015-12-29 16:45:49 -07001742 if (!pSwapchain->pDevice->swapchainExtensionEnabled) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001743 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001744 pSwapchain->pDevice, "VkDevice",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001745 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,
Michael Lentine010f4692015-11-03 16:19:46 -08001746 "%s() called even though the %s extension was not enabled for this VkDevice.",
Ian Elliott1dcd1092015-11-17 17:29:40 -07001747 __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001748 }
1749 if (index >= pSwapchain->imageCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001750 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001751 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001752 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001753 SWAPCHAIN_INDEX_TOO_LARGE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001754 "%s() called for an index that is too "
1755 "large (i.e. %d). There are only %d "
1756 "images in this VkSwapchainKHR.\n",
1757 __FUNCTION__, index,
1758 pSwapchain->imageCount);
1759 } else {
1760 if (!pSwapchain->images[index].ownedByApp) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001761 skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
Ian Elliott27d39c72015-11-20 16:39:34 -07001762 pPresentInfo->pSwapchains[i],
Ian Elliott0b4d6242015-09-22 10:51:24 -06001763 "VkSwapchainKHR",
Ian Elliottb0f474c2015-09-25 15:50:55 -06001764 SWAPCHAIN_INDEX_NOT_IN_USE,
Ian Elliott0b4d6242015-09-22 10:51:24 -06001765 "%s() returned an index (i.e. %d) "
1766 "for an image that is not owned by "
1767 "the application.",
1768 __FUNCTION__, index);
1769 }
1770 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001771 }
1772 }
1773
1774 if (VK_FALSE == skipCall) {
1775 // Call down the call chain:
Tobin Ehlis711ff312015-10-29 12:58:13 -06001776 result = my_data->device_dispatch_table->QueuePresentKHR(queue,
Ian Elliott046ed2c2015-12-30 17:07:17 -07001777 pPresentInfo);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001778
Ian Elliott046ed2c2015-12-30 17:07:17 -07001779 if (pPresentInfo &&
1780 ((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR))) {
Courtney Goeltzenleuchterdad30df2015-10-07 09:00:34 -06001781 for (uint32_t i = 0; i < pPresentInfo->swapchainCount ; i++) {
Ian Elliott27d39c72015-11-20 16:39:34 -07001782 int index = pPresentInfo->pImageIndices[i];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001783 SwpSwapchain *pSwapchain =
Ian Elliott27d39c72015-11-20 16:39:34 -07001784 &my_data->swapchainMap[pPresentInfo->pSwapchains[i]];
Ian Elliott0b4d6242015-09-22 10:51:24 -06001785 if (pSwapchain) {
1786 // Change the state of the image (no longer owned by the
1787 // application):
1788 pSwapchain->images[index].ownedByApp = false;
1789 }
1790 }
1791 }
1792
1793 return result;
1794 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001795 return VK_ERROR_VALIDATION_FAILED_EXT;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001796}
1797
1798static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)
1799{
1800 if (!name || name[0] != 'v' || name[1] != 'k')
1801 return NULL;
1802
1803 name += 2;
1804 if (!strcmp(name, "CreateInstance"))
1805 return (PFN_vkVoidFunction) vkCreateInstance;
1806 if (!strcmp(name, "DestroyInstance"))
1807 return (PFN_vkVoidFunction) vkDestroyInstance;
1808 if (!strcmp(name, "EnumeratePhysicalDevices"))
1809 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1810 if (!strcmp(name, "CreateDevice"))
1811 return (PFN_vkVoidFunction) vkCreateDevice;
1812 if (!strcmp(name, "DestroyDevice"))
1813 return (PFN_vkVoidFunction) vkDestroyDevice;
1814
1815 return NULL;
1816}
1817static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)
1818{
1819 if (!name || name[0] != 'v' || name[1] != 'k')
1820 return NULL;
1821
1822 name += 2;
1823 if (!strcmp(name, "CreateInstance"))
1824 return (PFN_vkVoidFunction) vkCreateInstance;
1825 if (!strcmp(name, "DestroyInstance"))
1826 return (PFN_vkVoidFunction) vkDestroyInstance;
1827 if (!strcmp(name, "EnumeratePhysicalDevices"))
1828 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
1829
1830 return NULL;
1831}
1832
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001833VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
1834 VkInstance instance,
1835 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
1836 const VkAllocationCallbacks* pAllocator,
1837 VkDebugReportCallbackEXT* pMsgCallback)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001838{
Tobin Ehlis711ff312015-10-29 12:58:13 -06001839 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001840 VkResult result = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001841 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001842 result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Ian Elliott68124ac2015-10-07 16:18:35 -06001843 }
1844 return result;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001845}
1846
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001847VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001848{
Ian Elliott68124ac2015-10-07 16:18:35 -06001849 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001850 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07001851 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001852}
1853
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001854VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001855 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001856 VkDebugReportFlagsEXT flags,
1857 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001858 uint64_t object,
1859 size_t location,
1860 int32_t msgCode,
1861 const char* pLayerPrefix,
1862 const char* pMsg)
1863{
1864 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001865 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07001866}
1867
Chia-I Wu9ab61502015-11-06 06:42:02 +08001868VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001869{
1870 PFN_vkVoidFunction addr;
1871 if (device == VK_NULL_HANDLE) {
1872 return NULL;
1873 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001874
Tobin Ehlis711ff312015-10-29 12:58:13 -06001875 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001876 /* loader uses this to force layer initialization; device object is wrapped */
1877 if (!strcmp("vkGetDeviceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001878 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) device;
1879 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
1880 my_data->device_dispatch_table = new VkLayerDispatchTable;
1881 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001882 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
1883 }
1884
1885 addr = layer_intercept_proc(funcName);
1886 if (addr)
1887 return addr;
1888
Tobin Ehlis711ff312015-10-29 12:58:13 -06001889 my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
1890 VkLayerDispatchTable *pDisp = my_data->device_dispatch_table;
1891 if (my_data->deviceMap.size() != 0 &&
Ian Elliott427058f2015-12-29 16:45:49 -07001892 my_data->deviceMap[device].swapchainExtensionEnabled)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001893 {
Ian Elliott0b4d6242015-09-22 10:51:24 -06001894 if (!strcmp("vkCreateSwapchainKHR", funcName))
1895 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR);
1896 if (!strcmp("vkDestroySwapchainKHR", funcName))
1897 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR);
1898 if (!strcmp("vkGetSwapchainImagesKHR", funcName))
1899 return reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR);
1900 if (!strcmp("vkAcquireNextImageKHR", funcName))
1901 return reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR);
1902 if (!strcmp("vkQueuePresentKHR", funcName))
1903 return reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR);
1904 }
1905 {
1906 if (pDisp->GetDeviceProcAddr == NULL)
1907 return NULL;
1908 return pDisp->GetDeviceProcAddr(device, funcName);
1909 }
1910}
1911
Chia-I Wu9ab61502015-11-06 06:42:02 +08001912VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Ian Elliott0b4d6242015-09-22 10:51:24 -06001913{
1914 PFN_vkVoidFunction addr;
1915 if (instance == VK_NULL_HANDLE) {
1916 return NULL;
1917 }
Ian Elliott0b4d6242015-09-22 10:51:24 -06001918
Tobin Ehlis711ff312015-10-29 12:58:13 -06001919 layer_data *my_data;
Ian Elliott0b4d6242015-09-22 10:51:24 -06001920 /* loader uses this to force layer initialization; instance object is wrapped */
1921 if (!strcmp("vkGetInstanceProcAddr", funcName)) {
Tobin Ehlis711ff312015-10-29 12:58:13 -06001922 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
1923 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
1924 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
1925 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Ian Elliott0b4d6242015-09-22 10:51:24 -06001926 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
1927 }
1928
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07001929 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
1930 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
1931 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
1932 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
1933
Ian Elliott0b4d6242015-09-22 10:51:24 -06001934 addr = layer_intercept_instance_proc(funcName);
1935 if (addr)
1936 return addr;
1937
Tobin Ehlis711ff312015-10-29 12:58:13 -06001938 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
1939 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Ian Elliott68124ac2015-10-07 16:18:35 -06001940 addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
1941 if (addr) {
1942 return addr;
1943 }
1944
Ian Elliotta983e9a2015-12-22 12:18:12 -07001945#ifdef VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001946 if (my_data->instanceMap.size() != 0 &&
1947 my_data->instanceMap[instance].androidSurfaceExtensionEnabled)
1948 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001949 if (!strcmp("vkCreateAndroidSurfaceKHR", funcName))
1950 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateAndroidSurfaceKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001951 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001952#endif // VK_USE_PLATFORM_ANDROID_KHR
1953#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001954 if (my_data->instanceMap.size() != 0 &&
1955 my_data->instanceMap[instance].mirSurfaceExtensionEnabled)
1956 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001957 if (!strcmp("vkCreateMirSurfaceKHR", funcName))
1958 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateMirSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001959 if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", funcName))
1960 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceMirPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001961 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001962#endif // VK_USE_PLATFORM_MIR_KHR
1963#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001964 if (my_data->instanceMap.size() != 0 &&
1965 my_data->instanceMap[instance].waylandSurfaceExtensionEnabled)
1966 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001967 if (!strcmp("vkCreateWaylandSurfaceKHR", funcName))
1968 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWaylandSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001969 if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", funcName))
1970 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001971 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001972#endif // VK_USE_PLATFORM_WAYLAND_KHR
1973#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001974 if (my_data->instanceMap.size() != 0 &&
1975 my_data->instanceMap[instance].win32SurfaceExtensionEnabled)
1976 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001977 if (!strcmp("vkCreateWin32SurfaceKHR", funcName))
1978 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWin32SurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001979 if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", funcName))
1980 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWin32PresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001981 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001982#endif // VK_USE_PLATFORM_WIN32_KHR
1983#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001984 if (my_data->instanceMap.size() != 0 &&
1985 my_data->instanceMap[instance].xcbSurfaceExtensionEnabled)
1986 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001987 if (!strcmp("vkCreateXcbSurfaceKHR", funcName))
1988 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXcbSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001989 if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", funcName))
1990 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXcbPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07001991 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07001992#endif // VK_USE_PLATFORM_XCB_KHR
1993#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07001994 if (my_data->instanceMap.size() != 0 &&
1995 my_data->instanceMap[instance].xlibSurfaceExtensionEnabled)
1996 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07001997 if (!strcmp("vkCreateXlibSurfaceKHR", funcName))
1998 return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXlibSurfaceKHR);
Ian Elliott55ff7962015-12-30 10:18:47 -07001999 if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", funcName))
2000 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXlibPresentationSupportKHR);
Ian Elliott8dffaf32016-01-04 14:10:30 -07002001 }
Ian Elliotta983e9a2015-12-22 12:18:12 -07002002#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott8dffaf32016-01-04 14:10:30 -07002003 if (my_data->instanceMap.size() != 0 &&
2004 my_data->instanceMap[instance].surfaceExtensionEnabled)
2005 {
Ian Elliotta983e9a2015-12-22 12:18:12 -07002006 if (!strcmp("vkDestroySurfaceKHR", funcName))
2007 return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySurfaceKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002008 if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", funcName))
2009 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceSupportKHR);
Ian Elliott27d39c72015-11-20 16:39:34 -07002010 if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", funcName))
2011 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
2012 if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", funcName))
2013 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceFormatsKHR);
2014 if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", funcName))
2015 return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfacePresentModesKHR);
Ian Elliott0b4d6242015-09-22 10:51:24 -06002016 }
2017
2018 if (pTable->GetInstanceProcAddr == NULL)
2019 return NULL;
2020 return pTable->GetInstanceProcAddr(instance, funcName);
2021}
2022