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