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, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 66 | reinterpret_cast<uint64_t>(physicalDevice), __LINE__, VALIDATION_ERROR_00031, "Swapchain", |
| 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 | |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 111 | // TODO This overload is only preserved for validateCreateSwapchainKHR(), which doesn't have a VU msgCode defined yet. |
| 112 | // When a VU msgCode is defined, this overload can be deleted, and the latter form used instead. |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 113 | static bool ValidateQueueFamilyIndex(layer_data *my_data, uint32_t queue_family_index, uint32_t queue_family_count, |
| 114 | VkPhysicalDevice physical_device, const char *function) { |
| 115 | bool skip_call = false; |
| 116 | if (queue_family_index >= queue_family_count) { |
| 117 | skip_call = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 118 | reinterpret_cast<uint64_t>(physical_device), __LINE__, SWAPCHAIN_QUEUE_FAMILY_INDEX_TOO_LARGE, |
| 119 | swapchain_layer_name, |
| 120 | "%s() called with a queueFamilyIndex that is too large (i.e. %d). The maximum value (returned by " |
| 121 | "vkGetPhysicalDeviceQueueFamilyProperties) is only %d.", |
| 122 | function, queue_family_index, queue_family_count); |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 123 | } |
| 124 | return skip_call; |
| 125 | } |
| 126 | |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 127 | static bool ValidateQueueFamilyIndex(layer_data *my_data, uint32_t queue_family_index, uint32_t queue_family_count, |
| 128 | VkPhysicalDevice physical_device, const char *function, |
| 129 | /*enum*/ UNIQUE_VALIDATION_ERROR_CODE msgCode) { |
| 130 | bool skip_call = false; |
| 131 | if (queue_family_index >= queue_family_count) { |
| 132 | skip_call = log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 133 | reinterpret_cast<uint64_t>(physical_device), __LINE__, msgCode, swapchain_layer_name, |
| 134 | "%s() called with a queueFamilyIndex that is too large (i.e. %d). The maximum value (returned by " |
| 135 | "vkGetPhysicalDeviceQueueFamilyProperties) is only %d. %s", |
| 136 | function, queue_family_index, queue_family_count, validation_error_map[msgCode]); |
| 137 | } |
| 138 | return skip_call; |
| 139 | } |
| 140 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 141 | VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 142 | VkInstance *pInstance) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 143 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 144 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 145 | assert(chain_info->u.pLayerInfo); |
| 146 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 147 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 148 | if (fpCreateInstance == NULL) { |
| 149 | return VK_ERROR_INITIALIZATION_FAILED; |
| 150 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 151 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 152 | // Advance the link info for the next element on the chain |
| 153 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 154 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 155 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 156 | if (result != VK_SUCCESS) { |
| 157 | return result; |
| 158 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 159 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 160 | 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] | 161 | my_data->instance = *pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 162 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 163 | layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 164 | my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance, |
| 165 | pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 166 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 167 | // Call the following function after my_data is initialized: |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 168 | checkInstanceRegisterExtensions(pCreateInfo, *pInstance); |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 169 | init_swapchain(my_data, pAllocator); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 170 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 171 | return result; |
| 172 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 173 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 174 | VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 175 | dispatch_key key = get_dispatch_key(instance); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 176 | layer_data *my_data = GetLayerDataPtr(key, layer_data_map); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 177 | SwpInstance *pInstance = NULL; |
| 178 | { |
| 179 | auto it = my_data->instanceMap.find(instance); |
| 180 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 181 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 182 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 183 | // Call down the call chain: |
| 184 | my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 185 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 186 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 187 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 188 | // Enable the temporary callback(s) here to catch cleanup issues: |
| 189 | bool callback_setup = false; |
| 190 | if (my_data->num_tmp_callbacks > 0) { |
| 191 | if (!layer_enable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_dbg_create_infos, |
| 192 | my_data->tmp_callbacks)) { |
| 193 | callback_setup = true; |
| 194 | } |
| 195 | } |
| 196 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 197 | // Do additional internal cleanup: |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 198 | if (pInstance) { |
| 199 | // Delete all of the SwpPhysicalDevice's, SwpSurface's, and the |
| 200 | // SwpInstance associated with this instance: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 201 | for (auto it = pInstance->physicalDevices.begin(); it != pInstance->physicalDevices.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 202 | // Free memory that was allocated for/by this SwpPhysicalDevice: |
| 203 | SwpPhysicalDevice *pPhysicalDevice = it->second; |
| 204 | if (pPhysicalDevice) { |
Ian Elliott | 458696a | 2016-02-04 06:11:17 -0700 | [diff] [blame] | 205 | if (pPhysicalDevice->pDevice) { |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 206 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 207 | reinterpret_cast<uint64_t>(pPhysicalDevice->pDevice->device), __LINE__, VALIDATION_ERROR_00018, |
| 208 | swapchain_layer_name, |
| 209 | "VkDestroyInstance() called before all of its associated VkDevices were destroyed. %s", |
| 210 | validation_error_map[VALIDATION_ERROR_00018]); |
Ian Elliott | 458696a | 2016-02-04 06:11:17 -0700 | [diff] [blame] | 211 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 212 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 213 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 214 | // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which |
| 215 | // are simply pointed to by the SwpInstance): |
| 216 | my_data->physicalDeviceMap.erase(it->second->physicalDevice); |
| 217 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 218 | for (auto it = pInstance->surfaces.begin(); it != pInstance->surfaces.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 219 | // Free memory that was allocated for/by this SwpPhysicalDevice: |
| 220 | SwpSurface *pSurface = it->second; |
| 221 | if (pSurface) { |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 222 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 223 | reinterpret_cast<uint64_t>(pInstance->instance), __LINE__, VALIDATION_ERROR_00018, swapchain_layer_name, |
| 224 | "VkDestroyInstance() called before all of its associated VkSurfaceKHRs were destroyed. %s", |
| 225 | validation_error_map[VALIDATION_ERROR_00018]); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | my_data->instanceMap.erase(instance); |
| 229 | } |
Mark Lobodzinski | 3c99d55 | 2016-02-04 13:50:23 -0700 | [diff] [blame] | 230 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 231 | // Disable and cleanup the temporary callback(s): |
| 232 | if (callback_setup) { |
| 233 | layer_disable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_callbacks); |
| 234 | } |
| 235 | if (my_data->num_tmp_callbacks > 0) { |
| 236 | layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos, my_data->tmp_callbacks); |
| 237 | my_data->num_tmp_callbacks = 0; |
| 238 | } |
| 239 | |
Mark Lobodzinski | 3c99d55 | 2016-02-04 13:50:23 -0700 | [diff] [blame] | 240 | // Clean up logging callback, if any |
| 241 | while (my_data->logging_callback.size() > 0) { |
| 242 | VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); |
| 243 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
| 244 | my_data->logging_callback.pop_back(); |
| 245 | } |
| 246 | layer_debug_report_destroy_instance(my_data->report_data); |
| 247 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 248 | delete my_data->instance_dispatch_table; |
| 249 | layer_data_map.erase(key); |
| 250 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 251 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 252 | VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 253 | uint32_t *pQueueFamilyPropertyCount, |
| 254 | VkQueueFamilyProperties *pQueueFamilyProperties) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 255 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 256 | |
| 257 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 258 | my_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, |
| 259 | pQueueFamilyProperties); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 260 | |
| 261 | // Record the result of this query: |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 262 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 263 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 264 | { |
| 265 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 266 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 267 | } |
Ian Elliott | a2bb0e0 | 2016-08-24 11:30:45 -0600 | [diff] [blame] | 268 | // Note: for poorly-written applications (e.g. that don't call this command |
| 269 | // twice, the first time with pQueueFamilyProperties set to NULL, and the |
| 270 | // second time with a non-NULL pQueueFamilyProperties and with the same |
| 271 | // count as returned the first time), record the count when |
| 272 | // pQueueFamilyProperties is non-NULL: |
| 273 | if (pPhysicalDevice && pQueueFamilyPropertyCount && pQueueFamilyProperties) { |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 274 | pPhysicalDevice->gotQueueFamilyPropertyCount = true; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 275 | pPhysicalDevice->numOfQueueFamilies = *pQueueFamilyPropertyCount; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 278 | |
| 279 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 280 | VKAPI_ATTR VkResult VKAPI_CALL CreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, |
| 281 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 282 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 283 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 284 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 285 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 286 | SwpInstance *pInstance = NULL; |
| 287 | { |
| 288 | auto it = my_data->instanceMap.find(instance); |
| 289 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 290 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 291 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 292 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 293 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 294 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 295 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 296 | result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 297 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 298 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 299 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 300 | { |
| 301 | auto it = my_data->instanceMap.find(instance); |
| 302 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 303 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 304 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 305 | // Record the VkSurfaceKHR returned by the ICD: |
| 306 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 307 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 308 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 309 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 310 | // Point to the associated SwpInstance: |
| 311 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 312 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 313 | lock.unlock(); |
| 314 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 315 | return result; |
| 316 | } |
| 317 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 318 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 319 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 320 | |
| 321 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 322 | VKAPI_ATTR VkResult VKAPI_CALL CreateMirSurfaceKHR(VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo, |
| 323 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 324 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 325 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 326 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 327 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 328 | SwpInstance *pInstance = NULL; |
| 329 | { |
| 330 | auto it = my_data->instanceMap.find(instance); |
| 331 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 332 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 333 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 334 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 335 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 336 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 337 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 338 | result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 339 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 340 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 341 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 342 | { |
| 343 | auto it = my_data->instanceMap.find(instance); |
| 344 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 345 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 346 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 347 | // Record the VkSurfaceKHR returned by the ICD: |
| 348 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 349 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 350 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 351 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 352 | // Point to the associated SwpInstance: |
| 353 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 354 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 355 | lock.unlock(); |
| 356 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 357 | return result; |
| 358 | } |
| 359 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 360 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 361 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 362 | VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceMirPresentationSupportKHR(VkPhysicalDevice physicalDevice, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 363 | uint32_t queueFamilyIndex, MirConnection *connection) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 364 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 365 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 366 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 367 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 368 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 369 | { |
| 370 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 371 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 372 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 373 | |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 374 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 375 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 376 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceMirPresentationSupportKHR", |
| 377 | VALIDATION_ERROR_01893); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 378 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 379 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 380 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 381 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 382 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 383 | result = my_data->instance_dispatch_table->GetPhysicalDeviceMirPresentationSupportKHR(physicalDevice, queueFamilyIndex, |
| 384 | connection); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 385 | } |
| 386 | return result; |
| 387 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 388 | #endif // VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 389 | |
| 390 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 391 | VKAPI_ATTR VkResult VKAPI_CALL CreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, |
| 392 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 393 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 394 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 395 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 396 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 397 | SwpInstance *pInstance = NULL; |
| 398 | { |
| 399 | auto it = my_data->instanceMap.find(instance); |
| 400 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 401 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 402 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 403 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 404 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 405 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 406 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 407 | result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 408 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 409 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 410 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 411 | { |
| 412 | auto it = my_data->instanceMap.find(instance); |
| 413 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 414 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 415 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 416 | // Record the VkSurfaceKHR returned by the ICD: |
| 417 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 418 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 419 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 420 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 421 | // Point to the associated SwpInstance: |
| 422 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 423 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 424 | lock.unlock(); |
| 425 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 426 | return result; |
| 427 | } |
| 428 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 429 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 430 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 431 | VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice, |
| 432 | uint32_t queueFamilyIndex, |
| 433 | struct wl_display *display) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 434 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 435 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 436 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 437 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 438 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 439 | { |
| 440 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 441 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 442 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 443 | |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 444 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 445 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 446 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceWaylandPresentationSupportKHR", |
| 447 | VALIDATION_ERROR_01896); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 448 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 449 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 450 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 451 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 452 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 453 | result = my_data->instance_dispatch_table->GetPhysicalDeviceWaylandPresentationSupportKHR(physicalDevice, queueFamilyIndex, |
| 454 | display); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 455 | } |
| 456 | return result; |
| 457 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 458 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 459 | |
| 460 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 461 | VKAPI_ATTR VkResult VKAPI_CALL CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, |
| 462 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 463 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 464 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 465 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 466 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 467 | SwpInstance *pInstance = NULL; |
| 468 | { |
| 469 | auto it = my_data->instanceMap.find(instance); |
| 470 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 471 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 472 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 473 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 474 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 475 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 476 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 477 | result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 478 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 479 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 480 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 481 | { |
| 482 | auto it = my_data->instanceMap.find(instance); |
| 483 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 484 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 485 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 486 | // Record the VkSurfaceKHR returned by the ICD: |
| 487 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 488 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 489 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 490 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 491 | // Point to the associated SwpInstance: |
| 492 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 493 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 494 | lock.unlock(); |
| 495 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 496 | return result; |
| 497 | } |
| 498 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 499 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 500 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 501 | VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice, |
| 502 | uint32_t queueFamilyIndex) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 503 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 504 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 505 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 506 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 507 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 508 | { |
| 509 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 510 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 511 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 512 | |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 513 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 514 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 515 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceWin32PresentationSupportKHR", |
| 516 | VALIDATION_ERROR_01899); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 517 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 518 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 519 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 520 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 521 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 522 | result = my_data->instance_dispatch_table->GetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamilyIndex); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 523 | } |
| 524 | return result; |
| 525 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 526 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 527 | |
| 528 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 529 | VKAPI_ATTR VkResult VKAPI_CALL CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, |
| 530 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 531 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 532 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 533 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 534 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 535 | SwpInstance *pInstance = NULL; |
| 536 | { |
| 537 | auto it = my_data->instanceMap.find(instance); |
| 538 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 539 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 540 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 541 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 542 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 543 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 544 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 545 | result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 546 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 547 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 548 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 549 | { |
| 550 | auto it = my_data->instanceMap.find(instance); |
| 551 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 552 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 553 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 554 | // Record the VkSurfaceKHR returned by the ICD: |
| 555 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 556 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 557 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 558 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 559 | // Point to the associated SwpInstance: |
| 560 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 561 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 562 | lock.unlock(); |
| 563 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 564 | return result; |
| 565 | } |
| 566 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 567 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 568 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 569 | VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice, |
| 570 | uint32_t queueFamilyIndex, xcb_connection_t *connection, |
| 571 | xcb_visualid_t visual_id) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 572 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 573 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 574 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 575 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 576 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 577 | { |
| 578 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 579 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 580 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 581 | |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 582 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 583 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 584 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceXcbPresentationSupportKHR", |
| 585 | VALIDATION_ERROR_01901); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 586 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 587 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 588 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 589 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 590 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 591 | result = my_data->instance_dispatch_table->GetPhysicalDeviceXcbPresentationSupportKHR(physicalDevice, queueFamilyIndex, |
| 592 | connection, visual_id); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 593 | } |
| 594 | return result; |
| 595 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 596 | #endif // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 597 | |
| 598 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 599 | VKAPI_ATTR VkResult VKAPI_CALL CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, |
| 600 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 601 | VkResult result = VK_SUCCESS; |
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 | SwpInstance *pInstance = NULL; |
| 606 | { |
| 607 | auto it = my_data->instanceMap.find(instance); |
| 608 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 609 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 610 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 611 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 612 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 613 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 614 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 615 | result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 616 | lock.lock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 617 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 618 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 619 | { |
| 620 | auto it = my_data->instanceMap.find(instance); |
| 621 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 622 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 623 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 624 | // Record the VkSurfaceKHR returned by the ICD: |
| 625 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 626 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 627 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 628 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 629 | // Point to the associated SwpInstance: |
| 630 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 631 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 632 | lock.unlock(); |
| 633 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 634 | return result; |
| 635 | } |
| 636 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 637 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 638 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 639 | VKAPI_ATTR VkBool32 VKAPI_CALL GetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 640 | uint32_t queueFamilyIndex, Display *dpy, |
| 641 | VisualID visualID) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 642 | VkBool32 result = VK_FALSE; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 643 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 644 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 645 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 646 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 647 | { |
| 648 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 649 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 650 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 651 | |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 652 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 653 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 654 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceXlibPresentationSupportKHR", |
| 655 | VALIDATION_ERROR_01904); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 656 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 657 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 658 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 659 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 660 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 661 | result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR(physicalDevice, queueFamilyIndex, |
| 662 | dpy, visualID); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 663 | } |
| 664 | return result; |
| 665 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 666 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 667 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 668 | VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 669 | VkDisplayPlanePropertiesKHR *pProperties) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 670 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 671 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 672 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 673 | std::unique_lock<std::mutex> lock(global_lock); |
| 674 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 675 | { |
| 676 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 677 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 678 | } |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 679 | lock.unlock(); |
| 680 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 681 | if (!skip_call) { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 682 | result = my_data->instance_dispatch_table->GetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, pPropertyCount, |
| 683 | pProperties); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 684 | |
| 685 | lock.lock(); |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 686 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 687 | pPhysicalDevice->displayPlanePropertyCount = *pPropertyCount; |
| 688 | pPhysicalDevice->gotDisplayPlanePropertyCount = true; |
| 689 | } |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 690 | // TODO store the properties for later checks |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 691 | lock.unlock(); |
| 692 | |
| 693 | return result; |
| 694 | } |
| 695 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 696 | } |
| 697 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 698 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
| 699 | uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 700 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 701 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 702 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 703 | std::unique_lock<std::mutex> lock(global_lock); |
| 704 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 705 | { |
| 706 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 707 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 708 | } |
| 709 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 710 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { |
| 711 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 712 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, |
| 713 | SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, swapchain_layer_name, |
| 714 | "Potential problem with calling vkGetDisplayPlaneSupportedDisplaysKHR() without first " |
| 715 | "querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR."); |
| 716 | } |
| 717 | |
| 718 | if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) { |
| 719 | skip_call |= |
| 720 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 721 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, VALIDATION_ERROR_01857, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 722 | swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 723 | "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] | 724 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded? %s", |
| 725 | pPhysicalDevice->displayPlanePropertyCount - 1, validation_error_map[VALIDATION_ERROR_01857]); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 726 | } |
| 727 | lock.unlock(); |
| 728 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 729 | if (!skip_call) { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 730 | result = my_data->instance_dispatch_table->GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, |
| 731 | pDisplays); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 732 | |
| 733 | return result; |
| 734 | } |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 735 | // TODO validate the returned display objects |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 736 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 737 | } |
| 738 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 739 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 740 | uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR *pCapabilities) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 741 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 742 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 743 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 744 | std::unique_lock<std::mutex> lock(global_lock); |
| 745 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 746 | { |
| 747 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 748 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 749 | } |
| 750 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 751 | if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { |
| 752 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 753 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, |
| 754 | SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, swapchain_layer_name, |
| 755 | "Potential problem with calling vkGetDisplayPlaneCapabilitiesKHR() without first " |
| 756 | "querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR."); |
| 757 | } |
| 758 | |
| 759 | if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) { |
| 760 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 761 | reinterpret_cast<uint64_t>(pPhysicalDevice->pInstance->instance), __LINE__, |
| 762 | SWAPCHAIN_PLANE_INDEX_TOO_LARGE, swapchain_layer_name, |
| 763 | "vkGetDisplayPlaneCapabilitiesKHR(): planeIndex must be in the range [0, %d] that was returned by " |
| 764 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded?", |
| 765 | pPhysicalDevice->displayPlanePropertyCount - 1); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 766 | } |
| 767 | |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 768 | lock.unlock(); |
| 769 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 770 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 771 | result = my_data->instance_dispatch_table->GetDisplayPlaneCapabilitiesKHR(physicalDevice, mode, planeIndex, pCapabilities); |
| 772 | return result; |
| 773 | } |
| 774 | |
| 775 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 776 | } |
| 777 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 778 | VKAPI_ATTR VkResult VKAPI_CALL CreateDisplayPlaneSurfaceKHR(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, |
| 779 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 780 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 781 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 782 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 783 | std::unique_lock<std::mutex> lock(global_lock); |
| 784 | SwpInstance *pInstance = &(my_data->instanceMap[instance]); |
| 785 | |
Jon Ashburn | e699f44 | 2016-06-30 09:01:27 -0600 | [diff] [blame] | 786 | // TODO more validation checks |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 787 | if (!skip_call) { |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 788 | // Call down the call chain: |
| 789 | lock.unlock(); |
| 790 | result = my_data->instance_dispatch_table->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); |
| 791 | lock.lock(); |
| 792 | |
| 793 | // Obtain this pointer again after locking: |
| 794 | pInstance = &(my_data->instanceMap[instance]); |
| 795 | if ((result == VK_SUCCESS) && pInstance && pSurface) { |
| 796 | // Record the VkSurfaceKHR returned by the ICD: |
| 797 | my_data->surfaceMap[*pSurface].surface = *pSurface; |
| 798 | my_data->surfaceMap[*pSurface].pInstance = pInstance; |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 799 | my_data->surfaceMap[*pSurface].numQueueFamilyIndexSupport = 0; |
| 800 | my_data->surfaceMap[*pSurface].pQueueFamilyIndexSupport = NULL; |
| 801 | // Point to the associated SwpInstance: |
| 802 | pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; |
| 803 | } |
| 804 | lock.unlock(); |
| 805 | return result; |
| 806 | } |
| 807 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 808 | } |
| 809 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 810 | 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] | 811 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 812 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 813 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 814 | SwpSurface *pSurface = NULL; |
| 815 | { |
| 816 | auto it = my_data->surfaceMap.find(surface); |
| 817 | pSurface = (it == my_data->surfaceMap.end()) ? NULL : &it->second; |
| 818 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 819 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 820 | // Regardless of skip_call value, do some internal cleanup: |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 821 | if (pSurface) { |
| 822 | // Delete the SwpSurface associated with this surface: |
| 823 | if (pSurface->pInstance) { |
| 824 | pSurface->pInstance->surfaces.erase(surface); |
| 825 | } |
| 826 | if (!pSurface->swapchains.empty()) { |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 827 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, |
| 828 | reinterpret_cast<uint64_t>(instance), __LINE__, VALIDATION_ERROR_01844, swapchain_layer_name, |
| 829 | "vkDestroySurfaceKHR() called before all of its associated VkSwapchainKHRs were destroyed. %s", |
| 830 | validation_error_map[VALIDATION_ERROR_01844]); |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 831 | |
| 832 | // Empty and then delete all SwpSwapchains |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 833 | for (auto it = pSurface->swapchains.begin(); it != pSurface->swapchains.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 834 | // Delete all SwpImage's |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 835 | // In case the swapchain's device hasn't been destroyed yet |
| 836 | // (which isn't likely, but is possible), delete its |
| 837 | // association with this swapchain (i.e. so we can't point to |
| 838 | // this swpchain from that device, later on): |
| 839 | if (it->second->pDevice) { |
| 840 | it->second->pDevice->swapchains.clear(); |
| 841 | } |
| 842 | } |
| 843 | pSurface->swapchains.clear(); |
| 844 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 845 | my_data->surfaceMap.erase(surface); |
| 846 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 847 | lock.unlock(); |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 848 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 849 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 850 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 851 | my_data->instance_dispatch_table->DestroySurfaceKHR(instance, surface, pAllocator); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 855 | VKAPI_ATTR VkResult VKAPI_CALL EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 856 | VkPhysicalDevice *pPhysicalDevices) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 857 | VkResult result = VK_SUCCESS; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 858 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 859 | |
| 860 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 861 | result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 862 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 863 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 864 | SwpInstance *pInstance = NULL; |
| 865 | { |
| 866 | auto it = my_data->instanceMap.find(instance); |
| 867 | pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; |
| 868 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 869 | if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices && (*pPhysicalDeviceCount > 0)) { |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 870 | // Record the VkPhysicalDevices returned by the ICD: |
| 871 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 872 | my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice = pPhysicalDevices[i]; |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 873 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance; |
| 874 | my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL; |
| 875 | my_data->physicalDeviceMap[pPhysicalDevices[i]].gotQueueFamilyPropertyCount = false; |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 876 | // Point to the associated SwpInstance: |
| 877 | if (pInstance) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 878 | pInstance->physicalDevices[pPhysicalDevices[i]] = &my_data->physicalDeviceMap[pPhysicalDevices[i]]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 879 | } |
| 880 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 881 | } |
Ian Elliott | a3c69bc | 2016-02-04 15:34:59 -0700 | [diff] [blame] | 882 | return result; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 885 | VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 886 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 887 | 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] | 888 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 889 | |
| 890 | assert(chain_info->u.pLayerInfo); |
| 891 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 892 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
Chia-I Wu | a673753 | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 893 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 894 | if (fpCreateDevice == NULL) { |
| 895 | return VK_ERROR_INITIALIZATION_FAILED; |
| 896 | } |
| 897 | |
| 898 | // Advance the link info for the next element on the chain |
| 899 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 900 | |
| 901 | VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); |
| 902 | if (result != VK_SUCCESS) { |
| 903 | return result; |
| 904 | } |
| 905 | |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 906 | std::lock_guard<std::mutex> lock(global_lock); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 907 | 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] | 908 | |
| 909 | // Setup device dispatch table |
| 910 | my_device_data->device_dispatch_table = new VkLayerDispatchTable; |
| 911 | layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); |
| 912 | |
| 913 | 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] | 914 | checkDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 915 | |
| 916 | return result; |
| 917 | } |
| 918 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 919 | VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 920 | dispatch_key key = get_dispatch_key(device); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 921 | layer_data *my_data = GetLayerDataPtr(key, layer_data_map); |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 922 | |
| 923 | // Call down the call chain: |
| 924 | my_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
| 925 | |
| 926 | // Do some internal cleanup: |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 927 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 928 | SwpDevice *pDevice = NULL; |
| 929 | { |
| 930 | auto it = my_data->deviceMap.find(device); |
| 931 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 932 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 933 | if (pDevice) { |
| 934 | // Delete the SwpDevice associated with this device: |
| 935 | if (pDevice->pPhysicalDevice) { |
| 936 | pDevice->pPhysicalDevice->pDevice = NULL; |
| 937 | } |
| 938 | if (!pDevice->swapchains.empty()) { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 939 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 940 | reinterpret_cast<uint64_t>(device), __LINE__, VALIDATION_ERROR_00049, swapchain_layer_name, |
| 941 | "vkDestroyDevice() called before all of its associated VkSwapchainKHRs were destroyed. %s", |
| 942 | validation_error_map[VALIDATION_ERROR_00049]); |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 943 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 944 | // Empty and then delete all SwpSwapchain's |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 945 | for (auto it = pDevice->swapchains.begin(); it != pDevice->swapchains.end(); it++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 946 | // Delete all SwpImage's |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 947 | // In case the swapchain's surface hasn't been destroyed yet |
| 948 | // (which is likely) delete its association with this swapchain |
| 949 | // (i.e. so we can't point to this swpchain from that surface, |
| 950 | // later on): |
| 951 | if (it->second->pSurface) { |
| 952 | it->second->pSurface->swapchains.clear(); |
| 953 | } |
| 954 | } |
| 955 | pDevice->swapchains.clear(); |
| 956 | } |
| 957 | my_data->deviceMap.erase(device); |
| 958 | } |
| 959 | delete my_data->device_dispatch_table; |
| 960 | layer_data_map.erase(key); |
| 961 | } |
| 962 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 963 | VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, |
| 964 | VkSurfaceKHR surface, VkBool32 *pSupported) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 965 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 966 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 967 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 968 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 969 | SwpPhysicalDevice *pPhysicalDevice = NULL; |
| 970 | { |
| 971 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 972 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 973 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 974 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 975 | if (!pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 976 | skip_call |= log_msg( |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 977 | my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 978 | reinterpret_cast<uint64_t>(pPhysicalDevice->physicalDevice), __LINE__, SWAPCHAIN_DID_NOT_QUERY_QUEUE_FAMILIES, |
| 979 | swapchain_layer_name, |
Mark Lobodzinski | 9b482fa | 2016-08-08 09:38:42 -0600 | [diff] [blame] | 980 | "vkGetPhysicalDeviceSurfaceSupportKHR() called before calling the vkGetPhysicalDeviceQueueFamilyProperties function."); |
Mark Lobodzinski | c3b7c46 | 2016-08-08 11:09:27 -0600 | [diff] [blame] | 981 | } else if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 982 | skip_call |= ValidateQueueFamilyIndex(my_data, queueFamilyIndex, pPhysicalDevice->numOfQueueFamilies, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 983 | pPhysicalDevice->physicalDevice, "vkGetPhysicalDeviceSurfaceSupportKHR", |
| 984 | VALIDATION_ERROR_01889); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 985 | } |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 986 | |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 987 | lock.unlock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 988 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 989 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 990 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 991 | result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, |
| 992 | pSupported); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 993 | lock.lock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 994 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 995 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 996 | { |
| 997 | auto it = my_data->physicalDeviceMap.find(physicalDevice); |
| 998 | pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; |
| 999 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1000 | if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) { |
| 1001 | // Record the result of this query: |
| 1002 | SwpInstance *pInstance = pPhysicalDevice->pInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1003 | SwpSurface *pSurface = (pInstance) ? pInstance->surfaces[surface] : NULL; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1004 | if (pSurface) { |
| 1005 | pPhysicalDevice->supportedSurfaces[surface] = pSurface; |
| 1006 | if (!pSurface->numQueueFamilyIndexSupport) { |
| 1007 | if (pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1008 | pSurface->pQueueFamilyIndexSupport = |
| 1009 | (VkBool32 *)malloc(pPhysicalDevice->numOfQueueFamilies * sizeof(VkBool32)); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1010 | if (pSurface->pQueueFamilyIndexSupport != NULL) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1011 | pSurface->numQueueFamilyIndexSupport = pPhysicalDevice->numOfQueueFamilies; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1012 | } |
| 1013 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1014 | } |
| 1015 | if (pSurface->numQueueFamilyIndexSupport) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1016 | pSurface->pQueueFamilyIndexSupport[queueFamilyIndex] = *pSupported; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1020 | lock.unlock(); |
| 1021 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1022 | return result; |
| 1023 | } |
| 1024 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1025 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 1026 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1027 | // This function does the up-front validation work for vkCreateSwapchainKHR(), |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1028 | // and returns true if a logging callback indicates that the call down the |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1029 | // chain should be skipped: |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1030 | static bool validateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, VkSwapchainKHR *pSwapchain) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1031 | // TODO: Validate cases of re-creating a swapchain (the current code |
| 1032 | // assumes a new swapchain is being created). |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1033 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1034 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1035 | SwpDevice *pDevice = NULL; |
| 1036 | { |
| 1037 | auto it = my_data->deviceMap.find(device); |
| 1038 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 1039 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1040 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1041 | // Keep around a useful pointer to pPhysicalDevice: |
| 1042 | SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice; |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1043 | |
Mark Lobodzinski | d40b2db | 2016-02-25 13:56:57 -0700 | [diff] [blame] | 1044 | // Validate pCreateInfo values with result of |
| 1045 | // vkGetPhysicalDeviceQueueFamilyProperties |
| 1046 | if (pPhysicalDevice && pPhysicalDevice->gotQueueFamilyPropertyCount) { |
Michael Mc Donnell | 75ecdb7 | 2016-04-03 14:47:51 -0700 | [diff] [blame] | 1047 | for (uint32_t i = 0; i < pCreateInfo->queueFamilyIndexCount; i++) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1048 | skip_call |= ValidateQueueFamilyIndex(my_data, pCreateInfo->pQueueFamilyIndices[i], pPhysicalDevice->numOfQueueFamilies, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1049 | pPhysicalDevice->physicalDevice, "vkCreateSwapchainKHR"); |
Mark Lobodzinski | d40b2db | 2016-02-25 13:56:57 -0700 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | |
Chris Forbes | e2d8383 | 2016-10-12 15:00:46 +1300 | [diff] [blame] | 1053 | if (pCreateInfo) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1054 | // Validate pCreateInfo->surface to make sure that |
| 1055 | // vkGetPhysicalDeviceSurfaceSupportKHR() reported this as a supported |
| 1056 | // surface: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1057 | SwpSurface *pSurface = ((pPhysicalDevice) ? pPhysicalDevice->supportedSurfaces[pCreateInfo->surface] : NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1058 | if (!pSurface) { |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 1059 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1060 | reinterpret_cast<uint64_t>(device), __LINE__, VALIDATION_ERROR_01922, swapchain_layer_name, |
| 1061 | "The surface in pCreateInfo->surface, that was given to vkCreateSwapchainKHR(), must be a surface " |
| 1062 | "that is supported by the device as determined by vkGetPhysicalDeviceSurfaceSupportKHR(). " |
| 1063 | "However, vkGetPhysicalDeviceSurfaceSupportKHR() was never called with this surface. %s", |
| 1064 | validation_error_map[VALIDATION_ERROR_01922]); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1065 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1066 | } |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 1067 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1068 | // Validate pCreateInfo->imageSharingMode and related values: |
| 1069 | if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) { |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 1070 | if (pCreateInfo->queueFamilyIndexCount <= 1) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1071 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 1072 | reinterpret_cast<uint64_t>(device), __LINE__, VALIDATION_ERROR_02338, swapchain_layer_name, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1073 | "vkCreateSwapchainKHR() called with a supported pCreateInfo->sharingMode of (i.e. %s), but with a " |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 1074 | "bad value(s) for pCreateInfo->queueFamilyIndexCount or pCreateInfo->pQueueFamilyIndices). %s", |
| 1075 | sharingModeStr(pCreateInfo->imageSharingMode), validation_error_map[VALIDATION_ERROR_02338]); |
| 1076 | } |
| 1077 | |
| 1078 | if (!pCreateInfo->pQueueFamilyIndices) { |
| 1079 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 1080 | reinterpret_cast<uint64_t>(device), __LINE__, VALIDATION_ERROR_02337, swapchain_layer_name, |
| 1081 | "vkCreateSwapchainKHR() called with a supported pCreateInfo->sharingMode of (i.e. %s), but with a " |
| 1082 | "bad value(s) for pCreateInfo->queueFamilyIndexCount or pCreateInfo->pQueueFamilyIndices). %s", |
| 1083 | sharingModeStr(pCreateInfo->imageSharingMode), validation_error_map[VALIDATION_ERROR_02337]); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1084 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1085 | } |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 1086 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1087 | return skip_call; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1088 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1089 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1090 | VKAPI_ATTR VkResult VKAPI_CALL CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1091 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1092 | VkResult result = VK_SUCCESS; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1093 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1094 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1095 | bool skip_call = validateCreateSwapchainKHR(device, pCreateInfo, pSwapchain); |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1096 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1097 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1098 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1099 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1100 | result = my_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1101 | lock.lock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1102 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1103 | if (result == VK_SUCCESS) { |
| 1104 | // Remember the swapchain's handle, and link it to the device: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1105 | SwpDevice *pDevice = NULL; |
| 1106 | { |
| 1107 | auto it = my_data->deviceMap.find(device); |
| 1108 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 1109 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1110 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1111 | my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain; |
| 1112 | if (pDevice) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1113 | pDevice->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1114 | } |
| 1115 | my_data->swapchainMap[*pSwapchain].pDevice = pDevice; |
| 1116 | my_data->swapchainMap[*pSwapchain].imageCount = 0; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1117 | // Store a pointer to the surface |
| 1118 | SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1119 | SwpInstance *pInstance = (pPhysicalDevice) ? pPhysicalDevice->pInstance : NULL; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1120 | layer_data *my_instance_data = |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1121 | ((pInstance) ? GetLayerDataPtr(get_dispatch_key(pInstance->instance), layer_data_map) : NULL); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1122 | SwpSurface *pSurface = ((my_data && pCreateInfo) ? &my_instance_data->surfaceMap[pCreateInfo->surface] : NULL); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1123 | my_data->swapchainMap[*pSwapchain].pSurface = pSurface; |
| 1124 | if (pSurface) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1125 | pSurface->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1126 | } |
| 1127 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1128 | lock.unlock(); |
| 1129 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1130 | return result; |
| 1131 | } |
| 1132 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1133 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1134 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1135 | 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] | 1136 | // TODOs: |
| 1137 | // |
| 1138 | // - Implement a check for validity language that reads: All uses of |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 1139 | // presentable images acquired from pname:swapchain must: have completed |
| 1140 | // execution |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1141 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1142 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1143 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1144 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1145 | // Regardless of skip_call value, do some internal cleanup: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1146 | SwpSwapchain *pSwapchain = NULL; |
| 1147 | { |
| 1148 | auto it = my_data->swapchainMap.find(swapchain); |
| 1149 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 1150 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1151 | if (pSwapchain) { |
| 1152 | // Delete the SwpSwapchain associated with this swapchain: |
| 1153 | if (pSwapchain->pDevice) { |
| 1154 | pSwapchain->pDevice->swapchains.erase(swapchain); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1155 | } |
| 1156 | if (pSwapchain->pSurface) { |
| 1157 | pSwapchain->pSurface->swapchains.erase(swapchain); |
| 1158 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1159 | my_data->swapchainMap.erase(swapchain); |
| 1160 | } |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1161 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1162 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1163 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1164 | // Call down the call chain: |
| 1165 | my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator); |
| 1166 | } |
| 1167 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1168 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1169 | VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, |
| 1170 | VkImage *pSwapchainImages) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1171 | VkResult result = VK_SUCCESS; |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1172 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1173 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1174 | std::unique_lock<std::mutex> lock(global_lock); |
Ian Elliott | 8b9e256 | 2016-01-05 13:00:50 -0700 | [diff] [blame] | 1175 | |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1176 | SwpSwapchain *pSwapchain = NULL; |
| 1177 | { |
| 1178 | auto it = my_data->swapchainMap.find(swapchain); |
| 1179 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 1180 | } |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1181 | if (pSwapchain && pSwapchainImages) { |
| 1182 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1183 | if (pSwapchain->imageCount == 0) { |
Mark Lobodzinski | 0f73c0b | 2016-08-08 09:57:09 -0600 | [diff] [blame] | 1184 | // Since we haven't recorded a preliminary value of *pSwapchainImageCount, that likely means that the application didn't |
| 1185 | // previously call this function with a NULL value of pSwapchainImages: |
Mark Lobodzinski | 6a7e933 | 2016-08-16 09:06:15 -0600 | [diff] [blame] | 1186 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1187 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_PRIOR_COUNT, swapchain_layer_name, |
| 1188 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive " |
| 1189 | "value has been seen for pSwapchainImages."); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1190 | } else if (*pSwapchainImageCount > pSwapchain->imageCount) { |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1191 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1192 | reinterpret_cast<uint64_t>(device), __LINE__, SWAPCHAIN_INVALID_COUNT, swapchain_layer_name, |
| 1193 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount, and with " |
| 1194 | "pSwapchainImages set to a value (%d) that is greater than the value (%d) that was returned when " |
| 1195 | "pSwapchainImageCount was NULL.", |
| 1196 | *pSwapchainImageCount, pSwapchain->imageCount); |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1197 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1198 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1199 | lock.unlock(); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1200 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1201 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1202 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1203 | result = my_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1204 | lock.lock(); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1205 | |
Ian Elliott | 3231183 | 2016-02-04 08:17:18 -0700 | [diff] [blame] | 1206 | // Obtain this pointer again after locking: |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1207 | { |
| 1208 | auto it = my_data->swapchainMap.find(swapchain); |
| 1209 | pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; |
| 1210 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1211 | if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages && pSwapchainImageCount) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1212 | // Record the result of this preliminary query: |
| 1213 | pSwapchain->imageCount = *pSwapchainImageCount; |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1214 | } else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages && pSwapchainImageCount && |
| 1215 | (*pSwapchainImageCount > 0)) { |
Ian Elliott | fdf3ffa | 2016-05-05 14:06:53 -0600 | [diff] [blame] | 1216 | // Record the images and their state: |
| 1217 | pSwapchain->imageCount = *pSwapchainImageCount; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1218 | } |
Ian Elliott | 970a2bd | 2016-06-21 11:08:43 -0600 | [diff] [blame] | 1219 | lock.unlock(); |
| 1220 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1221 | return result; |
| 1222 | } |
| 1223 | return VK_ERROR_VALIDATION_FAILED_EXT; |
| 1224 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1225 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1226 | 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] | 1227 | bool skip_call = false; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1228 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 1229 | |
Mark Lobodzinski | 38ece43 | 2016-08-08 14:36:58 -0600 | [diff] [blame] | 1230 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1231 | // Call down the call chain: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1232 | my_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 1233 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1234 | // Remember the queue's handle, and link it to the device: |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1235 | std::lock_guard<std::mutex> lock(global_lock); |
Ian Elliott | 77f46ca | 2016-05-05 14:10:49 -0600 | [diff] [blame] | 1236 | SwpDevice *pDevice = NULL; |
| 1237 | { |
| 1238 | auto it = my_data->deviceMap.find(device); |
| 1239 | pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; |
| 1240 | } |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1241 | my_data->queueMap[&pQueue].queue = *pQueue; |
| 1242 | if (pDevice) { |
| 1243 | pDevice->queues[*pQueue] = &my_data->queueMap[*pQueue]; |
| 1244 | } |
| 1245 | my_data->queueMap[&pQueue].pDevice = pDevice; |
| 1246 | my_data->queueMap[&pQueue].queueFamilyIndex = queueFamilyIndex; |
| 1247 | } |
| 1248 | } |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 1249 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1250 | VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance, |
| 1251 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 1252 | const VkAllocationCallbacks *pAllocator, |
| 1253 | VkDebugReportCallbackEXT *pMsgCallback) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1254 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1255 | VkResult result = |
| 1256 | my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1257 | if (VK_SUCCESS == result) { |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1258 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 1259 | 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] | 1260 | } |
| 1261 | return result; |
| 1262 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1263 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1264 | VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1265 | const VkAllocationCallbacks *pAllocator) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1266 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1267 | my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Jeremy Hayes | 9de0bd7 | 2016-04-13 11:57:20 -0600 | [diff] [blame] | 1268 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1269 | layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator); |
| 1270 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1271 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1272 | VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 1273 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 1274 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1275 | layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1276 | my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, |
| 1277 | pMsg); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1278 | } |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 1279 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1280 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1281 | return util_GetLayerProperties(1, &swapchain_layer, pCount, pProperties); |
| 1282 | } |
| 1283 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1284 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 1285 | VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1286 | return util_GetLayerProperties(1, &swapchain_layer, pCount, pProperties); |
| 1287 | } |
| 1288 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1289 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 1290 | VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1291 | if (pLayerName && !strcmp(pLayerName, swapchain_layer.layerName)) |
| 1292 | return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties); |
| 1293 | |
| 1294 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 1295 | } |
| 1296 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1297 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 1298 | uint32_t *pCount, VkExtensionProperties *pProperties) { |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 1299 | if (pLayerName && !strcmp(pLayerName, swapchain_layer.layerName)) |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1300 | return util_GetExtensionProperties(0, nullptr, pCount, pProperties); |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 1301 | |
| 1302 | assert(physicalDevice); |
| 1303 | |
| 1304 | dispatch_key key = get_dispatch_key(physicalDevice); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1305 | layer_data *my_data = GetLayerDataPtr(key, layer_data_map); |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 1306 | return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1307 | } |
| 1308 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1309 | static PFN_vkVoidFunction intercept_core_instance_command(const char *name); |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1310 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1311 | 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] | 1312 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1313 | static PFN_vkVoidFunction intercept_core_device_command(const char *name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1314 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1315 | 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] | 1316 | |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1317 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { |
| 1318 | PFN_vkVoidFunction proc = intercept_core_device_command(funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1319 | if (proc) return proc; |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1320 | |
| 1321 | assert(device); |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1322 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1323 | layer_data *my_data; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1324 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1325 | my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1326 | VkLayerDispatchTable *pDisp = my_data->device_dispatch_table; |
Chia-I Wu | 8324595 | 2016-05-05 16:13:19 +0800 | [diff] [blame] | 1327 | |
| 1328 | proc = intercept_khr_swapchain_command(funcName, device); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1329 | if (proc) return proc; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1330 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1331 | if (pDisp->GetDeviceProcAddr == NULL) return NULL; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1332 | return pDisp->GetDeviceProcAddr(device, funcName); |
| 1333 | } |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1334 | |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1335 | 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] | 1336 | PFN_vkVoidFunction proc = intercept_core_instance_command(funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1337 | if (!proc) proc = intercept_core_device_command(funcName); |
| 1338 | if (!proc) proc = intercept_khr_swapchain_command(funcName, VK_NULL_HANDLE); |
| 1339 | if (proc) return proc; |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 1340 | |
Chia-I Wu | 5ae2f65 | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 1341 | assert(instance); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1342 | |
| 1343 | layer_data *my_data; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1344 | my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1345 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 1346 | |
Chia-I Wu | 5ae2f65 | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 1347 | proc = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1348 | if (!proc) proc = intercept_khr_surface_command(funcName, instance); |
| 1349 | if (proc) return proc; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1350 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1351 | if (pTable->GetInstanceProcAddr == NULL) return NULL; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1352 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 1353 | } |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1354 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1355 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { |
| 1356 | assert(instance); |
| 1357 | |
| 1358 | layer_data *my_data; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 1359 | my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1360 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
| 1361 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1362 | if (pTable->GetPhysicalDeviceProcAddr == NULL) return NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1363 | return pTable->GetPhysicalDeviceProcAddr(instance, funcName); |
| 1364 | } |
| 1365 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1366 | static PFN_vkVoidFunction intercept_core_instance_command(const char *name) { |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1367 | static const struct { |
| 1368 | const char *name; |
| 1369 | PFN_vkVoidFunction proc; |
| 1370 | } core_instance_commands[] = { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1371 | {"vkGetInstanceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr)}, |
| 1372 | {"vkCreateInstance", reinterpret_cast<PFN_vkVoidFunction>(CreateInstance)}, |
| 1373 | {"vkDestroyInstance", reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance)}, |
| 1374 | {"vkCreateDevice", reinterpret_cast<PFN_vkVoidFunction>(CreateDevice)}, |
| 1375 | {"vkEnumeratePhysicalDevices", reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices)}, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1376 | {"vk_layerGetPhysicalDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProcAddr)}, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1377 | {"vkEnumerateInstanceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceLayerProperties)}, |
| 1378 | {"vkEnumerateDeviceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceLayerProperties)}, |
| 1379 | {"vkEnumerateInstanceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties)}, |
| 1380 | {"vkEnumerateDeviceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties)}, |
| 1381 | {"vkGetPhysicalDeviceQueueFamilyProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties)}, |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1382 | }; |
| 1383 | |
| 1384 | for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1385 | 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] | 1386 | } |
| 1387 | |
| 1388 | return nullptr; |
| 1389 | } |
| 1390 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1391 | 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] | 1392 | static const struct { |
| 1393 | const char *name; |
| 1394 | PFN_vkVoidFunction proc; |
| 1395 | } khr_surface_commands[] = { |
| 1396 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1397 | {"vkCreateAndroidSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateAndroidSurfaceKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1398 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1399 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1400 | {"vkCreateMirSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateMirSurfaceKHR)}, |
| 1401 | {"vkGetPhysicalDeviceMirPresentationSupportKHR", |
| 1402 | reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMirPresentationSupportKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1403 | #endif // VK_USE_PLATFORM_MIR_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1404 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1405 | {"vkCreateWaylandSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateWaylandSurfaceKHR)}, |
| 1406 | {"vkGetPhysicalDeviceWaylandPresentationSupportKHR", |
| 1407 | reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceWaylandPresentationSupportKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1408 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1409 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1410 | {"vkCreateWin32SurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateWin32SurfaceKHR)}, |
| 1411 | {"vkGetPhysicalDeviceWin32PresentationSupportKHR", |
| 1412 | reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceWin32PresentationSupportKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1413 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1414 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1415 | {"vkCreateXcbSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateXcbSurfaceKHR)}, |
| 1416 | {"vkGetPhysicalDeviceXcbPresentationSupportKHR", |
| 1417 | reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceXcbPresentationSupportKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1418 | #endif // VK_USE_PLATFORM_XCB_KHR |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1419 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1420 | {"vkCreateXlibSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateXlibSurfaceKHR)}, |
| 1421 | {"vkGetPhysicalDeviceXlibPresentationSupportKHR", |
| 1422 | reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceXlibPresentationSupportKHR)}, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1423 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1424 | {"vkDestroySurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(DestroySurfaceKHR)}, |
| 1425 | {"vkGetPhysicalDeviceSurfaceSupportKHR", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceSupportKHR)}, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1426 | {"vkGetPhysicalDeviceDisplayPlanePropertiesKHR", |
| 1427 | reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceDisplayPlanePropertiesKHR)}, |
| 1428 | {"vkGetDisplayPlaneSupportedDisplaysKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayPlaneSupportedDisplaysKHR)}, |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1429 | {"vkGetDisplayPlaneCapabilitiesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayPlaneCapabilitiesKHR)}, |
| 1430 | {"vkCreateDisplayPlaneSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateDisplayPlaneSurfaceKHR)}, |
Chia-I Wu | 22813c7 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1431 | }; |
| 1432 | |
| 1433 | // do not check if VK_KHR_*_surface is enabled (why?) |
| 1434 | |
| 1435 | for (size_t i = 0; i < ARRAY_SIZE(khr_surface_commands); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1436 | 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] | 1437 | } |
| 1438 | |
| 1439 | return nullptr; |
| 1440 | } |
| 1441 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1442 | static PFN_vkVoidFunction intercept_core_device_command(const char *name) { |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1443 | static const struct { |
| 1444 | const char *name; |
| 1445 | PFN_vkVoidFunction proc; |
| 1446 | } core_device_commands[] = { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1447 | {"vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr)}, |
| 1448 | {"vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice)}, |
| 1449 | {"vkGetDeviceQueue", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue)}, |
Chia-I Wu | 9bc0b58 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1450 | }; |
| 1451 | |
| 1452 | for (size_t i = 0; i < ARRAY_SIZE(core_device_commands); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1453 | 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] | 1454 | } |
| 1455 | |
| 1456 | return nullptr; |
| 1457 | } |
| 1458 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1459 | 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] | 1460 | static const struct { |
| 1461 | const char *name; |
| 1462 | PFN_vkVoidFunction proc; |
| 1463 | } khr_swapchain_commands[] = { |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1464 | {"vkCreateSwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR)}, |
| 1465 | {"vkDestroySwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR)}, |
| 1466 | {"vkGetSwapchainImagesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR)}, |
Chia-I Wu | 8324595 | 2016-05-05 16:13:19 +0800 | [diff] [blame] | 1467 | }; |
| 1468 | |
| 1469 | // do not check if VK_KHR_swapchain is enabled (why?) |
| 1470 | |
| 1471 | for (size_t i = 0; i < ARRAY_SIZE(khr_swapchain_commands); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1472 | 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] | 1473 | } |
| 1474 | |
| 1475 | return nullptr; |
| 1476 | } |
| 1477 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1478 | } // namespace swapchain |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1479 | |
| 1480 | // vk_layer_logging.h expects these to be defined |
| 1481 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1482 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance, |
| 1483 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 1484 | const VkAllocationCallbacks *pAllocator, |
| 1485 | VkDebugReportCallbackEXT *pMsgCallback) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1486 | return swapchain::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1487 | } |
| 1488 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1489 | VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, |
| 1490 | const VkAllocationCallbacks *pAllocator) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1491 | swapchain::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1492 | } |
| 1493 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1494 | VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 1495 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 1496 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Chia-I Wu | fccbfe4 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1497 | swapchain::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1498 | } |
| 1499 | |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1500 | // 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] | 1501 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1502 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 1503 | VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1504 | return swapchain::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1505 | } |
| 1506 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1507 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, |
| 1508 | VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1509 | return swapchain::EnumerateInstanceLayerProperties(pCount, pProperties); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1510 | } |
| 1511 | |
Mark Lobodzinski | d0ef521 | 2016-08-08 14:41:55 -0600 | [diff] [blame] | 1512 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 1513 | VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1514 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 1515 | assert(physicalDevice == VK_NULL_HANDLE); |
| 1516 | return swapchain::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 1520 | const char *pLayerName, uint32_t *pCount, |
| 1521 | VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1522 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 1523 | assert(physicalDevice == VK_NULL_HANDLE); |
Chia-I Wu | 2b48125 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 1524 | return swapchain::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | 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] | 1528 | return swapchain::GetDeviceProcAddr(dev, funcName); |
Chia-I Wu | 516b508 | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | 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] | 1532 | return swapchain::GetInstanceProcAddr(instance, funcName); |
Chia-I Wu | 045209e | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1533 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1534 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1535 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance, |
| 1536 | const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1537 | return swapchain::GetPhysicalDeviceProcAddr(instance, funcName); |
| 1538 | } |
| 1539 | |
| 1540 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) { |
| 1541 | assert(pVersionStruct != NULL); |
| 1542 | assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT); |
| 1543 | |
| 1544 | // Fill in the function pointers if our version is at least capable of having the structure contain them. |
| 1545 | if (pVersionStruct->loaderLayerInterfaceVersion >= 2) { |
| 1546 | pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr; |
| 1547 | pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr; |
| 1548 | pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr; |
| 1549 | } |
| 1550 | |
| 1551 | if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 1552 | swapchain::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion; |
| 1553 | } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 1554 | pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 1555 | } |
| 1556 | |
| 1557 | return VK_SUCCESS; |
| 1558 | } |