Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 17 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 18 | * Author: Ian Elliott <ian@lunarg.com> |
Ian Elliott | 578e7e2 | 2016-01-05 14:03:16 -0700 | [diff] [blame] | 19 | * Author: Ian Elliott <ianelliott@google.com> |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 22 | #include <mutex> |
Ian Elliott | d8c5db1 | 2015-10-07 11:32:31 -0600 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <string.h> |
Mark Lobodzinski | b49b6e5 | 2015-11-26 10:59:58 -0700 | [diff] [blame] | 25 | #include <vk_loader_platform.h> |
Cody Northrop | d08141b | 2016-02-01 09:52:07 -0700 | [diff] [blame] | 26 | #include <vulkan/vk_icd.h> |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 27 | #include "swapchain.h" |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 28 | #include "vk_layer_extension_utils.h" |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 29 | #include "vk_enum_string_helper.h" |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 30 | #include "vk_layer_utils.h" |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 31 | |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 32 | namespace swapchain { |
| 33 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 34 | static std::mutex global_lock; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 35 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 36 | // The following is for logging error messages: |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 37 | static std::unordered_map<void *, layer_data *> layer_data_map; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 38 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 39 | static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}}; |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 40 | |
Chia-I Wu | 40e25e7 | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 41 | static const VkLayerProperties swapchain_layer = { |
Jon Ashburn | dc9111c | 2016-03-22 12:57:13 -0600 | [diff] [blame] | 42 | "VK_LAYER_LUNARG_swapchain", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer", |
Chia-I Wu | 40e25e7 | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 43 | }; |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 44 | |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 45 | static void checkDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 46 | VkDevice device) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 47 | uint32_t i; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 48 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 49 | 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] | 50 | |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 51 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 52 | { |
| 53 | auto it = my_instance_data->physicalDeviceMap.find(physicalDevice); |
| 54 | pPhysicalDevice = (it == my_instance_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 55 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 56 | if (pPhysicalDevice) { |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 57 | my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice; |
| 58 | pPhysicalDevice->pDevice = &my_device_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 59 | } else { |
Ian Elliott | 07adb11 | 2016-01-05 12:51:03 -0700 | [diff] [blame] | 60 | // TBD: Should we leave error in (since Swapchain really needs this |
| 61 | // link)? |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 62 | log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 63 | reinterpret_cast<uint64_t>(physicalDevice), __LINE__, SWAPCHAIN_INVALID_HANDLE, "Swapchain", |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 64 | "vkCreateDevice() called with a non-valid VkPhysicalDevice."); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 65 | } |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 66 | my_device_data->deviceMap[device].device = device; |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 67 | my_device_data->deviceMap[device].swapchainExtensionEnabled = false; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 68 | |
| 69 | // Record whether the WSI device extension was enabled for this VkDevice. |
| 70 | // No need to check if the extension was advertised by |
| 71 | // vkEnumerateDeviceExtensionProperties(), since the loader handles that. |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 72 | for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 73 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 74 | |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 75 | my_device_data->deviceMap[device].swapchainExtensionEnabled = true; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 80 | static void checkInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 81 | uint32_t i; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 82 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 83 | |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 84 | // Remember this instance, and whether the VK_KHR_surface extension |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 85 | // was enabled for it: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 86 | my_data->instanceMap[instance].instance = instance; |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 87 | my_data->instanceMap[instance].surfaceExtensionEnabled = false; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 88 | my_data->instanceMap[instance].displayExtensionEnabled = false; |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 89 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 90 | my_data->instanceMap[instance].androidSurfaceExtensionEnabled = false; |
| 91 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 92 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 93 | my_data->instanceMap[instance].mirSurfaceExtensionEnabled = false; |
| 94 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 95 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 96 | my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = false; |
| 97 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 98 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 99 | my_data->instanceMap[instance].win32SurfaceExtensionEnabled = false; |
| 100 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 101 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 102 | my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = false; |
| 103 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 104 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 105 | my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = false; |
| 106 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 107 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 108 | // Look for one or more debug report create info structures, and copy the |
| 109 | // callback(s) for each one found (for use by vkDestroyInstance) |
| 110 | layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos, |
| 111 | &my_data->tmp_callbacks); |
| 112 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 113 | // Record whether the WSI instance extension was enabled for this |
| 114 | // VkInstance. No need to check if the extension was advertised by |
| 115 | // vkEnumerateInstanceExtensionProperties(), since the loader handles that. |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 116 | for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 117 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 118 | |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 119 | my_data->instanceMap[instance].surfaceExtensionEnabled = true; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 120 | } |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 121 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) { |
| 122 | |
| 123 | my_data->instanceMap[instance].displayExtensionEnabled = true; |
| 124 | } |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 125 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 126 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) { |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 127 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 128 | my_data->instanceMap[instance].androidSurfaceExtensionEnabled = true; |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 129 | } |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 130 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 131 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 132 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) { |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 133 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 134 | my_data->instanceMap[instance].mirSurfaceExtensionEnabled = true; |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 135 | } |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 136 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 137 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 138 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) { |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 139 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 140 | my_data->instanceMap[instance].waylandSurfaceExtensionEnabled = true; |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 141 | } |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 142 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 143 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 144 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) { |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 145 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 146 | my_data->instanceMap[instance].win32SurfaceExtensionEnabled = true; |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 147 | } |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 148 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 149 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 150 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) { |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 151 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 152 | my_data->instanceMap[instance].xcbSurfaceExtensionEnabled = true; |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 153 | } |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 154 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 155 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 156 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) { |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 157 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 158 | my_data->instanceMap[instance].xlibSurfaceExtensionEnabled = true; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 159 | } |
Jason Ekstrand | a5ebe8a | 2016-02-12 17:25:03 -0800 | [diff] [blame] | 160 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 164 | #include "vk_dispatch_table_helper.h" |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 165 | static void init_swapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 166 | |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 167 | layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_swapchain"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 168 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 169 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 170 | static const char *surfaceTransformStr(VkSurfaceTransformFlagBitsKHR value) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 171 | // Return a string corresponding to the value: |
| 172 | return string_VkSurfaceTransformFlagBitsKHR(value); |
| 173 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 174 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 175 | static const char *surfaceCompositeAlphaStr(VkCompositeAlphaFlagBitsKHR value) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 176 | // Return a string corresponding to the value: |
| 177 | return string_VkCompositeAlphaFlagBitsKHR(value); |
| 178 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 179 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 180 | static const char *presentModeStr(VkPresentModeKHR value) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 181 | // Return a string corresponding to the value: |
| 182 | return string_VkPresentModeKHR(value); |
| 183 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 184 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 185 | static const char *sharingModeStr(VkSharingMode value) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 186 | // Return a string corresponding to the value: |
| 187 | return string_VkSharingMode(value); |
| 188 | } |
Ian Elliott | 07adb11 | 2016-01-05 12:51:03 -0700 | [diff] [blame] | 189 | |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 190 | static bool ValidateQueueFamilyIndex(layer_data *my_data, uint32_t queue_family_index, uint32_t queue_family_count, |
| 191 | VkPhysicalDevice physical_device, const char *function) { |
| 192 | bool skip_call = false; |
| 193 | if (queue_family_index >= queue_family_count) { |
| 194 | skip_call = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 195 | reinterpret_cast<uint64_t>(physical_device), __LINE__, SWAPCHAIN_QUEUE_FAMILY_INDEX_TOO_LARGE, swapchain_layer_name, |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 196 | "%s() called with a queueFamilyIndex that is too large (i.e. %d). The maximum value (returned by " |
| 197 | "vkGetPhysicalDeviceQueueFamilyProperties) is only %d.", |
| 198 | function, queue_family_index, queue_family_count); |
| 199 | } |
| 200 | return skip_call; |
| 201 | } |
| 202 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 203 | VKAPI_ATTR VkResult VKAPI_CALL |
| 204 | CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 205 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 206 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 207 | assert(chain_info->u.pLayerInfo); |
| 208 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 209 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 210 | if (fpCreateInstance == NULL) { |
| 211 | return VK_ERROR_INITIALIZATION_FAILED; |
| 212 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 213 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 214 | // Advance the link info for the next element on the chain |
| 215 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 216 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 217 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 218 | if (result != VK_SUCCESS) { |
| 219 | return result; |
| 220 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 221 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 222 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
Chia-I Wu | a673753 | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 223 | my_data->instance = *pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 224 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 225 | layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 226 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 227 | my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance, |
| 228 | pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 229 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 230 | // Call the following function after my_data is initialized: |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 231 | checkInstanceRegisterExtensions(pCreateInfo, *pInstance); |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 232 | init_swapchain(my_data, pAllocator); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 233 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 234 | return result; |
| 235 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 236 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 237 | VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 238 | dispatch_key key = get_dispatch_key(instance); |
| 239 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 240 | SwpInstance *pInstance = NULL; |
| 241 | { |
| 242 | auto it = my_data->instanceMap.find(instance); |
| 243 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 244 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 245 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 246 | // Call down the call chain: |
| 247 | my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 248 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 249 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 250 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 251 | // Enable the temporary callback(s) here to catch cleanup issues: |
| 252 | bool callback_setup = false; |
| 253 | if (my_data->num_tmp_callbacks > 0) { |
| 254 | if (!layer_enable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_dbg_create_infos, |
| 255 | my_data->tmp_callbacks)) { |
| 256 | callback_setup = true; |
| 257 | } |
| 258 | } |
| 259 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 260 | // Do additional internal cleanup: |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 261 | if (pInstance) { |
| 262 | // Delete all of the SwpPhysicalDevice's, SwpSurface's, and the |
| 263 | // SwpInstance associated with this instance: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 264 | for (auto it = pInstance->physicalDevices.begin(); it != pInstance->physicalDevices.end(); it++) { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 265 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 266 | // Free memory that was allocated for/by this SwpPhysicalDevice: |
| 267 | SwpPhysicalDevice *pPhysicalDevice = it->second; |
| 268 | if (pPhysicalDevice) { |
Ian Elliott | 458696a | 2016-02-04 06:11:17 -0700 | [diff] [blame] | 269 | if (pPhysicalDevice->pDevice) { |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 270 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 271 | reinterpret_cast<uint64_t>(pPhysicalDevice->pDevice->device), __LINE__, SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 272 | swapchain_layer_name, |
| 273 | "VkDestroyInstance() called before all of its associated VkDevices were destroyed."); |
Ian Elliott | 458696a | 2016-02-04 06:11:17 -0700 | [diff] [blame] | 274 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 275 | free(pPhysicalDevice->pSurfaceFormats); |
| 276 | free(pPhysicalDevice->pPresentModes); |
| 277 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 278 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 279 | // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which |
| 280 | // are simply pointed to by the SwpInstance): |
| 281 | my_data->physicalDeviceMap.erase(it->second->physicalDevice); |
| 282 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 283 | for (auto it = pInstance->surfaces.begin(); it != pInstance->surfaces.end(); it++) { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 284 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 285 | // Free memory that was allocated for/by this SwpPhysicalDevice: |
| 286 | SwpSurface *pSurface = it->second; |
| 287 | if (pSurface) { |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 288 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 289 | reinterpret_cast<uint64_t>(pInstance->instance), __LINE__, SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 290 | "VkDestroyInstance() called before all of its associated VkSurfaceKHRs were destroyed."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | my_data->instanceMap.erase(instance); |
| 294 | } |
Mark Lobodzinski | 3c99d55 | 2016-02-04 13:50:23 -0700 | [diff] [blame] | 295 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 296 | // Disable and cleanup the temporary callback(s): |
| 297 | if (callback_setup) { |
| 298 | layer_disable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_callbacks); |
| 299 | } |
| 300 | if (my_data->num_tmp_callbacks > 0) { |
| 301 | layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos, my_data->tmp_callbacks); |
| 302 | my_data->num_tmp_callbacks = 0; |
| 303 | } |
| 304 | |
Mark Lobodzinski | 3c99d55 | 2016-02-04 13:50:23 -0700 | [diff] [blame] | 305 | // Clean up logging callback, if any |
| 306 | while (my_data->logging_callback.size() > 0) { |
| 307 | VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); |
| 308 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
| 309 | my_data->logging_callback.pop_back(); |
| 310 | } |
| 311 | layer_debug_report_destroy_instance(my_data->report_data); |
| 312 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 313 | delete my_data->instance_dispatch_table; |
| 314 | layer_data_map.erase(key); |
| 315 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 316 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 317 | VKAPI_ATTR void VKAPI_CALL |
| 318 | GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, |
| 319 | VkQueueFamilyProperties *pQueueFamilyProperties) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 320 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 321 | |
| 322 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 323 | my_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, |
| 324 | pQueueFamilyProperties); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 325 | |
| 326 | // Record the result of this query: |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 327 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 328 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 329 | { |
| 330 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 331 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 332 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 333 | if (pPhysicalDevice && pQueueFamilyPropertyCount && !pQueueFamilyProperties) { |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 334 | pPhysicalDevice->gotQueueFamilyPropertyCount = true; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 335 | pPhysicalDevice->numOfQueueFamilies = *pQueueFamilyPropertyCount; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 336 | } |
| 337 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 338 | |
| 339 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 340 | VKAPI_ATTR VkResult VKAPI_CALL |
| 341 | CreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, |
| 342 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 343 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 344 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 345 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 346 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 347 | SwpInstance *pInstance = NULL; |
| 348 | { |
| 349 | auto it = my_data->instanceMap.find(instance); |
| 350 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 351 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 352 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 353 | // Validate that the platform extension was enabled: |
Cody Northrop | d08141b | 2016-02-01 09:52:07 -0700 | [diff] [blame] | 354 | if (pInstance && !pInstance->androidSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 355 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 356 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 357 | "vkCreateAndroidSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 358 | VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 359 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 360 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 361 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 362 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 363 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 364 | result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 365 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 366 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 367 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 368 | { |
| 369 | auto it = my_data->instanceMap.find(instance); |
| 370 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 371 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 372 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 373 | // Record the VkSurfaceKHR returned by the ICD: |
| 374 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 375 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 376 | my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 377 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 378 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 379 | // Point to the associated SwpInstance: |
| 380 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 381 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 382 | lock.unlock(); |
| 383 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 384 | return result; |
| 385 | } |
| 386 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 387 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 388 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 389 | |
| 390 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 391 | VKAPI_ATTR VkResult VKAPI_CALL |
| 392 | CreateMirSurfaceKHR(VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 393 | VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 394 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 395 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 396 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 397 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 398 | SwpInstance *pInstance = NULL; |
| 399 | { |
| 400 | auto it = my_data->instanceMap.find(instance); |
| 401 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 402 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 403 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 404 | // Validate that the platform extension was enabled: |
| 405 | if (pInstance && !pInstance->mirSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 406 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 407 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 408 | "vkCreateMirSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 409 | VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 410 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 411 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 412 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 413 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 414 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 415 | result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 416 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 417 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 418 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 419 | { |
| 420 | auto it = my_data->instanceMap.find(instance); |
| 421 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 422 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 423 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 424 | // Record the VkSurfaceKHR returned by the ICD: |
| 425 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 426 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 427 | my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 428 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 429 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 430 | // Point to the associated SwpInstance: |
| 431 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 432 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 433 | lock.unlock(); |
| 434 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 435 | return result; |
| 436 | } |
| 437 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 438 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 439 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 440 | VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice, |
| 441 | uint32_t queueFamilyIndex, |
| 442 | MirConnection *connection) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 443 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 444 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 445 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 446 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 447 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 448 | { |
| 449 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 450 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 451 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 452 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 453 | // Validate that the platform extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 454 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->mirSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 455 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 456 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 457 | swapchain_layer_name, "vkGetPhysicalDeviceMirPresentationSupportKHR() called even though the %s " |
| 458 | "extension was not enabled for this VkInstance.", |
| 459 | VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 460 | } |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 461 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 462 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 463 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceMirPresentationSupportKHR"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 464 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 465 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 466 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 467 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 468 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 469 | result = my_data->instance_dispatch_table->GetPhysicalDeviceMirPresentationSupportKHR(physicalDevice, queueFamilyIndex, |
| 470 | connection); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 471 | } |
| 472 | return result; |
| 473 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 474 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 475 | |
| 476 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 477 | VKAPI_ATTR VkResult VKAPI_CALL |
| 478 | CreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, |
| 479 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 480 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 481 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 482 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 483 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 484 | SwpInstance *pInstance = NULL; |
| 485 | { |
| 486 | auto it = my_data->instanceMap.find(instance); |
| 487 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 488 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 489 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 490 | // Validate that the platform extension was enabled: |
| 491 | if (pInstance && !pInstance->waylandSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 492 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 493 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 494 | "vkCreateWaylandSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 495 | VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 496 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 497 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 498 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 499 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 500 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 501 | result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 502 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 503 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 504 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 505 | { |
| 506 | auto it = my_data->instanceMap.find(instance); |
| 507 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 508 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 509 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 510 | // Record the VkSurfaceKHR returned by the ICD: |
| 511 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 512 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 513 | my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 514 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 515 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 516 | // Point to the associated SwpInstance: |
| 517 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 518 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 519 | lock.unlock(); |
| 520 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 521 | return result; |
| 522 | } |
| 523 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 524 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 525 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 526 | VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice, |
| 527 | uint32_t queueFamilyIndex, |
| 528 | struct wl_display *display) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 529 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 530 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 531 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 532 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 533 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 534 | { |
| 535 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 536 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 537 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 538 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 539 | // Validate that the platform extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 540 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->waylandSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 541 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 542 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 543 | swapchain_layer_name, "vkGetPhysicalDeviceWaylandPresentationSupportKHR() called even though the %s " |
| 544 | "extension was not enabled for this VkInstance.", |
| 545 | VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 546 | } |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 547 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 548 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 549 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceWaylandPresentationSupportKHR"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 550 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 551 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 552 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 553 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 554 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 555 | result = my_data->instance_dispatch_table->GetPhysicalDeviceWaylandPresentationSupportKHR(physicalDevice, queueFamilyIndex, |
| 556 | display); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 557 | } |
| 558 | return result; |
| 559 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 560 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 561 | |
| 562 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 563 | VKAPI_ATTR VkResult VKAPI_CALL |
| 564 | CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, |
| 565 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 566 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 567 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 568 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 569 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 570 | SwpInstance *pInstance = NULL; |
| 571 | { |
| 572 | auto it = my_data->instanceMap.find(instance); |
| 573 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 574 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 575 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 576 | // Validate that the platform extension was enabled: |
| 577 | if (pInstance && !pInstance->win32SurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 578 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 579 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 580 | "vkCreateWin32SurfaceKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 581 | VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 582 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 583 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 584 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 585 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 586 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 587 | result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 588 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 589 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 590 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 591 | { |
| 592 | auto it = my_data->instanceMap.find(instance); |
| 593 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 594 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 595 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 596 | // Record the VkSurfaceKHR returned by the ICD: |
| 597 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 598 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 599 | my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 600 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 601 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 602 | // Point to the associated SwpInstance: |
| 603 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 604 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 605 | lock.unlock(); |
| 606 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 607 | return result; |
| 608 | } |
| 609 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 610 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 611 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 612 | VKAPI_ATTR VkBool32 VKAPI_CALL |
| 613 | GetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 614 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 615 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 616 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 617 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 618 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 619 | { |
| 620 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 621 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 622 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 623 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 624 | // Validate that the platform extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 625 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->win32SurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 626 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 627 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 628 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 629 | "vkGetPhysicalDeviceWin32PresentationSupportKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 630 | VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 631 | } |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 632 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 633 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 634 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceWin32PresentationSupportKHR"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 635 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 636 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 637 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 638 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 639 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 640 | result = my_data->instance_dispatch_table->GetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamilyIndex); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 641 | } |
| 642 | return result; |
| 643 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 644 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 645 | |
| 646 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 647 | VKAPI_ATTR VkResult VKAPI_CALL |
| 648 | CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 649 | VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 650 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 651 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 652 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 653 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 654 | SwpInstance *pInstance = NULL; |
| 655 | { |
| 656 | auto it = my_data->instanceMap.find(instance); |
| 657 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 658 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 659 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 660 | // Validate that the platform extension was enabled: |
| 661 | if (pInstance && !pInstance->xcbSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 662 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 663 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 664 | "vkCreateXcbSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 665 | VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 666 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 667 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 668 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 669 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 670 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 671 | result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 672 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 673 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 674 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 675 | { |
| 676 | auto it = my_data->instanceMap.find(instance); |
| 677 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 678 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 679 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 680 | // Record the VkSurfaceKHR returned by the ICD: |
| 681 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 682 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 683 | my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 684 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 685 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 686 | // Point to the associated SwpInstance: |
| 687 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 688 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 689 | lock.unlock(); |
| 690 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 691 | return result; |
| 692 | } |
| 693 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 694 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 695 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 696 | VKAPI_ATTR VkBool32 VKAPI_CALL |
| 697 | GetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, |
| 698 | xcb_connection_t *connection, xcb_visualid_t visual_id) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 699 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 700 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 701 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 702 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 703 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 704 | { |
| 705 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 706 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 707 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 708 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 709 | // Validate that the platform extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 710 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->xcbSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 711 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 712 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 713 | swapchain_layer_name, "vkGetPhysicalDeviceXcbPresentationSupportKHR() called even though the %s " |
| 714 | "extension was not enabled for this VkInstance.", |
| 715 | VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 716 | } |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 717 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 718 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 719 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceXcbPresentationSupportKHR"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 720 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 721 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 722 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 723 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 724 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 725 | result = my_data->instance_dispatch_table->GetPhysicalDeviceXcbPresentationSupportKHR(physicalDevice, queueFamilyIndex, |
| 726 | connection, visual_id); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 727 | } |
| 728 | return result; |
| 729 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 730 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 731 | |
| 732 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 733 | VKAPI_ATTR VkResult VKAPI_CALL |
| 734 | CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 735 | VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 736 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 737 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 738 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 739 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 740 | SwpInstance *pInstance = NULL; |
| 741 | { |
| 742 | auto it = my_data->instanceMap.find(instance); |
| 743 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 744 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 745 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 746 | // Validate that the platform extension was enabled: |
| 747 | if (pInstance && !pInstance->xlibSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 748 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 749 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 750 | "vkCreateXlibSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 751 | VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 752 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 753 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 754 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 755 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 756 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 757 | result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 758 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 759 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 760 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 761 | { |
| 762 | auto it = my_data->instanceMap.find(instance); |
| 763 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 764 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 765 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 766 | // Record the VkSurfaceKHR returned by the ICD: |
| 767 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 768 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 769 | my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 770 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 771 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 772 | // Point to the associated SwpInstance: |
| 773 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 774 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 775 | lock.unlock(); |
| 776 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 777 | return result; |
| 778 | } |
| 779 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 780 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 781 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 782 | VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice, |
| 783 | uint32_t queueFamilyIndex, |
| 784 | Display *dpy, VisualID visualID) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 785 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 786 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 787 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 788 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 789 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 790 | { |
| 791 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 792 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 793 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 794 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 795 | // Validate that the platform extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 796 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->xlibSurfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 797 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 798 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 799 | swapchain_layer_name, "vkGetPhysicalDeviceXlibPresentationSupportKHR() called even though the %s " |
| 800 | "extension was not enabled for this VkInstance.", |
| 801 | VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 802 | } |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 803 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 804 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 805 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceXlibPresentationSupportKHR"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 806 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 807 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 808 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 809 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 810 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 811 | result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR(physicalDevice, queueFamilyIndex, |
| 812 | dpy, visualID); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 813 | } |
| 814 | return result; |
| 815 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 816 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 817 | |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 818 | VKAPI_ATTR VkResult VKAPI_CALL |
| 819 | GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPropertiesKHR *pProperties) { |
| 820 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 821 | bool skip_call = false; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 822 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 823 | std::unique_lock<std::mutex> lock(global_lock); |
| 824 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 825 | { |
| 826 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 827 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 828 | } |
| 829 | |
| 830 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 831 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 832 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 833 | swapchain_layer_name, "vkGetPhysicalDeviceDisplayPropertiesKHR() called even though the %s " |
| 834 | "extension was not enabled for this VkInstance.", |
| 835 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 836 | } |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 837 | lock.unlock(); |
| 838 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 839 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 840 | result = my_data->instance_dispatch_table->GetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties); |
| 841 | return result; |
| 842 | } |
| 843 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 844 | } |
| 845 | |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 846 | VKAPI_ATTR VkResult VKAPI_CALL |
| 847 | GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlanePropertiesKHR *pProperties) { |
| 848 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 849 | bool skip_call = false; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 850 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 851 | std::unique_lock<std::mutex> lock(global_lock); |
| 852 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 853 | { |
| 854 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 855 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 856 | } |
| 857 | |
| 858 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 859 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 860 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 861 | swapchain_layer_name, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR() called even though the %s " |
| 862 | "extension was not enabled for this VkInstance.", |
| 863 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 864 | } |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 865 | lock.unlock(); |
| 866 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 867 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 868 | result = my_data->instance_dispatch_table->GetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, pPropertyCount, pProperties); |
| 869 | |
| 870 | lock.lock(); |
| 871 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) |
| 872 | { |
| 873 | pPhysicalDevice->displayPlanePropertyCount = *pPropertyCount; |
| 874 | pPhysicalDevice->gotDisplayPlanePropertyCount = true; |
| 875 | } |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 876 | // TODO store the properties for later checks |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 877 | lock.unlock(); |
| 878 | |
| 879 | return result; |
| 880 | } |
| 881 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 882 | } |
| 883 | |
| 884 | VKAPI_ATTR VkResult VKAPI_CALL |
| 885 | GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) { |
| 886 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 887 | bool skip_call = false; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 888 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 889 | std::unique_lock<std::mutex> lock(global_lock); |
| 890 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 891 | { |
| 892 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 893 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 894 | } |
| 895 | |
| 896 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 897 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 898 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 899 | swapchain_layer_name, "vkGetDisplayPlaneSupportedDisplaysKHR() called even though the %s " |
| 900 | "extension was not enabled for this VkInstance.", |
| 901 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 902 | } |
| 903 | |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 904 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 905 | { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 906 | skip_call |= |
Mark Lobodzinski | d2f2baa | 2016-08-08 11:20:36 -0600 | [diff] [blame] | 907 | log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 908 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, |
Mark Lobodzinski | d2f2baa | 2016-08-08 11:20:36 -0600 | [diff] [blame] | 909 | swapchain_layer_name, "Potential problem with calling vkGetDisplayPlaneSupportedDisplaysKHR() without first " |
| 910 | "querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR."); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 911 | } |
| 912 | |
Jon Ashburn | 1e85790 | 2016-07-01 10:08:31 -0600 | [diff] [blame] | 913 | if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 914 | { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 915 | skip_call |= |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 916 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 917 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_PLANE_INDEX_TOO_LARGE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 918 | "vkGetDisplayPlaneSupportedDisplaysKHR(): planeIndex must be in the range [0, %d] that was returned by " |
| 919 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded?", |
| 920 | pPhysicalDevice->displayPlanePropertyCount - 1); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 921 | } |
| 922 | lock.unlock(); |
| 923 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 924 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 925 | result = my_data->instance_dispatch_table->GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, pDisplays); |
| 926 | |
| 927 | return result; |
| 928 | } |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 929 | // TODO validate the returned display objects |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 930 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 931 | } |
| 932 | |
| 933 | VKAPI_ATTR VkResult VKAPI_CALL |
| 934 | GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModePropertiesKHR* pProperties) { |
| 935 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 936 | bool skip_call = false; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 937 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 938 | std::unique_lock<std::mutex> lock(global_lock); |
| 939 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 940 | { |
| 941 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 942 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 943 | } |
| 944 | |
| 945 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 946 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 947 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 948 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 949 | "vkGetDisplayModePropertiesKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 950 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 951 | } |
| 952 | |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 953 | |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 954 | lock.unlock(); |
| 955 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 956 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 957 | result = my_data->instance_dispatch_table->GetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties); |
| 958 | return result; |
| 959 | } |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 960 | // TODO store the displayMode for later checking |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 961 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 962 | } |
| 963 | |
| 964 | VKAPI_ATTR VkResult VKAPI_CALL |
| 965 | CreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, const VkDisplayModeCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode) { |
| 966 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 967 | bool skip_call = false; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 968 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 969 | std::unique_lock<std::mutex> lock(global_lock); |
| 970 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 971 | { |
| 972 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 973 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 974 | } |
| 975 | |
| 976 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 977 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 978 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 979 | swapchain_layer_name, |
| 980 | "vkCreateDisplayModeKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 981 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 982 | } |
| 983 | |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 984 | lock.unlock(); |
| 985 | |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 986 | // TODO more validation checks needed |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 987 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 988 | result = my_data->instance_dispatch_table->CreateDisplayModeKHR(physicalDevice, display, pCreateInfo, pAllocator, pMode); |
| 989 | return result; |
| 990 | } |
| 991 | |
| 992 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 993 | } |
| 994 | |
| 995 | VKAPI_ATTR VkResult VKAPI_CALL |
| 996 | GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR* pCapabilities) { |
| 997 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 998 | bool skip_call = false; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 999 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 1000 | std::unique_lock<std::mutex> lock(global_lock); |
| 1001 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 1002 | { |
| 1003 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1004 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1005 | } |
| 1006 | |
| 1007 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->displayExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1008 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1009 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1010 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1011 | "vkGetDisplayPlaneCapabilitiesKHR) called even though the %s extension was not enabled for this VkInstance.", |
| 1012 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1015 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1016 | { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1017 | skip_call |= |
Mark Lobodzinski | d2f2baa | 2016-08-08 11:20:36 -0600 | [diff] [blame] | 1018 | log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1019 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, |
Mark Lobodzinski | d2f2baa | 2016-08-08 11:20:36 -0600 | [diff] [blame] | 1020 | swapchain_layer_name, "Potential problem with calling vkGetDisplayPlaneCapabilitiesKHR() without first " |
| 1021 | "querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR."); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1024 | if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1025 | { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1026 | skip_call |= |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1027 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1028 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_PLANE_INDEX_TOO_LARGE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1029 | "vkGetDisplayPlaneCapabilitiesKHR(): planeIndex must be in the range [0, %d] that was returned by " |
| 1030 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded?", |
| 1031 | pPhysicalDevice->displayPlanePropertyCount - 1); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1032 | } |
| 1033 | |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1034 | lock.unlock(); |
| 1035 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1036 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1037 | result = my_data->instance_dispatch_table->GetDisplayPlaneCapabilitiesKHR(physicalDevice, mode, planeIndex, pCapabilities); |
| 1038 | return result; |
| 1039 | } |
| 1040 | |
| 1041 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1042 | } |
| 1043 | |
| 1044 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1045 | CreateDisplayPlaneSurfaceKHR(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 1046 | VkSurfaceKHR *pSurface) { |
| 1047 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1048 | bool skip_call = false; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1049 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 1050 | std::unique_lock<std::mutex> lock(global_lock); |
| 1051 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 1052 | |
| 1053 | // Validate that the platform extension was enabled: |
| 1054 | if (pInstance && !pInstance->displayExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1055 | skip_call |= |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1056 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1057 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1058 | "vkCreateDisplayPlaneSurfaceKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 1059 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1060 | } |
| 1061 | |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 1062 | // TODO more validation checks |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1063 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1064 | // Call down the call chain: |
| 1065 | lock.unlock(); |
| 1066 | result = my_data->instance_dispatch_table->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
| 1067 | lock.lock(); |
| 1068 | |
| 1069 | // Obtain this pointer again after locking: |
| 1070 | pInstance = &(my_data->instanceMap[instance]); |
| 1071 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 1072 | // Record the VkSurfaceKHR returned by the ICD: |
| 1073 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 1074 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
| 1075 | my_data->surfaceMap[*pSurface].usedAllocatorToCreate = (pAllocator != NULL); |
| 1076 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 1077 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 1078 | // Point to the associated SwpInstance: |
| 1079 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 1080 | } |
| 1081 | lock.unlock(); |
| 1082 | return result; |
| 1083 | } |
| 1084 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1085 | } |
| 1086 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1087 | VKAPI_ATTR void VKAPI_CALL |
| 1088 | DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1089 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1090 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1091 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1092 | SwpSurface *pSurface = NULL; |
| 1093 | { |
| 1094 | auto it = my_data->surfaceMap.find(surface); |
| 1095 | pSurface = (it == my_data->surfaceMap.end()) ? NULL : &it->second; |
| 1096 | } |
| 1097 | SwpInstance *pInstance = NULL; |
| 1098 | { |
| 1099 | auto it = my_data->instanceMap.find(instance); |
| 1100 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 1101 | } |
Ian Elliott | f6b8c78 | 2016-04-29 13:03:17 -0600 | [diff] [blame] | 1102 | |
| 1103 | // Validate that the platform extension was enabled: |
| 1104 | if (pInstance && !pInstance->surfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1105 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 1106 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1107 | "vkDestroySurfaceKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 1108 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Ian Elliott | f6b8c78 | 2016-04-29 13:03:17 -0600 | [diff] [blame] | 1109 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1110 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1111 | // Regardless of skip_call value, do some internal cleanup: |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1112 | if (pSurface) { |
| 1113 | // Delete the SwpSurface associated with this surface: |
| 1114 | if (pSurface->pInstance) { |
| 1115 | pSurface->pInstance->surfaces.erase(surface); |
| 1116 | } |
| 1117 | if (!pSurface->swapchains.empty()) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1118 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 1119 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1120 | "vkDestroySurfaceKHR() called before all of its associated VkSwapchainKHRs were destroyed."); |
| 1121 | |
| 1122 | // Empty and then delete all SwpSwapchains |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1123 | for (auto it = pSurface->swapchains.begin(); it != pSurface->swapchains.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1124 | // Delete all SwpImage's |
| 1125 | it->second->images.clear(); |
| 1126 | // In case the swapchain's device hasn't been destroyed yet |
| 1127 | // (which isn't likely, but is possible), delete its |
| 1128 | // association with this swapchain (i.e. so we can't point to |
| 1129 | // this swpchain from that device, later on): |
| 1130 | if (it->second->pDevice) { |
| 1131 | it->second->pDevice->swapchains.clear(); |
| 1132 | } |
| 1133 | } |
| 1134 | pSurface->swapchains.clear(); |
| 1135 | } |
| 1136 | if ((pAllocator != NULL) != pSurface->usedAllocatorToCreate) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1137 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 1138 | reinterpret_cast<uint64_t>(instance), __LINE__, SWAPCHAIN_INCOMPATIBLE_ALLOCATOR, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1139 | "vkDestroySurfaceKHR() called with incompatible pAllocator from when the object was created."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1140 | } |
| 1141 | my_data->surfaceMap.erase(surface); |
| 1142 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1143 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1144 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1145 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1146 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1147 | my_data->instance_dispatch_table->DestroySurfaceKHR(instance, surface, pAllocator); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1151 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1152 | EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1153 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1154 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1155 | |
| 1156 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1157 | result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1158 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1159 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1160 | SwpInstance *pInstance = NULL; |
| 1161 | { |
| 1162 | auto it = my_data->instanceMap.find(instance); |
| 1163 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 1164 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1165 | if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices && (*pPhysicalDeviceCount > 0)) { |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1166 | // Record the VkPhysicalDevices returned by the ICD: |
| 1167 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1168 | my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice = pPhysicalDevices[i]; |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1169 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance; |
| 1170 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL; |
| 1171 | my_data->physicalDeviceMap[pPhysicalDevices[i]].gotQueueFamilyPropertyCount = false; |
| 1172 | my_data->physicalDeviceMap[pPhysicalDevices[i]].gotSurfaceCapabilities = false; |
| 1173 | my_data->physicalDeviceMap[pPhysicalDevices[i]].surfaceFormatCount = 0; |
| 1174 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pSurfaceFormats = NULL; |
| 1175 | my_data->physicalDeviceMap[pPhysicalDevices[i]].presentModeCount = 0; |
| 1176 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pPresentModes = NULL; |
| 1177 | // Point to the associated SwpInstance: |
| 1178 | if (pInstance) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1179 | pInstance->physicalDevices[pPhysicalDevices[i]] = &my_data->physicalDeviceMap[pPhysicalDevices[i]]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1180 | } |
| 1181 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1182 | } |
Ian Elliott | a3c69bc | 2016-02-04 15:34:59 -0700 | [diff] [blame] | 1183 | return result; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1186 | VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, |
| 1187 | const VkDeviceCreateInfo *pCreateInfo, |
| 1188 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Chia-I Wu | a673753 | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 1189 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1190 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 1191 | |
| 1192 | assert(chain_info->u.pLayerInfo); |
| 1193 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 1194 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
Chia-I Wu | a673753 | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 1195 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1196 | if (fpCreateDevice == NULL) { |
| 1197 | return VK_ERROR_INITIALIZATION_FAILED; |
| 1198 | } |
| 1199 | |
| 1200 | // Advance the link info for the next element on the chain |
| 1201 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 1202 | |
| 1203 | VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); |
| 1204 | if (result != VK_SUCCESS) { |
| 1205 | return result; |
| 1206 | } |
| 1207 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1208 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1209 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 1210 | |
| 1211 | // Setup device dispatch table |
| 1212 | my_device_data->device_dispatch_table = new VkLayerDispatchTable; |
| 1213 | layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); |
| 1214 | |
| 1215 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 1216 | checkDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1217 | |
| 1218 | return result; |
| 1219 | } |
| 1220 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1221 | VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1222 | dispatch_key key = get_dispatch_key(device); |
| 1223 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1224 | |
| 1225 | // Call down the call chain: |
| 1226 | my_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
| 1227 | |
| 1228 | // Do some internal cleanup: |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1229 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1230 | SwpDevice *pDevice = NULL; |
| 1231 | { |
| 1232 | auto it = my_data->deviceMap.find(device); |
| 1233 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 1234 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1235 | if (pDevice) { |
| 1236 | // Delete the SwpDevice associated with this device: |
| 1237 | if (pDevice->pPhysicalDevice) { |
| 1238 | pDevice->pPhysicalDevice->pDevice = NULL; |
| 1239 | } |
| 1240 | if (!pDevice->swapchains.empty()) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1241 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, reinterpret_cast<uint64_t>(device), |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1242 | __LINE__, SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, swapchain_layer_name, |
| 1243 | "vkDestroyDevice() called before all of its associated VkSwapchainKHRs were destroyed."); |
| 1244 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1245 | // Empty and then delete all SwpSwapchain's |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1246 | for (auto it = pDevice->swapchains.begin(); it != pDevice->swapchains.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1247 | // Delete all SwpImage's |
| 1248 | it->second->images.clear(); |
| 1249 | // In case the swapchain's surface hasn't been destroyed yet |
| 1250 | // (which is likely) delete its association with this swapchain |
| 1251 | // (i.e. so we can't point to this swpchain from that surface, |
| 1252 | // later on): |
| 1253 | if (it->second->pSurface) { |
| 1254 | it->second->pSurface->swapchains.clear(); |
| 1255 | } |
| 1256 | } |
| 1257 | pDevice->swapchains.clear(); |
| 1258 | } |
| 1259 | my_data->deviceMap.erase(device); |
| 1260 | } |
| 1261 | delete my_data->device_dispatch_table; |
| 1262 | layer_data_map.erase(key); |
| 1263 | } |
| 1264 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1265 | VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, |
| 1266 | uint32_t queueFamilyIndex, VkSurfaceKHR surface, |
| 1267 | VkBool32 *pSupported) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1268 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1269 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1270 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1271 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1272 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 1273 | { |
| 1274 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1275 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1276 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1277 | |
| 1278 | // Validate that the surface extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1279 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->surfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1280 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1281 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1282 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1283 | "vkGetPhysicalDeviceSurfaceSupportKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 1284 | VK_KHR_SURFACE_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1285 | } |
| 1286 | if (!pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1287 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1288 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1289 | reinterpret_cast<uint64_t>(pPhysicalDevice->physicalDevice), __LINE__, SWAPCHAIN_DID_NOT_QUERY_QUEUE_FAMILIES, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1290 | "vkGetPhysicalDeviceSurfaceSupportKHR() called before calling the vkGetPhysicalDeviceQueueFamilyProperties function."); |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 1291 | } else if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1292 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 1293 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceSurfaceSupportKHR"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1294 | } |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1295 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1296 | lock.unlock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1297 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1298 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1299 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1300 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, |
| 1301 | pSupported); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1302 | lock.lock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1303 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1304 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1305 | { |
| 1306 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1307 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1308 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1309 | if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) { |
| 1310 | // Record the result of this query: |
| 1311 | SwpInstance *pInstance = pPhysicalDevice->pInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1312 | SwpSurface *pSurface = (pInstance) ? pInstance->surfaces[surface] : NULL; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1313 | if (pSurface) { |
| 1314 | pPhysicalDevice->supportedSurfaces[surface] = pSurface; |
| 1315 | if (!pSurface->numQueueFamilyIndexSupport) { |
| 1316 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1317 | pSurface->pQueueFamilyIndexSupport = |
| 1318 | (VkBool32 *)malloc(pPhysicalDevice->numOfQueueFamilies * sizeof(VkBool32)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1319 | if (pSurface->pQueueFamilyIndexSupport != NULL) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1320 | pSurface->numQueueFamilyIndexSupport = pPhysicalDevice->numOfQueueFamilies; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1321 | } |
| 1322 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1323 | } |
| 1324 | if (pSurface->numQueueFamilyIndexSupport) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1325 | pSurface->pQueueFamilyIndexSupport[queueFamilyIndex] = *pSupported; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1329 | lock.unlock(); |
| 1330 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1331 | return result; |
| 1332 | } |
| 1333 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1334 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1335 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1336 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1337 | GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 1338 | VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1339 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1340 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1341 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1342 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1343 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 1344 | { |
| 1345 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1346 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1347 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1348 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1349 | // Validate that the surface extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1350 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->surfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1351 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1352 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1353 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1354 | "vkGetPhysicalDeviceSurfaceCapabilitiesKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 1355 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1356 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1357 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1358 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1359 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1360 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1361 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, |
| 1362 | pSurfaceCapabilities); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1363 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1364 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1365 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1366 | { |
| 1367 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1368 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1369 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1370 | if ((result == VK_SUCCESS) && pPhysicalDevice) { |
| 1371 | // Record the result of this query: |
| 1372 | pPhysicalDevice->gotSurfaceCapabilities = true; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1373 | // FIXME: NEED TO COPY THIS DATA, BECAUSE pSurfaceCapabilities POINTS TO APP-ALLOCATED DATA |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1374 | pPhysicalDevice->surfaceCapabilities = *pSurfaceCapabilities; |
| 1375 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1376 | lock.unlock(); |
| 1377 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1378 | return result; |
| 1379 | } |
| 1380 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1381 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1382 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1383 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1384 | GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t *pSurfaceFormatCount, |
| 1385 | VkSurfaceFormatKHR *pSurfaceFormats) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1386 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1387 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1388 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1389 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1390 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 1391 | { |
| 1392 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1393 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1394 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1395 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1396 | // Validate that the surface extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1397 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->surfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1398 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1399 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1400 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1401 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 1402 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1403 | } |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1404 | if (pPhysicalDevice && pSurfaceFormats) { |
| 1405 | // Compare the preliminary value of *pSurfaceFormatCount with the value this time: |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1406 | if (pPhysicalDevice->surfaceFormatCount == 0) { |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1407 | // Since we haven't recorded a preliminary value of *pSurfaceFormatCount, that likely means that the application didn't |
| 1408 | // previously call this function with a NULL value of pSurfaceFormats: |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1409 | skip_call |= |
Mark Lobodzinski | ca708d9 | 2016-08-08 10:29:34 -0600 | [diff] [blame] | 1410 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1411 | reinterpret_cast<uint64_t>(pPhysicalDevice->physicalDevice), __LINE__, SWAPCHAIN_PRIOR_COUNT, swapchain_layer_name, |
Mark Lobodzinski | ca708d9 | 2016-08-08 10:29:34 -0600 | [diff] [blame] | 1412 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount; but no prior positive " |
| 1413 | "value has been seen for pSurfaceFormats."); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1414 | } else if (*pSurfaceFormatCount > pPhysicalDevice->surfaceFormatCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1415 | skip_call |= log_msg( |
Mark Lobodzinski | 2511de1 | 2016-08-08 10:18:49 -0600 | [diff] [blame] | 1416 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1417 | reinterpret_cast<uint64_t>(pPhysicalDevice->physicalDevice), __LINE__, SWAPCHAIN_INVALID_COUNT, swapchain_layer_name, |
Mark Lobodzinski | 2511de1 | 2016-08-08 10:18:49 -0600 | [diff] [blame] | 1418 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount, and with pSurfaceFormats set to " |
| 1419 | "a value (%d) that is greater than the value (%d) that was returned when pSurfaceFormatCount was NULL.", |
| 1420 | *pSurfaceFormatCount, pPhysicalDevice->surfaceFormatCount); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1421 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1422 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1423 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1424 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1425 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1426 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1427 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pSurfaceFormatCount, |
| 1428 | pSurfaceFormats); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1429 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1430 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1431 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1432 | { |
| 1433 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1434 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1435 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1436 | if ((result == VK_SUCCESS) && pPhysicalDevice && !pSurfaceFormats && pSurfaceFormatCount) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1437 | // Record the result of this preliminary query: |
| 1438 | pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount; |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1439 | } else if ((result == VK_SUCCESS) && pPhysicalDevice && |
| 1440 | pSurfaceFormats && pSurfaceFormatCount && |
| 1441 | (*pSurfaceFormatCount > 0)) { |
| 1442 | // Record the result of this query: |
| 1443 | pPhysicalDevice->surfaceFormatCount = *pSurfaceFormatCount; |
| 1444 | pPhysicalDevice->pSurfaceFormats = (VkSurfaceFormatKHR *)malloc(*pSurfaceFormatCount * sizeof(VkSurfaceFormatKHR)); |
| 1445 | if (pPhysicalDevice->pSurfaceFormats) { |
| 1446 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
| 1447 | pPhysicalDevice->pSurfaceFormats[i] = pSurfaceFormats[i]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1448 | } |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1449 | } else { |
| 1450 | pPhysicalDevice->surfaceFormatCount = 0; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1453 | lock.unlock(); |
| 1454 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1455 | return result; |
| 1456 | } |
| 1457 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1458 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1459 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1460 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1461 | GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t *pPresentModeCount, |
| 1462 | VkPresentModeKHR *pPresentModes) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1463 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1464 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1465 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1466 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1467 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 1468 | { |
| 1469 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1470 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1471 | } |
Ian Elliott | 07adb11 | 2016-01-05 12:51:03 -0700 | [diff] [blame] | 1472 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1473 | // Validate that the surface extension was enabled: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1474 | if (pPhysicalDevice && pPhysicalDevice->pInstance && !pPhysicalDevice->pInstance->surfaceExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1475 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1476 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1477 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1478 | "vkGetPhysicalDeviceSurfacePresentModesKHR() called even though the %s extension was not enabled for this VkInstance.", |
| 1479 | VK_KHR_DISPLAY_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1480 | } |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1481 | if (pPhysicalDevice && pPresentModes) { |
| 1482 | // Compare the preliminary value of *pPresentModeCount with the value this time: |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1483 | if (pPhysicalDevice->presentModeCount == 0) { |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1484 | // Since we haven't recorded a preliminary value of *pPresentModeCount, that likely means that the application didn't |
| 1485 | // previously call this function with a NULL value of pPresentModes: |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1486 | skip_call |= |
Mark Lobodzinski | ca708d9 | 2016-08-08 10:29:34 -0600 | [diff] [blame] | 1487 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1488 | reinterpret_cast<uint64_t>(pPhysicalDevice->physicalDevice), __LINE__, SWAPCHAIN_PRIOR_COUNT, swapchain_layer_name, |
Mark Lobodzinski | ca708d9 | 2016-08-08 10:29:34 -0600 | [diff] [blame] | 1489 | "vkGetPhysicalDeviceSurfacePresentModesKHR() called with non-NULL pPresentModeCount; but no prior positive " |
| 1490 | "value has been seen for pPresentModes."); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1491 | } else if (*pPresentModeCount > pPhysicalDevice->presentModeCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1492 | skip_call |= log_msg( |
Mark Lobodzinski | 2511de1 | 2016-08-08 10:18:49 -0600 | [diff] [blame] | 1493 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1494 | reinterpret_cast<uint64_t>(pPhysicalDevice->physicalDevice), __LINE__, SWAPCHAIN_INVALID_COUNT, swapchain_layer_name, |
Mark Lobodzinski | 2511de1 | 2016-08-08 10:18:49 -0600 | [diff] [blame] | 1495 | "vkGetPhysicalDeviceSurfacePresentModesKHR() called with non-NULL pPresentModeCount, and with pPresentModes set to " |
| 1496 | "a value (%d) that is greater than the value (%d) that was returned when pPresentModeCount was NULL.", |
| 1497 | *pPresentModeCount, pPhysicalDevice->presentModeCount); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1498 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1499 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1500 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1501 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1502 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1503 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1504 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, |
| 1505 | pPresentModeCount, pPresentModes); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1506 | lock.lock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1507 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1508 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1509 | { |
| 1510 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 1511 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 1512 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1513 | if ((result == VK_SUCCESS) && pPhysicalDevice && !pPresentModes && pPresentModeCount) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1514 | // Record the result of this preliminary query: |
| 1515 | pPhysicalDevice->presentModeCount = *pPresentModeCount; |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1516 | } else if ((result == VK_SUCCESS) && pPhysicalDevice && |
| 1517 | pPresentModes && pPresentModeCount && |
| 1518 | (*pPresentModeCount > 0)) { |
| 1519 | // Record the result of this query: |
| 1520 | pPhysicalDevice->presentModeCount = *pPresentModeCount; |
| 1521 | pPhysicalDevice->pPresentModes = (VkPresentModeKHR *)malloc(*pPresentModeCount * sizeof(VkPresentModeKHR)); |
| 1522 | if (pPhysicalDevice->pPresentModes) { |
| 1523 | for (uint32_t i = 0; i < *pPresentModeCount; i++) { |
| 1524 | pPhysicalDevice->pPresentModes[i] = pPresentModes[i]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1525 | } |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1526 | } else { |
| 1527 | pPhysicalDevice->presentModeCount = 0; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1528 | } |
| 1529 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1530 | lock.unlock(); |
| 1531 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1532 | return result; |
| 1533 | } |
| 1534 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1535 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1536 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1537 | // This function does the up-front validation work for vkCreateSwapchainKHR(), |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1538 | // and returns true if a logging callback indicates that the call down the |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1539 | // chain should be skipped: |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1540 | static bool validateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, VkSwapchainKHR *pSwapchain) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1541 | // TODO: Validate cases of re-creating a swapchain (the current code |
| 1542 | // assumes a new swapchain is being created). |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1543 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1544 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 1545 | char fn[] = "vkCreateSwapchainKHR"; |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1546 | SwpDevice *pDevice = NULL; |
| 1547 | { |
| 1548 | auto it = my_data->deviceMap.find(device); |
| 1549 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 1550 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1551 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1552 | // Validate that the swapchain extension was enabled: |
| 1553 | if (pDevice && !pDevice->swapchainExtensionEnabled) { |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1554 | return log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1555 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1556 | "vkCreateSwapchainKHR() called even though the %s extension was not enabled for this VkDevice.", |
| 1557 | VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1558 | } |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1559 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1560 | // Keep around a useful pointer to pPhysicalDevice: |
| 1561 | SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice; |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1562 | |
Mark Lobodzinski | d40b2db | 2016-02-25 13:56:57 -0700 | [diff] [blame] | 1563 | // Validate pCreateInfo values with result of |
| 1564 | // vkGetPhysicalDeviceQueueFamilyProperties |
| 1565 | if (pPhysicalDevice && pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Michael Mc Donnell | 75ecdb7 | 2016-04-03 14:47:51 -0700 | [diff] [blame] | 1566 | for (uint32_t i = 0; i < pCreateInfo->queueFamilyIndexCount; i++) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1567 | skip_call |= ValidateQueueFamilyIndex(my_data, pCreateInfo->pQueueFamilyIndices[i], pPhysicalDevice->numOfQueueFamilies, |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 1568 | pPhysicalDevice->physicalDevice, "vkCreateSwapchainKHR"); |
Mark Lobodzinski | d40b2db | 2016-02-25 13:56:57 -0700 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1572 | // Validate pCreateInfo values with the results of |
| 1573 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 1574 | if (!pPhysicalDevice || !pPhysicalDevice->gotSurfaceCapabilities) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1575 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1576 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1577 | "vkCreateSwapchainKHR() called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1578 | } else if (pCreateInfo) { |
| 1579 | // Validate pCreateInfo->surface to make sure that |
| 1580 | // vkGetPhysicalDeviceSurfaceSupportKHR() reported this as a supported |
| 1581 | // surface: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1582 | SwpSurface *pSurface = ((pPhysicalDevice) ? pPhysicalDevice->supportedSurfaces[pCreateInfo->surface] : NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1583 | if (!pSurface) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1584 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1585 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_UNSUPPORTED_SURFACE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1586 | "The surface in pCreateInfo->surface, that was given to vkCreateSwapchainKHR(), must be a surface " |
| 1587 | "that is supported by the device as determined by vkGetPhysicalDeviceSurfaceSupportKHR(). " |
| 1588 | "However, vkGetPhysicalDeviceSurfaceSupportKHR() was never called with this surface."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1589 | } |
Ian Elliott | 4f147fc | 2016-01-20 08:52:08 -0700 | [diff] [blame] | 1590 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1591 | // Validate pCreateInfo->minImageCount against |
| 1592 | // VkSurfaceCapabilitiesKHR::{min|max}ImageCount: |
| 1593 | VkSurfaceCapabilitiesKHR *pCapabilities = &pPhysicalDevice->surfaceCapabilities; |
| 1594 | if ((pCreateInfo->minImageCount < pCapabilities->minImageCount) || |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1595 | ((pCapabilities->maxImageCount > 0) && (pCreateInfo->minImageCount > pCapabilities->maxImageCount))) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1596 | skip_call |= |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1597 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1598 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1599 | "vkCreateSwapchainKHR() called with pCreateInfo->minImageCount = %d, which is outside the bounds returned " |
| 1600 | "by vkGetPhysicalDeviceSurfaceCapabilitiesKHR() (i.e. minImageCount = %d, maxImageCount = %d).", |
| 1601 | pCreateInfo->minImageCount, pCapabilities->minImageCount, pCapabilities->maxImageCount); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1602 | } |
| 1603 | // Validate pCreateInfo->imageExtent against |
| 1604 | // VkSurfaceCapabilitiesKHR::{current|min|max}ImageExtent: |
| 1605 | if ((pCapabilities->currentExtent.width == -1) && |
| 1606 | ((pCreateInfo->imageExtent.width < pCapabilities->minImageExtent.width) || |
| 1607 | (pCreateInfo->imageExtent.width > pCapabilities->maxImageExtent.width) || |
| 1608 | (pCreateInfo->imageExtent.height < pCapabilities->minImageExtent.height) || |
| 1609 | (pCreateInfo->imageExtent.height > pCapabilities->maxImageExtent.height))) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1610 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1611 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1612 | "vkCreateSwapchainKHR() called with pCreateInfo->imageExtent = (%d,%d), which is outside the " |
| 1613 | "bounds returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): currentExtent = (%d,%d), " |
| 1614 | "minImageExtent = (%d,%d), maxImageExtent = (%d,%d).", |
| 1615 | pCreateInfo->imageExtent.width, pCreateInfo->imageExtent.height, pCapabilities->currentExtent.width, |
| 1616 | pCapabilities->currentExtent.height, pCapabilities->minImageExtent.width, |
| 1617 | pCapabilities->minImageExtent.height, pCapabilities->maxImageExtent.width, |
| 1618 | pCapabilities->maxImageExtent.height); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1619 | } |
| 1620 | if ((pCapabilities->currentExtent.width != -1) && |
| 1621 | ((pCreateInfo->imageExtent.width != pCapabilities->currentExtent.width) || |
| 1622 | (pCreateInfo->imageExtent.height != pCapabilities->currentExtent.height))) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1623 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1624 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1625 | "vkCreateSwapchainKHR() called with pCreateInfo->imageExtent = (%d,%d), which is not equal to the " |
| 1626 | "currentExtent = (%d,%d) returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR().", |
| 1627 | pCreateInfo->imageExtent.width, pCreateInfo->imageExtent.height, pCapabilities->currentExtent.width, |
| 1628 | pCapabilities->currentExtent.height); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1629 | } |
| 1630 | // Validate pCreateInfo->preTransform has one bit set (1st two |
| 1631 | // lines of if-statement), which bit is also set in |
| 1632 | // VkSurfaceCapabilitiesKHR::supportedTransforms (3rd line of if-statement): |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1633 | if (!pCreateInfo->preTransform || (pCreateInfo->preTransform & (pCreateInfo->preTransform - 1)) || |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1634 | !(pCreateInfo->preTransform & pCapabilities->supportedTransforms)) { |
| 1635 | // This is an error situation; one for which we'd like to give |
| 1636 | // the developer a helpful, multi-line error message. Build it |
| 1637 | // up a little at a time, and then log it: |
| 1638 | std::string errorString = ""; |
| 1639 | char str[1024]; |
| 1640 | // Here's the first part of the message: |
| 1641 | sprintf(str, "%s() called with a non-supported " |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1642 | "pCreateInfo->preTransform (i.e. %s). " |
| 1643 | "Supported values are:\n", |
| 1644 | fn, surfaceTransformStr(pCreateInfo->preTransform)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1645 | errorString += str; |
| 1646 | for (int i = 0; i < 32; i++) { |
| 1647 | // Build up the rest of the message: |
| 1648 | if ((1 << i) & pCapabilities->supportedTransforms) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1649 | const char *newStr = surfaceTransformStr((VkSurfaceTransformFlagBitsKHR)(1 << i)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1650 | sprintf(str, " %s\n", newStr); |
| 1651 | errorString += str; |
| 1652 | } |
| 1653 | } |
| 1654 | // Log the message that we've built up: |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1655 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | a4cbbcd | 2016-05-24 15:44:50 -0600 | [diff] [blame] | 1656 | reinterpret_cast<uint64_t &>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM, LAYER_NAME, |
| 1657 | "%s", errorString.c_str()); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1658 | } |
| 1659 | // Validate pCreateInfo->compositeAlpha has one bit set (1st two |
| 1660 | // lines of if-statement), which bit is also set in |
| 1661 | // VkSurfaceCapabilitiesKHR::supportedCompositeAlpha (3rd line of if-statement): |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1662 | if (!pCreateInfo->compositeAlpha || (pCreateInfo->compositeAlpha & (pCreateInfo->compositeAlpha - 1)) || |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1663 | !((pCreateInfo->compositeAlpha) & pCapabilities->supportedCompositeAlpha)) { |
| 1664 | // This is an error situation; one for which we'd like to give |
| 1665 | // the developer a helpful, multi-line error message. Build it |
| 1666 | // up a little at a time, and then log it: |
| 1667 | std::string errorString = ""; |
| 1668 | char str[1024]; |
| 1669 | // Here's the first part of the message: |
| 1670 | sprintf(str, "%s() called with a non-supported " |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1671 | "pCreateInfo->compositeAlpha (i.e. %s). " |
| 1672 | "Supported values are:\n", |
| 1673 | fn, surfaceCompositeAlphaStr(pCreateInfo->compositeAlpha)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1674 | errorString += str; |
| 1675 | for (int i = 0; i < 32; i++) { |
| 1676 | // Build up the rest of the message: |
| 1677 | if ((1 << i) & pCapabilities->supportedCompositeAlpha) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1678 | const char *newStr = surfaceCompositeAlphaStr((VkCompositeAlphaFlagBitsKHR)(1 << i)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1679 | sprintf(str, " %s\n", newStr); |
| 1680 | errorString += str; |
| 1681 | } |
| 1682 | } |
| 1683 | // Log the message that we've built up: |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1684 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | a4cbbcd | 2016-05-24 15:44:50 -0600 | [diff] [blame] | 1685 | reinterpret_cast<uint64_t &>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA, |
| 1686 | LAYER_NAME, "%s", errorString.c_str()); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1687 | } |
David McFarland | e22cfb0 | 2016-05-20 18:26:28 -0300 | [diff] [blame] | 1688 | // Validate pCreateInfo->imageArrayLayers against |
| 1689 | // VkSurfaceCapabilitiesKHR::maxImageArrayLayers: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1690 | if ((pCreateInfo->imageArrayLayers < 1) || (pCreateInfo->imageArrayLayers > pCapabilities->maxImageArrayLayers)) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1691 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1692 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_LAYERS, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1693 | "vkCreateSwapchainKHR() called with a non-supported pCreateInfo->imageArrayLayers (i.e. %d). " |
| 1694 | "Minimum value is 1, maximum value is %d.", |
| 1695 | pCreateInfo->imageArrayLayers, pCapabilities->maxImageArrayLayers); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1696 | } |
| 1697 | // Validate pCreateInfo->imageUsage against |
| 1698 | // VkSurfaceCapabilitiesKHR::supportedUsageFlags: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1699 | if (pCreateInfo->imageUsage != (pCreateInfo->imageUsage & pCapabilities->supportedUsageFlags)) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1700 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1701 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1702 | "vkCreateSwapchainKHR() called with a non-supported pCreateInfo->imageUsage (i.e. 0x%08x). " |
| 1703 | "Supported flag bits are 0x%08x.", |
| 1704 | pCreateInfo->imageUsage, pCapabilities->supportedUsageFlags); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1705 | } |
| 1706 | } |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1707 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1708 | // Validate pCreateInfo values with the results of |
| 1709 | // vkGetPhysicalDeviceSurfaceFormatsKHR(): |
| 1710 | if (!pPhysicalDevice || !pPhysicalDevice->surfaceFormatCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1711 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1712 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1713 | "vkCreateSwapchainKHR() called before calling vkGetPhysicalDeviceSurfaceFormatsKHR()."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1714 | } else if (pCreateInfo) { |
| 1715 | // Validate pCreateInfo->imageFormat against |
| 1716 | // VkSurfaceFormatKHR::format: |
| 1717 | bool foundFormat = false; |
| 1718 | bool foundColorSpace = false; |
| 1719 | bool foundMatch = false; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1720 | for (uint32_t i = 0; i < pPhysicalDevice->surfaceFormatCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1721 | if (pCreateInfo->imageFormat == pPhysicalDevice->pSurfaceFormats[i].format) { |
| 1722 | // Validate pCreateInfo->imageColorSpace against |
| 1723 | // VkSurfaceFormatKHR::colorSpace: |
| 1724 | foundFormat = true; |
| 1725 | if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) { |
| 1726 | foundMatch = true; |
| 1727 | break; |
| 1728 | } |
| 1729 | } else { |
| 1730 | if (pCreateInfo->imageColorSpace == pPhysicalDevice->pSurfaceFormats[i].colorSpace) { |
| 1731 | foundColorSpace = true; |
| 1732 | } |
| 1733 | } |
| 1734 | } |
| 1735 | if (!foundMatch) { |
| 1736 | if (!foundFormat) { |
| 1737 | if (!foundColorSpace) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1738 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1739 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1740 | "vkCreateSwapchainKHR() called with neither a supported pCreateInfo->imageFormat " |
| 1741 | "(i.e. %d) nor a supported " |
| 1742 | "pCreateInfo->imageColorSpace (i.e. %d).", |
| 1743 | pCreateInfo->imageFormat, pCreateInfo->imageColorSpace); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1744 | } else { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1745 | skip_call |= |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1746 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1747 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1748 | "vkCreateSwapchainKHR() called with a non-supported pCreateInfo->imageFormat (i.e. %d)", |
| 1749 | pCreateInfo->imageFormat); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1750 | } |
| 1751 | } else if (!foundColorSpace) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1752 | skip_call |= |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1753 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1754 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1755 | "vkCreateSwapchainKHR() called with a non-supported pCreateInfo->imageColorSpace (i.e. %d).", |
| 1756 | pCreateInfo->imageColorSpace); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1757 | } |
| 1758 | } |
| 1759 | } |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1760 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1761 | // Validate pCreateInfo values with the results of |
| 1762 | // vkGetPhysicalDeviceSurfacePresentModesKHR(): |
| 1763 | if (!pPhysicalDevice || !pPhysicalDevice->presentModeCount) { |
szdarkhack | fb287d3 | 2016-03-12 18:41:19 +0200 | [diff] [blame] | 1764 | if (!pCreateInfo || (pCreateInfo->presentMode != VK_PRESENT_MODE_FIFO_KHR)) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1765 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1766 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1767 | "vkCreateSwapchainKHR() called before calling " |
| 1768 | "vkGetPhysicalDeviceSurfacePresentModesKHR()."); |
szdarkhack | fb287d3 | 2016-03-12 18:41:19 +0200 | [diff] [blame] | 1769 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1770 | } else if (pCreateInfo) { |
| 1771 | // Validate pCreateInfo->presentMode against |
| 1772 | // vkGetPhysicalDeviceSurfacePresentModesKHR(): |
| 1773 | bool foundMatch = false; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1774 | for (uint32_t i = 0; i < pPhysicalDevice->presentModeCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1775 | if (pPhysicalDevice->pPresentModes[i] == pCreateInfo->presentMode) { |
| 1776 | foundMatch = true; |
| 1777 | break; |
| 1778 | } |
| 1779 | } |
| 1780 | if (!foundMatch) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1781 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1782 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1783 | "vkCreateSwapchainKHR() called with a non-supported pCreateInfo->presentMode (i.e. %s).", |
| 1784 | presentModeStr(pCreateInfo->presentMode)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1785 | } |
| 1786 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1787 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1788 | // Validate pCreateInfo->imageSharingMode and related values: |
| 1789 | if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1790 | if ((pCreateInfo->queueFamilyIndexCount <= 1) || !pCreateInfo->pQueueFamilyIndices) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1791 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1792 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1793 | "vkCreateSwapchainKHR() called with a supported pCreateInfo->sharingMode of (i.e. %s), but with a " |
| 1794 | "bad value(s) for pCreateInfo->queueFamilyIndexCount or pCreateInfo->pQueueFamilyIndices).", |
| 1795 | sharingModeStr(pCreateInfo->imageSharingMode)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1796 | } |
| 1797 | } else if (pCreateInfo->imageSharingMode != VK_SHARING_MODE_EXCLUSIVE) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1798 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1799 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_BAD_SHARING_MODE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1800 | "vkCreateSwapchainKHR() called with a non-supported pCreateInfo->imageSharingMode (i.e. %s).", |
| 1801 | sharingModeStr(pCreateInfo->imageSharingMode)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1802 | } |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1803 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1804 | // Validate pCreateInfo->clipped: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1805 | if (pCreateInfo && (pCreateInfo->clipped != VK_FALSE) && (pCreateInfo->clipped != VK_TRUE)) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1806 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1807 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_BAD_BOOL, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1808 | "vkCreateSwapchainKHR() called with a VkBool32 value that is neither VK_TRUE nor VK_FALSE, but " |
| 1809 | "has the numeric value of %d.", |
| 1810 | pCreateInfo->clipped); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1811 | } |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 1812 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1813 | // Validate pCreateInfo->oldSwapchain: |
| 1814 | if (pCreateInfo && pCreateInfo->oldSwapchain) { |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1815 | SwpSwapchain *pOldSwapchain = NULL; |
| 1816 | { |
| 1817 | auto it = my_data->swapchainMap.find(pCreateInfo->oldSwapchain); |
| 1818 | pOldSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 1819 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1820 | if (pOldSwapchain) { |
| 1821 | if (device != pOldSwapchain->pDevice->device) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1822 | skip_call |= log_msg( |
| 1823 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, reinterpret_cast<uint64_t>(device), |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1824 | __LINE__, SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE, swapchain_layer_name, |
| 1825 | "vkCreateSwapchainKHR() called with a different VkDevice than the VkSwapchainKHR was created with."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1826 | } |
| 1827 | if (pCreateInfo->surface != pOldSwapchain->pSurface->surface) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1828 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1829 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1830 | "vkCreateSwapchainKHR() called with pCreateInfo->oldSwapchain pCreateInfo->surface."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1831 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1834 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1835 | return skip_call; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1836 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1837 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1838 | VKAPI_ATTR VkResult VKAPI_CALL CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 1839 | const VkAllocationCallbacks *pAllocator, |
| 1840 | VkSwapchainKHR *pSwapchain) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1841 | VkResult result = VK_SUCCESS; |
| 1842 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1843 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1844 | bool skip_call = validateCreateSwapchainKHR(device, pCreateInfo, pSwapchain); |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1845 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1846 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1847 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1848 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1849 | result = my_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1850 | lock.lock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1851 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1852 | if (result == VK_SUCCESS) { |
| 1853 | // Remember the swapchain's handle, and link it to the device: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1854 | SwpDevice *pDevice = NULL; |
| 1855 | { |
| 1856 | auto it = my_data->deviceMap.find(device); |
| 1857 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 1858 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1859 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1860 | my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain; |
| 1861 | if (pDevice) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1862 | pDevice->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1863 | } |
| 1864 | my_data->swapchainMap[*pSwapchain].pDevice = pDevice; |
| 1865 | my_data->swapchainMap[*pSwapchain].imageCount = 0; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1866 | my_data->swapchainMap[*pSwapchain].usedAllocatorToCreate = (pAllocator != NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1867 | // Store a pointer to the surface |
| 1868 | SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1869 | SwpInstance *pInstance = (pPhysicalDevice) ? pPhysicalDevice->pInstance : NULL; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1870 | layer_data *my_instance_data = |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1871 | ((pInstance) ? get_my_data_ptr(get_dispatch_key(pInstance->instance), layer_data_map) : NULL); |
| 1872 | SwpSurface *pSurface = ((my_data && pCreateInfo) ? &my_instance_data->surfaceMap[pCreateInfo->surface] : NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1873 | my_data->swapchainMap[*pSwapchain].pSurface = pSurface; |
| 1874 | if (pSurface) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1875 | pSurface->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1876 | } |
| 1877 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1878 | lock.unlock(); |
| 1879 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1880 | return result; |
| 1881 | } |
| 1882 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1883 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1884 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1885 | VKAPI_ATTR void VKAPI_CALL |
| 1886 | DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1887 | // TODOs: |
| 1888 | // |
| 1889 | // - Implement a check for validity language that reads: All uses of |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 1890 | // presentable images acquired from pname:swapchain must: have completed |
| 1891 | // execution |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1892 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1893 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1894 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1895 | SwpDevice *pDevice = NULL; |
| 1896 | { |
| 1897 | auto it = my_data->deviceMap.find(device); |
| 1898 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 1899 | } |
Ian Elliott | 8b9e256 | 2016-01-05 13:00:50 -0700 | [diff] [blame] | 1900 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1901 | // Validate that the swapchain extension was enabled: |
| 1902 | if (pDevice && !pDevice->swapchainExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1903 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1904 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1905 | "vkDestroySwapchainKHR() called even though the %s extension was not enabled for this VkDevice.", |
| 1906 | VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1907 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1908 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1909 | // Regardless of skip_call value, do some internal cleanup: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1910 | SwpSwapchain *pSwapchain = NULL; |
| 1911 | { |
| 1912 | auto it = my_data->swapchainMap.find(swapchain); |
| 1913 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 1914 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1915 | if (pSwapchain) { |
| 1916 | // Delete the SwpSwapchain associated with this swapchain: |
| 1917 | if (pSwapchain->pDevice) { |
| 1918 | pSwapchain->pDevice->swapchains.erase(swapchain); |
| 1919 | if (device != pSwapchain->pDevice->device) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1920 | skip_call |= |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1921 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1922 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1923 | "vkDestroySwapchainKHR() called with a different VkDevice than the VkSwapchainKHR was created with."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1924 | } |
| 1925 | } |
| 1926 | if (pSwapchain->pSurface) { |
| 1927 | pSwapchain->pSurface->swapchains.erase(swapchain); |
| 1928 | } |
| 1929 | if (pSwapchain->imageCount) { |
| 1930 | pSwapchain->images.clear(); |
| 1931 | } |
| 1932 | if ((pAllocator != NULL) != pSwapchain->usedAllocatorToCreate) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1933 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1934 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_INCOMPATIBLE_ALLOCATOR, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1935 | "vkDestroySwapchainKHR() called with incompatible pAllocator from when the object was created."); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1936 | } |
| 1937 | my_data->swapchainMap.erase(swapchain); |
| 1938 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1939 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1940 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1941 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1942 | // Call down the call chain: |
| 1943 | my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator); |
| 1944 | } |
| 1945 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1946 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1947 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1948 | GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1949 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1950 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1951 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1952 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1953 | SwpDevice *pDevice = NULL; |
| 1954 | { |
| 1955 | auto it = my_data->deviceMap.find(device); |
| 1956 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 1957 | } |
Ian Elliott | 8b9e256 | 2016-01-05 13:00:50 -0700 | [diff] [blame] | 1958 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1959 | // Validate that the swapchain extension was enabled: |
| 1960 | if (pDevice && !pDevice->swapchainExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1961 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1962 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 1963 | "vkGetSwapchainImagesKHR() called even though the %s extension was not enabled for this VkDevice.", |
| 1964 | VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1965 | } |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1966 | SwpSwapchain *pSwapchain = NULL; |
| 1967 | { |
| 1968 | auto it = my_data->swapchainMap.find(swapchain); |
| 1969 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 1970 | } |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1971 | if (pSwapchain && pSwapchainImages) { |
| 1972 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1973 | if (pSwapchain->imageCount == 0) { |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1974 | // Since we haven't recorded a preliminary value of *pSwapchainImageCount, that likely means that the application didn't |
| 1975 | // previously call this function with a NULL value of pSwapchainImages: |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1976 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1977 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_PRIOR_COUNT, swapchain_layer_name, |
Mark Lobodzinski | ca708d9 | 2016-08-08 10:29:34 -0600 | [diff] [blame] | 1978 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive " |
| 1979 | "value has been seen for pSwapchainImages."); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1980 | } else if (*pSwapchainImageCount > pSwapchain->imageCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1981 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1982 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_INVALID_COUNT, swapchain_layer_name, |
Mark Lobodzinski | 2511de1 | 2016-08-08 10:18:49 -0600 | [diff] [blame] | 1983 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount, and with " |
| 1984 | "pSwapchainImages set to a value (%d) that is greater than the value (%d) that was returned when " |
| 1985 | "pSwapchainImageCount was NULL.", |
| 1986 | *pSwapchainImageCount, pSwapchain->imageCount); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1987 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1988 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1989 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1990 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 1991 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1992 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1993 | result = my_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1994 | lock.lock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1995 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1996 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1997 | { |
| 1998 | auto it = my_data->swapchainMap.find(swapchain); |
| 1999 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 2000 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2001 | if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages && pSwapchainImageCount) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2002 | // Record the result of this preliminary query: |
| 2003 | pSwapchain->imageCount = *pSwapchainImageCount; |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 2004 | } else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages && |
| 2005 | pSwapchainImageCount && (*pSwapchainImageCount > 0)) { |
| 2006 | // Record the images and their state: |
| 2007 | pSwapchain->imageCount = *pSwapchainImageCount; |
| 2008 | for (uint32_t i = 0; i < *pSwapchainImageCount; i++) { |
| 2009 | pSwapchain->images[i].image = pSwapchainImages[i]; |
| 2010 | pSwapchain->images[i].pSwapchain = pSwapchain; |
| 2011 | pSwapchain->images[i].acquiredByApp = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 2014 | lock.unlock(); |
| 2015 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2016 | return result; |
| 2017 | } |
| 2018 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 2019 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2020 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2021 | VKAPI_ATTR VkResult VKAPI_CALL AcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 2022 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2023 | // TODOs: |
| 2024 | // |
| 2025 | // - Address the timeout. Possibilities include looking at the state of the |
| 2026 | // swapchain's images, depending on the timeout value. |
| 2027 | // - Implement a check for validity language that reads: If pname:semaphore is |
| 2028 | // not sname:VK_NULL_HANDLE it must: be unsignalled |
| 2029 | // - Implement a check for validity language that reads: If pname:fence is not |
| 2030 | // sname:VK_NULL_HANDLE it must: be unsignalled and mustnot: be associated |
| 2031 | // with any other queue command that has not yet completed execution on that |
| 2032 | // queue |
| 2033 | // - Record/update the state of the swapchain, in case an error occurs |
| 2034 | // (e.g. VK_ERROR_OUT_OF_DATE_KHR). |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2035 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2036 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2037 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 2038 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 2039 | SwpDevice *pDevice = NULL; |
| 2040 | { |
| 2041 | auto it = my_data->deviceMap.find(device); |
| 2042 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 2043 | } |
Ian Elliott | 8b9e256 | 2016-01-05 13:00:50 -0700 | [diff] [blame] | 2044 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2045 | // Validate that the swapchain extension was enabled: |
| 2046 | if (pDevice && !pDevice->swapchainExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2047 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 2048 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 2049 | "vkAcquireNextImageKHR() called even though the %s extension was not enabled for this VkDevice.", |
| 2050 | VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2051 | } |
Ian Elliott | fa8f032 | 2016-03-23 08:28:54 -0600 | [diff] [blame] | 2052 | if ((semaphore == VK_NULL_HANDLE) && (fence == VK_NULL_HANDLE)) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2053 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 2054 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_NO_SYNC_FOR_ACQUIRE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 2055 | "vkAcquireNextImageKHR() called with both the semaphore and fence parameters set to VK_NULL_HANDLE (at " |
| 2056 | "least one should be used)."); |
Ian Elliott | fa8f032 | 2016-03-23 08:28:54 -0600 | [diff] [blame] | 2057 | } |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 2058 | SwpSwapchain *pSwapchain = NULL; |
| 2059 | { |
| 2060 | auto it = my_data->swapchainMap.find(swapchain); |
| 2061 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 2062 | } |
Ian Elliott | 5c68028 | 2016-04-06 14:29:56 -0600 | [diff] [blame] | 2063 | SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice; |
| 2064 | if (pSwapchain && pPhysicalDevice && pPhysicalDevice->gotSurfaceCapabilities) { |
| 2065 | // Look to see if the application has already acquired the maximum |
| 2066 | // number of images, and this will push it past the spec-defined |
| 2067 | // limits: |
| 2068 | uint32_t minImageCount = pPhysicalDevice->surfaceCapabilities.minImageCount; |
| 2069 | uint32_t imagesAcquiredByApp = 0; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2070 | for (uint32_t i = 0; i < pSwapchain->imageCount; i++) { |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 2071 | if (pSwapchain->images[i].acquiredByApp) { |
Ian Elliott | 5c68028 | 2016-04-06 14:29:56 -0600 | [diff] [blame] | 2072 | imagesAcquiredByApp++; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2073 | } |
| 2074 | } |
Ian Elliott | 5c68028 | 2016-04-06 14:29:56 -0600 | [diff] [blame] | 2075 | if (imagesAcquiredByApp > (pSwapchain->imageCount - minImageCount)) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2076 | skip_call |= log_msg( |
| 2077 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, reinterpret_cast<uint64_t>(device), |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 2078 | __LINE__, SWAPCHAIN_APP_ACQUIRES_TOO_MANY_IMAGES, swapchain_layer_name, |
| 2079 | "vkAcquireNextImageKHR() called when it cannot succeed. The application has acquired %d image(s) that have not yet " |
| 2080 | "been presented. The maximum number of images that the application can simultaneously acquire from this swapchain " |
| 2081 | "(including this call to vkCreateSwapchainKHR()) is %d. That value is derived by subtracting " |
| 2082 | "VkSurfaceCapabilitiesKHR::minImageCount (%d) from the number of images in the swapchain (%d) and adding 1.", |
| 2083 | imagesAcquiredByApp, (pSwapchain->imageCount - minImageCount + 1), minImageCount, pSwapchain->imageCount); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2084 | } |
| 2085 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 2086 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2087 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2088 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2089 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2090 | result = my_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 2091 | lock.lock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2092 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 2093 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 2094 | { |
| 2095 | auto it = my_data->swapchainMap.find(swapchain); |
| 2096 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 2097 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2098 | if (((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR)) && pSwapchain) { |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 2099 | // Change the state of the image (now acquired by the application): |
| 2100 | pSwapchain->images[*pImageIndex].acquiredByApp = true; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2101 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 2102 | lock.unlock(); |
| 2103 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2104 | return result; |
| 2105 | } |
| 2106 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 2107 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2108 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2109 | VKAPI_ATTR VkResult VKAPI_CALL QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2110 | // TODOs: |
| 2111 | // |
| 2112 | // - Implement a check for validity language that reads: Any given element of |
| 2113 | // sname:VkSemaphore in pname:pWaitSemaphores must: refer to a prior signal |
| 2114 | // of that sname:VkSemaphore that won't be consumed by any other wait on that |
| 2115 | // semaphore |
| 2116 | // - Record/update the state of the swapchain, in case an error occurs |
| 2117 | // (e.g. VK_ERROR_OUT_OF_DATE_KHR). |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2118 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2119 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2120 | 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] | 2121 | |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 2122 | // Note: pPresentInfo->pResults is allowed to be NULL |
Ian Elliott | 046ed2c | 2015-12-30 17:07:17 -0700 | [diff] [blame] | 2123 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 2124 | std::unique_lock<std::mutex> lock(global_lock); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2125 | for (uint32_t i = 0; pPresentInfo && (i < pPresentInfo->swapchainCount); i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2126 | uint32_t index = pPresentInfo->pImageIndices[i]; |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 2127 | SwpSwapchain *pSwapchain = NULL; |
| 2128 | { |
| 2129 | auto it = my_data->swapchainMap.find(pPresentInfo->pSwapchains[i]); |
| 2130 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 2131 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2132 | if (pSwapchain) { |
| 2133 | if (!pSwapchain->pDevice->swapchainExtensionEnabled) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2134 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 2135 | reinterpret_cast<uint64_t>(pSwapchain->pDevice->device), __LINE__, |
| 2136 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, swapchain_layer_name, |
| 2137 | "vkQueuePresentKHR() called even though the %s extension was not enabled for this VkDevice.", |
| 2138 | VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2139 | } |
| 2140 | if (index >= pSwapchain->imageCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2141 | skip_call |= |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 2142 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2143 | reinterpret_cast<const uint64_t &>(pPresentInfo->pSwapchains[i]), __LINE__, SWAPCHAIN_INDEX_TOO_LARGE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 2144 | "vkQueuePresentKHR() called for an index that is too large (i.e. %d). There are only %d images in " |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2145 | "this VkSwapchainKHR.", |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 2146 | index, pSwapchain->imageCount); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2147 | } else { |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 2148 | if (!pSwapchain->images[index].acquiredByApp) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2149 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 2150 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2151 | reinterpret_cast<const uint64_t &>(pPresentInfo->pSwapchains[i]), __LINE__, SWAPCHAIN_INDEX_NOT_IN_USE, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 2152 | "vkQueuePresentKHR() returned an index (i.e. %d) for an image that is not acquired by the application.", |
| 2153 | index); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2154 | } |
| 2155 | } |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 2156 | SwpQueue *pQueue = NULL; |
| 2157 | { |
| 2158 | auto it = my_data->queueMap.find(queue); |
| 2159 | pQueue = (it == my_data->queueMap.end()) ? NULL : &it->second; |
| 2160 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2161 | SwpSurface *pSurface = pSwapchain->pSurface; |
| 2162 | if (pQueue && pSurface && pSurface->numQueueFamilyIndexSupport) { |
| 2163 | uint32_t queueFamilyIndex = pQueue->queueFamilyIndex; |
| 2164 | // Note: the 1st test is to ensure queueFamilyIndex is in range, |
| 2165 | // and the 2nd test is the validation check: |
| 2166 | if ((pSurface->numQueueFamilyIndexSupport > queueFamilyIndex) && |
| 2167 | (!pSurface->pQueueFamilyIndexSupport[queueFamilyIndex])) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2168 | skip_call |= |
| 2169 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, |
| 2170 | reinterpret_cast<const uint64_t &>(pPresentInfo->pSwapchains[i]), __LINE__, |
| 2171 | SWAPCHAIN_SURFACE_NOT_SUPPORTED_WITH_QUEUE, swapchain_layer_name, |
| 2172 | "vkQueuePresentKHR() called with a swapchain whose surface is not supported for presention " |
| 2173 | "on this device with the queueFamilyIndex (i.e. %d) of the given queue.", |
| 2174 | queueFamilyIndex); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2175 | } |
| 2176 | } |
| 2177 | } |
| 2178 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 2179 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2180 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2181 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2182 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2183 | result = my_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 2184 | lock.lock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2185 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2186 | if (pPresentInfo && ((result == VK_SUCCESS) || (result == VK_SUBOPTIMAL_KHR))) { |
| 2187 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2188 | int index = pPresentInfo->pImageIndices[i]; |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 2189 | SwpSwapchain *pSwapchain = NULL; |
| 2190 | { |
| 2191 | auto it = my_data->swapchainMap.find(pPresentInfo->pSwapchains[i]); |
| 2192 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 2193 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2194 | if (pSwapchain) { |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 2195 | // Change the state of the image (no longer acquired by the |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2196 | // application): |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 2197 | pSwapchain->images[index].acquiredByApp = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 2201 | lock.unlock(); |
| 2202 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2203 | return result; |
| 2204 | } |
| 2205 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 2206 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2207 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2208 | VKAPI_ATTR void VKAPI_CALL |
| 2209 | GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2210 | bool skip_call = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2211 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 2212 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame^] | 2213 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2214 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2215 | my_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 2216 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2217 | // Remember the queue's handle, and link it to the device: |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 2218 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 2219 | SwpDevice *pDevice = NULL; |
| 2220 | { |
| 2221 | auto it = my_data->deviceMap.find(device); |
| 2222 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 2223 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2224 | my_data->queueMap[&pQueue].queue = *pQueue; |
| 2225 | if (pDevice) { |
| 2226 | pDevice->queues[*pQueue] = &my_data->queueMap[*pQueue]; |
| 2227 | } |
| 2228 | my_data->queueMap[&pQueue].pDevice = pDevice; |
| 2229 | my_data->queueMap[&pQueue].queueFamilyIndex = queueFamilyIndex; |
| 2230 | } |
| 2231 | } |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 2232 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2233 | VKAPI_ATTR VkResult VKAPI_CALL |
| 2234 | CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 2235 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2236 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2237 | VkResult result = |
| 2238 | my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2239 | if (VK_SUCCESS == result) { |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 2240 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 2241 | result = layer_create_msg_callback(my_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2242 | } |
| 2243 | return result; |
| 2244 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2245 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2246 | VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, |
| 2247 | VkDebugReportCallbackEXT msgCallback, |
| 2248 | const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2249 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 2250 | my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 2251 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2252 | layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator); |
| 2253 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2254 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2255 | VKAPI_ATTR void VKAPI_CALL |
| 2256 | DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, |
| 2257 | size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2258 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2259 | my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, |
| 2260 | pMsg); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2261 | } |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 2262 | |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 2263 | VKAPI_ATTR VkResult VKAPI_CALL |
| 2264 | EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
| 2265 | return util_GetLayerProperties(1, &swapchain_layer, pCount, pProperties); |
| 2266 | } |
| 2267 | |
| 2268 | VKAPI_ATTR VkResult VKAPI_CALL |
| 2269 | EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) { |
| 2270 | return util_GetLayerProperties(1, &swapchain_layer, pCount, pProperties); |
| 2271 | } |
| 2272 | |
| 2273 | VKAPI_ATTR VkResult VKAPI_CALL |
| 2274 | EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) { |
| 2275 | if (pLayerName && !strcmp(pLayerName, swapchain_layer.layerName)) |
| 2276 | return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties); |
| 2277 | |
| 2278 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 2279 | } |
| 2280 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2281 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 2282 | const char *pLayerName, uint32_t *pCount, |
| 2283 | VkExtensionProperties *pProperties) { |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 2284 | if (pLayerName && !strcmp(pLayerName, swapchain_layer.layerName)) |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 2285 | return util_GetExtensionProperties(0, nullptr, pCount, pProperties); |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 2286 | |
| 2287 | assert(physicalDevice); |
| 2288 | |
| 2289 | dispatch_key key = get_dispatch_key(physicalDevice); |
| 2290 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 2291 | return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 2292 | } |
| 2293 | |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2294 | static PFN_vkVoidFunction |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2295 | intercept_core_instance_command(const char *name); |
| 2296 | |
| 2297 | static PFN_vkVoidFunction |
| 2298 | intercept_khr_surface_command(const char *name, VkInstance instance); |
| 2299 | |
| 2300 | static PFN_vkVoidFunction |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2301 | intercept_core_device_command(const char *name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 2302 | |
Chia-I Wu | 8324595 | 2016-05-05 16:13:19 +0800 | [diff] [blame] | 2303 | static PFN_vkVoidFunction |
| 2304 | intercept_khr_swapchain_command(const char *name, VkDevice dev); |
| 2305 | |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2306 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { |
| 2307 | PFN_vkVoidFunction proc = intercept_core_device_command(funcName); |
| 2308 | if (proc) |
| 2309 | return proc; |
| 2310 | |
| 2311 | assert(device); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2312 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2313 | layer_data *my_data; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2314 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2315 | my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Courtney Goeltzenleuchter | 1e9e6c8 | 2016-03-19 10:38:52 -0600 | [diff] [blame] | 2316 | VkLayerDispatchTable *pDisp = my_data->device_dispatch_table; |
Chia-I Wu | 8324595 | 2016-05-05 16:13:19 +0800 | [diff] [blame] | 2317 | |
| 2318 | proc = intercept_khr_swapchain_command(funcName, device); |
| 2319 | if (proc) |
| 2320 | return proc; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 2321 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2322 | if (pDisp->GetDeviceProcAddr == NULL) |
| 2323 | return NULL; |
| 2324 | return pDisp->GetDeviceProcAddr(device, funcName); |
| 2325 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2326 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2327 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2328 | PFN_vkVoidFunction proc = intercept_core_instance_command(funcName); |
Chia-I Wu | 5ae2f65 | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 2329 | if (!proc) |
| 2330 | proc = intercept_core_device_command(funcName); |
| 2331 | if (!proc) |
| 2332 | proc = intercept_khr_swapchain_command(funcName, VK_NULL_HANDLE); |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2333 | if (proc) |
| 2334 | return proc; |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 2335 | |
Chia-I Wu | 5ae2f65 | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 2336 | assert(instance); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2337 | |
| 2338 | layer_data *my_data; |
| 2339 | my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 2340 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 2341 | |
Chia-I Wu | 5ae2f65 | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 2342 | proc = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
| 2343 | if (!proc) |
| 2344 | proc = intercept_khr_surface_command(funcName, instance); |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2345 | if (proc) |
| 2346 | return proc; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2347 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 2348 | if (pTable->GetInstanceProcAddr == NULL) |
| 2349 | return NULL; |
| 2350 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 2351 | } |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 2352 | |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2353 | static PFN_vkVoidFunction |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2354 | intercept_core_instance_command(const char *name) { |
| 2355 | static const struct { |
| 2356 | const char *name; |
| 2357 | PFN_vkVoidFunction proc; |
| 2358 | } core_instance_commands[] = { |
| 2359 | { "vkGetInstanceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr) }, |
| 2360 | { "vkCreateInstance", reinterpret_cast<PFN_vkVoidFunction>(CreateInstance) }, |
| 2361 | { "vkDestroyInstance", reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance) }, |
| 2362 | { "vkCreateDevice", reinterpret_cast<PFN_vkVoidFunction>(CreateDevice) }, |
| 2363 | { "vkEnumeratePhysicalDevices", reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices) }, |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 2364 | { "vkEnumerateInstanceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceLayerProperties) }, |
| 2365 | { "vkEnumerateDeviceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceLayerProperties) }, |
| 2366 | { "vkEnumerateInstanceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties) }, |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2367 | { "vkEnumerateDeviceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties) }, |
| 2368 | { "vkGetPhysicalDeviceQueueFamilyProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties) }, |
| 2369 | }; |
| 2370 | |
| 2371 | for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++) { |
| 2372 | if (!strcmp(core_instance_commands[i].name, name)) |
| 2373 | return core_instance_commands[i].proc; |
| 2374 | } |
| 2375 | |
| 2376 | return nullptr; |
| 2377 | } |
| 2378 | |
| 2379 | static PFN_vkVoidFunction |
| 2380 | intercept_khr_surface_command(const char *name, VkInstance instance) { |
| 2381 | static const struct { |
| 2382 | const char *name; |
| 2383 | PFN_vkVoidFunction proc; |
| 2384 | } khr_surface_commands[] = { |
| 2385 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 2386 | { "vkCreateAndroidSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateAndroidSurfaceKHR) }, |
| 2387 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 2388 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 2389 | { "vkCreateMirSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateMirSurfaceKHR) }, |
| 2390 | { "vkGetPhysicalDeviceMirPresentationSupportKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMirPresentationSupportKHR) }, |
| 2391 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 2392 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 2393 | { "vkCreateWaylandSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateWaylandSurfaceKHR) }, |
| 2394 | { "vkGetPhysicalDeviceWaylandPresentationSupportKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceWaylandPresentationSupportKHR) }, |
| 2395 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 2396 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 2397 | { "vkCreateWin32SurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateWin32SurfaceKHR) }, |
| 2398 | { "vkGetPhysicalDeviceWin32PresentationSupportKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceWin32PresentationSupportKHR) }, |
| 2399 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 2400 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 2401 | { "vkCreateXcbSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateXcbSurfaceKHR) }, |
| 2402 | { "vkGetPhysicalDeviceXcbPresentationSupportKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceXcbPresentationSupportKHR) }, |
| 2403 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2404 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 2405 | { "vkCreateXlibSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateXlibSurfaceKHR) }, |
| 2406 | { "vkGetPhysicalDeviceXlibPresentationSupportKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceXlibPresentationSupportKHR) }, |
| 2407 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 2408 | { "vkDestroySurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(DestroySurfaceKHR) }, |
| 2409 | { "vkGetPhysicalDeviceSurfaceSupportKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceSupportKHR) }, |
| 2410 | { "vkGetPhysicalDeviceSurfaceCapabilitiesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilitiesKHR) }, |
| 2411 | { "vkGetPhysicalDeviceSurfaceFormatsKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormatsKHR) }, |
| 2412 | { "vkGetPhysicalDeviceSurfacePresentModesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfacePresentModesKHR) }, |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 2413 | { "vkGetPhysicalDeviceDisplayPropertiesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceDisplayPropertiesKHR) }, |
| 2414 | { "vkGetPhysicalDeviceDisplayPlanePropertiesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceDisplayPlanePropertiesKHR) }, |
| 2415 | { "vkGetDisplayPlaneSupportedDisplaysKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayPlaneSupportedDisplaysKHR) }, |
| 2416 | { "vkGetDisplayModePropertiesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayModePropertiesKHR) }, |
| 2417 | { "vkCreateDisplayModeKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateDisplayModeKHR) }, |
| 2418 | { "vkGetDisplayPlaneCapabilitiesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayPlaneCapabilitiesKHR) }, |
| 2419 | { "vkCreateDisplayPlaneSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateDisplayPlaneSurfaceKHR) }, |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2420 | }; |
| 2421 | |
| 2422 | // do not check if VK_KHR_*_surface is enabled (why?) |
| 2423 | |
| 2424 | for (size_t i = 0; i < ARRAY_SIZE(khr_surface_commands); i++) { |
| 2425 | if (!strcmp(khr_surface_commands[i].name, name)) |
| 2426 | return khr_surface_commands[i].proc; |
| 2427 | } |
| 2428 | |
| 2429 | return nullptr; |
| 2430 | } |
| 2431 | |
| 2432 | static PFN_vkVoidFunction |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 2433 | intercept_core_device_command(const char *name) { |
| 2434 | static const struct { |
| 2435 | const char *name; |
| 2436 | PFN_vkVoidFunction proc; |
| 2437 | } core_device_commands[] = { |
| 2438 | { "vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr) }, |
| 2439 | { "vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice) }, |
| 2440 | { "vkGetDeviceQueue", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue) }, |
| 2441 | }; |
| 2442 | |
| 2443 | for (size_t i = 0; i < ARRAY_SIZE(core_device_commands); i++) { |
| 2444 | if (!strcmp(core_device_commands[i].name, name)) |
| 2445 | return core_device_commands[i].proc; |
| 2446 | } |
| 2447 | |
| 2448 | return nullptr; |
| 2449 | } |
| 2450 | |
Chia-I Wu | 8324595 | 2016-05-05 16:13:19 +0800 | [diff] [blame] | 2451 | static PFN_vkVoidFunction |
| 2452 | intercept_khr_swapchain_command(const char *name, VkDevice dev) { |
| 2453 | static const struct { |
| 2454 | const char *name; |
| 2455 | PFN_vkVoidFunction proc; |
| 2456 | } khr_swapchain_commands[] = { |
| 2457 | { "vkCreateSwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR) }, |
| 2458 | { "vkDestroySwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR) }, |
| 2459 | { "vkGetSwapchainImagesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR) }, |
| 2460 | { "vkAcquireNextImageKHR", reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImageKHR) }, |
| 2461 | { "vkQueuePresentKHR", reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR) }, |
| 2462 | }; |
| 2463 | |
| 2464 | // do not check if VK_KHR_swapchain is enabled (why?) |
| 2465 | |
| 2466 | for (size_t i = 0; i < ARRAY_SIZE(khr_swapchain_commands); i++) { |
| 2467 | if (!strcmp(khr_swapchain_commands[i].name, name)) |
| 2468 | return khr_swapchain_commands[i].proc; |
| 2469 | } |
| 2470 | |
| 2471 | return nullptr; |
| 2472 | } |
| 2473 | |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2474 | } // namespace swapchain |
| 2475 | |
| 2476 | // vk_layer_logging.h expects these to be defined |
| 2477 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2478 | VKAPI_ATTR VkResult VKAPI_CALL |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2479 | vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 2480 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2481 | return swapchain::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2482 | } |
| 2483 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2484 | VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2485 | VkDebugReportCallbackEXT msgCallback, |
| 2486 | const VkAllocationCallbacks *pAllocator) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2487 | swapchain::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2488 | } |
| 2489 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2490 | VKAPI_ATTR void VKAPI_CALL |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2491 | vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, |
| 2492 | size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2493 | swapchain::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2494 | } |
| 2495 | |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 2496 | // loader-layer interface v0, just wrappers since there is only a layer |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2497 | |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 2498 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 2499 | vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 2500 | return swapchain::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 2504 | vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 2505 | return swapchain::EnumerateInstanceLayerProperties(pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 2509 | vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 2510 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 2511 | assert(physicalDevice == VK_NULL_HANDLE); |
| 2512 | return swapchain::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 2516 | const char *pLayerName, uint32_t *pCount, |
| 2517 | VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 2518 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 2519 | assert(physicalDevice == VK_NULL_HANDLE); |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 2520 | return swapchain::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2524 | return swapchain::GetDeviceProcAddr(dev, funcName); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 2528 | return swapchain::GetInstanceProcAddr(instance, funcName); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 2529 | } |