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