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 | |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 22 | // For Windows, this #include must come before other Vk headers. |
| 23 | #include <vk_loader_platform.h> |
| 24 | |
| 25 | #include "swapchain.h" |
| 26 | #include "vk_enum_string_helper.h" |
| 27 | #include "vk_layer_extension_utils.h" |
| 28 | #include "vk_layer_utils.h" |
| 29 | #include "vk_validation_error_messages.h" |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 30 | #include <mutex> |
Ian Elliott | d8c5db1 | 2015-10-07 11:32:31 -0600 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <string.h> |
Cody Northrop | d08141b | 2016-02-01 09:52:07 -0700 | [diff] [blame] | 33 | #include <vulkan/vk_icd.h> |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 34 | |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 35 | namespace swapchain { |
| 36 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 37 | static std::mutex global_lock; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 38 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 39 | // The following is for logging error messages: |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 40 | static std::unordered_map<void *, layer_data *> layer_data_map; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 41 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 42 | static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 43 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 44 | 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] | 45 | |
Chia-I Wu | 40e25e7 | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 46 | static const VkLayerProperties swapchain_layer = { |
Jon Ashburn | dc9111c | 2016-03-22 12:57:13 -0600 | [diff] [blame] | 47 | "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] | 48 | }; |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 49 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 50 | static void checkDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, VkDevice device) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 51 | layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 52 | layer_data *my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 53 | |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 54 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 55 | { |
| 56 | auto it = my_instance_data->physicalDeviceMap.find(physicalDevice); |
| 57 | pPhysicalDevice = (it == my_instance_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 58 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 59 | if (pPhysicalDevice) { |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 60 | my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice; |
| 61 | pPhysicalDevice->pDevice = &my_device_data->deviceMap[device]; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 62 | } else { |
Ian Elliott | 07adb11 | 2016-01-05 12:51:03 -0700 | [diff] [blame] | 63 | // TBD: Should we leave error in (since Swapchain really needs this |
| 64 | // link)? |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 65 | log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 66 | HandleToUint64(physicalDevice), __LINE__, VALIDATION_ERROR_00031, "Swapchain", |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 67 | "vkCreateDevice() called with a non-valid VkPhysicalDevice. %s", validation_error_map[VALIDATION_ERROR_00031]); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 68 | } |
Mark Lobodzinski | 55cd49b | 2015-11-27 15:23:23 -0700 | [diff] [blame] | 69 | my_device_data->deviceMap[device].device = device; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 70 | } |
| 71 | |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 72 | static void checkInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 73 | uint32_t i; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 74 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 75 | |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 76 | // Remember this instance, and whether the VK_KHR_surface extension |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 77 | // was enabled for it: |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 78 | my_data->instanceMap[instance].instance = instance; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 79 | my_data->instanceMap[instance].displayExtensionEnabled = false; |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 80 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 81 | // Look for one or more debug report create info structures, and copy the |
| 82 | // callback(s) for each one found (for use by vkDestroyInstance) |
| 83 | layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos, |
| 84 | &my_data->tmp_callbacks); |
| 85 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 86 | // Record whether the WSI instance extension was enabled for this |
| 87 | // VkInstance. No need to check if the extension was advertised by |
| 88 | // vkEnumerateInstanceExtensionProperties(), since the loader handles that. |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 89 | for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 90 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 91 | my_data->instanceMap[instance].displayExtensionEnabled = true; |
| 92 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 96 | #include "vk_dispatch_table_helper.h" |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 97 | static void init_swapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 98 | 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] | 99 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 100 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 101 | static const char *presentModeStr(VkPresentModeKHR value) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 102 | // Return a string corresponding to the value: |
| 103 | return string_VkPresentModeKHR(value); |
| 104 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 105 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 106 | static const char *sharingModeStr(VkSharingMode value) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 107 | // Return a string corresponding to the value: |
| 108 | return string_VkSharingMode(value); |
| 109 | } |
Ian Elliott | 07adb11 | 2016-01-05 12:51:03 -0700 | [diff] [blame] | 110 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 111 | VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 112 | VkInstance *pInstance) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 113 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 114 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 115 | assert(chain_info->u.pLayerInfo); |
| 116 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 117 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 118 | if (fpCreateInstance == NULL) { |
| 119 | return VK_ERROR_INITIALIZATION_FAILED; |
| 120 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 121 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 122 | // Advance the link info for the next element on the chain |
| 123 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 124 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 125 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 126 | if (result != VK_SUCCESS) { |
| 127 | return result; |
| 128 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 129 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 130 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map); |
Chia-I Wu | a673753 | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 131 | my_data->instance = *pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 132 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 133 | layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 134 | my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance, |
| 135 | pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 136 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 137 | // Call the following function after my_data is initialized: |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 138 | checkInstanceRegisterExtensions(pCreateInfo, *pInstance); |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 139 | init_swapchain(my_data, pAllocator); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 140 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 141 | return result; |
| 142 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 143 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 144 | VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 145 | dispatch_key key = get_dispatch_key(instance); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 146 | layer_data *my_data = GetLayerDataPtr(key, layer_data_map); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 147 | SwpInstance *pInstance = NULL; |
| 148 | { |
| 149 | auto it = my_data->instanceMap.find(instance); |
| 150 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 151 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 152 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 153 | // Call down the call chain: |
| 154 | my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 155 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 156 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 157 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 158 | // Enable the temporary callback(s) here to catch cleanup issues: |
| 159 | bool callback_setup = false; |
| 160 | if (my_data->num_tmp_callbacks > 0) { |
| 161 | if (!layer_enable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_dbg_create_infos, |
| 162 | my_data->tmp_callbacks)) { |
| 163 | callback_setup = true; |
| 164 | } |
| 165 | } |
| 166 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 167 | // Do additional internal cleanup: |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 168 | if (pInstance) { |
| 169 | // Delete all of the SwpPhysicalDevice's, SwpSurface's, and the |
| 170 | // SwpInstance associated with this instance: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 171 | for (auto it = pInstance->physicalDevices.begin(); it != pInstance->physicalDevices.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 172 | // Free memory that was allocated for/by this SwpPhysicalDevice: |
| 173 | SwpPhysicalDevice *pPhysicalDevice = it->second; |
| 174 | if (pPhysicalDevice) { |
Ian Elliott | 458696a | 2016-02-04 06:11:17 -0700 | [diff] [blame] | 175 | if (pPhysicalDevice->pDevice) { |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 176 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 177 | HandleToUint64(pPhysicalDevice->pDevice->device), __LINE__, VALIDATION_ERROR_00018, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 178 | swapchain_layer_name, |
| 179 | "VkDestroyInstance() called before all of its associated VkDevices were destroyed. %s", |
| 180 | validation_error_map[VALIDATION_ERROR_00018]); |
Ian Elliott | 458696a | 2016-02-04 06:11:17 -0700 | [diff] [blame] | 181 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 182 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 183 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 184 | // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which |
| 185 | // are simply pointed to by the SwpInstance): |
| 186 | my_data->physicalDeviceMap.erase(it->second->physicalDevice); |
| 187 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 188 | for (auto it = pInstance->surfaces.begin(); it != pInstance->surfaces.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 189 | // Free memory that was allocated for/by this SwpPhysicalDevice: |
| 190 | SwpSurface *pSurface = it->second; |
| 191 | if (pSurface) { |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 192 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 193 | HandleToUint64(pInstance->instance), __LINE__, VALIDATION_ERROR_00018, swapchain_layer_name, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 194 | "VkDestroyInstance() called before all of its associated VkSurfaceKHRs were destroyed. %s", |
| 195 | validation_error_map[VALIDATION_ERROR_00018]); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | my_data->instanceMap.erase(instance); |
| 199 | } |
Mark Lobodzinski | 3c99d55 | 2016-02-04 13:50:23 -0700 | [diff] [blame] | 200 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 201 | // Disable and cleanup the temporary callback(s): |
| 202 | if (callback_setup) { |
| 203 | layer_disable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_callbacks); |
| 204 | } |
| 205 | if (my_data->num_tmp_callbacks > 0) { |
| 206 | layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos, my_data->tmp_callbacks); |
| 207 | my_data->num_tmp_callbacks = 0; |
| 208 | } |
| 209 | |
Mark Lobodzinski | 3c99d55 | 2016-02-04 13:50:23 -0700 | [diff] [blame] | 210 | // Clean up logging callback, if any |
| 211 | while (my_data->logging_callback.size() > 0) { |
| 212 | VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); |
| 213 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
| 214 | my_data->logging_callback.pop_back(); |
| 215 | } |
| 216 | layer_debug_report_destroy_instance(my_data->report_data); |
| 217 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 218 | delete my_data->instance_dispatch_table; |
| 219 | layer_data_map.erase(key); |
| 220 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 221 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 222 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 223 | VKAPI_ATTR VkResult VKAPI_CALL CreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, |
| 224 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 225 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 226 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 227 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 228 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 229 | SwpInstance *pInstance = NULL; |
| 230 | { |
| 231 | auto it = my_data->instanceMap.find(instance); |
| 232 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 233 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 234 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 235 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 236 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 237 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 238 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 239 | result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 240 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 241 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 242 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 243 | { |
| 244 | auto it = my_data->instanceMap.find(instance); |
| 245 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 246 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 247 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 248 | // Record the VkSurfaceKHR returned by the ICD: |
| 249 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 250 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 251 | // Point to the associated SwpInstance: |
| 252 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 253 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 254 | lock.unlock(); |
| 255 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 256 | return result; |
| 257 | } |
| 258 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 259 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 260 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 261 | |
| 262 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 263 | VKAPI_ATTR VkResult VKAPI_CALL CreateMirSurfaceKHR(VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo, |
| 264 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 265 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 266 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 267 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 268 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 269 | SwpInstance *pInstance = NULL; |
| 270 | { |
| 271 | auto it = my_data->instanceMap.find(instance); |
| 272 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 273 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 274 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 275 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 276 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 277 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 278 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 279 | result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 280 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 281 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 282 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 283 | { |
| 284 | auto it = my_data->instanceMap.find(instance); |
| 285 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 286 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 287 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 288 | // Record the VkSurfaceKHR returned by the ICD: |
| 289 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 290 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 291 | // Point to the associated SwpInstance: |
| 292 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 293 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 294 | lock.unlock(); |
| 295 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 296 | return result; |
| 297 | } |
| 298 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 299 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 300 | #endif // VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 301 | |
| 302 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 303 | VKAPI_ATTR VkResult VKAPI_CALL CreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, |
| 304 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 305 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 306 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 307 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 308 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 309 | SwpInstance *pInstance = NULL; |
| 310 | { |
| 311 | auto it = my_data->instanceMap.find(instance); |
| 312 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 313 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 314 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 315 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 316 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 317 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 318 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 319 | result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 320 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 321 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 322 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 323 | { |
| 324 | auto it = my_data->instanceMap.find(instance); |
| 325 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 326 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 327 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 328 | // Record the VkSurfaceKHR returned by the ICD: |
| 329 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 330 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 331 | // Point to the associated SwpInstance: |
| 332 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 333 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 334 | lock.unlock(); |
| 335 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 336 | return result; |
| 337 | } |
| 338 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 339 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 340 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 341 | |
| 342 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 343 | VKAPI_ATTR VkResult VKAPI_CALL CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, |
| 344 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 345 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 346 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 347 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 348 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 349 | SwpInstance *pInstance = NULL; |
| 350 | { |
| 351 | auto it = my_data->instanceMap.find(instance); |
| 352 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 353 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 354 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 355 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 356 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 357 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 358 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 359 | result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 360 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 361 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 362 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 363 | { |
| 364 | auto it = my_data->instanceMap.find(instance); |
| 365 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 366 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 367 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 368 | // Record the VkSurfaceKHR returned by the ICD: |
| 369 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 370 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 371 | // Point to the associated SwpInstance: |
| 372 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 373 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 374 | lock.unlock(); |
| 375 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 376 | return result; |
| 377 | } |
| 378 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 379 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 380 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 381 | |
| 382 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 383 | VKAPI_ATTR VkResult VKAPI_CALL CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, |
| 384 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 385 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 386 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 387 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 388 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 389 | SwpInstance *pInstance = NULL; |
| 390 | { |
| 391 | auto it = my_data->instanceMap.find(instance); |
| 392 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 393 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 394 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 395 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 396 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 397 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 398 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 399 | result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 400 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 401 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 402 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 403 | { |
| 404 | auto it = my_data->instanceMap.find(instance); |
| 405 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 406 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 407 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 408 | // Record the VkSurfaceKHR returned by the ICD: |
| 409 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 410 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 411 | // Point to the associated SwpInstance: |
| 412 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 413 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 414 | lock.unlock(); |
| 415 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 416 | return result; |
| 417 | } |
| 418 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 419 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 420 | #endif // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 421 | |
| 422 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 423 | VKAPI_ATTR VkResult VKAPI_CALL CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, |
| 424 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 425 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 426 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 427 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 428 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 429 | SwpInstance *pInstance = NULL; |
| 430 | { |
| 431 | auto it = my_data->instanceMap.find(instance); |
| 432 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 433 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 434 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 435 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 436 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 437 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 438 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 439 | result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 440 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 441 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 442 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 443 | { |
| 444 | auto it = my_data->instanceMap.find(instance); |
| 445 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 446 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 447 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 448 | // Record the VkSurfaceKHR returned by the ICD: |
| 449 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 450 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 451 | // Point to the associated SwpInstance: |
| 452 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 453 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 454 | lock.unlock(); |
| 455 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 456 | return result; |
| 457 | } |
| 458 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 459 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 460 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 461 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 462 | VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 463 | VkDisplayPlanePropertiesKHR *pProperties) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 464 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 465 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 466 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 467 | std::unique_lock<std::mutex> lock(global_lock); |
| 468 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 469 | { |
| 470 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 471 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 472 | } |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 473 | lock.unlock(); |
| 474 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 475 | if (!skip_call) { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 476 | result = my_data->instance_dispatch_table->GetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, pPropertyCount, |
| 477 | pProperties); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 478 | |
| 479 | lock.lock(); |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 480 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 481 | pPhysicalDevice->displayPlanePropertyCount = *pPropertyCount; |
| 482 | pPhysicalDevice->gotDisplayPlanePropertyCount = true; |
| 483 | } |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 484 | // TODO store the properties for later checks |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 485 | lock.unlock(); |
| 486 | |
| 487 | return result; |
| 488 | } |
| 489 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 490 | } |
| 491 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 492 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
| 493 | uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 494 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 495 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 496 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 497 | std::unique_lock<std::mutex> lock(global_lock); |
| 498 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 499 | { |
| 500 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 501 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 502 | } |
| 503 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 504 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { |
| 505 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 506 | HandleToUint64(pPhysicalDevice->pInstance->instance), __LINE__, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 507 | SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, swapchain_layer_name, |
| 508 | "Potential problem with calling vkGetDisplayPlaneSupportedDisplaysKHR() without first " |
| 509 | "querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR."); |
| 510 | } |
| 511 | |
| 512 | if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) { |
| 513 | skip_call |= |
| 514 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 515 | HandleToUint64(pPhysicalDevice->pInstance->instance), __LINE__, VALIDATION_ERROR_01857, swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 516 | "vkGetDisplayPlaneSupportedDisplaysKHR(): planeIndex must be in the range [0, %d] that was returned by " |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 517 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded? %s", |
| 518 | pPhysicalDevice->displayPlanePropertyCount - 1, validation_error_map[VALIDATION_ERROR_01857]); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 519 | } |
| 520 | lock.unlock(); |
| 521 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 522 | if (!skip_call) { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 523 | result = my_data->instance_dispatch_table->GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, |
| 524 | pDisplays); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 525 | |
| 526 | return result; |
| 527 | } |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 528 | // TODO validate the returned display objects |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 529 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 530 | } |
| 531 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 532 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 533 | uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR *pCapabilities) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 534 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 535 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 536 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 537 | std::unique_lock<std::mutex> lock(global_lock); |
| 538 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 539 | { |
| 540 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 541 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 542 | } |
| 543 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 544 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { |
| 545 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 546 | HandleToUint64(pPhysicalDevice->pInstance->instance), __LINE__, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 547 | SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, swapchain_layer_name, |
| 548 | "Potential problem with calling vkGetDisplayPlaneCapabilitiesKHR() without first " |
| 549 | "querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR."); |
| 550 | } |
| 551 | |
| 552 | if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) { |
| 553 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 554 | HandleToUint64(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_PLANE_INDEX_TOO_LARGE, |
| 555 | swapchain_layer_name, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 556 | "vkGetDisplayPlaneCapabilitiesKHR(): planeIndex must be in the range [0, %d] that was returned by " |
| 557 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded?", |
| 558 | pPhysicalDevice->displayPlanePropertyCount - 1); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 561 | lock.unlock(); |
| 562 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 563 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 564 | result = my_data->instance_dispatch_table->GetDisplayPlaneCapabilitiesKHR(physicalDevice, mode, planeIndex, pCapabilities); |
| 565 | return result; |
| 566 | } |
| 567 | |
| 568 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 569 | } |
| 570 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 571 | VKAPI_ATTR VkResult VKAPI_CALL CreateDisplayPlaneSurfaceKHR(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, |
| 572 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 573 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 574 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 575 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 576 | std::unique_lock<std::mutex> lock(global_lock); |
| 577 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 578 | |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 579 | // TODO more validation checks |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 580 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 581 | // Call down the call chain: |
| 582 | lock.unlock(); |
| 583 | result = my_data->instance_dispatch_table->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
| 584 | lock.lock(); |
| 585 | |
| 586 | // Obtain this pointer again after locking: |
| 587 | pInstance = &(my_data->instanceMap[instance]); |
| 588 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 589 | // Record the VkSurfaceKHR returned by the ICD: |
| 590 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 591 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 592 | // Point to the associated SwpInstance: |
| 593 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 594 | } |
| 595 | lock.unlock(); |
| 596 | return result; |
| 597 | } |
| 598 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 599 | } |
| 600 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 601 | 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] | 602 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 603 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 604 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 605 | SwpSurface *pSurface = NULL; |
| 606 | { |
| 607 | auto it = my_data->surfaceMap.find(surface); |
| 608 | pSurface = (it == my_data->surfaceMap.end()) ? NULL : &it->second; |
| 609 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 610 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 611 | // Regardless of skip_call value, do some internal cleanup: |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 612 | if (pSurface) { |
| 613 | // Delete the SwpSurface associated with this surface: |
| 614 | if (pSurface->pInstance) { |
| 615 | pSurface->pInstance->surfaces.erase(surface); |
| 616 | } |
| 617 | if (!pSurface->swapchains.empty()) { |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 618 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 619 | HandleToUint64(instance), __LINE__, VALIDATION_ERROR_01844, swapchain_layer_name, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 620 | "vkDestroySurfaceKHR() called before all of its associated VkSwapchainKHRs were destroyed. %s", |
| 621 | validation_error_map[VALIDATION_ERROR_01844]); |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 622 | |
| 623 | // Empty and then delete all SwpSwapchains |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 624 | for (auto it = pSurface->swapchains.begin(); it != pSurface->swapchains.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 625 | // Delete all SwpImage's |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 626 | // In case the swapchain's device hasn't been destroyed yet |
| 627 | // (which isn't likely, but is possible), delete its |
| 628 | // association with this swapchain (i.e. so we can't point to |
| 629 | // this swpchain from that device, later on): |
| 630 | if (it->second->pDevice) { |
| 631 | it->second->pDevice->swapchains.clear(); |
| 632 | } |
| 633 | } |
| 634 | pSurface->swapchains.clear(); |
| 635 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 636 | my_data->surfaceMap.erase(surface); |
| 637 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 638 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 639 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 640 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 641 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 642 | my_data->instance_dispatch_table->DestroySurfaceKHR(instance, surface, pAllocator); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 646 | VKAPI_ATTR VkResult VKAPI_CALL EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 647 | VkPhysicalDevice *pPhysicalDevices) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 648 | VkResult result = VK_SUCCESS; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 649 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 650 | |
| 651 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 652 | result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 653 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 654 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 655 | SwpInstance *pInstance = NULL; |
| 656 | { |
| 657 | auto it = my_data->instanceMap.find(instance); |
| 658 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 659 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 660 | if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices && (*pPhysicalDeviceCount > 0)) { |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 661 | // Record the VkPhysicalDevices returned by the ICD: |
| 662 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 663 | my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice = pPhysicalDevices[i]; |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 664 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance; |
| 665 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL; |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 666 | // Point to the associated SwpInstance: |
| 667 | if (pInstance) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 668 | pInstance->physicalDevices[pPhysicalDevices[i]] = &my_data->physicalDeviceMap[pPhysicalDevices[i]]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 669 | } |
| 670 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 671 | } |
Ian Elliott | a3c69bc | 2016-02-04 15:34:59 -0700 | [diff] [blame] | 672 | return result; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 675 | VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 676 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 677 | layer_data *my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 678 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 679 | |
| 680 | assert(chain_info->u.pLayerInfo); |
| 681 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 682 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
Chia-I Wu | a673753 | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 683 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 684 | if (fpCreateDevice == NULL) { |
| 685 | return VK_ERROR_INITIALIZATION_FAILED; |
| 686 | } |
| 687 | |
| 688 | // Advance the link info for the next element on the chain |
| 689 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 690 | |
| 691 | VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); |
| 692 | if (result != VK_SUCCESS) { |
| 693 | return result; |
| 694 | } |
| 695 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 696 | std::lock_guard<std::mutex> lock(global_lock); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 697 | layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 698 | |
| 699 | // Setup device dispatch table |
| 700 | my_device_data->device_dispatch_table = new VkLayerDispatchTable; |
| 701 | layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); |
| 702 | |
| 703 | 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] | 704 | checkDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 705 | |
| 706 | return result; |
| 707 | } |
| 708 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 709 | VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 710 | dispatch_key key = get_dispatch_key(device); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 711 | layer_data *my_data = GetLayerDataPtr(key, layer_data_map); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 712 | |
| 713 | // Call down the call chain: |
| 714 | my_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
| 715 | |
| 716 | // Do some internal cleanup: |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 717 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 718 | SwpDevice *pDevice = NULL; |
| 719 | { |
| 720 | auto it = my_data->deviceMap.find(device); |
| 721 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 722 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 723 | if (pDevice) { |
| 724 | // Delete the SwpDevice associated with this device: |
| 725 | if (pDevice->pPhysicalDevice) { |
| 726 | pDevice->pPhysicalDevice->pDevice = NULL; |
| 727 | } |
| 728 | if (!pDevice->swapchains.empty()) { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 729 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 730 | HandleToUint64(device), __LINE__, VALIDATION_ERROR_00049, swapchain_layer_name, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 731 | "vkDestroyDevice() called before all of its associated VkSwapchainKHRs were destroyed. %s", |
| 732 | validation_error_map[VALIDATION_ERROR_00049]); |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 733 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 734 | // Empty and then delete all SwpSwapchain's |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 735 | for (auto it = pDevice->swapchains.begin(); it != pDevice->swapchains.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 736 | // Delete all SwpImage's |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 737 | // In case the swapchain's surface hasn't been destroyed yet |
| 738 | // (which is likely) delete its association with this swapchain |
| 739 | // (i.e. so we can't point to this swpchain from that surface, |
| 740 | // later on): |
| 741 | if (it->second->pSurface) { |
| 742 | it->second->pSurface->swapchains.clear(); |
| 743 | } |
| 744 | } |
| 745 | pDevice->swapchains.clear(); |
| 746 | } |
| 747 | my_data->deviceMap.erase(device); |
| 748 | } |
| 749 | delete my_data->device_dispatch_table; |
| 750 | layer_data_map.erase(key); |
| 751 | } |
| 752 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 753 | VKAPI_ATTR VkResult VKAPI_CALL CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 754 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 755 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Petr Kraus | 9729175 | 2017-05-11 01:05:16 +0200 | [diff] [blame] | 756 | |
| 757 | // Call down the call chain: |
| 758 | VkResult result = my_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 759 | std::unique_lock<std::mutex> lock(global_lock); |
Petr Kraus | 9729175 | 2017-05-11 01:05:16 +0200 | [diff] [blame] | 760 | |
| 761 | if (result == VK_SUCCESS) { |
| 762 | // Remember the swapchain's handle, and link it to the device: |
| 763 | SwpDevice *pDevice = NULL; |
| 764 | { |
| 765 | auto it = my_data->deviceMap.find(device); |
| 766 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 767 | } |
| 768 | |
| 769 | my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain; |
| 770 | if (pDevice) { |
| 771 | pDevice->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; |
| 772 | } |
| 773 | my_data->swapchainMap[*pSwapchain].pDevice = pDevice; |
| 774 | my_data->swapchainMap[*pSwapchain].imageCount = 0; |
| 775 | // Store a pointer to the surface |
| 776 | SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice; |
| 777 | SwpInstance *pInstance = (pPhysicalDevice) ? pPhysicalDevice->pInstance : NULL; |
| 778 | layer_data *my_instance_data = |
| 779 | ((pInstance) ? GetLayerDataPtr(get_dispatch_key(pInstance->instance), layer_data_map) : NULL); |
| 780 | SwpSurface *pSurface = ((my_data && pCreateInfo) ? &my_instance_data->surfaceMap[pCreateInfo->surface] : NULL); |
| 781 | my_data->swapchainMap[*pSwapchain].pSurface = pSurface; |
| 782 | if (pSurface) { |
| 783 | pSurface->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; |
| 784 | } |
| 785 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 786 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 787 | |
Petr Kraus | 9729175 | 2017-05-11 01:05:16 +0200 | [diff] [blame] | 788 | return result; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 789 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 790 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 791 | 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] | 792 | // TODOs: |
| 793 | // |
| 794 | // - Implement a check for validity language that reads: All uses of |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 795 | // presentable images acquired from pname:swapchain must: have completed |
| 796 | // execution |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 797 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 798 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 799 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 800 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 801 | // Regardless of skip_call value, do some internal cleanup: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 802 | SwpSwapchain *pSwapchain = NULL; |
| 803 | { |
| 804 | auto it = my_data->swapchainMap.find(swapchain); |
| 805 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 806 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 807 | if (pSwapchain) { |
| 808 | // Delete the SwpSwapchain associated with this swapchain: |
| 809 | if (pSwapchain->pDevice) { |
| 810 | pSwapchain->pDevice->swapchains.erase(swapchain); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 811 | } |
| 812 | if (pSwapchain->pSurface) { |
| 813 | pSwapchain->pSurface->swapchains.erase(swapchain); |
| 814 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 815 | my_data->swapchainMap.erase(swapchain); |
| 816 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 817 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [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: |
| 821 | my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator); |
| 822 | } |
| 823 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 824 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 825 | VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, |
| 826 | VkImage *pSwapchainImages) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 827 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 828 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 829 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 830 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 8b9e256 | 2016-01-05 13:00:50 -0700 | [diff] [blame] | 831 | |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 832 | SwpSwapchain *pSwapchain = NULL; |
| 833 | { |
| 834 | auto it = my_data->swapchainMap.find(swapchain); |
| 835 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 836 | } |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 837 | if (pSwapchain && pSwapchainImages) { |
| 838 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 839 | if (pSwapchain->imageCount == 0) { |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 840 | // Since we haven't recorded a preliminary value of *pSwapchainImageCount, that likely means that the application didn't |
| 841 | // previously call this function with a NULL value of pSwapchainImages: |
Mark Lobodzinski | 6a7e933 | 2016-08-16 09:06:15 -0600 | [diff] [blame] | 842 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 843 | HandleToUint64(device), __LINE__, SWAPCHAIN_PRIOR_COUNT, swapchain_layer_name, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 844 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive " |
| 845 | "value has been seen for pSwapchainImages."); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 846 | } else if (*pSwapchainImageCount > pSwapchain->imageCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 847 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame^] | 848 | HandleToUint64(device), __LINE__, SWAPCHAIN_INVALID_COUNT, swapchain_layer_name, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 849 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount, and with " |
| 850 | "pSwapchainImages set to a value (%d) that is greater than the value (%d) that was returned when " |
| 851 | "pSwapchainImageCount was NULL.", |
| 852 | *pSwapchainImageCount, pSwapchain->imageCount); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 853 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 854 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 855 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 856 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 857 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 858 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 859 | result = my_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 860 | lock.lock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 861 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 862 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 863 | { |
| 864 | auto it = my_data->swapchainMap.find(swapchain); |
| 865 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 866 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 867 | if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages && pSwapchainImageCount) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 868 | // Record the result of this preliminary query: |
| 869 | pSwapchain->imageCount = *pSwapchainImageCount; |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 870 | } else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages && pSwapchainImageCount && |
| 871 | (*pSwapchainImageCount > 0)) { |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 872 | // Record the images and their state: |
| 873 | pSwapchain->imageCount = *pSwapchainImageCount; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 874 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 875 | lock.unlock(); |
| 876 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 877 | return result; |
| 878 | } |
| 879 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 880 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 881 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 882 | 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] | 883 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 884 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 885 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 886 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 887 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 888 | my_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 889 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 890 | // Remember the queue's handle, and link it to the device: |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 891 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 892 | SwpDevice *pDevice = NULL; |
| 893 | { |
| 894 | auto it = my_data->deviceMap.find(device); |
| 895 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 896 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 897 | my_data->queueMap[&pQueue].queue = *pQueue; |
| 898 | if (pDevice) { |
| 899 | pDevice->queues[*pQueue] = &my_data->queueMap[*pQueue]; |
| 900 | } |
| 901 | my_data->queueMap[&pQueue].pDevice = pDevice; |
| 902 | my_data->queueMap[&pQueue].queueFamilyIndex = queueFamilyIndex; |
| 903 | } |
| 904 | } |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 905 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 906 | VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance, |
| 907 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 908 | const VkAllocationCallbacks *pAllocator, |
| 909 | VkDebugReportCallbackEXT *pMsgCallback) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 910 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 911 | VkResult result = |
| 912 | my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 913 | if (VK_SUCCESS == result) { |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 914 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 915 | 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] | 916 | } |
| 917 | return result; |
| 918 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 919 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 920 | VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 921 | const VkAllocationCallbacks *pAllocator) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 922 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 923 | my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 924 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 925 | layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator); |
| 926 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 927 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 928 | VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 929 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 930 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 931 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 932 | my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, |
| 933 | pMsg); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 934 | } |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 935 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 936 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 937 | return util_GetLayerProperties(1, &swapchain_layer, pCount, pProperties); |
| 938 | } |
| 939 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 940 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 941 | VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 942 | return util_GetLayerProperties(1, &swapchain_layer, pCount, pProperties); |
| 943 | } |
| 944 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 945 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 946 | VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 947 | if (pLayerName && !strcmp(pLayerName, swapchain_layer.layerName)) |
| 948 | return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties); |
| 949 | |
| 950 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 951 | } |
| 952 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 953 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 954 | uint32_t *pCount, VkExtensionProperties *pProperties) { |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 955 | if (pLayerName && !strcmp(pLayerName, swapchain_layer.layerName)) |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 956 | return util_GetExtensionProperties(0, nullptr, pCount, pProperties); |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 957 | |
| 958 | assert(physicalDevice); |
| 959 | |
| 960 | dispatch_key key = get_dispatch_key(physicalDevice); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 961 | layer_data *my_data = GetLayerDataPtr(key, layer_data_map); |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 962 | return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 963 | } |
| 964 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 965 | static PFN_vkVoidFunction intercept_core_instance_command(const char *name); |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 966 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 967 | 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] | 968 | |
Mike Schuchardt | 046e3cf | 2017-03-10 14:12:35 -0700 | [diff] [blame] | 969 | static PFN_vkVoidFunction intercept_extension_instance_commands(const char *name); |
| 970 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 971 | static PFN_vkVoidFunction intercept_core_device_command(const char *name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 972 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 973 | 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] | 974 | |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 975 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { |
| 976 | PFN_vkVoidFunction proc = intercept_core_device_command(funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 977 | if (proc) return proc; |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 978 | |
| 979 | assert(device); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 980 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 981 | layer_data *my_data; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 982 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 983 | my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 984 | VkLayerDispatchTable *pDisp = my_data->device_dispatch_table; |
Chia-I Wu | 8324595 | 2016-05-05 16:13:19 +0800 | [diff] [blame] | 985 | |
| 986 | proc = intercept_khr_swapchain_command(funcName, device); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 987 | if (proc) return proc; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 988 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 989 | if (pDisp->GetDeviceProcAddr == NULL) return NULL; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 990 | return pDisp->GetDeviceProcAddr(device, funcName); |
| 991 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 992 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 993 | 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] | 994 | PFN_vkVoidFunction proc = intercept_core_instance_command(funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 995 | if (!proc) proc = intercept_core_device_command(funcName); |
| 996 | if (!proc) proc = intercept_khr_swapchain_command(funcName, VK_NULL_HANDLE); |
| 997 | if (proc) return proc; |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 998 | |
Chia-I Wu | 5ae2f65 | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 999 | assert(instance); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1000 | |
| 1001 | layer_data *my_data; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1002 | my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1003 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1004 | |
Chia-I Wu | 5ae2f65 | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 1005 | proc = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1006 | if (!proc) proc = intercept_khr_surface_command(funcName, instance); |
Mike Schuchardt | 046e3cf | 2017-03-10 14:12:35 -0700 | [diff] [blame] | 1007 | if (!proc) proc = intercept_extension_instance_commands(funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1008 | if (proc) return proc; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1009 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1010 | if (pTable->GetInstanceProcAddr == NULL) return NULL; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1011 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 1012 | } |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1013 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1014 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { |
| 1015 | assert(instance); |
| 1016 | |
| 1017 | layer_data *my_data; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1018 | my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1019 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
| 1020 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1021 | if (pTable->GetPhysicalDeviceProcAddr == NULL) return NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1022 | return pTable->GetPhysicalDeviceProcAddr(instance, funcName); |
| 1023 | } |
| 1024 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1025 | static PFN_vkVoidFunction intercept_core_instance_command(const char *name) { |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1026 | static const struct { |
| 1027 | const char *name; |
| 1028 | PFN_vkVoidFunction proc; |
| 1029 | } core_instance_commands[] = { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1030 | {"vkGetInstanceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr)}, |
| 1031 | {"vkCreateInstance", reinterpret_cast<PFN_vkVoidFunction>(CreateInstance)}, |
| 1032 | {"vkDestroyInstance", reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance)}, |
| 1033 | {"vkCreateDevice", reinterpret_cast<PFN_vkVoidFunction>(CreateDevice)}, |
| 1034 | {"vkEnumeratePhysicalDevices", reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices)}, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1035 | {"vk_layerGetPhysicalDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProcAddr)}, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1036 | {"vkEnumerateInstanceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceLayerProperties)}, |
| 1037 | {"vkEnumerateDeviceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceLayerProperties)}, |
| 1038 | {"vkEnumerateInstanceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties)}, |
| 1039 | {"vkEnumerateDeviceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties)}, |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1040 | }; |
| 1041 | |
| 1042 | for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1043 | if (!strcmp(core_instance_commands[i].name, name)) return core_instance_commands[i].proc; |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | return nullptr; |
| 1047 | } |
| 1048 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1049 | 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] | 1050 | static const struct { |
| 1051 | const char *name; |
| 1052 | PFN_vkVoidFunction proc; |
| 1053 | } khr_surface_commands[] = { |
| 1054 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1055 | {"vkCreateAndroidSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateAndroidSurfaceKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1056 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1057 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1058 | {"vkCreateMirSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateMirSurfaceKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1059 | #endif // VK_USE_PLATFORM_MIR_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1060 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1061 | {"vkCreateWaylandSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateWaylandSurfaceKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1062 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1063 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1064 | {"vkCreateWin32SurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateWin32SurfaceKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1065 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1066 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1067 | {"vkCreateXcbSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateXcbSurfaceKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1068 | #endif // VK_USE_PLATFORM_XCB_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1069 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1070 | {"vkCreateXlibSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateXlibSurfaceKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1071 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1072 | {"vkDestroySurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(DestroySurfaceKHR)}, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1073 | {"vkGetPhysicalDeviceDisplayPlanePropertiesKHR", |
| 1074 | reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceDisplayPlanePropertiesKHR)}, |
| 1075 | {"vkGetDisplayPlaneSupportedDisplaysKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayPlaneSupportedDisplaysKHR)}, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1076 | {"vkGetDisplayPlaneCapabilitiesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayPlaneCapabilitiesKHR)}, |
| 1077 | {"vkCreateDisplayPlaneSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateDisplayPlaneSurfaceKHR)}, |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1078 | }; |
| 1079 | |
| 1080 | // do not check if VK_KHR_*_surface is enabled (why?) |
| 1081 | |
| 1082 | for (size_t i = 0; i < ARRAY_SIZE(khr_surface_commands); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1083 | if (!strcmp(khr_surface_commands[i].name, name)) return khr_surface_commands[i].proc; |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | return nullptr; |
| 1087 | } |
| 1088 | |
Mike Schuchardt | 046e3cf | 2017-03-10 14:12:35 -0700 | [diff] [blame] | 1089 | static PFN_vkVoidFunction intercept_extension_instance_commands(const char *name) { |
Mike Schuchardt | 046e3cf | 2017-03-10 14:12:35 -0700 | [diff] [blame] | 1090 | return nullptr; |
| 1091 | } |
| 1092 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1093 | static PFN_vkVoidFunction intercept_core_device_command(const char *name) { |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1094 | static const struct { |
| 1095 | const char *name; |
| 1096 | PFN_vkVoidFunction proc; |
| 1097 | } core_device_commands[] = { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1098 | {"vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr)}, |
| 1099 | {"vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice)}, |
| 1100 | {"vkGetDeviceQueue", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue)}, |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1101 | }; |
| 1102 | |
| 1103 | for (size_t i = 0; i < ARRAY_SIZE(core_device_commands); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1104 | if (!strcmp(core_device_commands[i].name, name)) return core_device_commands[i].proc; |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | return nullptr; |
| 1108 | } |
| 1109 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1110 | 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] | 1111 | static const struct { |
| 1112 | const char *name; |
| 1113 | PFN_vkVoidFunction proc; |
| 1114 | } khr_swapchain_commands[] = { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1115 | {"vkCreateSwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR)}, |
| 1116 | {"vkDestroySwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR)}, |
| 1117 | {"vkGetSwapchainImagesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR)}, |
Chia-I Wu | 8324595 | 2016-05-05 16:13:19 +0800 | [diff] [blame] | 1118 | }; |
| 1119 | |
| 1120 | // do not check if VK_KHR_swapchain is enabled (why?) |
| 1121 | |
| 1122 | for (size_t i = 0; i < ARRAY_SIZE(khr_swapchain_commands); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1123 | if (!strcmp(khr_swapchain_commands[i].name, name)) return khr_swapchain_commands[i].proc; |
Chia-I Wu | 8324595 | 2016-05-05 16:13:19 +0800 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | return nullptr; |
| 1127 | } |
| 1128 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1129 | } // namespace swapchain |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1130 | |
| 1131 | // vk_layer_logging.h expects these to be defined |
| 1132 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1133 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance, |
| 1134 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 1135 | const VkAllocationCallbacks *pAllocator, |
| 1136 | VkDebugReportCallbackEXT *pMsgCallback) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1137 | return swapchain::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1138 | } |
| 1139 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1140 | VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, |
| 1141 | const VkAllocationCallbacks *pAllocator) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1142 | swapchain::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1143 | } |
| 1144 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1145 | VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 1146 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 1147 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1148 | swapchain::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1149 | } |
| 1150 | |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1151 | // 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] | 1152 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1153 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 1154 | VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1155 | return swapchain::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1156 | } |
| 1157 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1158 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, |
| 1159 | VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1160 | return swapchain::EnumerateInstanceLayerProperties(pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1161 | } |
| 1162 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1163 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 1164 | VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1165 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 1166 | assert(physicalDevice == VK_NULL_HANDLE); |
| 1167 | return swapchain::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 1171 | const char *pLayerName, uint32_t *pCount, |
| 1172 | VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1173 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 1174 | assert(physicalDevice == VK_NULL_HANDLE); |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 1175 | return swapchain::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | 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] | 1179 | return swapchain::GetDeviceProcAddr(dev, funcName); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | 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] | 1183 | return swapchain::GetInstanceProcAddr(instance, funcName); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1184 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1185 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1186 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance, |
| 1187 | const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1188 | return swapchain::GetPhysicalDeviceProcAddr(instance, funcName); |
| 1189 | } |
| 1190 | |
| 1191 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) { |
| 1192 | assert(pVersionStruct != NULL); |
| 1193 | assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT); |
| 1194 | |
| 1195 | // Fill in the function pointers if our version is at least capable of having the structure contain them. |
| 1196 | if (pVersionStruct->loaderLayerInterfaceVersion >= 2) { |
| 1197 | pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr; |
| 1198 | pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr; |
| 1199 | pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr; |
| 1200 | } |
| 1201 | |
| 1202 | if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 1203 | swapchain::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion; |
| 1204 | } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 1205 | pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 1206 | } |
| 1207 | |
| 1208 | return VK_SUCCESS; |
| 1209 | } |