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