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