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