| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 5 | * Copyright (c) 2015-2016 Google, Inc. |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * Author: Tobin Ehlis <tobine@google.com> |
| 20 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 21 | */ |
| 22 | |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 23 | #define NOMINMAX |
| John Zulauf | 0fe5bfe | 2018-05-23 09:36:00 -0600 | [diff] [blame^] | 24 | #define VALIDATION_ERROR_MAP_IMPL |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 25 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <unordered_map> |
| 30 | #include <vector> |
| 31 | #include <list> |
| 32 | #include <memory> |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 33 | #include <algorithm> |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 34 | |
| Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 35 | // For Windows, this #include must come before other Vk headers. |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 36 | #include "vk_loader_platform.h" |
| Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 37 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 38 | #include "unique_objects.h" |
| 39 | #include "vk_dispatch_table_helper.h" |
| Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 40 | #include "vk_layer_config.h" |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 41 | #include "vk_layer_data.h" |
| Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 42 | #include "vk_layer_extension_utils.h" |
| 43 | #include "vk_layer_logging.h" |
| 44 | #include "vk_layer_table.h" |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 45 | #include "vk_layer_utils.h" |
| Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 46 | #include "vk_layer_utils.h" |
| Mark Lobodzinski | 9acd2e3 | 2016-12-21 15:22:39 -0700 | [diff] [blame] | 47 | #include "vk_enum_string_helper.h" |
| Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 48 | #include "vk_validation_error_messages.h" |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 49 | #include "vk_object_types.h" |
| Mark Lobodzinski | 75a4631 | 2018-01-03 11:23:55 -0700 | [diff] [blame] | 50 | #include "vk_extension_helper.h" |
| Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 51 | #include "vulkan/vk_layer.h" |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 52 | |
| Mike Stroyan | b985fca | 2016-11-01 11:50:16 -0600 | [diff] [blame] | 53 | // This intentionally includes a cpp file |
| 54 | #include "vk_safe_struct.cpp" |
| 55 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 56 | #include "unique_objects_wrappers.h" |
| 57 | |
| 58 | namespace unique_objects { |
| 59 | |
| Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 60 | static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 61 | |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 62 | static void initUniqueObjects(instance_layer_data *instance_data, const VkAllocationCallbacks *pAllocator) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 63 | layer_debug_report_actions(instance_data->report_data, instance_data->logging_callback, pAllocator, "google_unique_objects"); |
| 64 | layer_debug_messenger_actions(instance_data->report_data, instance_data->logging_messenger, pAllocator, |
| 65 | "google_unique_objects"); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 66 | } |
| 67 | |
| Mark Lobodzinski | c014147 | 2017-06-09 09:51:34 -0600 | [diff] [blame] | 68 | // Check enabled instance extensions against supported instance extension whitelist |
| 69 | static void InstanceExtensionWhitelist(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 70 | instance_layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 71 | |
| Mark Lobodzinski | 38686e9 | 2017-06-07 16:04:50 -0600 | [diff] [blame] | 72 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 73 | // Check for recognized instance extensions |
| Mark Lobodzinski | 75a4631 | 2018-01-03 11:23:55 -0700 | [diff] [blame] | 74 | if (!white_list(pCreateInfo->ppEnabledExtensionNames[i], kInstanceExtensionNames)) { |
| Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 75 | log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 76 | VALIDATION_ERROR_UNDEFINED, |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 77 | "Instance Extension %s is not supported by this layer. Using this extension may adversely affect validation " |
| 78 | "results and/or produce undefined behavior.", |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 79 | pCreateInfo->ppEnabledExtensionNames[i]); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| Mark Lobodzinski | c014147 | 2017-06-09 09:51:34 -0600 | [diff] [blame] | 84 | // Check enabled device extensions against supported device extension whitelist |
| 85 | static void DeviceExtensionWhitelist(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) { |
| Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 86 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 87 | |
| 88 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 89 | // Check for recognized device extensions |
| Mark Lobodzinski | 75a4631 | 2018-01-03 11:23:55 -0700 | [diff] [blame] | 90 | if (!white_list(pCreateInfo->ppEnabledExtensionNames[i], kDeviceExtensionNames)) { |
| Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 91 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 92 | VALIDATION_ERROR_UNDEFINED, |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 93 | "Device Extension %s is not supported by this layer. Using this extension may adversely affect validation " |
| 94 | "results and/or produce undefined behavior.", |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 95 | pCreateInfo->ppEnabledExtensionNames[i]); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 101 | VkInstance *pInstance) { |
| 102 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 103 | |
| 104 | assert(chain_info->u.pLayerInfo); |
| 105 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 106 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
| 107 | if (fpCreateInstance == NULL) { |
| 108 | return VK_ERROR_INITIALIZATION_FAILED; |
| 109 | } |
| 110 | |
| 111 | // Advance the link info for the next element on the chain |
| 112 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 113 | |
| 114 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 115 | if (result != VK_SUCCESS) { |
| 116 | return result; |
| 117 | } |
| 118 | |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 119 | instance_layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), instance_layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 120 | instance_data->instance = *pInstance; |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 121 | layer_init_instance_dispatch_table(*pInstance, &instance_data->dispatch_table, fpGetInstanceProcAddr); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 122 | |
| 123 | instance_data->instance = *pInstance; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 124 | instance_data->report_data = debug_utils_create_instance( |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 125 | &instance_data->dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 126 | |
| 127 | // Set up temporary debug callbacks to output messages at CreateInstance-time |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 128 | if (!layer_copy_tmp_debug_messengers(pCreateInfo->pNext, &instance_data->num_tmp_debug_messengers, |
| 129 | &instance_data->tmp_messenger_create_infos, &instance_data->tmp_debug_messengers)) { |
| 130 | if (instance_data->num_tmp_debug_messengers > 0) { |
| 131 | if (layer_enable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers, |
| 132 | instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers)) { |
| 133 | layer_free_tmp_debug_messengers(instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers); |
| 134 | instance_data->num_tmp_debug_messengers = 0; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | if (!layer_copy_tmp_report_callbacks(pCreateInfo->pNext, &instance_data->num_tmp_report_callbacks, |
| 139 | &instance_data->tmp_report_create_infos, &instance_data->tmp_report_callbacks)) { |
| 140 | if (instance_data->num_tmp_report_callbacks > 0) { |
| 141 | if (layer_enable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks, |
| 142 | instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks)) { |
| 143 | layer_free_tmp_report_callbacks(instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks); |
| 144 | instance_data->num_tmp_report_callbacks = 0; |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | initUniqueObjects(instance_data, pAllocator); |
| Mark Lobodzinski | c014147 | 2017-06-09 09:51:34 -0600 | [diff] [blame] | 150 | InstanceExtensionWhitelist(pCreateInfo, *pInstance); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 151 | |
| 152 | // Disable and free tmp callbacks, no longer necessary |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 153 | if (instance_data->num_tmp_debug_messengers > 0) { |
| 154 | layer_disable_tmp_debug_messengers(instance_data->report_data, instance_data->num_tmp_debug_messengers, |
| 155 | instance_data->tmp_debug_messengers); |
| 156 | layer_free_tmp_debug_messengers(instance_data->tmp_messenger_create_infos, instance_data->tmp_debug_messengers); |
| 157 | instance_data->num_tmp_debug_messengers = 0; |
| 158 | } |
| 159 | if (instance_data->num_tmp_report_callbacks > 0) { |
| 160 | layer_disable_tmp_report_callbacks(instance_data->report_data, instance_data->num_tmp_report_callbacks, |
| 161 | instance_data->tmp_report_callbacks); |
| 162 | layer_free_tmp_report_callbacks(instance_data->tmp_report_create_infos, instance_data->tmp_report_callbacks); |
| 163 | instance_data->num_tmp_report_callbacks = 0; |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | return result; |
| 167 | } |
| 168 | |
| 169 | VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
| 170 | dispatch_key key = get_dispatch_key(instance); |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 171 | instance_layer_data *instance_data = GetLayerDataPtr(key, instance_layer_data_map); |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 172 | VkLayerInstanceDispatchTable *disp_table = &instance_data->dispatch_table; |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 173 | disp_table->DestroyInstance(instance, pAllocator); |
| 174 | |
| 175 | // Clean up logging callback, if any |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 176 | while (instance_data->logging_messenger.size() > 0) { |
| 177 | VkDebugUtilsMessengerEXT messenger = instance_data->logging_messenger.back(); |
| 178 | layer_destroy_messenger_callback(instance_data->report_data, messenger, pAllocator); |
| 179 | instance_data->logging_messenger.pop_back(); |
| 180 | } |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 181 | while (instance_data->logging_callback.size() > 0) { |
| 182 | VkDebugReportCallbackEXT callback = instance_data->logging_callback.back(); |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 183 | layer_destroy_report_callback(instance_data->report_data, callback, pAllocator); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 184 | instance_data->logging_callback.pop_back(); |
| 185 | } |
| 186 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 187 | layer_debug_utils_destroy_instance(instance_data->report_data); |
| Gabríel Arthúr Pétursson | 2c5e750 | 2017-06-03 23:27:59 +0000 | [diff] [blame] | 188 | FreeLayerDataPtr(key, instance_layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 192 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 193 | instance_layer_data *my_instance_data = GetLayerDataPtr(get_dispatch_key(gpu), instance_layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 194 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 195 | |
| 196 | assert(chain_info->u.pLayerInfo); |
| 197 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 198 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
| 199 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); |
| 200 | if (fpCreateDevice == NULL) { |
| 201 | return VK_ERROR_INITIALIZATION_FAILED; |
| 202 | } |
| 203 | |
| 204 | // Advance the link info for the next element on the chain |
| 205 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 206 | |
| 207 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| 208 | if (result != VK_SUCCESS) { |
| 209 | return result; |
| 210 | } |
| 211 | |
| Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 212 | layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 213 | my_device_data->report_data = layer_debug_utils_create_device(my_instance_data->report_data, *pDevice); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 214 | |
| 215 | // Setup layer's device dispatch table |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 216 | layer_init_device_dispatch_table(*pDevice, &my_device_data->dispatch_table, fpGetDeviceProcAddr); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 217 | |
| Mark Lobodzinski | c014147 | 2017-06-09 09:51:34 -0600 | [diff] [blame] | 218 | DeviceExtensionWhitelist(pCreateInfo, *pDevice); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 219 | |
| Mark Lobodzinski | c014147 | 2017-06-09 09:51:34 -0600 | [diff] [blame] | 220 | // Set gpu for this device in order to get at any objects mapped at instance level |
| Chris Forbes | 7fcfde1 | 2017-05-02 16:54:24 -0700 | [diff] [blame] | 221 | my_device_data->instance_data = my_instance_data; |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 222 | |
| 223 | return result; |
| 224 | } |
| 225 | |
| 226 | VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
| 227 | dispatch_key key = get_dispatch_key(device); |
| Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 228 | layer_data *dev_data = GetLayerDataPtr(key, layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 229 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 230 | layer_debug_utils_destroy_device(device); |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 231 | dev_data->dispatch_table.DestroyDevice(device, pAllocator); |
| Gabríel Arthúr Pétursson | 2c5e750 | 2017-06-03 23:27:59 +0000 | [diff] [blame] | 232 | |
| 233 | FreeLayerDataPtr(key, layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static const VkLayerProperties globalLayerProps = {"VK_LAYER_GOOGLE_unique_objects", |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 237 | VK_LAYER_API_VERSION, // specVersion |
| 238 | 1, // implementationVersion |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 239 | "Google Validation Layer"}; |
| 240 | |
| Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 241 | /// Declare prototype for these functions |
| 242 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName); |
| 243 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 244 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
| 245 | return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties); |
| 246 | } |
| 247 | |
| 248 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 249 | VkLayerProperties *pProperties) { |
| 250 | return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties); |
| 251 | } |
| 252 | |
| 253 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 254 | VkExtensionProperties *pProperties) { |
| 255 | if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName)) |
| 256 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 257 | |
| 258 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 259 | } |
| 260 | |
| 261 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 262 | uint32_t *pCount, VkExtensionProperties *pProperties) { |
| 263 | if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName)) |
| 264 | return util_GetExtensionProperties(0, nullptr, pCount, pProperties); |
| 265 | |
| 266 | assert(physicalDevice); |
| 267 | |
| 268 | dispatch_key key = get_dispatch_key(physicalDevice); |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 269 | instance_layer_data *instance_data = GetLayerDataPtr(key, instance_layer_data_map); |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 270 | return instance_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { |
| Mark Lobodzinski | 38686e9 | 2017-06-07 16:04:50 -0600 | [diff] [blame] | 274 | const auto item = name_to_funcptr_map.find(funcName); |
| 275 | if (item != name_to_funcptr_map.end()) { |
| 276 | return reinterpret_cast<PFN_vkVoidFunction>(item->second); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 277 | } |
| 278 | |
| Mark Lobodzinski | 38686e9 | 2017-06-07 16:04:50 -0600 | [diff] [blame] | 279 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 280 | const auto &table = device_data->dispatch_table; |
| 281 | if (!table.GetDeviceProcAddr) return nullptr; |
| 282 | return table.GetDeviceProcAddr(device, funcName); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { |
| Mark Lobodzinski | 38686e9 | 2017-06-07 16:04:50 -0600 | [diff] [blame] | 286 | const auto item = name_to_funcptr_map.find(funcName); |
| 287 | if (item != name_to_funcptr_map.end()) { |
| 288 | return reinterpret_cast<PFN_vkVoidFunction>(item->second); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 289 | } |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 290 | |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 291 | instance_layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map); |
| Mark Lobodzinski | 38686e9 | 2017-06-07 16:04:50 -0600 | [diff] [blame] | 292 | const auto &table = instance_data->dispatch_table; |
| 293 | if (!table.GetInstanceProcAddr) return nullptr; |
| 294 | return table.GetInstanceProcAddr(instance, funcName); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 295 | } |
| 296 | |
| Mark Lobodzinski | 38686e9 | 2017-06-07 16:04:50 -0600 | [diff] [blame] | 297 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 298 | instance_layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map); |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 299 | VkLayerInstanceDispatchTable *disp_table = &instance_data->dispatch_table; |
| Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 300 | if (disp_table->GetPhysicalDeviceProcAddr == NULL) { |
| 301 | return NULL; |
| 302 | } |
| 303 | return disp_table->GetPhysicalDeviceProcAddr(instance, funcName); |
| 304 | } |
| 305 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 306 | VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 307 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 308 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) { |
| Chris Forbes | 6956a31 | 2017-05-02 17:36:28 -0700 | [diff] [blame] | 309 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 310 | safe_VkComputePipelineCreateInfo *local_pCreateInfos = NULL; |
| 311 | if (pCreateInfos) { |
| 312 | std::lock_guard<std::mutex> lock(global_lock); |
| 313 | local_pCreateInfos = new safe_VkComputePipelineCreateInfo[createInfoCount]; |
| 314 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
| 315 | local_pCreateInfos[idx0].initialize(&pCreateInfos[idx0]); |
| 316 | if (pCreateInfos[idx0].basePipelineHandle) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 317 | local_pCreateInfos[idx0].basePipelineHandle = Unwrap(pCreateInfos[idx0].basePipelineHandle); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 318 | } |
| 319 | if (pCreateInfos[idx0].layout) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 320 | local_pCreateInfos[idx0].layout = Unwrap(pCreateInfos[idx0].layout); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 321 | } |
| 322 | if (pCreateInfos[idx0].stage.module) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 323 | local_pCreateInfos[idx0].stage.module = Unwrap(pCreateInfos[idx0].stage.module); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | } |
| 327 | if (pipelineCache) { |
| 328 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 329 | pipelineCache = Unwrap(pipelineCache); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 330 | } |
| 331 | |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 332 | VkResult result = device_data->dispatch_table.CreateComputePipelines(device, pipelineCache, createInfoCount, |
| 333 | local_pCreateInfos->ptr(), pAllocator, pPipelines); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 334 | delete[] local_pCreateInfos; |
| Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 335 | { |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 336 | std::lock_guard<std::mutex> lock(global_lock); |
| 337 | for (uint32_t i = 0; i < createInfoCount; ++i) { |
| Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 338 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 339 | pPipelines[i] = WrapNew(pPipelines[i]); |
| Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 340 | } |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | return result; |
| 344 | } |
| 345 | |
| 346 | VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 347 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 348 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) { |
| Chris Forbes | 6956a31 | 2017-05-02 17:36:28 -0700 | [diff] [blame] | 349 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 350 | safe_VkGraphicsPipelineCreateInfo *local_pCreateInfos = nullptr; |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 351 | if (pCreateInfos) { |
| 352 | local_pCreateInfos = new safe_VkGraphicsPipelineCreateInfo[createInfoCount]; |
| 353 | std::lock_guard<std::mutex> lock(global_lock); |
| 354 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
| Petr Kraus | e91f7a1 | 2017-12-14 20:57:36 +0100 | [diff] [blame] | 355 | bool uses_color_attachment = false; |
| 356 | bool uses_depthstencil_attachment = false; |
| 357 | { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 358 | const auto subpasses_uses_it = device_data->renderpasses_states.find(Unwrap(pCreateInfos[idx0].renderPass)); |
| Petr Kraus | e91f7a1 | 2017-12-14 20:57:36 +0100 | [diff] [blame] | 359 | if (subpasses_uses_it != device_data->renderpasses_states.end()) { |
| 360 | const auto &subpasses_uses = subpasses_uses_it->second; |
| 361 | if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[idx0].subpass)) |
| 362 | uses_color_attachment = true; |
| 363 | if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[idx0].subpass)) |
| 364 | uses_depthstencil_attachment = true; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | local_pCreateInfos[idx0].initialize(&pCreateInfos[idx0], uses_color_attachment, uses_depthstencil_attachment); |
| 369 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 370 | if (pCreateInfos[idx0].basePipelineHandle) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 371 | local_pCreateInfos[idx0].basePipelineHandle = Unwrap(pCreateInfos[idx0].basePipelineHandle); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 372 | } |
| 373 | if (pCreateInfos[idx0].layout) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 374 | local_pCreateInfos[idx0].layout = Unwrap(pCreateInfos[idx0].layout); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 375 | } |
| 376 | if (pCreateInfos[idx0].pStages) { |
| 377 | for (uint32_t idx1 = 0; idx1 < pCreateInfos[idx0].stageCount; ++idx1) { |
| 378 | if (pCreateInfos[idx0].pStages[idx1].module) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 379 | local_pCreateInfos[idx0].pStages[idx1].module = Unwrap(pCreateInfos[idx0].pStages[idx1].module); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | } |
| 383 | if (pCreateInfos[idx0].renderPass) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 384 | local_pCreateInfos[idx0].renderPass = Unwrap(pCreateInfos[idx0].renderPass); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | } |
| 388 | if (pipelineCache) { |
| 389 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 390 | pipelineCache = Unwrap(pipelineCache); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 391 | } |
| 392 | |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 393 | VkResult result = device_data->dispatch_table.CreateGraphicsPipelines(device, pipelineCache, createInfoCount, |
| 394 | local_pCreateInfos->ptr(), pAllocator, pPipelines); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 395 | delete[] local_pCreateInfos; |
| Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 396 | { |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 397 | std::lock_guard<std::mutex> lock(global_lock); |
| 398 | for (uint32_t i = 0; i < createInfoCount; ++i) { |
| Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 399 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 400 | pPipelines[i] = WrapNew(pPipelines[i]); |
| Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 401 | } |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | return result; |
| 405 | } |
| 406 | |
| Petr Kraus | e91f7a1 | 2017-12-14 20:57:36 +0100 | [diff] [blame] | 407 | static void PostCallCreateRenderPass(layer_data *dev_data, const VkRenderPassCreateInfo *pCreateInfo, VkRenderPass renderPass) { |
| 408 | auto &renderpass_state = dev_data->renderpasses_states[renderPass]; |
| 409 | |
| 410 | for (uint32_t subpass = 0; subpass < pCreateInfo->subpassCount; ++subpass) { |
| 411 | bool uses_color = false; |
| 412 | for (uint32_t i = 0; i < pCreateInfo->pSubpasses[subpass].colorAttachmentCount && !uses_color; ++i) |
| 413 | if (pCreateInfo->pSubpasses[subpass].pColorAttachments[i].attachment != VK_ATTACHMENT_UNUSED) uses_color = true; |
| 414 | |
| 415 | bool uses_depthstencil = false; |
| 416 | if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment) |
| 417 | if (pCreateInfo->pSubpasses[subpass].pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) |
| 418 | uses_depthstencil = true; |
| 419 | |
| 420 | if (uses_color) renderpass_state.subpasses_using_color_attachment.insert(subpass); |
| 421 | if (uses_depthstencil) renderpass_state.subpasses_using_depthstencil_attachment.insert(subpass); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | VKAPI_ATTR VkResult VKAPI_CALL CreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, |
| 426 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) { |
| 427 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 428 | VkResult result = dev_data->dispatch_table.CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass); |
| 429 | if (VK_SUCCESS == result) { |
| 430 | std::lock_guard<std::mutex> lock(global_lock); |
| 431 | |
| 432 | PostCallCreateRenderPass(dev_data, pCreateInfo, *pRenderPass); |
| 433 | |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 434 | *pRenderPass = WrapNew(*pRenderPass); |
| Petr Kraus | e91f7a1 | 2017-12-14 20:57:36 +0100 | [diff] [blame] | 435 | } |
| 436 | return result; |
| 437 | } |
| 438 | |
| 439 | static void PostCallDestroyRenderPass(layer_data *dev_data, VkRenderPass renderPass) { |
| 440 | dev_data->renderpasses_states.erase(renderPass); |
| 441 | } |
| 442 | |
| 443 | VKAPI_ATTR void VKAPI_CALL DestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator) { |
| 444 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 445 | std::unique_lock<std::mutex> lock(global_lock); |
| 446 | uint64_t renderPass_id = reinterpret_cast<uint64_t &>(renderPass); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 447 | renderPass = (VkRenderPass)unique_id_mapping[renderPass_id]; |
| 448 | unique_id_mapping.erase(renderPass_id); |
| Petr Kraus | e91f7a1 | 2017-12-14 20:57:36 +0100 | [diff] [blame] | 449 | lock.unlock(); |
| 450 | dev_data->dispatch_table.DestroyRenderPass(device, renderPass, pAllocator); |
| 451 | |
| 452 | lock.lock(); |
| 453 | PostCallDestroyRenderPass(dev_data, renderPass); |
| 454 | } |
| 455 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 456 | VKAPI_ATTR VkResult VKAPI_CALL CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 457 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) { |
| Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 458 | layer_data *my_map_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 459 | safe_VkSwapchainCreateInfoKHR *local_pCreateInfo = NULL; |
| 460 | if (pCreateInfo) { |
| 461 | std::lock_guard<std::mutex> lock(global_lock); |
| 462 | local_pCreateInfo = new safe_VkSwapchainCreateInfoKHR(pCreateInfo); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 463 | local_pCreateInfo->oldSwapchain = Unwrap(pCreateInfo->oldSwapchain); |
| Chris Forbes | 6956a31 | 2017-05-02 17:36:28 -0700 | [diff] [blame] | 464 | // Surface is instance-level object |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 465 | local_pCreateInfo->surface = Unwrap(pCreateInfo->surface); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 466 | } |
| 467 | |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 468 | VkResult result = my_map_data->dispatch_table.CreateSwapchainKHR(device, local_pCreateInfo->ptr(), pAllocator, pSwapchain); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 469 | delete local_pCreateInfo; |
| 470 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 471 | if (VK_SUCCESS == result) { |
| 472 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 473 | *pSwapchain = WrapNew(*pSwapchain); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 474 | } |
| 475 | return result; |
| 476 | } |
| 477 | |
| Dustin Graves | 9a6eb05 | 2017-03-28 14:18:54 -0600 | [diff] [blame] | 478 | VKAPI_ATTR VkResult VKAPI_CALL CreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 479 | const VkSwapchainCreateInfoKHR *pCreateInfos, |
| 480 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchains) { |
| 481 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 482 | safe_VkSwapchainCreateInfoKHR *local_pCreateInfos = NULL; |
| 483 | { |
| 484 | std::lock_guard<std::mutex> lock(global_lock); |
| 485 | if (pCreateInfos) { |
| Dustin Graves | 9a6eb05 | 2017-03-28 14:18:54 -0600 | [diff] [blame] | 486 | local_pCreateInfos = new safe_VkSwapchainCreateInfoKHR[swapchainCount]; |
| 487 | for (uint32_t i = 0; i < swapchainCount; ++i) { |
| 488 | local_pCreateInfos[i].initialize(&pCreateInfos[i]); |
| 489 | if (pCreateInfos[i].surface) { |
| Chris Forbes | 6956a31 | 2017-05-02 17:36:28 -0700 | [diff] [blame] | 490 | // Surface is instance-level object |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 491 | local_pCreateInfos[i].surface = Unwrap(pCreateInfos[i].surface); |
| Dustin Graves | 9a6eb05 | 2017-03-28 14:18:54 -0600 | [diff] [blame] | 492 | } |
| 493 | if (pCreateInfos[i].oldSwapchain) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 494 | local_pCreateInfos[i].oldSwapchain = Unwrap(pCreateInfos[i].oldSwapchain); |
| Dustin Graves | 9a6eb05 | 2017-03-28 14:18:54 -0600 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | } |
| 498 | } |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 499 | VkResult result = dev_data->dispatch_table.CreateSharedSwapchainsKHR(device, swapchainCount, local_pCreateInfos->ptr(), |
| 500 | pAllocator, pSwapchains); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 501 | delete[] local_pCreateInfos; |
| Dustin Graves | 9a6eb05 | 2017-03-28 14:18:54 -0600 | [diff] [blame] | 502 | if (VK_SUCCESS == result) { |
| 503 | std::lock_guard<std::mutex> lock(global_lock); |
| 504 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 505 | pSwapchains[i] = WrapNew(pSwapchains[i]); |
| Dustin Graves | 9a6eb05 | 2017-03-28 14:18:54 -0600 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | return result; |
| 509 | } |
| 510 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 511 | VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, |
| 512 | VkImage *pSwapchainImages) { |
| Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 513 | layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Mark Lobodzinski | 2eb39bc | 2018-02-16 11:24:21 -0700 | [diff] [blame] | 514 | VkSwapchainKHR wrapped_swapchain_handle = swapchain; |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 515 | if (VK_NULL_HANDLE != swapchain) { |
| 516 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 517 | swapchain = Unwrap(swapchain); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 518 | } |
| 519 | VkResult result = |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 520 | my_device_data->dispatch_table.GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); |
| Mark Lobodzinski | 2eb39bc | 2018-02-16 11:24:21 -0700 | [diff] [blame] | 521 | if ((VK_SUCCESS == result) || (VK_INCOMPLETE == result)) { |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 522 | if ((*pSwapchainImageCount > 0) && pSwapchainImages) { |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 523 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | 2eb39bc | 2018-02-16 11:24:21 -0700 | [diff] [blame] | 524 | auto &wrapped_swapchain_image_handles = my_device_data->swapchain_wrapped_image_handle_map[wrapped_swapchain_handle]; |
| 525 | for (uint32_t i = static_cast<uint32_t>(wrapped_swapchain_image_handles.size()); i < *pSwapchainImageCount; i++) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 526 | wrapped_swapchain_image_handles.emplace_back(WrapNew(pSwapchainImages[i])); |
| Mark Lobodzinski | 2eb39bc | 2018-02-16 11:24:21 -0700 | [diff] [blame] | 527 | } |
| 528 | for (uint32_t i = 0; i < *pSwapchainImageCount; i++) { |
| 529 | pSwapchainImages[i] = wrapped_swapchain_image_handles[i]; |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | } |
| 533 | return result; |
| 534 | } |
| 535 | |
| Mark Lobodzinski | 1ce83f4 | 2018-02-16 09:58:07 -0700 | [diff] [blame] | 536 | VKAPI_ATTR void VKAPI_CALL DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) { |
| 537 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 538 | std::unique_lock<std::mutex> lock(global_lock); |
| Mark Lobodzinski | 2eb39bc | 2018-02-16 11:24:21 -0700 | [diff] [blame] | 539 | |
| 540 | auto &image_array = dev_data->swapchain_wrapped_image_handle_map[swapchain]; |
| 541 | for (auto &image_handle : image_array) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 542 | unique_id_mapping.erase(HandleToUint64(image_handle)); |
| Mark Lobodzinski | 2eb39bc | 2018-02-16 11:24:21 -0700 | [diff] [blame] | 543 | } |
| 544 | dev_data->swapchain_wrapped_image_handle_map.erase(swapchain); |
| 545 | |
| 546 | uint64_t swapchain_id = HandleToUint64(swapchain); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 547 | swapchain = (VkSwapchainKHR)unique_id_mapping[swapchain_id]; |
| 548 | unique_id_mapping.erase(swapchain_id); |
| Mark Lobodzinski | 1ce83f4 | 2018-02-16 09:58:07 -0700 | [diff] [blame] | 549 | lock.unlock(); |
| 550 | dev_data->dispatch_table.DestroySwapchainKHR(device, swapchain, pAllocator); |
| 551 | } |
| 552 | |
| Chris Forbes | 0f507f2 | 2017-04-16 13:13:17 +1200 | [diff] [blame] | 553 | VKAPI_ATTR VkResult VKAPI_CALL QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) { |
| 554 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map); |
| 555 | safe_VkPresentInfoKHR *local_pPresentInfo = NULL; |
| 556 | { |
| 557 | std::lock_guard<std::mutex> lock(global_lock); |
| 558 | if (pPresentInfo) { |
| 559 | local_pPresentInfo = new safe_VkPresentInfoKHR(pPresentInfo); |
| 560 | if (local_pPresentInfo->pWaitSemaphores) { |
| 561 | for (uint32_t index1 = 0; index1 < local_pPresentInfo->waitSemaphoreCount; ++index1) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 562 | local_pPresentInfo->pWaitSemaphores[index1] = Unwrap(pPresentInfo->pWaitSemaphores[index1]); |
| Chris Forbes | 0f507f2 | 2017-04-16 13:13:17 +1200 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | if (local_pPresentInfo->pSwapchains) { |
| 566 | for (uint32_t index1 = 0; index1 < local_pPresentInfo->swapchainCount; ++index1) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 567 | local_pPresentInfo->pSwapchains[index1] = Unwrap(pPresentInfo->pSwapchains[index1]); |
| Chris Forbes | 0f507f2 | 2017-04-16 13:13:17 +1200 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | } |
| 571 | } |
| Chris Forbes | 6956a31 | 2017-05-02 17:36:28 -0700 | [diff] [blame] | 572 | VkResult result = dev_data->dispatch_table.QueuePresentKHR(queue, local_pPresentInfo->ptr()); |
| Chris Forbes | 0f507f2 | 2017-04-16 13:13:17 +1200 | [diff] [blame] | 573 | |
| 574 | // pResults is an output array embedded in a structure. The code generator neglects to copy back from the safe_* version, |
| 575 | // so handle it as a special case here: |
| 576 | if (pPresentInfo && pPresentInfo->pResults) { |
| 577 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) { |
| 578 | pPresentInfo->pResults[i] = local_pPresentInfo->pResults[i]; |
| 579 | } |
| 580 | } |
| 581 | |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 582 | delete local_pPresentInfo; |
| Chris Forbes | 0f507f2 | 2017-04-16 13:13:17 +1200 | [diff] [blame] | 583 | return result; |
| 584 | } |
| 585 | |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 586 | // This is the core version of this routine. The extension version is below. |
| 587 | VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorUpdateTemplate(VkDevice device, |
| 588 | const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, |
| 589 | const VkAllocationCallbacks *pAllocator, |
| 590 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate) { |
| 591 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 592 | safe_VkDescriptorUpdateTemplateCreateInfo *local_create_info = NULL; |
| 593 | { |
| 594 | std::lock_guard<std::mutex> lock(global_lock); |
| 595 | if (pCreateInfo) { |
| 596 | local_create_info = new safe_VkDescriptorUpdateTemplateCreateInfo(pCreateInfo); |
| 597 | if (pCreateInfo->descriptorSetLayout) { |
| Mark Lobodzinski | 4bed025 | 2018-02-28 14:04:56 -0700 | [diff] [blame] | 598 | local_create_info->descriptorSetLayout = Unwrap(pCreateInfo->descriptorSetLayout); |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 599 | } |
| 600 | if (pCreateInfo->pipelineLayout) { |
| Mark Lobodzinski | 4bed025 | 2018-02-28 14:04:56 -0700 | [diff] [blame] | 601 | local_create_info->pipelineLayout = Unwrap(pCreateInfo->pipelineLayout); |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | } |
| 605 | VkResult result = dev_data->dispatch_table.CreateDescriptorUpdateTemplate(device, local_create_info->ptr(), pAllocator, |
| 606 | pDescriptorUpdateTemplate); |
| 607 | if (VK_SUCCESS == result) { |
| 608 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | 4bed025 | 2018-02-28 14:04:56 -0700 | [diff] [blame] | 609 | *pDescriptorUpdateTemplate = WrapNew(*pDescriptorUpdateTemplate); |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 610 | |
| 611 | // Shadow template createInfo for later updates |
| 612 | std::unique_ptr<TEMPLATE_STATE> template_state(new TEMPLATE_STATE(*pDescriptorUpdateTemplate, local_create_info)); |
| 613 | dev_data->desc_template_map[(uint64_t)*pDescriptorUpdateTemplate] = std::move(template_state); |
| 614 | } |
| 615 | return result; |
| 616 | } |
| 617 | |
| 618 | // This is the extension version of this routine. The core version is above. |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 619 | VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorUpdateTemplateKHR(VkDevice device, |
| 620 | const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, |
| 621 | const VkAllocationCallbacks *pAllocator, |
| 622 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate) { |
| 623 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Mark Lobodzinski | ef4da50 | 2017-09-28 15:18:18 -0600 | [diff] [blame] | 624 | safe_VkDescriptorUpdateTemplateCreateInfo *local_create_info = NULL; |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 625 | { |
| 626 | std::lock_guard<std::mutex> lock(global_lock); |
| 627 | if (pCreateInfo) { |
| Mark Lobodzinski | ef4da50 | 2017-09-28 15:18:18 -0600 | [diff] [blame] | 628 | local_create_info = new safe_VkDescriptorUpdateTemplateCreateInfo(pCreateInfo); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 629 | if (pCreateInfo->descriptorSetLayout) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 630 | local_create_info->descriptorSetLayout = Unwrap(pCreateInfo->descriptorSetLayout); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 631 | } |
| 632 | if (pCreateInfo->pipelineLayout) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 633 | local_create_info->pipelineLayout = Unwrap(pCreateInfo->pipelineLayout); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | } |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 637 | VkResult result = dev_data->dispatch_table.CreateDescriptorUpdateTemplateKHR(device, local_create_info->ptr(), pAllocator, |
| 638 | pDescriptorUpdateTemplate); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 639 | if (VK_SUCCESS == result) { |
| 640 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 641 | *pDescriptorUpdateTemplate = WrapNew(*pDescriptorUpdateTemplate); |
| Mark Lobodzinski | 4f3ce67 | 2017-03-03 10:28:21 -0700 | [diff] [blame] | 642 | |
| 643 | // Shadow template createInfo for later updates |
| Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 644 | std::unique_ptr<TEMPLATE_STATE> template_state(new TEMPLATE_STATE(*pDescriptorUpdateTemplate, local_create_info)); |
| Chris Forbes | 6956a31 | 2017-05-02 17:36:28 -0700 | [diff] [blame] | 645 | dev_data->desc_template_map[(uint64_t)*pDescriptorUpdateTemplate] = std::move(template_state); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 646 | } |
| 647 | return result; |
| 648 | } |
| 649 | |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 650 | // This is the core version of this routine. The extension version is below. |
| 651 | VKAPI_ATTR void VKAPI_CALL DestroyDescriptorUpdateTemplate(VkDevice device, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 652 | const VkAllocationCallbacks *pAllocator) { |
| 653 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 654 | std::unique_lock<std::mutex> lock(global_lock); |
| 655 | uint64_t descriptor_update_template_id = reinterpret_cast<uint64_t &>(descriptorUpdateTemplate); |
| 656 | dev_data->desc_template_map.erase(descriptor_update_template_id); |
| Mark Lobodzinski | 4bed025 | 2018-02-28 14:04:56 -0700 | [diff] [blame] | 657 | descriptorUpdateTemplate = (VkDescriptorUpdateTemplate)unique_id_mapping[descriptor_update_template_id]; |
| 658 | unique_id_mapping.erase(descriptor_update_template_id); |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 659 | lock.unlock(); |
| 660 | dev_data->dispatch_table.DestroyDescriptorUpdateTemplate(device, descriptorUpdateTemplate, pAllocator); |
| 661 | } |
| 662 | |
| 663 | // This is the extension version of this routine. The core version is above. |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 664 | VKAPI_ATTR void VKAPI_CALL DestroyDescriptorUpdateTemplateKHR(VkDevice device, |
| 665 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 666 | const VkAllocationCallbacks *pAllocator) { |
| 667 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 668 | std::unique_lock<std::mutex> lock(global_lock); |
| Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 669 | uint64_t descriptor_update_template_id = reinterpret_cast<uint64_t &>(descriptorUpdateTemplate); |
| 670 | dev_data->desc_template_map.erase(descriptor_update_template_id); |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 671 | descriptorUpdateTemplate = (VkDescriptorUpdateTemplate)unique_id_mapping[descriptor_update_template_id]; |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 672 | unique_id_mapping.erase(descriptor_update_template_id); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 673 | lock.unlock(); |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 674 | dev_data->dispatch_table.DestroyDescriptorUpdateTemplateKHR(device, descriptorUpdateTemplate, pAllocator); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 677 | void *BuildUnwrappedUpdateTemplateBuffer(layer_data *dev_data, uint64_t descriptorUpdateTemplate, const void *pData) { |
| 678 | auto const template_map_entry = dev_data->desc_template_map.find(descriptorUpdateTemplate); |
| 679 | if (template_map_entry == dev_data->desc_template_map.end()) { |
| 680 | assert(0); |
| 681 | } |
| 682 | auto const &create_info = template_map_entry->second->create_info; |
| 683 | size_t allocation_size = 0; |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 684 | std::vector<std::tuple<size_t, VulkanObjectType, void *>> template_entries; |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 685 | |
| 686 | for (uint32_t i = 0; i < create_info.descriptorUpdateEntryCount; i++) { |
| 687 | for (uint32_t j = 0; j < create_info.pDescriptorUpdateEntries[i].descriptorCount; j++) { |
| 688 | size_t offset = create_info.pDescriptorUpdateEntries[i].offset + j * create_info.pDescriptorUpdateEntries[i].stride; |
| 689 | char *update_entry = (char *)(pData) + offset; |
| 690 | |
| 691 | switch (create_info.pDescriptorUpdateEntries[i].descriptorType) { |
| 692 | case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 693 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 694 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 695 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 696 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: { |
| 697 | auto image_entry = reinterpret_cast<VkDescriptorImageInfo *>(update_entry); |
| 698 | allocation_size = std::max(allocation_size, offset + sizeof(VkDescriptorImageInfo)); |
| 699 | |
| 700 | VkDescriptorImageInfo *wrapped_entry = new VkDescriptorImageInfo(*image_entry); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 701 | wrapped_entry->sampler = Unwrap(image_entry->sampler); |
| 702 | wrapped_entry->imageView = Unwrap(image_entry->imageView); |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 703 | template_entries.emplace_back(offset, kVulkanObjectTypeImage, reinterpret_cast<void *>(wrapped_entry)); |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 704 | } break; |
| 705 | |
| 706 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 707 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 708 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 709 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { |
| 710 | auto buffer_entry = reinterpret_cast<VkDescriptorBufferInfo *>(update_entry); |
| 711 | allocation_size = std::max(allocation_size, offset + sizeof(VkDescriptorBufferInfo)); |
| 712 | |
| 713 | VkDescriptorBufferInfo *wrapped_entry = new VkDescriptorBufferInfo(*buffer_entry); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 714 | wrapped_entry->buffer = Unwrap(buffer_entry->buffer); |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 715 | template_entries.emplace_back(offset, kVulkanObjectTypeBuffer, reinterpret_cast<void *>(wrapped_entry)); |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 716 | } break; |
| 717 | |
| 718 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 719 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: { |
| Chris Forbes | 6956a31 | 2017-05-02 17:36:28 -0700 | [diff] [blame] | 720 | auto buffer_view_handle = reinterpret_cast<VkBufferView *>(update_entry); |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 721 | allocation_size = std::max(allocation_size, offset + sizeof(VkBufferView)); |
| 722 | |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 723 | VkBufferView wrapped_entry = Unwrap(*buffer_view_handle); |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 724 | template_entries.emplace_back(offset, kVulkanObjectTypeBufferView, reinterpret_cast<void *>(wrapped_entry)); |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 725 | } break; |
| 726 | default: |
| 727 | assert(0); |
| 728 | break; |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | // Allocate required buffer size and populate with source/unwrapped data |
| 733 | void *unwrapped_data = malloc(allocation_size); |
| 734 | for (auto &this_entry : template_entries) { |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 735 | VulkanObjectType type = std::get<1>(this_entry); |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 736 | void *destination = (char *)unwrapped_data + std::get<0>(this_entry); |
| 737 | void *source = (char *)std::get<2>(this_entry); |
| 738 | |
| 739 | switch (type) { |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 740 | case kVulkanObjectTypeImage: |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 741 | *(reinterpret_cast<VkDescriptorImageInfo *>(destination)) = *(reinterpret_cast<VkDescriptorImageInfo *>(source)); |
| 742 | delete reinterpret_cast<VkDescriptorImageInfo *>(source); |
| 743 | break; |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 744 | case kVulkanObjectTypeBuffer: |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 745 | *(reinterpret_cast<VkDescriptorBufferInfo *>(destination)) = *(reinterpret_cast<VkDescriptorBufferInfo *>(source)); |
| 746 | delete reinterpret_cast<VkDescriptorBufferInfo *>(source); |
| 747 | break; |
| Mark Lobodzinski | 2d9de65 | 2017-04-24 08:58:52 -0600 | [diff] [blame] | 748 | case kVulkanObjectTypeBufferView: |
| Mark Lobodzinski | d5197d0 | 2017-03-15 13:13:49 -0600 | [diff] [blame] | 749 | *(reinterpret_cast<VkBufferView *>(destination)) = reinterpret_cast<VkBufferView>(source); |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 750 | break; |
| 751 | default: |
| 752 | assert(0); |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | return (void *)unwrapped_data; |
| 757 | } |
| 758 | |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 759 | // This is the core version of this routine. The extension version is below. |
| 760 | VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet, |
| 761 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 762 | const void *pData) { |
| 763 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 764 | uint64_t template_handle = reinterpret_cast<uint64_t &>(descriptorUpdateTemplate); |
| 765 | { |
| 766 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | 4bed025 | 2018-02-28 14:04:56 -0700 | [diff] [blame] | 767 | descriptorSet = Unwrap(descriptorSet); |
| 768 | descriptorUpdateTemplate = (VkDescriptorUpdateTemplate)unique_id_mapping[template_handle]; |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 769 | } |
| 770 | void *unwrapped_buffer = BuildUnwrappedUpdateTemplateBuffer(dev_data, template_handle, pData); |
| 771 | dev_data->dispatch_table.UpdateDescriptorSetWithTemplate(device, descriptorSet, descriptorUpdateTemplate, unwrapped_buffer); |
| 772 | free(unwrapped_buffer); |
| 773 | } |
| 774 | |
| 775 | // This is the extension version of this routine. The core version is above. |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 776 | VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet, |
| 777 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 778 | const void *pData) { |
| 779 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 780 | uint64_t template_handle = reinterpret_cast<uint64_t &>(descriptorUpdateTemplate); |
| Mark Lobodzinski | c8a0c9b | 2017-11-13 09:42:58 -0700 | [diff] [blame] | 781 | void *unwrapped_buffer = nullptr; |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 782 | { |
| 783 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 784 | descriptorSet = Unwrap(descriptorSet); |
| Mark Lobodzinski | ab9a875 | 2017-10-25 16:56:42 -0600 | [diff] [blame] | 785 | descriptorUpdateTemplate = (VkDescriptorUpdateTemplate)unique_id_mapping[template_handle]; |
| Mark Lobodzinski | c8a0c9b | 2017-11-13 09:42:58 -0700 | [diff] [blame] | 786 | unwrapped_buffer = BuildUnwrappedUpdateTemplateBuffer(dev_data, template_handle, pData); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 787 | } |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 788 | dev_data->dispatch_table.UpdateDescriptorSetWithTemplateKHR(device, descriptorSet, descriptorUpdateTemplate, unwrapped_buffer); |
| Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 789 | free(unwrapped_buffer); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer, |
| 793 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 794 | VkPipelineLayout layout, uint32_t set, const void *pData) { |
| 795 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map); |
| Mark Lobodzinski | 1c47126 | 2017-03-28 16:22:56 -0600 | [diff] [blame] | 796 | uint64_t template_handle = reinterpret_cast<uint64_t &>(descriptorUpdateTemplate); |
| Mark Lobodzinski | c8a0c9b | 2017-11-13 09:42:58 -0700 | [diff] [blame] | 797 | void *unwrapped_buffer = nullptr; |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 798 | { |
| 799 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 800 | descriptorUpdateTemplate = Unwrap(descriptorUpdateTemplate); |
| 801 | layout = Unwrap(layout); |
| Mark Lobodzinski | c8a0c9b | 2017-11-13 09:42:58 -0700 | [diff] [blame] | 802 | unwrapped_buffer = BuildUnwrappedUpdateTemplateBuffer(dev_data, template_handle, pData); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 803 | } |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 804 | dev_data->dispatch_table.CmdPushDescriptorSetWithTemplateKHR(commandBuffer, descriptorUpdateTemplate, layout, set, |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 805 | unwrapped_buffer); |
| Mark Lobodzinski | 1c47126 | 2017-03-28 16:22:56 -0600 | [diff] [blame] | 806 | free(unwrapped_buffer); |
| Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 809 | #ifndef __ANDROID__ |
| 810 | VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 811 | VkDisplayPropertiesKHR *pProperties) { |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 812 | instance_layer_data *my_map_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 813 | |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 814 | VkResult result = |
| 815 | my_map_data->dispatch_table.GetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, pProperties); |
| Chris Forbes | f1e49bf | 2017-05-02 17:36:57 -0700 | [diff] [blame] | 816 | if ((result == VK_SUCCESS || result == VK_INCOMPLETE) && pProperties) { |
| 817 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 818 | for (uint32_t idx0 = 0; idx0 < *pPropertyCount; ++idx0) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 819 | pProperties[idx0].display = WrapNew(pProperties[idx0].display); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 820 | } |
| 821 | } |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 822 | return result; |
| 823 | } |
| 824 | |
| 825 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
| 826 | uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) { |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 827 | instance_layer_data *my_map_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map); |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 828 | VkResult result = |
| 829 | my_map_data->dispatch_table.GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, pDisplays); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 830 | if (VK_SUCCESS == result) { |
| 831 | if ((*pDisplayCount > 0) && pDisplays) { |
| 832 | std::lock_guard<std::mutex> lock(global_lock); |
| 833 | for (uint32_t i = 0; i < *pDisplayCount; i++) { |
| Chris Forbes | 824c117 | 2017-05-02 17:45:29 -0700 | [diff] [blame] | 834 | // TODO: this looks like it really wants a /reverse/ mapping. What's going on here? |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 835 | auto it = unique_id_mapping.find(reinterpret_cast<const uint64_t &>(pDisplays[i])); |
| 836 | assert(it != unique_id_mapping.end()); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 837 | pDisplays[i] = reinterpret_cast<VkDisplayKHR &>(it->second); |
| 838 | } |
| 839 | } |
| 840 | } |
| 841 | return result; |
| 842 | } |
| 843 | |
| 844 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, |
| 845 | uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) { |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 846 | instance_layer_data *my_map_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 847 | { |
| 848 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 849 | display = Unwrap(display); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 850 | } |
| 851 | |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 852 | VkResult result = my_map_data->dispatch_table.GetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, pProperties); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 853 | if (result == VK_SUCCESS && pProperties) { |
| Chris Forbes | ef35afd | 2017-05-02 17:45:45 -0700 | [diff] [blame] | 854 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 855 | for (uint32_t idx0 = 0; idx0 < *pPropertyCount; ++idx0) { |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 856 | pProperties[idx0].displayMode = WrapNew(pProperties[idx0].displayMode); |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 857 | } |
| 858 | } |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 859 | return result; |
| 860 | } |
| Norbert Nopper | 1dec9a5 | 2016-11-25 07:55:13 +0100 | [diff] [blame] | 861 | |
| 862 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 863 | uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR *pCapabilities) { |
| Chris Forbes | 5279a8c | 2017-05-02 16:26:23 -0700 | [diff] [blame] | 864 | instance_layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map); |
| Norbert Nopper | 1dec9a5 | 2016-11-25 07:55:13 +0100 | [diff] [blame] | 865 | { |
| 866 | std::lock_guard<std::mutex> lock(global_lock); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 867 | mode = Unwrap(mode); |
| Norbert Nopper | 1dec9a5 | 2016-11-25 07:55:13 +0100 | [diff] [blame] | 868 | } |
| Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 869 | VkResult result = dev_data->dispatch_table.GetDisplayPlaneCapabilitiesKHR(physicalDevice, mode, planeIndex, pCapabilities); |
| Norbert Nopper | 1dec9a5 | 2016-11-25 07:55:13 +0100 | [diff] [blame] | 870 | return result; |
| 871 | } |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 872 | #endif |
| 873 | |
| Mark Lobodzinski | e4f2c5f | 2017-07-17 14:26:47 -0600 | [diff] [blame] | 874 | VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectTagEXT(VkDevice device, const VkDebugMarkerObjectTagInfoEXT *pTagInfo) { |
| Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 875 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 876 | safe_VkDebugMarkerObjectTagInfoEXT local_tag_info(pTagInfo); |
| Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 877 | { |
| 878 | std::lock_guard<std::mutex> lock(global_lock); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 879 | auto it = unique_id_mapping.find(reinterpret_cast<uint64_t &>(local_tag_info.object)); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 880 | if (it != unique_id_mapping.end()) { |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 881 | local_tag_info.object = it->second; |
| Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 882 | } |
| 883 | } |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 884 | VkResult result = device_data->dispatch_table.DebugMarkerSetObjectTagEXT( |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 885 | device, reinterpret_cast<VkDebugMarkerObjectTagInfoEXT *>(&local_tag_info)); |
| Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 886 | return result; |
| 887 | } |
| 888 | |
| Mark Lobodzinski | e4f2c5f | 2017-07-17 14:26:47 -0600 | [diff] [blame] | 889 | VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) { |
| Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 890 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 891 | safe_VkDebugMarkerObjectNameInfoEXT local_name_info(pNameInfo); |
| Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 892 | { |
| 893 | std::lock_guard<std::mutex> lock(global_lock); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 894 | auto it = unique_id_mapping.find(reinterpret_cast<uint64_t &>(local_name_info.object)); |
| Mark Lobodzinski | c7eda92 | 2018-02-28 13:38:45 -0700 | [diff] [blame] | 895 | if (it != unique_id_mapping.end()) { |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 896 | local_name_info.object = it->second; |
| Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 897 | } |
| 898 | } |
| Chris Forbes | 44c0530 | 2017-05-02 16:42:55 -0700 | [diff] [blame] | 899 | VkResult result = device_data->dispatch_table.DebugMarkerSetObjectNameEXT( |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 900 | device, reinterpret_cast<VkDebugMarkerObjectNameInfoEXT *>(&local_name_info)); |
| Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 901 | return result; |
| 902 | } |
| 903 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 904 | // VK_EXT_debug_utils |
| 905 | VKAPI_ATTR VkResult VKAPI_CALL SetDebugUtilsObjectTagEXT(VkDevice device, const VkDebugUtilsObjectTagInfoEXT *pTagInfo) { |
| 906 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 907 | safe_VkDebugUtilsObjectTagInfoEXT local_tag_info(pTagInfo); |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 908 | { |
| 909 | std::lock_guard<std::mutex> lock(global_lock); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 910 | auto it = unique_id_mapping.find(reinterpret_cast<uint64_t &>(local_tag_info.objectHandle)); |
| Mark Lobodzinski | 4bed025 | 2018-02-28 14:04:56 -0700 | [diff] [blame] | 911 | if (it != unique_id_mapping.end()) { |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 912 | local_tag_info.objectHandle = it->second; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | VkResult result = device_data->dispatch_table.SetDebugUtilsObjectTagEXT( |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 916 | device, reinterpret_cast<const VkDebugUtilsObjectTagInfoEXT *>(&local_tag_info)); |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 917 | return result; |
| 918 | } |
| 919 | |
| 920 | VKAPI_ATTR VkResult VKAPI_CALL SetDebugUtilsObjectNameEXT(VkDevice device, const VkDebugUtilsObjectNameInfoEXT *pNameInfo) { |
| 921 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 922 | safe_VkDebugUtilsObjectNameInfoEXT local_name_info(pNameInfo); |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 923 | { |
| 924 | std::lock_guard<std::mutex> lock(global_lock); |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 925 | auto it = unique_id_mapping.find(reinterpret_cast<uint64_t &>(local_name_info.objectHandle)); |
| Mark Lobodzinski | 4bed025 | 2018-02-28 14:04:56 -0700 | [diff] [blame] | 926 | if (it != unique_id_mapping.end()) { |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 927 | local_name_info.objectHandle = it->second; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | VkResult result = device_data->dispatch_table.SetDebugUtilsObjectNameEXT( |
| Gabríel Arthúr Pétursson | 06c5f0d | 2018-03-20 21:37:56 +0000 | [diff] [blame] | 931 | device, reinterpret_cast<const VkDebugUtilsObjectNameInfoEXT *>(&local_name_info)); |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 932 | return result; |
| 933 | } |
| 934 | |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 935 | } // namespace unique_objects |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 936 | |
| Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 937 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 938 | VkExtensionProperties *pProperties) { |
| 939 | return unique_objects::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); |
| 940 | } |
| 941 | |
| 942 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, |
| 943 | VkLayerProperties *pProperties) { |
| 944 | return unique_objects::EnumerateInstanceLayerProperties(pCount, pProperties); |
| 945 | } |
| 946 | |
| 947 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 948 | VkLayerProperties *pProperties) { |
| 949 | assert(physicalDevice == VK_NULL_HANDLE); |
| 950 | return unique_objects::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); |
| 951 | } |
| 952 | |
| 953 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) { |
| 954 | return unique_objects::GetDeviceProcAddr(dev, funcName); |
| 955 | } |
| 956 | |
| 957 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { |
| 958 | return unique_objects::GetInstanceProcAddr(instance, funcName); |
| 959 | } |
| 960 | |
| 961 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 962 | const char *pLayerName, uint32_t *pCount, |
| 963 | VkExtensionProperties *pProperties) { |
| 964 | assert(physicalDevice == VK_NULL_HANDLE); |
| 965 | return unique_objects::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
| 966 | } |
| Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 967 | |
| Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 968 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance, |
| 969 | const char *funcName) { |
| Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 970 | return unique_objects::GetPhysicalDeviceProcAddr(instance, funcName); |
| 971 | } |
| 972 | |
| 973 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) { |
| 974 | assert(pVersionStruct != NULL); |
| 975 | assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT); |
| 976 | |
| 977 | // Fill in the function pointers if our version is at least capable of having the structure contain them. |
| 978 | if (pVersionStruct->loaderLayerInterfaceVersion >= 2) { |
| 979 | pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr; |
| 980 | pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr; |
| 981 | pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr; |
| 982 | } |
| 983 | |
| 984 | if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 985 | unique_objects::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion; |
| 986 | } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 987 | pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 988 | } |
| 989 | |
| 990 | return VK_SUCCESS; |
| 991 | } |