Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1 | /* |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 4 | * |
| 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 Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 23 | * Author: Ian Elliott <ian@lunarg.com> |
| 24 | * |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 25 | */ |
| 26 | |
Ian Elliott | d8c5db1 | 2015-10-07 11:32:31 -0600 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | #include <string.h> |
Mark Lobodzinski | b49b6e5 | 2015-11-26 10:59:58 -0700 | [diff] [blame] | 29 | #include <vk_loader_platform.h> |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 30 | #include <vk_icd.h> |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 31 | #include "swapchain.h" |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 32 | #include "vk_layer_extension_utils.h" |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 33 | #include "vk_enum_string_helper.h" |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 34 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 35 | // FIXME/TODO: Make sure this layer is thread-safe! |
| 36 | |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 37 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 38 | // The following is for logging error messages: |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 39 | static std::unordered_map<void *, layer_data *> layer_data_map; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 40 | |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 41 | template layer_data *get_my_data_ptr<layer_data>( |
| 42 | void *data_key, |
| 43 | std::unordered_map<void *, layer_data *> &data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 44 | |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 45 | static const VkExtensionProperties instance_extensions[] = { |
| 46 | { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 47 | VK_EXT_DEBUG_REPORT_EXTENSION_NAME, |
| 48 | VK_EXT_DEBUG_REPORT_REVISION |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 49 | } |
| 50 | }; |
| 51 | |
| 52 | VK_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 | |
| 60 | static const VkLayerProperties swapchain_global_layers[] = { |
| 61 | { |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 62 | "swapchain", |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 63 | VK_API_VERSION, |
| 64 | VK_MAKE_VERSION(0, 1, 0), |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 65 | "Validation layer: swapchain", |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 66 | } |
| 67 | }; |
| 68 | |
| 69 | VK_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 Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 78 | // This function validates a VkSurfaceKHR object: |
| 79 | static VkBool32 validateSurface(layer_data *my_data, VkSurfaceKHR surface, char *fn) |
| 80 | { |
| 81 | VkBool32 skipCall = VK_FALSE; |
| 82 | bool found_error = false; |
| 83 | |
| 84 | SwpSurface *pSurface = &my_data->surfaceMap[surface]; |
| 85 | if ((pSurface == NULL) || (pSurface->surface != surface)) { |
| 86 | found_error = true; |
| 87 | } else { |
| 88 | #if !defined(__ANDROID__) |
| 89 | VkIcdSurfaceBase *pIcdSurface = (VkIcdSurfaceBase *) surface; |
| 90 | if (pSurface->platform != pIcdSurface->platform) { |
| 91 | found_error = true; |
| 92 | } |
| 93 | #else // !defined(__ANDROID__) |
| 94 | if (pSurface->platform != VK_ICD_WSI_PLATFORM_ANDROID) { |
| 95 | found_error = true; |
| 96 | } |
| 97 | #endif // !defined(__ANDROID__) |
| 98 | } |
| 99 | if (found_error) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 100 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, surface, "VkSurfaceKHR", |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 101 | SWAPCHAIN_INVALID_HANDLE, |
| 102 | "%s() called with an invalid surface object.", |
| 103 | fn); |
| 104 | } |
| 105 | return skipCall; |
| 106 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 107 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 108 | static void createDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice device) |
| 109 | { |
| 110 | uint32_t i; |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 111 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 112 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 113 | |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 114 | VkLayerDispatchTable *pDisp = my_device_data->device_dispatch_table; |
| 115 | PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr; |
| 116 | |
| 117 | pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR"); |
| 118 | pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR"); |
| 119 | pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR"); |
| 120 | pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR"); |
| 121 | pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR"); |
| 122 | |
| 123 | SwpPhysicalDevice *pPhysicalDevice = &my_instance_data->physicalDeviceMap[physicalDevice]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 124 | if (pPhysicalDevice) { |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 125 | my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice; |
| 126 | pPhysicalDevice->pDevice = &my_device_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 127 | } else { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 128 | log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 80e774f | 2016-01-04 15:54:59 -0700 | [diff] [blame] | 129 | (uint64_t)physicalDevice , __LINE__, SWAPCHAIN_INVALID_HANDLE, "Swapchain", |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 130 | "vkCreateDevice() called with a non-valid VkPhysicalDevice."); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 131 | } |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 132 | my_device_data->deviceMap[device].device = device; |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 133 | my_device_data->deviceMap[device].swapchainExtensionEnabled = false; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 134 | |
| 135 | // Record whether the WSI device extension was enabled for this VkDevice. |
| 136 | // No need to check if the extension was advertised by |
| 137 | // vkEnumerateDeviceExtensionProperties(), since the loader handles that. |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 138 | for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 139 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 140 | |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 141 | my_device_data->deviceMap[device].swapchainExtensionEnabled = true; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance) |
| 147 | { |
| 148 | uint32_t i; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 149 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 150 | VkLayerInstanceDispatchTable *pDisp = my_data->instance_dispatch_table; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 151 | PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr; |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 152 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 153 | pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR) gpa(instance, "vkCreateAndroidSurfaceKHR"); |
| 154 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 155 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 156 | pDisp->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR) gpa(instance, "vkCreateMirSurfaceKHR"); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 157 | pDisp->GetPhysicalDeviceMirPresentationSupportKHR = (PFN_vkGetPhysicalDeviceMirPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceMirPresentationSupportKHR"); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 158 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 159 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 160 | pDisp->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR) gpa(instance, "vkCreateWaylandSurfaceKHR"); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 161 | pDisp->GetPhysicalDeviceWaylandPresentationSupportKHR = (PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWaylandPresentationSupportKHR"); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 162 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 163 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 164 | pDisp->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) gpa(instance, "vkCreateWin32SurfaceKHR"); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 165 | pDisp->GetPhysicalDeviceWin32PresentationSupportKHR = (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR"); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 166 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 167 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 168 | pDisp->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) gpa(instance, "vkCreateXcbSurfaceKHR"); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 169 | pDisp->GetPhysicalDeviceXcbPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR"); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 170 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 171 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 172 | pDisp->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR) gpa(instance, "vkCreateXlibSurfaceKHR"); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 173 | pDisp->GetPhysicalDeviceXlibPresentationSupportKHR = (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR) gpa(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR"); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 174 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 175 | pDisp->DestroySurfaceKHR = (PFN_vkDestroySurfaceKHR) gpa(instance, "vkDestroySurfaceKHR"); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 176 | pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR"); |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 177 | pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"); |
| 178 | pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR"); |
| 179 | pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR"); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 180 | |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 181 | // Remember this instance, and whether the VK_KHR_surface extension |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 182 | // was enabled for it: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 183 | my_data->instanceMap[instance].instance = instance; |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 184 | my_data->instanceMap[instance].surfaceExtensionEnabled = false; |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 185 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 186 | my_data->instanceMap[instance].androidSurfaceExtensionEnabled = false; |
| 187 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 188 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 189 | my_data->instanceMap[instance].mirSurfaceExtensionEnabled = false; |
| 190 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 191 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 192 | my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = false; |
| 193 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 194 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 195 | my_data->instanceMap[instance].win32SurfaceExtensionEnabled = false; |
| 196 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 197 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 198 | my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = false; |
| 199 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 200 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 201 | my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = false; |
| 202 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 203 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 204 | |
| 205 | // Record whether the WSI instance extension was enabled for this |
| 206 | // VkInstance. No need to check if the extension was advertised by |
| 207 | // vkEnumerateInstanceExtensionProperties(), since the loader handles that. |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 208 | for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 209 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 210 | |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 211 | my_data->instanceMap[instance].surfaceExtensionEnabled = true; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 212 | } |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 213 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 214 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) { |
| 215 | |
| 216 | my_data->instanceMap[instance].androidSurfaceExtensionEnabled = true; |
| 217 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 218 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 219 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) { |
| 220 | |
| 221 | my_data->instanceMap[instance].mirSurfaceExtensionEnabled = true; |
| 222 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 223 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 224 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) { |
| 225 | |
| 226 | my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = true; |
| 227 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 228 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 229 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) { |
| 230 | |
| 231 | my_data->instanceMap[instance].win32SurfaceExtensionEnabled = true; |
| 232 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 233 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 234 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) { |
| 235 | |
| 236 | my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = true; |
| 237 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 238 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 239 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) { |
| 240 | |
| 241 | my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = true; |
| 242 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 243 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | |
| 248 | #include "vk_dispatch_table_helper.h" |
Courtney Goeltzenleuchter | 6d8e818 | 2015-11-25 14:31:49 -0700 | [diff] [blame] | 249 | static void initSwapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 250 | { |
| 251 | uint32_t report_flags = 0; |
| 252 | uint32_t debug_action = 0; |
| 253 | FILE *log_output = NULL; |
| 254 | const char *option_str; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 255 | VkDebugReportCallbackEXT callback; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 256 | |
| 257 | // Initialize Swapchain options: |
| 258 | report_flags = getLayerOptionFlags("SwapchainReportFlags", 0); |
| 259 | getLayerOptionEnum("SwapchainDebugAction", (uint32_t *) &debug_action); |
| 260 | |
| 261 | if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) |
| 262 | { |
| 263 | // Turn on logging, since it was requested: |
| 264 | option_str = getLayerOption("SwapchainLogFilename"); |
| 265 | log_output = getLayerLogOutput(option_str, "Swapchain"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 266 | VkDebugReportCallbackCreateInfoEXT dbgInfo; |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 267 | memset(&dbgInfo, 0, sizeof(dbgInfo)); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 268 | dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 269 | dbgInfo.pfnCallback = log_callback; |
| 270 | dbgInfo.pUserData = log_output; |
| 271 | dbgInfo.flags = report_flags; |
| 272 | layer_create_msg_callback(my_data->report_data, |
| 273 | &dbgInfo, |
| 274 | pAllocator, |
Courtney Goeltzenleuchter | cf60e0a | 2015-10-08 17:07:25 -0600 | [diff] [blame] | 275 | &callback); |
| 276 | my_data->logging_callback.push_back(callback); |
| 277 | } |
| 278 | if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 279 | VkDebugReportCallbackCreateInfoEXT dbgInfo; |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 280 | memset(&dbgInfo, 0, sizeof(dbgInfo)); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 281 | dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 282 | dbgInfo.pfnCallback = win32_debug_output_msg; |
| 283 | dbgInfo.pUserData = log_output; |
| 284 | dbgInfo.flags = report_flags; |
| 285 | layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback); |
Courtney Goeltzenleuchter | cf60e0a | 2015-10-08 17:07:25 -0600 | [diff] [blame] | 286 | my_data->logging_callback.push_back(callback); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 290 | static const char *surfaceTransformStr(VkSurfaceTransformFlagBitsKHR value) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 291 | { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 292 | // Return a string corresponding to the value: |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 293 | return string_VkSurfaceTransformFlagBitsKHR(value); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 294 | } |
| 295 | |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 296 | static const char *surfaceCompositeAlphaStr(VkCompositeAlphaFlagBitsKHR value) |
| 297 | { |
| 298 | // Return a string corresponding to the value: |
| 299 | return string_VkCompositeAlphaFlagBitsKHR(value); |
| 300 | } |
| 301 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 302 | static const char *presentModeStr(VkPresentModeKHR value) |
| 303 | { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 304 | // Return a string corresponding to the value: |
Ian Elliott | 24491af | 2015-12-28 15:04:49 -0700 | [diff] [blame] | 305 | return string_VkPresentModeKHR(value); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 306 | } |
| 307 | |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 308 | static const char *sharingModeStr(VkSharingMode value) |
| 309 | { |
| 310 | // Return a string corresponding to the value: |
| 311 | return string_VkSharingMode(value); |
| 312 | } |
| 313 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 314 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 315 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 316 | { |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 317 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 318 | // Call down the call chain: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 319 | VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 320 | VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 321 | if (result == VK_SUCCESS) { |
| 322 | // Since it succeeded, do layer-specific work: |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 323 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 324 | my_data->report_data = debug_report_create_instance( |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 325 | pTable, |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 326 | *pInstance, |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 327 | pCreateInfo->enabledExtensionNameCount, |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 328 | pCreateInfo->ppEnabledExtensionNames); |
| 329 | // Call the following function after my_data is initialized: |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 330 | createInstanceRegisterExtensions(pCreateInfo, *pInstance); |
Courtney Goeltzenleuchter | 6d8e818 | 2015-11-25 14:31:49 -0700 | [diff] [blame] | 331 | initSwapchain(my_data, pAllocator); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 332 | } |
| 333 | return result; |
| 334 | } |
| 335 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 336 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 337 | { |
| 338 | VkBool32 skipCall = VK_FALSE; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 339 | dispatch_key key = get_dispatch_key(instance); |
| 340 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 341 | // Validate that a valid VkInstance was used: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 342 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 343 | if (!pInstance) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 344 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 345 | instance, |
| 346 | "VkInstance"); |
| 347 | } |
| 348 | |
| 349 | if (VK_FALSE == skipCall) { |
| 350 | // Call down the call chain: |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 351 | my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator); |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 352 | |
| 353 | // Clean up logging callback, if any |
Courtney Goeltzenleuchter | cf60e0a | 2015-10-08 17:07:25 -0600 | [diff] [blame] | 354 | while (my_data->logging_callback.size() > 0) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 355 | VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 356 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
Courtney Goeltzenleuchter | cf60e0a | 2015-10-08 17:07:25 -0600 | [diff] [blame] | 357 | my_data->logging_callback.pop_back(); |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 358 | } |
| 359 | layer_debug_report_destroy_instance(my_data->report_data); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | // Regardless of skipCall value, do some internal cleanup: |
| 363 | if (pInstance) { |
| 364 | // Delete all of the SwpPhysicalDevice's and the SwpInstance associated |
| 365 | // with this instance: |
| 366 | for (auto it = pInstance->physicalDevices.begin() ; |
| 367 | it != pInstance->physicalDevices.end() ; it++) { |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 368 | |
| 369 | // Free memory that was allocated for/by this SwpPhysicalDevice: |
| 370 | SwpPhysicalDevice *pPhysicalDevice = it->second; |
| 371 | free(pPhysicalDevice->pSurfaceFormats); |
| 372 | free(pPhysicalDevice->pPresentModes); |
| 373 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 374 | // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 375 | // are simply pointed to by the SwpInstance): |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 376 | my_data->physicalDeviceMap.erase(it->second->physicalDevice); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 377 | } |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 378 | my_data->instanceMap.erase(instance); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 379 | } |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 380 | delete my_data->instance_dispatch_table; |
| 381 | layer_data_map.erase(key); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 382 | } |
| 383 | |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 384 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 385 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR( |
| 386 | VkInstance instance, |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 387 | const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 388 | const VkAllocationCallbacks* pAllocator, |
| 389 | VkSurfaceKHR* pSurface) |
| 390 | { |
| 391 | VkResult result = VK_SUCCESS; |
| 392 | VkBool32 skipCall = VK_FALSE; |
| 393 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 394 | |
| 395 | // Validate that a valid VkInstance was used: |
| 396 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 397 | if (!pInstance) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 398 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 399 | instance, |
| 400 | "VkInstance"); |
| 401 | } |
Ian Elliott | f575829 | 2015-12-30 17:39:02 -0700 | [diff] [blame] | 402 | 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_ANDROID_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_ANDROID_SURFACE_CREATE_INFO_KHR"); |
| 412 | } |
| 413 | if (pCreateInfo->pNext != NULL) { |
| 414 | skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 415 | device, |
| 416 | "pCreateInfo"); |
| 417 | } |
| 418 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 419 | |
| 420 | if (VK_FALSE == skipCall) { |
| 421 | // Call down the call chain: |
| 422 | result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR( |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 423 | instance, pCreateInfo, pAllocator, pSurface); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 424 | |
| 425 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 426 | // Record the VkSurfaceKHR returned by the ICD: |
| 427 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 428 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
| 429 | my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_ANDROID; |
| 430 | // Point to the associated SwpInstance: |
| 431 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 432 | skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__); |
| 433 | } |
| 434 | return result; |
| 435 | } |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 436 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 437 | } |
| 438 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 439 | |
| 440 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 441 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR( |
| 442 | VkInstance instance, |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 443 | const VkMirSurfaceCreateInfoKHR* pCreateInfo, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 444 | const VkAllocationCallbacks* pAllocator, |
| 445 | VkSurfaceKHR* pSurface) |
| 446 | { |
| 447 | VkResult result = VK_SUCCESS; |
| 448 | VkBool32 skipCall = VK_FALSE; |
| 449 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 450 | |
| 451 | // Validate that a valid VkInstance was used: |
| 452 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 453 | if (!pInstance) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 454 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 455 | instance, |
| 456 | "VkInstance"); |
| 457 | } |
Ian Elliott | f575829 | 2015-12-30 17:39:02 -0700 | [diff] [blame] | 458 | if (!pCreateInfo) { |
| 459 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 460 | device, |
| 461 | "pCreateInfo"); |
| 462 | } else { |
| 463 | if (pCreateInfo->sType != VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR) { |
| 464 | skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 465 | device, |
| 466 | "pCreateInfo", |
| 467 | "VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR"); |
| 468 | } |
| 469 | if (pCreateInfo->pNext != NULL) { |
| 470 | skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 471 | device, |
| 472 | "pCreateInfo"); |
| 473 | } |
| 474 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 475 | |
| 476 | if (VK_FALSE == skipCall) { |
| 477 | // Call down the call chain: |
| 478 | result = my_data->instance_dispatch_table->CreateMirSurfaceKHR( |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 479 | instance, pCreateInfo, pAllocator, pSurface); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 480 | |
| 481 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 482 | // Record the VkSurfaceKHR returned by the ICD: |
| 483 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 484 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
| 485 | my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_MIR; |
| 486 | // Point to the associated SwpInstance: |
| 487 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 488 | skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__); |
| 489 | } |
| 490 | return result; |
| 491 | } |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 492 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 493 | } |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 494 | |
| 495 | VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceMirPresentationSupportKHR( |
| 496 | VkPhysicalDevice physicalDevice, |
| 497 | uint32_t queueFamilyIndex, |
| 498 | MirConnection* connection) |
| 499 | { |
| 500 | VkBool32 result = VK_FALSE; |
| 501 | VkBool32 skipCall = VK_FALSE; |
| 502 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 503 | |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 504 | // Validate that a valid VkPhysicalDevice was used, and that the platform |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 505 | // extension was enabled: |
| 506 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
| 507 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
| 508 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 509 | physicalDevice, |
| 510 | "VkPhysicalDevice"); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 511 | } else if (!pPhysicalDevice->pInstance->mirSurfaceExtensionEnabled) { |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 512 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 513 | pPhysicalDevice->pInstance, |
| 514 | "VkInstance", |
| 515 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
| 516 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 517 | __FUNCTION__, VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | if (VK_FALSE == skipCall) { |
| 521 | // Call down the call chain: |
| 522 | result = my_data->instance_dispatch_table->GetPhysicalDeviceMirPresentationSupportKHR( |
| 523 | physicalDevice, queueFamilyIndex, connection); |
| 524 | |
| 525 | if (pPhysicalDevice) { |
| 526 | // Record the result of this query: |
| 527 | pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result; |
| 528 | } |
| 529 | } |
| 530 | return result; |
| 531 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 532 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 533 | |
| 534 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 535 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR( |
| 536 | VkInstance instance, |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 537 | const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 538 | const VkAllocationCallbacks* pAllocator, |
| 539 | VkSurfaceKHR* pSurface) |
| 540 | { |
| 541 | VkResult result = VK_SUCCESS; |
| 542 | VkBool32 skipCall = VK_FALSE; |
| 543 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 544 | |
| 545 | // Validate that a valid VkInstance was used: |
| 546 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 547 | if (!pInstance) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 548 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 549 | instance, |
| 550 | "VkInstance"); |
| 551 | } |
Ian Elliott | f575829 | 2015-12-30 17:39:02 -0700 | [diff] [blame] | 552 | if (!pCreateInfo) { |
| 553 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 554 | device, |
| 555 | "pCreateInfo"); |
| 556 | } else { |
| 557 | if (pCreateInfo->sType != VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR) { |
| 558 | skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 559 | device, |
| 560 | "pCreateInfo", |
| 561 | "VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR"); |
| 562 | } |
| 563 | if (pCreateInfo->pNext != NULL) { |
| 564 | skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 565 | device, |
| 566 | "pCreateInfo"); |
| 567 | } |
| 568 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 569 | |
| 570 | if (VK_FALSE == skipCall) { |
| 571 | // Call down the call chain: |
| 572 | result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR( |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 573 | instance, pCreateInfo, pAllocator, pSurface); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 574 | |
| 575 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 576 | // Record the VkSurfaceKHR returned by the ICD: |
| 577 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 578 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
| 579 | my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_WAYLAND; |
| 580 | // Point to the associated SwpInstance: |
| 581 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 582 | skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__); |
| 583 | } |
| 584 | return result; |
| 585 | } |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 586 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 587 | } |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 588 | |
| 589 | VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR( |
| 590 | VkPhysicalDevice physicalDevice, |
| 591 | uint32_t queueFamilyIndex, |
| 592 | struct wl_display* display) |
| 593 | { |
| 594 | VkBool32 result = VK_FALSE; |
| 595 | VkBool32 skipCall = VK_FALSE; |
| 596 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 597 | |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 598 | // Validate that a valid VkPhysicalDevice was used, and that the platform |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 599 | // extension was enabled: |
| 600 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
| 601 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
| 602 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 603 | physicalDevice, |
| 604 | "VkPhysicalDevice"); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 605 | } else if (!pPhysicalDevice->pInstance->waylandSurfaceExtensionEnabled) { |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 606 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 607 | pPhysicalDevice->pInstance, |
| 608 | "VkInstance", |
| 609 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
| 610 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 611 | __FUNCTION__, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | if (VK_FALSE == skipCall) { |
| 615 | // Call down the call chain: |
| 616 | result = my_data->instance_dispatch_table->GetPhysicalDeviceWaylandPresentationSupportKHR( |
| 617 | physicalDevice, queueFamilyIndex, display); |
| 618 | |
| 619 | if (pPhysicalDevice) { |
| 620 | // Record the result of this query: |
| 621 | pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result; |
| 622 | } |
| 623 | } |
| 624 | return result; |
| 625 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 626 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 627 | |
| 628 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 629 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR( |
| 630 | VkInstance instance, |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 631 | const VkWin32SurfaceCreateInfoKHR* pCreateInfo, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 632 | const VkAllocationCallbacks* pAllocator, |
| 633 | VkSurfaceKHR* pSurface) |
| 634 | { |
| 635 | VkResult result = VK_SUCCESS; |
| 636 | VkBool32 skipCall = VK_FALSE; |
| 637 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 638 | |
| 639 | // Validate that a valid VkInstance was used: |
| 640 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 641 | if (!pInstance) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 642 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 643 | instance, |
| 644 | "VkInstance"); |
| 645 | } |
Ian Elliott | f575829 | 2015-12-30 17:39:02 -0700 | [diff] [blame] | 646 | if (!pCreateInfo) { |
| 647 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 648 | device, |
| 649 | "pCreateInfo"); |
| 650 | } else { |
| 651 | if (pCreateInfo->sType != VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR) { |
| 652 | skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 653 | device, |
| 654 | "pCreateInfo", |
| 655 | "VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR"); |
| 656 | } |
| 657 | if (pCreateInfo->pNext != NULL) { |
| 658 | skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 659 | device, |
| 660 | "pCreateInfo"); |
| 661 | } |
| 662 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 663 | |
| 664 | if (VK_FALSE == skipCall) { |
| 665 | // Call down the call chain: |
| 666 | result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR( |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 667 | instance, pCreateInfo, pAllocator, pSurface); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 668 | |
| 669 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 670 | // Record the VkSurfaceKHR returned by the ICD: |
| 671 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 672 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
| 673 | my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_WIN32; |
| 674 | // Point to the associated SwpInstance: |
| 675 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 676 | skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__); |
| 677 | } |
| 678 | return result; |
| 679 | } |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 680 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 681 | } |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 682 | |
| 683 | VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR( |
| 684 | VkPhysicalDevice physicalDevice, |
| 685 | uint32_t queueFamilyIndex) |
| 686 | { |
| 687 | VkBool32 result = VK_FALSE; |
| 688 | VkBool32 skipCall = VK_FALSE; |
| 689 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 690 | |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 691 | // Validate that a valid VkPhysicalDevice was used, and that the platform |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 692 | // extension was enabled: |
| 693 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
| 694 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
| 695 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 696 | physicalDevice, |
| 697 | "VkPhysicalDevice"); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 698 | } else if (!pPhysicalDevice->pInstance->win32SurfaceExtensionEnabled) { |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 699 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 700 | pPhysicalDevice->pInstance, |
| 701 | "VkInstance", |
| 702 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
| 703 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 704 | __FUNCTION__, VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | if (VK_FALSE == skipCall) { |
| 708 | // Call down the call chain: |
| 709 | result = my_data->instance_dispatch_table->GetPhysicalDeviceWin32PresentationSupportKHR( |
| 710 | physicalDevice, queueFamilyIndex); |
| 711 | |
| 712 | if (pPhysicalDevice) { |
| 713 | // Record the result of this query: |
| 714 | pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result; |
| 715 | } |
| 716 | } |
| 717 | return result; |
| 718 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 719 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 720 | |
| 721 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 722 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( |
| 723 | VkInstance instance, |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 724 | const VkXcbSurfaceCreateInfoKHR* pCreateInfo, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 725 | const VkAllocationCallbacks* pAllocator, |
| 726 | VkSurfaceKHR* pSurface) |
| 727 | { |
| 728 | VkResult result = VK_SUCCESS; |
| 729 | VkBool32 skipCall = VK_FALSE; |
| 730 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 731 | |
| 732 | // Validate that a valid VkInstance was used: |
| 733 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 734 | if (!pInstance) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 735 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 736 | instance, |
| 737 | "VkInstance"); |
| 738 | } |
Ian Elliott | f575829 | 2015-12-30 17:39:02 -0700 | [diff] [blame] | 739 | if (!pCreateInfo) { |
| 740 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 741 | device, |
| 742 | "pCreateInfo"); |
| 743 | } else { |
| 744 | if (pCreateInfo->sType != VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR) { |
| 745 | skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 746 | device, |
| 747 | "pCreateInfo", |
| 748 | "VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR"); |
| 749 | } |
| 750 | if (pCreateInfo->pNext != NULL) { |
| 751 | skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 752 | device, |
| 753 | "pCreateInfo"); |
| 754 | } |
| 755 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 756 | |
| 757 | if (VK_FALSE == skipCall) { |
| 758 | // Call down the call chain: |
| 759 | result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR( |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 760 | instance, pCreateInfo, pAllocator, pSurface); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 761 | |
| 762 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 763 | // Record the VkSurfaceKHR returned by the ICD: |
| 764 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 765 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
| 766 | my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_XCB; |
| 767 | // Point to the associated SwpInstance: |
| 768 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 769 | skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__); |
| 770 | } |
| 771 | return result; |
| 772 | } |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 773 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 774 | } |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 775 | |
| 776 | VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( |
| 777 | VkPhysicalDevice physicalDevice, |
| 778 | uint32_t queueFamilyIndex, |
| 779 | xcb_connection_t* connection, |
| 780 | xcb_visualid_t visual_id) |
| 781 | { |
| 782 | VkBool32 result = VK_FALSE; |
| 783 | VkBool32 skipCall = VK_FALSE; |
| 784 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 785 | |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 786 | // Validate that a valid VkPhysicalDevice was used, and that the platform |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 787 | // extension was enabled: |
| 788 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
| 789 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
| 790 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 791 | physicalDevice, |
| 792 | "VkPhysicalDevice"); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 793 | } else if (!pPhysicalDevice->pInstance->xcbSurfaceExtensionEnabled) { |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 794 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 795 | pPhysicalDevice->pInstance, |
| 796 | "VkInstance", |
| 797 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
| 798 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 799 | __FUNCTION__, VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | if (VK_FALSE == skipCall) { |
| 803 | // Call down the call chain: |
| 804 | result = my_data->instance_dispatch_table->GetPhysicalDeviceXcbPresentationSupportKHR( |
| 805 | physicalDevice, queueFamilyIndex, connection, visual_id); |
| 806 | |
| 807 | if (pPhysicalDevice) { |
| 808 | // Record the result of this query: |
| 809 | pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result; |
| 810 | } |
| 811 | } |
| 812 | return result; |
| 813 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 814 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 815 | |
| 816 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 817 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( |
| 818 | VkInstance instance, |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 819 | const VkXlibSurfaceCreateInfoKHR* pCreateInfo, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 820 | const VkAllocationCallbacks* pAllocator, |
| 821 | VkSurfaceKHR* pSurface) |
| 822 | { |
| 823 | VkResult result = VK_SUCCESS; |
| 824 | VkBool32 skipCall = VK_FALSE; |
| 825 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 826 | |
| 827 | // Validate that a valid VkInstance was used: |
| 828 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 829 | if (!pInstance) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 830 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 831 | instance, |
| 832 | "VkInstance"); |
| 833 | } |
Ian Elliott | f575829 | 2015-12-30 17:39:02 -0700 | [diff] [blame] | 834 | if (!pCreateInfo) { |
| 835 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 836 | device, |
| 837 | "pCreateInfo"); |
| 838 | } else { |
| 839 | if (pCreateInfo->sType != VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR) { |
| 840 | skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 841 | device, |
| 842 | "pCreateInfo", |
| 843 | "VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR"); |
| 844 | } |
| 845 | if (pCreateInfo->pNext != NULL) { |
| 846 | skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 847 | device, |
| 848 | "pCreateInfo"); |
| 849 | } |
| 850 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 851 | |
| 852 | if (VK_FALSE == skipCall) { |
| 853 | // Call down the call chain: |
| 854 | result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR( |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 855 | instance, pCreateInfo, pAllocator, pSurface); |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 856 | |
| 857 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 858 | // Record the VkSurfaceKHR returned by the ICD: |
| 859 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 860 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
| 861 | my_data->surfaceMap[*pSurface].platform = VK_ICD_WSI_PLATFORM_XLIB; |
| 862 | // Point to the associated SwpInstance: |
| 863 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 864 | skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__); |
| 865 | } |
| 866 | return result; |
| 867 | } |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 868 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 869 | } |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 870 | |
| 871 | VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( |
| 872 | VkPhysicalDevice physicalDevice, |
| 873 | uint32_t queueFamilyIndex, |
| 874 | Display* dpy, |
| 875 | VisualID visualID) |
| 876 | { |
| 877 | VkBool32 result = VK_FALSE; |
| 878 | VkBool32 skipCall = VK_FALSE; |
| 879 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 880 | |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 881 | // Validate that a valid VkPhysicalDevice was used, and that the platform |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 882 | // extension was enabled: |
| 883 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
| 884 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
| 885 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 886 | physicalDevice, |
| 887 | "VkPhysicalDevice"); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 888 | } else if (!pPhysicalDevice->pInstance->xlibSurfaceExtensionEnabled) { |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 889 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 890 | pPhysicalDevice->pInstance, |
| 891 | "VkInstance", |
| 892 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
| 893 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 894 | __FUNCTION__, VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | if (VK_FALSE == skipCall) { |
| 898 | // Call down the call chain: |
| 899 | result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR( |
| 900 | physicalDevice, queueFamilyIndex, dpy, visualID); |
| 901 | |
| 902 | if (pPhysicalDevice) { |
| 903 | // Record the result of this query: |
| 904 | pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result; |
| 905 | } |
| 906 | } |
| 907 | return result; |
| 908 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 909 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 910 | |
| 911 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator) |
| 912 | { |
| 913 | VkBool32 skipCall = VK_FALSE; |
| 914 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 915 | |
| 916 | // Validate that a valid VkInstance was used: |
| 917 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 918 | if (!pInstance) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 919 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 920 | instance, |
| 921 | "VkInstance"); |
| 922 | } |
| 923 | |
| 924 | if (VK_FALSE == skipCall) { |
| 925 | // Validate that a valid VkSurfaceKHR was used: |
| 926 | skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__); |
| 927 | } |
| 928 | |
| 929 | if (VK_FALSE == skipCall) { |
| 930 | // Call down the call chain: |
| 931 | my_data->instance_dispatch_table->DestroySurfaceKHR( |
| 932 | instance, surface, pAllocator); |
| 933 | } |
| 934 | |
| 935 | // Regardless of skipCall value, do some internal cleanup: |
| 936 | SwpSurface *pSurface = &my_data->surfaceMap[surface]; |
| 937 | if (pSurface && pSurface->pInstance) { |
| 938 | pSurface->pInstance->surfaces.erase(surface); |
| 939 | } |
| 940 | my_data->surfaceMap.erase(surface); |
| 941 | } |
| 942 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 943 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 944 | { |
| 945 | VkResult result = VK_SUCCESS; |
| 946 | VkBool32 skipCall = VK_FALSE; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 947 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 948 | |
| 949 | // Validate that a valid VkInstance was used: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 950 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 951 | if (!pInstance) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 952 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 953 | instance, |
| 954 | "VkInstance"); |
| 955 | } |
| 956 | |
| 957 | if (VK_FALSE == skipCall) { |
| 958 | // Call down the call chain: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 959 | result = my_data->instance_dispatch_table->EnumeratePhysicalDevices( |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 960 | instance, pPhysicalDeviceCount, pPhysicalDevices); |
| 961 | |
| 962 | if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices && |
| 963 | (*pPhysicalDeviceCount > 0)) { |
| 964 | // Record the VkPhysicalDevices returned by the ICD: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 965 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
Courtney Goeltzenleuchter | dad30df | 2015-10-07 09:00:34 -0600 | [diff] [blame] | 966 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 967 | my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice = |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 968 | pPhysicalDevices[i]; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 969 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance; |
| 970 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL; |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 971 | my_data->physicalDeviceMap[pPhysicalDevices[i]].gotSurfaceCapabilities = false; |
| 972 | my_data->physicalDeviceMap[pPhysicalDevices[i]].surfaceFormatCount = 0; |
| 973 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pSurfaceFormats = NULL; |
| 974 | my_data->physicalDeviceMap[pPhysicalDevices[i]].presentModeCount = 0; |
| 975 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pPresentModes = NULL; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 976 | // Point to the associated SwpInstance: |
| 977 | pInstance->physicalDevices[pPhysicalDevices[i]] = |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 978 | &my_data->physicalDeviceMap[pPhysicalDevices[i]]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
| 982 | return result; |
| 983 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 984 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 985 | } |
| 986 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 987 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 988 | { |
| 989 | VkResult result = VK_SUCCESS; |
| 990 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 991 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 992 | |
| 993 | // Validate that a valid VkPhysicalDevice was used: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 994 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 995 | if (!pPhysicalDevice) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 996 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 6c1cb5a | 2015-11-05 15:27:03 -0700 | [diff] [blame] | 997 | physicalDevice, "VkPhysicalDevice"); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 998 | } |
| 999 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1000 | if (VK_TRUE == skipCall) |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1001 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1002 | |
| 1003 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 1004 | // Call down the call chain: |
| 1005 | result = my_device_data->device_dispatch_table->CreateDevice( |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1006 | physicalDevice, pCreateInfo, pAllocator, pDevice); |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1007 | if (result == VK_SUCCESS) { |
| 1008 | // Since it succeeded, do layer-specific work: |
Mark Lobodzinski | 6c1cb5a | 2015-11-05 15:27:03 -0700 | [diff] [blame] | 1009 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 1010 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
| 1011 | createDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1012 | } |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1013 | return result; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1014 | } |
| 1015 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 1016 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1017 | { |
| 1018 | VkBool32 skipCall = VK_FALSE; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1019 | dispatch_key key = get_dispatch_key(device); |
| 1020 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1021 | // Validate that a valid VkDevice was used: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1022 | SwpDevice *pDevice = &my_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1023 | if (!pDevice) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1024 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1025 | device, |
| 1026 | "VkDevice"); |
| 1027 | } |
| 1028 | |
| 1029 | if (VK_FALSE == skipCall) { |
| 1030 | // Call down the call chain: |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1031 | my_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | // Regardless of skipCall value, do some internal cleanup: |
| 1035 | if (pDevice) { |
| 1036 | // Delete the SwpDevice associated with this device: |
| 1037 | if (pDevice->pPhysicalDevice) { |
| 1038 | pDevice->pPhysicalDevice->pDevice = NULL; |
| 1039 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1040 | if (!pDevice->swapchains.empty()) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1041 | LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1042 | SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1043 | "%s() called before all of its associated " |
| 1044 | "VkSwapchainKHRs were destroyed.", |
| 1045 | __FUNCTION__); |
| 1046 | // Empty and then delete all SwpSwapchain's |
| 1047 | for (auto it = pDevice->swapchains.begin() ; |
| 1048 | it != pDevice->swapchains.end() ; it++) { |
| 1049 | // Delete all SwpImage's |
| 1050 | it->second->images.clear(); |
| 1051 | } |
| 1052 | pDevice->swapchains.clear(); |
| 1053 | } |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1054 | my_data->deviceMap.erase(device); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1055 | } |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1056 | delete my_data->device_dispatch_table; |
| 1057 | layer_data_map.erase(key); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1058 | } |
| 1059 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1060 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR( |
| 1061 | VkPhysicalDevice physicalDevice, |
| 1062 | uint32_t queueFamilyIndex, |
| 1063 | VkSurfaceKHR surface, |
| 1064 | VkBool32* pSupported) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1065 | { |
Ian Elliott | 320d0fc | 2015-12-30 12:04:43 -0700 | [diff] [blame] | 1066 | // TODOs: |
| 1067 | // |
| 1068 | // - Ensure that queueFamilyIndex is a valid queue family index for |
| 1069 | // physicalDevice. How? Probably need to record data from another function |
| 1070 | // call(s). |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1071 | VkResult result = VK_SUCCESS; |
| 1072 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1073 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1074 | |
| 1075 | // Validate that a valid VkPhysicalDevice was used, and that the instance |
| 1076 | // extension was enabled: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1077 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1078 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1079 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1080 | physicalDevice, |
| 1081 | "VkPhysicalDevice"); |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 1082 | } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1083 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1084 | pPhysicalDevice->pInstance, |
| 1085 | "VkInstance", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1086 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 1087 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1088 | __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1089 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 1090 | skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__); |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1091 | if (!pSupported) { |
| 1092 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 1093 | physicalDevice, |
| 1094 | "pSupported"); |
| 1095 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1096 | |
| 1097 | if (VK_FALSE == skipCall) { |
| 1098 | // Call down the call chain: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1099 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR( |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1100 | physicalDevice, queueFamilyIndex, surface, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1101 | pSupported); |
| 1102 | |
| 1103 | if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) { |
| 1104 | // Record the result of this query: |
| 1105 | pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = |
| 1106 | *pSupported; |
| 1107 | // TODO: We need to compare this with the actual queue used for |
| 1108 | // presentation, to ensure it was advertised to the application as |
| 1109 | // supported for presentation. |
| 1110 | } |
| 1111 | |
| 1112 | return result; |
| 1113 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1114 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1115 | } |
| 1116 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1117 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR( |
| 1118 | VkPhysicalDevice physicalDevice, |
| 1119 | VkSurfaceKHR surface, |
| 1120 | VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1121 | { |
| 1122 | VkResult result = VK_SUCCESS; |
| 1123 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1124 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1125 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1126 | // Validate that a valid VkPhysicalDevice was used, and that the instance |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1127 | // extension was enabled: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1128 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
| 1129 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1130 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1131 | physicalDevice, |
| 1132 | "VkPhysicalDevice"); |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 1133 | } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1134 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1135 | pPhysicalDevice->pInstance, |
| 1136 | "VkInstance", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1137 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1138 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
| 1139 | __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1140 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 1141 | skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__); |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1142 | if (!pSurfaceCapabilities) { |
| 1143 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 1144 | physicalDevice, |
| 1145 | "pSurfaceCapabilities"); |
| 1146 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1147 | |
| 1148 | if (VK_FALSE == skipCall) { |
| 1149 | // Call down the call chain: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1150 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceCapabilitiesKHR( |
| 1151 | physicalDevice, surface, pSurfaceCapabilities); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1152 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1153 | if ((result == VK_SUCCESS) && pPhysicalDevice) { |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1154 | // Record the result of this query: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1155 | pPhysicalDevice->gotSurfaceCapabilities = true; |
| 1156 | // FIXME: NEED TO COPY THIS DATA, BECAUSE pSurfaceCapabilities POINTS TO APP-ALLOCATED DATA |
| 1157 | pPhysicalDevice->surfaceCapabilities = *pSurfaceCapabilities; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | return result; |
| 1161 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1162 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1163 | } |
| 1164 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1165 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR( |
| 1166 | VkPhysicalDevice physicalDevice, |
| 1167 | VkSurfaceKHR surface, |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1168 | uint32_t* pSurfaceFormatCount, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1169 | VkSurfaceFormatKHR* pSurfaceFormats) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1170 | { |
| 1171 | VkResult result = VK_SUCCESS; |
| 1172 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1173 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1174 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1175 | // Validate that a valid VkPhysicalDevice was used, and that the instance |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1176 | // extension was enabled: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1177 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
| 1178 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1179 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1180 | physicalDevice, |
| 1181 | "VkPhysicalDevice"); |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 1182 | } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1183 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1184 | pPhysicalDevice->pInstance, |
| 1185 | "VkInstance", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1186 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1187 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
| 1188 | __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1189 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 1190 | skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__); |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1191 | if (!pSurfaceFormatCount) { |
| 1192 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 1193 | physicalDevice, |
| 1194 | "pSurfaceFormatCount"); |
| 1195 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1196 | |
| 1197 | if (VK_FALSE == skipCall) { |
| 1198 | // Call down the call chain: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1199 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceFormatsKHR( |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1200 | physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1201 | |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1202 | if ((result == VK_SUCCESS) && pPhysicalDevice && !pSurfaceFormats && |
| 1203 | pSurfaceFormatCount) { |
| 1204 | // Record the result of this preliminary query: |
| 1205 | pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount; |
| 1206 | } |
Ian Elliott | 9059b30 | 2015-12-30 13:14:36 -0700 | [diff] [blame] | 1207 | else if ((result == VK_SUCCESS) && pPhysicalDevice && pSurfaceFormats && |
| 1208 | pSurfaceFormatCount) { |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1209 | // Compare the preliminary value of *pSurfaceFormatCount with the |
| 1210 | // value this time: |
| 1211 | if (*pSurfaceFormatCount != pPhysicalDevice->surfaceFormatCount) { |
| 1212 | LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 1213 | physicalDevice, |
| 1214 | "pSurfaceFormatCount", |
| 1215 | "pSurfaceFormats", |
| 1216 | pPhysicalDevice->surfaceFormatCount); |
| 1217 | } |
Ian Elliott | 9059b30 | 2015-12-30 13:14:36 -0700 | [diff] [blame] | 1218 | else if (*pSurfaceFormatCount > 0) { |
| 1219 | // Record the result of this query: |
| 1220 | pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount; |
| 1221 | pPhysicalDevice->pSurfaceFormats = (VkSurfaceFormatKHR *) |
| 1222 | malloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR)); |
| 1223 | if (pPhysicalDevice->pSurfaceFormats) { |
| 1224 | for (uint32_t i = 0 ; i < *pSurfaceFormatCount ; i++) { |
| 1225 | pPhysicalDevice->pSurfaceFormats[i] = pSurfaceFormats[i]; |
| 1226 | } |
| 1227 | } else { |
| 1228 | pPhysicalDevice->surfaceFormatCount = 0; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1229 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | return result; |
| 1234 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1235 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1236 | } |
| 1237 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1238 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1239 | VkPhysicalDevice physicalDevice, |
| 1240 | VkSurfaceKHR surface, |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1241 | uint32_t* pPresentModeCount, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1242 | VkPresentModeKHR* pPresentModes) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1243 | { |
| 1244 | VkResult result = VK_SUCCESS; |
| 1245 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1246 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1247 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1248 | // Validate that a valid VkPhysicalDevice was used, and that the instance |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1249 | // extension was enabled: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1250 | SwpPhysicalDevice *pPhysicalDevice = &my_data->physicalDeviceMap[physicalDevice]; |
| 1251 | if (!pPhysicalDevice || !pPhysicalDevice->pInstance) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1252 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1253 | physicalDevice, |
| 1254 | "VkPhysicalDevice"); |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 1255 | } else if (!pPhysicalDevice->pInstance->surfaceExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1256 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1257 | pPhysicalDevice->pInstance, |
| 1258 | "VkInstance", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1259 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1260 | "%s() called even though the %s extension was not enabled for this VkInstance.", |
| 1261 | __FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1262 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 1263 | skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__); |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1264 | if (!pPresentModeCount) { |
| 1265 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 1266 | physicalDevice, |
| 1267 | "pPresentModeCount"); |
| 1268 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1269 | |
| 1270 | if (VK_FALSE == skipCall) { |
| 1271 | // Call down the call chain: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1272 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfacePresentModesKHR( |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1273 | physicalDevice, surface, pPresentModeCount, pPresentModes); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1274 | |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1275 | if ((result == VK_SUCCESS) && pPhysicalDevice && !pPresentModes && |
| 1276 | pPresentModeCount) { |
| 1277 | // Record the result of this preliminary query: |
| 1278 | pPhysicalDevice->presentModeCount = *pPresentModeCount; |
| 1279 | } |
Ian Elliott | 9059b30 | 2015-12-30 13:14:36 -0700 | [diff] [blame] | 1280 | else if ((result == VK_SUCCESS) && pPhysicalDevice && pPresentModes && |
| 1281 | pPresentModeCount) { |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1282 | // Compare the preliminary value of *pPresentModeCount with the |
| 1283 | // value this time: |
| 1284 | if (*pPresentModeCount != pPhysicalDevice->presentModeCount) { |
| 1285 | LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 1286 | physicalDevice, |
| 1287 | "pPresentModeCount", |
| 1288 | "pPresentModes", |
| 1289 | pPhysicalDevice->presentModeCount); |
| 1290 | } |
Ian Elliott | 9059b30 | 2015-12-30 13:14:36 -0700 | [diff] [blame] | 1291 | else if (*pPresentModeCount > 0) { |
| 1292 | // Record the result of this query: |
| 1293 | pPhysicalDevice->presentModeCount = *pPresentModeCount; |
| 1294 | pPhysicalDevice->pPresentModes = (VkPresentModeKHR *) |
| 1295 | malloc(*pPresentModeCount * sizeof(VkPresentModeKHR)); |
| 1296 | if (pPhysicalDevice->pSurfaceFormats) { |
| 1297 | for (uint32_t i = 0 ; i < *pPresentModeCount ; i++) { |
| 1298 | pPhysicalDevice->pPresentModes[i] = pPresentModes[i]; |
| 1299 | } |
| 1300 | } else { |
| 1301 | pPhysicalDevice->presentModeCount = 0; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1302 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | return result; |
| 1307 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1308 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | // This function does the up-front validation work for vkCreateSwapchainKHR(), |
| 1312 | // and returns VK_TRUE if a logging callback indicates that the call down the |
| 1313 | // chain should be skipped: |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1314 | static VkBool32 validateCreateSwapchainKHR( |
| 1315 | VkDevice device, |
| 1316 | const VkSwapchainCreateInfoKHR* pCreateInfo, |
| 1317 | VkSwapchainKHR* pSwapchain) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1318 | { |
| 1319 | // TODO: Validate cases of re-creating a swapchain (the current code |
| 1320 | // assumes a new swapchain is being created). |
| 1321 | VkResult result = VK_SUCCESS; |
| 1322 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1323 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1324 | char fn[] = "vkCreateSwapchainKHR"; |
| 1325 | |
| 1326 | // Validate that a valid VkDevice was used, and that the device |
| 1327 | // extension was enabled: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1328 | SwpDevice *pDevice = &my_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1329 | if (!pDevice) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1330 | return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1331 | SWAPCHAIN_INVALID_HANDLE, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1332 | "%s() called with a non-valid %s.", |
| 1333 | fn, "VkDevice"); |
| 1334 | |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 1335 | } else if (!pDevice->swapchainExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1336 | return LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1337 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 1338 | "%s() called even though the %s extension was not enabled for this VkDevice.", |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1339 | fn, VK_KHR_SWAPCHAIN_EXTENSION_NAME ); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1340 | } |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1341 | if (!pCreateInfo) { |
| 1342 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1343 | device, |
| 1344 | "pCreateInfo"); |
Ian Elliott | f575829 | 2015-12-30 17:39:02 -0700 | [diff] [blame] | 1345 | } else { |
| 1346 | if (pCreateInfo->sType != VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR) { |
| 1347 | skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1348 | device, |
| 1349 | "pCreateInfo", |
| 1350 | "VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR"); |
| 1351 | } |
| 1352 | if (pCreateInfo->pNext != NULL) { |
| 1353 | skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1354 | device, |
| 1355 | "pCreateInfo"); |
| 1356 | } |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1357 | } |
| 1358 | if (!pSwapchain) { |
| 1359 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1360 | device, |
| 1361 | "pSwapchain"); |
| 1362 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1363 | |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1364 | // Keep around a useful pointer to pPhysicalDevice: |
| 1365 | SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice; |
| 1366 | |
| 1367 | // Validate pCreateInfo->surface: |
| 1368 | if (pPhysicalDevice) { |
| 1369 | // Note: in order to validate, we must lookup layer_data based on the |
| 1370 | // VkInstance associated with this VkDevice: |
| 1371 | SwpInstance *pInstance = |
| 1372 | (pPhysicalDevice) ? pPhysicalDevice->pInstance : NULL; |
| 1373 | layer_data *my_instance_data = |
| 1374 | (pInstance) ? get_my_data_ptr(get_dispatch_key(pInstance->instance), layer_data_map) : NULL; |
| 1375 | skipCall |= validateSurface(my_instance_data, |
| 1376 | pCreateInfo->surface, |
| 1377 | (char *) "vkCreateSwapchainKHR"); |
| 1378 | } |
| 1379 | |
| 1380 | // Validate pCreateInfo values with the results of |
| 1381 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 1382 | if (!pPhysicalDevice || !pPhysicalDevice->gotSurfaceCapabilities) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1383 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1384 | SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1385 | "%s() called before calling " |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1386 | "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().", |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1387 | fn); |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1388 | } else if (pCreateInfo) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1389 | // Validate pCreateInfo->minImageCount against |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1390 | // VkSurfaceCapabilitiesKHR::{min|max}ImageCount: |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1391 | VkSurfaceCapabilitiesKHR *pCapabilities = &pPhysicalDevice->surfaceCapabilities; |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1392 | if ((pCreateInfo->minImageCount < pCapabilities->minImageCount) || |
| 1393 | ((pCapabilities->maxImageCount > 0) && |
| 1394 | (pCreateInfo->minImageCount > pCapabilities->maxImageCount))) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1395 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1396 | SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1397 | "%s() called with pCreateInfo->minImageCount " |
| 1398 | "= %d, which is outside the bounds returned " |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1399 | "by vkGetPhysicalDeviceSurfaceCapabilitiesKHR() (i.e. " |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1400 | "minImageCount = %d, maxImageCount = %d).", |
| 1401 | fn, |
| 1402 | pCreateInfo->minImageCount, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1403 | pCapabilities->minImageCount, |
| 1404 | pCapabilities->maxImageCount); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1405 | } |
| 1406 | // Validate pCreateInfo->imageExtent against |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1407 | // VkSurfaceCapabilitiesKHR::{current|min|max}ImageExtent: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1408 | if ((pCapabilities->currentExtent.width == -1) && |
| 1409 | ((pCreateInfo->imageExtent.width < pCapabilities->minImageExtent.width) || |
| 1410 | (pCreateInfo->imageExtent.width > pCapabilities->maxImageExtent.width) || |
| 1411 | (pCreateInfo->imageExtent.height < pCapabilities->minImageExtent.height) || |
| 1412 | (pCreateInfo->imageExtent.height > pCapabilities->maxImageExtent.height))) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1413 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1414 | SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1415 | "%s() called with pCreateInfo->imageExtent = " |
| 1416 | "(%d,%d), which is outside the bounds " |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1417 | "returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): " |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1418 | "currentExtent = (%d,%d), minImageExtent = " |
| 1419 | "(%d,%d), maxImageExtent = (%d,%d).", |
| 1420 | fn, |
| 1421 | pCreateInfo->imageExtent.width, |
| 1422 | pCreateInfo->imageExtent.height, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1423 | pCapabilities->currentExtent.width, |
| 1424 | pCapabilities->currentExtent.height, |
| 1425 | pCapabilities->minImageExtent.width, |
| 1426 | pCapabilities->minImageExtent.height, |
| 1427 | pCapabilities->maxImageExtent.width, |
| 1428 | pCapabilities->maxImageExtent.height); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1429 | } |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1430 | if ((pCapabilities->currentExtent.width != -1) && |
| 1431 | ((pCreateInfo->imageExtent.width != pCapabilities->currentExtent.width) || |
| 1432 | (pCreateInfo->imageExtent.height != pCapabilities->currentExtent.height))) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1433 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1434 | SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1435 | "%s() called with pCreateInfo->imageExtent = " |
| 1436 | "(%d,%d), which is not equal to the " |
| 1437 | "currentExtent = (%d,%d) returned by " |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1438 | "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().", |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1439 | fn, |
| 1440 | pCreateInfo->imageExtent.width, |
| 1441 | pCreateInfo->imageExtent.height, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1442 | pCapabilities->currentExtent.width, |
| 1443 | pCapabilities->currentExtent.height); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1444 | } |
| 1445 | // Validate pCreateInfo->preTransform against |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1446 | // VkSurfaceCapabilitiesKHR::supportedTransforms: |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 1447 | if (!((pCreateInfo->preTransform) & pCapabilities->supportedTransforms)) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1448 | // This is an error situation; one for which we'd like to give |
| 1449 | // the developer a helpful, multi-line error message. Build it |
| 1450 | // up a little at a time, and then log it: |
| 1451 | std::string errorString = ""; |
| 1452 | char str[1024]; |
| 1453 | // Here's the first part of the message: |
| 1454 | sprintf(str, "%s() called with a non-supported " |
| 1455 | "pCreateInfo->preTransform (i.e. %s). " |
| 1456 | "Supported values are:\n", |
| 1457 | fn, |
| 1458 | surfaceTransformStr(pCreateInfo->preTransform)); |
| 1459 | errorString += str; |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 1460 | for (int i = 0; i < 32; i++) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1461 | // Build up the rest of the message: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1462 | if ((1 << i) & pCapabilities->supportedTransforms) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1463 | const char *newStr = |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1464 | surfaceTransformStr((VkSurfaceTransformFlagBitsKHR) (1 << i)); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1465 | sprintf(str, " %s\n", newStr); |
| 1466 | errorString += str; |
| 1467 | } |
| 1468 | } |
| 1469 | // Log the message that we've built up: |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1470 | skipCall |= debug_report_log_msg(my_data->report_data, |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1471 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1472 | VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | 80e774f | 2016-01-04 15:54:59 -0700 | [diff] [blame] | 1473 | (uint64_t) device, __LINE__, |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1474 | SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM, |
| 1475 | LAYER_NAME, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1476 | errorString.c_str()); |
| 1477 | } |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1478 | // Validate pCreateInfo->compositeAlpha against |
| 1479 | // VkSurfaceCapabilitiesKHR::supportedCompositeAlpha: |
| 1480 | if (!((pCreateInfo->compositeAlpha) & pCapabilities->supportedCompositeAlpha)) { |
| 1481 | // This is an error situation; one for which we'd like to give |
| 1482 | // the developer a helpful, multi-line error message. Build it |
| 1483 | // up a little at a time, and then log it: |
| 1484 | std::string errorString = ""; |
| 1485 | char str[1024]; |
| 1486 | // Here's the first part of the message: |
| 1487 | sprintf(str, "%s() called with a non-supported " |
| 1488 | "pCreateInfo->compositeAlpha (i.e. %s). " |
| 1489 | "Supported values are:\n", |
| 1490 | fn, |
| 1491 | surfaceCompositeAlphaStr(pCreateInfo->compositeAlpha)); |
| 1492 | errorString += str; |
| 1493 | for (int i = 0; i < 32; i++) { |
| 1494 | // Build up the rest of the message: |
| 1495 | if ((1 << i) & pCapabilities->supportedCompositeAlpha) { |
| 1496 | const char *newStr = |
| 1497 | surfaceCompositeAlphaStr((VkCompositeAlphaFlagBitsKHR) (1 << i)); |
| 1498 | sprintf(str, " %s\n", newStr); |
| 1499 | errorString += str; |
| 1500 | } |
| 1501 | } |
| 1502 | // Log the message that we've built up: |
| 1503 | skipCall |= debug_report_log_msg(my_data->report_data, |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 1504 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1505 | VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1506 | (uint64_t) device, 0, |
| 1507 | SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA, |
| 1508 | LAYER_NAME, |
| 1509 | errorString.c_str()); |
| 1510 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1511 | // Validate pCreateInfo->imageArraySize against |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1512 | // VkSurfaceCapabilitiesKHR::maxImageArraySize: |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1513 | if ((pCreateInfo->imageArrayLayers > 0) && |
| 1514 | (pCreateInfo->imageArrayLayers > pCapabilities->maxImageArrayLayers)) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1515 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1516 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_SIZE, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1517 | "%s() called with a non-supported " |
| 1518 | "pCreateInfo->imageArraySize (i.e. %d). " |
| 1519 | "Maximum value is %d.", |
| 1520 | fn, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1521 | pCreateInfo->imageArrayLayers, |
| 1522 | pCapabilities->maxImageArrayLayers); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1523 | } |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1524 | // Validate pCreateInfo->imageUsage against |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1525 | // VkSurfaceCapabilitiesKHR::supportedUsageFlags: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1526 | if (pCreateInfo->imageUsage && |
| 1527 | (pCreateInfo->imageUsage != |
| 1528 | (pCreateInfo->imageUsage & pCapabilities->supportedUsageFlags))) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1529 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1530 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1531 | "%s() called with a non-supported " |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1532 | "pCreateInfo->imageUsage (i.e. 0x%08x)." |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1533 | " Supported flag bits are 0x%08x.", |
| 1534 | fn, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1535 | pCreateInfo->imageUsage, |
| 1536 | pCapabilities->supportedUsageFlags); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1537 | } |
| 1538 | } |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1539 | |
| 1540 | // Validate pCreateInfo values with the results of |
| 1541 | // vkGetPhysicalDeviceSurfaceFormatsKHR(): |
| 1542 | if (!pPhysicalDevice || !pPhysicalDevice->surfaceFormatCount) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1543 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1544 | SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1545 | "%s() called before calling " |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1546 | "vkGetPhysicalDeviceSurfaceFormatsKHR().", |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1547 | fn); |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1548 | } else if (pCreateInfo) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1549 | // Validate pCreateInfo->imageFormat against |
| 1550 | // VkSurfaceFormatKHR::format: |
| 1551 | bool foundFormat = false; |
| 1552 | bool foundColorSpace = false; |
| 1553 | bool foundMatch = false; |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1554 | for (uint32_t i = 0 ; i < pPhysicalDevice->surfaceFormatCount ; i++) { |
| 1555 | if (pCreateInfo->imageFormat == pPhysicalDevice->pSurfaceFormats[i].format) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1556 | // Validate pCreateInfo->imageColorSpace against |
| 1557 | // VkSurfaceFormatKHR::colorSpace: |
| 1558 | foundFormat = true; |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1559 | if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1560 | foundMatch = true; |
| 1561 | break; |
| 1562 | } |
| 1563 | } else { |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1564 | if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1565 | foundColorSpace = true; |
| 1566 | } |
| 1567 | } |
| 1568 | } |
| 1569 | if (!foundMatch) { |
| 1570 | if (!foundFormat) { |
| 1571 | if (!foundColorSpace) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1572 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1573 | "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1574 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1575 | "%s() called with neither a " |
| 1576 | "supported pCreateInfo->imageFormat " |
| 1577 | "(i.e. %d) nor a supported " |
| 1578 | "pCreateInfo->imageColorSpace " |
| 1579 | "(i.e. %d).", |
| 1580 | fn, |
| 1581 | pCreateInfo->imageFormat, |
| 1582 | pCreateInfo->imageColorSpace); |
| 1583 | } else { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1584 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1585 | "VkDevice", |
| 1586 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1587 | "%s() called with a non-supported " |
| 1588 | "pCreateInfo->imageFormat (i.e. %d).", |
| 1589 | fn, pCreateInfo->imageFormat); |
| 1590 | } |
| 1591 | } else if (!foundColorSpace) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1592 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1593 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1594 | "%s() called with a non-supported " |
| 1595 | "pCreateInfo->imageColorSpace (i.e. %d).", |
| 1596 | fn, pCreateInfo->imageColorSpace); |
| 1597 | } |
| 1598 | } |
| 1599 | } |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1600 | |
| 1601 | // Validate pCreateInfo values with the results of |
| 1602 | // vkGetPhysicalDeviceSurfacePresentModesKHR(): |
| 1603 | if (!pPhysicalDevice || !pPhysicalDevice->presentModeCount) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1604 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1605 | SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1606 | "%s() called before calling " |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1607 | "vkGetPhysicalDeviceSurfacePresentModesKHR().", |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1608 | fn); |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1609 | } else if (pCreateInfo) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1610 | // Validate pCreateInfo->presentMode against |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1611 | // vkGetPhysicalDeviceSurfacePresentModesKHR(): |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1612 | bool foundMatch = false; |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1613 | for (uint32_t i = 0 ; i < pPhysicalDevice->presentModeCount ; i++) { |
| 1614 | if (pPhysicalDevice->pPresentModes[i] == pCreateInfo->presentMode) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1615 | foundMatch = true; |
| 1616 | break; |
| 1617 | } |
| 1618 | } |
| 1619 | if (!foundMatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1620 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1621 | SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1622 | "%s() called with a non-supported " |
| 1623 | "pCreateInfo->presentMode (i.e. %s).", |
| 1624 | fn, |
| 1625 | presentModeStr(pCreateInfo->presentMode)); |
| 1626 | } |
| 1627 | } |
| 1628 | |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1629 | // Validate pCreateInfo->imageSharingMode and related values: |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1630 | if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) { |
| 1631 | if ((pCreateInfo->queueFamilyIndexCount <= 1) || |
| 1632 | !pCreateInfo->pQueueFamilyIndices) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 1633 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1634 | SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES, |
| 1635 | "%s() called with a supported " |
| 1636 | "pCreateInfo->sharingMode of (i.e. %s)," |
| 1637 | "but with a bad value(s) for " |
| 1638 | "pCreateInfo->queueFamilyIndexCount or " |
| 1639 | "pCreateInfo->pQueueFamilyIndices).", |
| 1640 | fn, |
| 1641 | sharingModeStr(pCreateInfo->imageSharingMode)); |
| 1642 | } |
| 1643 | } else if (pCreateInfo->imageSharingMode != VK_SHARING_MODE_EXCLUSIVE) { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 1644 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1645 | SWAPCHAIN_CREATE_SWAP_BAD_SHARING_MODE, |
| 1646 | "%s() called with a non-supported " |
| 1647 | "pCreateInfo->imageSharingMode (i.e. %s).", |
| 1648 | fn, |
| 1649 | sharingModeStr(pCreateInfo->imageSharingMode)); |
| 1650 | } |
| 1651 | |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1652 | // Validate pCreateInfo->clipped: |
| 1653 | if (pCreateInfo && |
| 1654 | (pCreateInfo->clipped != VK_FALSE) && |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1655 | (pCreateInfo->clipped != VK_TRUE)) { |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1656 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1657 | device, "VkDevice", |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1658 | SWAPCHAIN_BAD_BOOL, |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1659 | "%s() called with a VkBool32 value that is " |
| 1660 | "neither VK_TRUE nor VK_FALSE, but has the " |
| 1661 | "numeric value of %d.", |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1662 | fn, |
| 1663 | pCreateInfo->clipped); |
| 1664 | } |
| 1665 | |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1666 | // Validate pCreateInfo->oldSwapchain: |
| 1667 | if (pCreateInfo && pCreateInfo->oldSwapchain) { |
| 1668 | SwpSwapchain *pOldSwapchain = &my_data->swapchainMap[pCreateInfo->oldSwapchain]; |
| 1669 | if (pOldSwapchain) { |
| 1670 | if (device != pOldSwapchain->pDevice->device) { |
| 1671 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1672 | device, "VkDevice", |
| 1673 | SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE, |
| 1674 | "%s() called with a different VkDevice " |
| 1675 | "than the VkSwapchainKHR was created with.", |
| 1676 | __FUNCTION__); |
| 1677 | } |
| 1678 | if (pCreateInfo->surface != pOldSwapchain->surface) { |
| 1679 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1680 | device, "VkDevice", |
| 1681 | SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE, |
| 1682 | "%s() called with pCreateInfo->oldSwapchain " |
| 1683 | "that has a different VkSurfaceKHR than " |
| 1684 | "pCreateInfo->surface.", |
| 1685 | fn); |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1686 | } |
| 1687 | } else { |
Ian Elliott | 1bf155f | 2015-12-29 17:35:46 -0700 | [diff] [blame] | 1688 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1689 | pCreateInfo->oldSwapchain, |
| 1690 | "VkSwapchainKHR"); |
| 1691 | } |
| 1692 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1693 | |
| 1694 | return skipCall; |
| 1695 | } |
| 1696 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1697 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR( |
| 1698 | VkDevice device, |
| 1699 | const VkSwapchainCreateInfoKHR* pCreateInfo, |
| 1700 | const VkAllocationCallbacks* pAllocator, |
| 1701 | VkSwapchainKHR* pSwapchain) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1702 | { |
| 1703 | VkResult result = VK_SUCCESS; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1704 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1705 | VkBool32 skipCall = validateCreateSwapchainKHR(device, pCreateInfo, |
| 1706 | pSwapchain); |
| 1707 | |
| 1708 | if (VK_FALSE == skipCall) { |
| 1709 | // Call down the call chain: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1710 | result = my_data->device_dispatch_table->CreateSwapchainKHR( |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1711 | device, pCreateInfo, pAllocator, pSwapchain); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1712 | |
| 1713 | if (result == VK_SUCCESS) { |
| 1714 | // Remember the swapchain's handle, and link it to the device: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1715 | SwpDevice *pDevice = &my_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1716 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1717 | my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain; |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1718 | pDevice->swapchains[*pSwapchain] = |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1719 | &my_data->swapchainMap[*pSwapchain]; |
| 1720 | my_data->swapchainMap[*pSwapchain].pDevice = pDevice; |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1721 | my_data->swapchainMap[*pSwapchain].surface = |
| 1722 | (pCreateInfo) ? pCreateInfo->surface : 0; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1723 | my_data->swapchainMap[*pSwapchain].imageCount = 0; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | return result; |
| 1727 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1728 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1729 | } |
| 1730 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1731 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR( |
| 1732 | VkDevice device, |
| 1733 | VkSwapchainKHR swapchain, |
| 1734 | const VkAllocationCallbacks* pAllocator) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1735 | { |
| 1736 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1737 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1738 | |
| 1739 | // Validate that a valid VkDevice was used, and that the device |
| 1740 | // extension was enabled: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1741 | SwpDevice *pDevice = &my_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1742 | if (!pDevice) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1743 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1744 | device, |
| 1745 | "VkDevice"); |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 1746 | } else if (!pDevice->swapchainExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1747 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1748 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 1749 | "%s() called even though the %s extension was not enabled for this VkDevice.", |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1750 | __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | // Regardless of skipCall value, do some internal cleanup: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1754 | SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1755 | if (pSwapchain) { |
| 1756 | // Delete the SwpSwapchain associated with this swapchain: |
| 1757 | if (pSwapchain->pDevice) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1758 | pSwapchain->pDevice->swapchains.erase(swapchain); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1759 | if (device != pSwapchain->pDevice->device) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1760 | LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1761 | SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1762 | "%s() called with a different VkDevice than the " |
| 1763 | "VkSwapchainKHR was created with.", |
| 1764 | __FUNCTION__); |
| 1765 | } |
| 1766 | } |
| 1767 | if (pSwapchain->imageCount) { |
| 1768 | pSwapchain->images.clear(); |
| 1769 | } |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1770 | my_data->swapchainMap.erase(swapchain); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1771 | } else { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1772 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1773 | swapchain, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1774 | "VkSwapchainKHR"); |
| 1775 | } |
| 1776 | |
| 1777 | if (VK_FALSE == skipCall) { |
| 1778 | // Call down the call chain: |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1779 | my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1780 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1781 | } |
| 1782 | |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1783 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR( |
| 1784 | VkDevice device, |
| 1785 | VkSwapchainKHR swapchain, |
| 1786 | uint32_t* pSwapchainImageCount, |
| 1787 | VkImage* pSwapchainImages) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1788 | { |
| 1789 | VkResult result = VK_SUCCESS; |
| 1790 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1791 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1792 | |
| 1793 | // Validate that a valid VkDevice was used, and that the device |
| 1794 | // extension was enabled: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1795 | SwpDevice *pDevice = &my_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1796 | if (!pDevice) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1797 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1798 | device, |
| 1799 | "VkDevice"); |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 1800 | } else if (!pDevice->swapchainExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1801 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1802 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 1803 | "%s() called even though the %s extension was not enabled for this VkDevice.", |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1804 | __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1805 | } |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1806 | SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1807 | if (!pSwapchain) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1808 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1809 | swapchain.handle, |
| 1810 | "VkSwapchainKHR"); |
| 1811 | } |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1812 | if (!pSwapchainImageCount) { |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1813 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1814 | device, |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1815 | "pSwapchainImageCount"); |
| 1816 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1817 | |
| 1818 | if (VK_FALSE == skipCall) { |
| 1819 | // Call down the call chain: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1820 | result = my_data->device_dispatch_table->GetSwapchainImagesKHR( |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1821 | device, swapchain, pSwapchainImageCount, pSwapchainImages); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1822 | |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1823 | if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages && |
| 1824 | pSwapchainImageCount) { |
| 1825 | // Record the result of this preliminary query: |
| 1826 | pSwapchain->imageCount = *pSwapchainImageCount; |
| 1827 | } |
Ian Elliott | 9059b30 | 2015-12-30 13:14:36 -0700 | [diff] [blame] | 1828 | else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages && |
| 1829 | pSwapchainImageCount) { |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 1830 | // Compare the preliminary value of *pSwapchainImageCount with the |
| 1831 | // value this time: |
| 1832 | if (*pSwapchainImageCount != pSwapchain->imageCount) { |
| 1833 | LOG_ERROR_INVALID_COUNT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1834 | device, |
| 1835 | "pSwapchainImageCount", |
| 1836 | "pSwapchainImages", |
| 1837 | pSwapchain->imageCount); |
| 1838 | } |
Ian Elliott | 9059b30 | 2015-12-30 13:14:36 -0700 | [diff] [blame] | 1839 | else if (*pSwapchainImageCount > 0) { |
| 1840 | // Record the images and their state: |
| 1841 | pSwapchain->imageCount = *pSwapchainImageCount; |
| 1842 | for (uint32_t i = 0 ; i < *pSwapchainImageCount ; i++) { |
| 1843 | pSwapchain->images[i].image = pSwapchainImages[i]; |
| 1844 | pSwapchain->images[i].pSwapchain = pSwapchain; |
| 1845 | pSwapchain->images[i].ownedByApp = false; |
| 1846 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | return result; |
| 1851 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1852 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1853 | } |
| 1854 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1855 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR( |
| 1856 | VkDevice device, |
| 1857 | VkSwapchainKHR swapchain, |
| 1858 | uint64_t timeout, |
| 1859 | VkSemaphore semaphore, |
| 1860 | VkFence fence, |
| 1861 | uint32_t* pImageIndex) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1862 | { |
Ian Elliott | dd45e46 | 2015-12-29 17:52:10 -0700 | [diff] [blame] | 1863 | // TODOs: |
| 1864 | // |
| 1865 | // - Address the timeout. Possibilities include looking at the state of the |
| 1866 | // swapchain's images, depending on the timeout value. |
| 1867 | // - Validate that semaphore and fence are either VK_NULL_HANDLE or valid |
| 1868 | // handles. |
| 1869 | // - Record/update the state of the swapchain, in case an error occurs |
| 1870 | // (e.g. VK_ERROR_OUT_OF_DATE_KHR). |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1871 | VkResult result = VK_SUCCESS; |
| 1872 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1873 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1874 | |
| 1875 | // Validate that a valid VkDevice was used, and that the device |
| 1876 | // extension was enabled: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1877 | SwpDevice *pDevice = &my_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1878 | if (!pDevice) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1879 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1880 | device, |
| 1881 | "VkDevice"); |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 1882 | } else if (!pDevice->swapchainExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1883 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1884 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 1885 | "%s() called even though the %s extension was not enabled for this VkDevice.", |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 1886 | __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1887 | } |
| 1888 | // Validate that a valid VkSwapchainKHR was used: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1889 | SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1890 | if (!pSwapchain) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1891 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1892 | swapchain, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1893 | "VkSwapchainKHR"); |
| 1894 | } else { |
| 1895 | // Look to see if the application is trying to own too many images at |
| 1896 | // the same time (i.e. not leave any to display): |
Courtney Goeltzenleuchter | dad30df | 2015-10-07 09:00:34 -0600 | [diff] [blame] | 1897 | uint32_t imagesOwnedByApp = 0; |
| 1898 | for (uint32_t i = 0 ; i < pSwapchain->imageCount ; i++) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1899 | if (pSwapchain->images[i].ownedByApp) { |
| 1900 | imagesOwnedByApp++; |
| 1901 | } |
| 1902 | } |
| 1903 | if (imagesOwnedByApp >= (pSwapchain->imageCount - 1)) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1904 | skipCall |= LOG_PERF_WARNING(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Ian Elliott | 4a99445 | 2015-09-24 18:33:16 -0600 | [diff] [blame] | 1905 | swapchain, |
| 1906 | "VkSwapchainKHR", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 1907 | SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES, |
Ian Elliott | 4a99445 | 2015-09-24 18:33:16 -0600 | [diff] [blame] | 1908 | "%s() called when the application " |
| 1909 | "already owns all presentable images " |
| 1910 | "in this swapchain except for the " |
| 1911 | "image currently being displayed. " |
| 1912 | "This call to %s() cannot succeed " |
| 1913 | "unless another thread calls the " |
| 1914 | "vkQueuePresentKHR() function in " |
| 1915 | "order to release ownership of one of " |
| 1916 | "the presentable images of this " |
| 1917 | "swapchain.", |
| 1918 | __FUNCTION__, __FUNCTION__); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1919 | } |
| 1920 | } |
Ian Elliott | dd45e46 | 2015-12-29 17:52:10 -0700 | [diff] [blame] | 1921 | if (!pImageIndex) { |
| 1922 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1923 | device, |
| 1924 | "pImageIndex"); |
| 1925 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1926 | |
| 1927 | if (VK_FALSE == skipCall) { |
| 1928 | // Call down the call chain: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 1929 | result = my_data->device_dispatch_table->AcquireNextImageKHR( |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1930 | device, swapchain, timeout, semaphore, fence, pImageIndex); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1931 | |
| 1932 | if (((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)) && |
| 1933 | pSwapchain) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1934 | // Change the state of the image (now owned by the application): |
| 1935 | pSwapchain->images[*pImageIndex].ownedByApp = true; |
| 1936 | } |
| 1937 | |
| 1938 | return result; |
| 1939 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1940 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1941 | } |
| 1942 | |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 1943 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR( |
| 1944 | VkQueue queue, |
| 1945 | const VkPresentInfoKHR* pPresentInfo) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1946 | { |
| 1947 | // TODOs: |
| 1948 | // |
| 1949 | // - Ensure that the queue is active, and is one of the queueFamilyIndex's |
| 1950 | // that was returned by a previuos query. |
| 1951 | // - Record/update the state of the swapchain, in case an error occurs |
| 1952 | // (e.g. VK_ERROR_OUT_OF_DATE_KHR). |
| 1953 | VkResult result = VK_SUCCESS; |
| 1954 | VkBool32 skipCall = VK_FALSE; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1955 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1956 | |
Ian Elliott | 046ed2c | 2015-12-30 17:07:17 -0700 | [diff] [blame] | 1957 | if (!pPresentInfo) { |
| 1958 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1959 | device, |
| 1960 | "pPresentInfo"); |
| 1961 | } else { |
| 1962 | if (pPresentInfo->sType != VK_STRUCTURE_TYPE_PRESENT_INFO_KHR) { |
| 1963 | skipCall |= LOG_ERROR_WRONG_STYPE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1964 | device, |
| 1965 | "pPresentInfo", |
| 1966 | "VK_STRUCTURE_TYPE_PRESENT_INFO_KHR"); |
| 1967 | } |
| 1968 | if (pPresentInfo->pNext != NULL) { |
| 1969 | skipCall |= LOG_ERROR_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1970 | device, |
| 1971 | "pPresentInfo"); |
| 1972 | } |
| 1973 | if (!pPresentInfo->waitSemaphoreCount) { |
| 1974 | skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1975 | device, |
| 1976 | "pPresentInfo->waitSemaphoreCount"); |
| 1977 | } |
| 1978 | if (!pPresentInfo->pWaitSemaphores) { |
| 1979 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1980 | device, |
| 1981 | "pPresentInfo->pWaitSemaphores"); |
| 1982 | } |
| 1983 | if (!pPresentInfo->swapchainCount) { |
| 1984 | skipCall |= LOG_ERROR_ZERO_VALUE(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1985 | device, |
| 1986 | "pPresentInfo->swapchainCount"); |
| 1987 | } |
| 1988 | if (!pPresentInfo->pSwapchains) { |
| 1989 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1990 | device, |
| 1991 | "pPresentInfo->pSwapchains"); |
| 1992 | } |
| 1993 | if (!pPresentInfo->pImageIndices) { |
| 1994 | skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1995 | device, |
| 1996 | "pPresentInfo->pImageIndices"); |
| 1997 | } |
| 1998 | // Note: pPresentInfo->pResults is allowed to be NULL |
| 1999 | } |
| 2000 | |
| 2001 | for (uint32_t i = 0; |
| 2002 | pPresentInfo && (i < pPresentInfo->swapchainCount); |
| 2003 | i++) { |
| 2004 | uint32_t swapchainCount = pPresentInfo->swapchainCount; |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 2005 | uint32_t index = pPresentInfo->pImageIndices[i]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2006 | SwpSwapchain *pSwapchain = |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 2007 | &my_data->swapchainMap[pPresentInfo->pSwapchains[i]]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2008 | if (pSwapchain) { |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 2009 | if (!pSwapchain->pDevice->swapchainExtensionEnabled) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2010 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2011 | pSwapchain->pDevice, "VkDevice", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 2012 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 2013 | "%s() called even though the %s extension was not enabled for this VkDevice.", |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 2014 | __FUNCTION__, VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2015 | } |
| 2016 | if (index >= pSwapchain->imageCount) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2017 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 2018 | pPresentInfo->pSwapchains[i], |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2019 | "VkSwapchainKHR", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 2020 | SWAPCHAIN_INDEX_TOO_LARGE, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2021 | "%s() called for an index that is too " |
| 2022 | "large (i.e. %d). There are only %d " |
| 2023 | "images in this VkSwapchainKHR.\n", |
| 2024 | __FUNCTION__, index, |
| 2025 | pSwapchain->imageCount); |
| 2026 | } else { |
| 2027 | if (!pSwapchain->images[index].ownedByApp) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2028 | skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 2029 | pPresentInfo->pSwapchains[i], |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2030 | "VkSwapchainKHR", |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 2031 | SWAPCHAIN_INDEX_NOT_IN_USE, |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2032 | "%s() returned an index (i.e. %d) " |
| 2033 | "for an image that is not owned by " |
| 2034 | "the application.", |
| 2035 | __FUNCTION__, index); |
| 2036 | } |
| 2037 | } |
| 2038 | } else { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2039 | skipCall |= LOG_ERROR_NON_VALID_OBJ(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 2040 | pPresentInfo->pSwapchains[i], |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2041 | "VkSwapchainKHR"); |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | if (VK_FALSE == skipCall) { |
| 2046 | // Call down the call chain: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 2047 | result = my_data->device_dispatch_table->QueuePresentKHR(queue, |
Ian Elliott | 046ed2c | 2015-12-30 17:07:17 -0700 | [diff] [blame] | 2048 | pPresentInfo); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2049 | |
Ian Elliott | 046ed2c | 2015-12-30 17:07:17 -0700 | [diff] [blame] | 2050 | if (pPresentInfo && |
| 2051 | ((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR))) { |
Courtney Goeltzenleuchter | dad30df | 2015-10-07 09:00:34 -0600 | [diff] [blame] | 2052 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount ; i++) { |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 2053 | int index = pPresentInfo->pImageIndices[i]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2054 | SwpSwapchain *pSwapchain = |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 2055 | &my_data->swapchainMap[pPresentInfo->pSwapchains[i]]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2056 | if (pSwapchain) { |
| 2057 | // Change the state of the image (no longer owned by the |
| 2058 | // application): |
| 2059 | pSwapchain->images[index].ownedByApp = false; |
| 2060 | } |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | return result; |
| 2065 | } |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 2066 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | static inline PFN_vkVoidFunction layer_intercept_proc(const char *name) |
| 2070 | { |
| 2071 | if (!name || name[0] != 'v' || name[1] != 'k') |
| 2072 | return NULL; |
| 2073 | |
| 2074 | name += 2; |
| 2075 | if (!strcmp(name, "CreateInstance")) |
| 2076 | return (PFN_vkVoidFunction) vkCreateInstance; |
| 2077 | if (!strcmp(name, "DestroyInstance")) |
| 2078 | return (PFN_vkVoidFunction) vkDestroyInstance; |
| 2079 | if (!strcmp(name, "EnumeratePhysicalDevices")) |
| 2080 | return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices; |
| 2081 | if (!strcmp(name, "CreateDevice")) |
| 2082 | return (PFN_vkVoidFunction) vkCreateDevice; |
| 2083 | if (!strcmp(name, "DestroyDevice")) |
| 2084 | return (PFN_vkVoidFunction) vkDestroyDevice; |
| 2085 | |
| 2086 | return NULL; |
| 2087 | } |
| 2088 | static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name) |
| 2089 | { |
| 2090 | if (!name || name[0] != 'v' || name[1] != 'k') |
| 2091 | return NULL; |
| 2092 | |
| 2093 | name += 2; |
| 2094 | if (!strcmp(name, "CreateInstance")) |
| 2095 | return (PFN_vkVoidFunction) vkCreateInstance; |
| 2096 | if (!strcmp(name, "DestroyInstance")) |
| 2097 | return (PFN_vkVoidFunction) vkDestroyInstance; |
| 2098 | if (!strcmp(name, "EnumeratePhysicalDevices")) |
| 2099 | return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices; |
| 2100 | |
| 2101 | return NULL; |
| 2102 | } |
| 2103 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2104 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT( |
| 2105 | VkInstance instance, |
| 2106 | const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, |
| 2107 | const VkAllocationCallbacks* pAllocator, |
| 2108 | VkDebugReportCallbackEXT* pMsgCallback) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2109 | { |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 2110 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2111 | VkResult result = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 2112 | if (VK_SUCCESS == result) { |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 2113 | result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback); |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 2114 | } |
| 2115 | return result; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2116 | } |
| 2117 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2118 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2119 | { |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 2120 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2121 | my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 2122 | layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2123 | } |
| 2124 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2125 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT( |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 2126 | VkInstance instance, |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2127 | VkDebugReportFlagsEXT flags, |
| 2128 | VkDebugReportObjectTypeEXT objType, |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 2129 | uint64_t object, |
| 2130 | size_t location, |
| 2131 | int32_t msgCode, |
| 2132 | const char* pLayerPrefix, |
| 2133 | const char* pMsg) |
| 2134 | { |
| 2135 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2136 | my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 2139 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2140 | { |
| 2141 | PFN_vkVoidFunction addr; |
| 2142 | if (device == VK_NULL_HANDLE) { |
| 2143 | return NULL; |
| 2144 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2145 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 2146 | layer_data *my_data; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2147 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 2148 | if (!strcmp("vkGetDeviceProcAddr", funcName)) { |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 2149 | VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) device; |
| 2150 | my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map); |
| 2151 | my_data->device_dispatch_table = new VkLayerDispatchTable; |
| 2152 | layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2153 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
| 2154 | } |
| 2155 | |
| 2156 | addr = layer_intercept_proc(funcName); |
| 2157 | if (addr) |
| 2158 | return addr; |
| 2159 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 2160 | my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 2161 | VkLayerDispatchTable *pDisp = my_data->device_dispatch_table; |
| 2162 | if (my_data->deviceMap.size() != 0 && |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 2163 | my_data->deviceMap[device].swapchainExtensionEnabled) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2164 | { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2165 | if (!strcmp("vkCreateSwapchainKHR", funcName)) |
| 2166 | return reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR); |
| 2167 | if (!strcmp("vkDestroySwapchainKHR", funcName)) |
| 2168 | return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR); |
| 2169 | if (!strcmp("vkGetSwapchainImagesKHR", funcName)) |
| 2170 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR); |
| 2171 | if (!strcmp("vkAcquireNextImageKHR", funcName)) |
| 2172 | return reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR); |
| 2173 | if (!strcmp("vkQueuePresentKHR", funcName)) |
| 2174 | return reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR); |
| 2175 | } |
| 2176 | { |
| 2177 | if (pDisp->GetDeviceProcAddr == NULL) |
| 2178 | return NULL; |
| 2179 | return pDisp->GetDeviceProcAddr(device, funcName); |
| 2180 | } |
| 2181 | } |
| 2182 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 2183 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2184 | { |
| 2185 | PFN_vkVoidFunction addr; |
| 2186 | if (instance == VK_NULL_HANDLE) { |
| 2187 | return NULL; |
| 2188 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2189 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 2190 | layer_data *my_data; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2191 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 2192 | if (!strcmp("vkGetInstanceProcAddr", funcName)) { |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 2193 | VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance; |
| 2194 | my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map); |
| 2195 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 2196 | layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2197 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
| 2198 | } |
| 2199 | |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 2200 | if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties")) |
| 2201 | return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties; |
| 2202 | if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties")) |
| 2203 | return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties; |
| 2204 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2205 | addr = layer_intercept_instance_proc(funcName); |
| 2206 | if (addr) |
| 2207 | return addr; |
| 2208 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 2209 | my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 2210 | VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 2211 | addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
| 2212 | if (addr) { |
| 2213 | return addr; |
| 2214 | } |
| 2215 | |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2216 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2217 | if (my_data->instanceMap.size() != 0 && |
| 2218 | my_data->instanceMap[instance].androidSurfaceExtensionEnabled) |
| 2219 | { |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2220 | if (!strcmp("vkCreateAndroidSurfaceKHR", funcName)) |
| 2221 | return reinterpret_cast<PFN_vkVoidFunction>(vkCreateAndroidSurfaceKHR); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2222 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2223 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 2224 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2225 | if (my_data->instanceMap.size() != 0 && |
| 2226 | my_data->instanceMap[instance].mirSurfaceExtensionEnabled) |
| 2227 | { |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2228 | if (!strcmp("vkCreateMirSurfaceKHR", funcName)) |
| 2229 | return reinterpret_cast<PFN_vkVoidFunction>(vkCreateMirSurfaceKHR); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 2230 | if (!strcmp("vkGetPhysicalDeviceMirPresentationSupportKHR", funcName)) |
| 2231 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceMirPresentationSupportKHR); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2232 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2233 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 2234 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2235 | if (my_data->instanceMap.size() != 0 && |
| 2236 | my_data->instanceMap[instance].waylandSurfaceExtensionEnabled) |
| 2237 | { |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2238 | if (!strcmp("vkCreateWaylandSurfaceKHR", funcName)) |
| 2239 | return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWaylandSurfaceKHR); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 2240 | if (!strcmp("vkGetPhysicalDeviceWaylandPresentationSupportKHR", funcName)) |
| 2241 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWaylandPresentationSupportKHR); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2242 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2243 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 2244 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2245 | if (my_data->instanceMap.size() != 0 && |
| 2246 | my_data->instanceMap[instance].win32SurfaceExtensionEnabled) |
| 2247 | { |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2248 | if (!strcmp("vkCreateWin32SurfaceKHR", funcName)) |
| 2249 | return reinterpret_cast<PFN_vkVoidFunction>(vkCreateWin32SurfaceKHR); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 2250 | if (!strcmp("vkGetPhysicalDeviceWin32PresentationSupportKHR", funcName)) |
| 2251 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceWin32PresentationSupportKHR); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2252 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2253 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 2254 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2255 | if (my_data->instanceMap.size() != 0 && |
| 2256 | my_data->instanceMap[instance].xcbSurfaceExtensionEnabled) |
| 2257 | { |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2258 | if (!strcmp("vkCreateXcbSurfaceKHR", funcName)) |
| 2259 | return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXcbSurfaceKHR); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 2260 | if (!strcmp("vkGetPhysicalDeviceXcbPresentationSupportKHR", funcName)) |
| 2261 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXcbPresentationSupportKHR); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2262 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2263 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2264 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2265 | if (my_data->instanceMap.size() != 0 && |
| 2266 | my_data->instanceMap[instance].xlibSurfaceExtensionEnabled) |
| 2267 | { |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2268 | if (!strcmp("vkCreateXlibSurfaceKHR", funcName)) |
| 2269 | return reinterpret_cast<PFN_vkVoidFunction>(vkCreateXlibSurfaceKHR); |
Ian Elliott | 55ff796 | 2015-12-30 10:18:47 -0700 | [diff] [blame] | 2270 | if (!strcmp("vkGetPhysicalDeviceXlibPresentationSupportKHR", funcName)) |
| 2271 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceXlibPresentationSupportKHR); |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2272 | } |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2273 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame^] | 2274 | if (my_data->instanceMap.size() != 0 && |
| 2275 | my_data->instanceMap[instance].surfaceExtensionEnabled) |
| 2276 | { |
Ian Elliott | a983e9a | 2015-12-22 12:18:12 -0700 | [diff] [blame] | 2277 | if (!strcmp("vkDestroySurfaceKHR", funcName)) |
| 2278 | return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySurfaceKHR); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2279 | if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", funcName)) |
| 2280 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceSupportKHR); |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 2281 | if (!strcmp("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", funcName)) |
| 2282 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceCapabilitiesKHR); |
| 2283 | if (!strcmp("vkGetPhysicalDeviceSurfaceFormatsKHR", funcName)) |
| 2284 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceFormatsKHR); |
| 2285 | if (!strcmp("vkGetPhysicalDeviceSurfacePresentModesKHR", funcName)) |
| 2286 | return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfacePresentModesKHR); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | if (pTable->GetInstanceProcAddr == NULL) |
| 2290 | return NULL; |
| 2291 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 2292 | } |
| 2293 | |