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 |
| 24 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <unordered_map> |
| 29 | #include <vector> |
| 30 | #include <list> |
| 31 | #include <memory> |
Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 32 | #include <algorithm> |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 33 | |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 34 | // For Windows, this #include must come before other Vk headers. |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 35 | #include "vk_loader_platform.h" |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 36 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 37 | #include "unique_objects.h" |
| 38 | #include "vk_dispatch_table_helper.h" |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 39 | #include "vk_layer_config.h" |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 40 | #include "vk_layer_data.h" |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 41 | #include "vk_layer_extension_utils.h" |
| 42 | #include "vk_layer_logging.h" |
| 43 | #include "vk_layer_table.h" |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 44 | #include "vk_layer_utils.h" |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 45 | #include "vk_layer_utils.h" |
Mark Lobodzinski | 9acd2e3 | 2016-12-21 15:22:39 -0700 | [diff] [blame] | 46 | #include "vk_enum_string_helper.h" |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 47 | #include "vk_validation_error_messages.h" |
| 48 | #include "vulkan/vk_layer.h" |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 49 | |
Mike Stroyan | b985fca | 2016-11-01 11:50:16 -0600 | [diff] [blame] | 50 | // This intentionally includes a cpp file |
| 51 | #include "vk_safe_struct.cpp" |
| 52 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 53 | #include "unique_objects_wrappers.h" |
| 54 | |
| 55 | namespace unique_objects { |
| 56 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 57 | static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 58 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 59 | static void initUniqueObjects(layer_data *instance_data, const VkAllocationCallbacks *pAllocator) { |
| 60 | layer_debug_actions(instance_data->report_data, instance_data->logging_callback, pAllocator, "google_unique_objects"); |
| 61 | } |
| 62 | |
| 63 | // Handle CreateInstance Extensions |
| 64 | static void checkInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { |
| 65 | uint32_t i; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 66 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 67 | VkLayerInstanceDispatchTable *disp_table = instance_data->instance_dispatch_table; |
| 68 | instance_ext_map[disp_table] = {}; |
| 69 | |
| 70 | for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 71 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) { |
| 72 | instance_ext_map[disp_table].wsi_enabled = true; |
| 73 | } |
| 74 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) { |
| 75 | instance_ext_map[disp_table].display_enabled = true; |
| 76 | } |
| 77 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 78 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) { |
| 79 | instance_ext_map[disp_table].xlib_enabled = true; |
| 80 | } |
| 81 | #endif |
| 82 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 83 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) { |
| 84 | instance_ext_map[disp_table].xcb_enabled = true; |
| 85 | } |
| 86 | #endif |
| 87 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 88 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) { |
| 89 | instance_ext_map[disp_table].wayland_enabled = true; |
| 90 | } |
| 91 | #endif |
| 92 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 93 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) { |
| 94 | instance_ext_map[disp_table].mir_enabled = true; |
| 95 | } |
| 96 | #endif |
| 97 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 98 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) { |
| 99 | instance_ext_map[disp_table].android_enabled = true; |
| 100 | } |
| 101 | #endif |
| 102 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 103 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) { |
| 104 | instance_ext_map[disp_table].win32_enabled = true; |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | // Check for recognized instance extensions |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 109 | if (!white_list(pCreateInfo->ppEnabledExtensionNames[i], kUniqueObjectsSupportedInstanceExtensions)) { |
| 110 | log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 111 | VALIDATION_ERROR_UNDEFINED, "UniqueObjects", |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 112 | "Instance Extension %s is not supported by this layer. Using this extension may adversely affect " |
| 113 | "validation results and/or produce undefined behavior.", |
| 114 | pCreateInfo->ppEnabledExtensionNames[i]); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // Handle CreateDevice Extensions |
| 120 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 121 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 122 | VkLayerDispatchTable *disp_table = device_data->device_dispatch_table; |
| 123 | PFN_vkGetDeviceProcAddr gpa = disp_table->GetDeviceProcAddr; |
| 124 | |
| 125 | device_data->device_dispatch_table->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR)gpa(device, "vkCreateSwapchainKHR"); |
| 126 | disp_table->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR)gpa(device, "vkDestroySwapchainKHR"); |
| 127 | disp_table->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR)gpa(device, "vkGetSwapchainImagesKHR"); |
| 128 | disp_table->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR)gpa(device, "vkAcquireNextImageKHR"); |
| 129 | disp_table->QueuePresentKHR = (PFN_vkQueuePresentKHR)gpa(device, "vkQueuePresentKHR"); |
| 130 | device_data->wsi_enabled = false; |
| 131 | |
| 132 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 133 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) { |
| 134 | device_data->wsi_enabled = true; |
| 135 | } |
| 136 | // Check for recognized device extensions |
| 137 | if (!white_list(pCreateInfo->ppEnabledExtensionNames[i], kUniqueObjectsSupportedDeviceExtensions)) { |
| 138 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Mike Weiblen | 6a27de5 | 2016-12-09 17:36:28 -0700 | [diff] [blame] | 139 | VALIDATION_ERROR_UNDEFINED, "UniqueObjects", |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 140 | "Device Extension %s is not supported by this layer. Using this extension may adversely affect " |
| 141 | "validation results and/or produce undefined behavior.", |
| 142 | pCreateInfo->ppEnabledExtensionNames[i]); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 148 | VkInstance *pInstance) { |
| 149 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 150 | |
| 151 | assert(chain_info->u.pLayerInfo); |
| 152 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 153 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
| 154 | if (fpCreateInstance == NULL) { |
| 155 | return VK_ERROR_INITIALIZATION_FAILED; |
| 156 | } |
| 157 | |
| 158 | // Advance the link info for the next element on the chain |
| 159 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 160 | |
| 161 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 162 | if (result != VK_SUCCESS) { |
| 163 | return result; |
| 164 | } |
| 165 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 166 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 167 | instance_data->instance = *pInstance; |
| 168 | instance_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 169 | layer_init_instance_dispatch_table(*pInstance, instance_data->instance_dispatch_table, fpGetInstanceProcAddr); |
| 170 | |
| 171 | instance_data->instance = *pInstance; |
| 172 | instance_data->report_data = |
| 173 | debug_report_create_instance(instance_data->instance_dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount, |
| 174 | pCreateInfo->ppEnabledExtensionNames); |
| 175 | |
| 176 | // Set up temporary debug callbacks to output messages at CreateInstance-time |
| 177 | if (!layer_copy_tmp_callbacks(pCreateInfo->pNext, &instance_data->num_tmp_callbacks, &instance_data->tmp_dbg_create_infos, |
| 178 | &instance_data->tmp_callbacks)) { |
| 179 | if (instance_data->num_tmp_callbacks > 0) { |
| 180 | if (layer_enable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks, |
| 181 | instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks)) { |
| 182 | layer_free_tmp_callbacks(instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks); |
| 183 | instance_data->num_tmp_callbacks = 0; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | initUniqueObjects(instance_data, pAllocator); |
| 189 | checkInstanceRegisterExtensions(pCreateInfo, *pInstance); |
| 190 | |
| 191 | // Disable and free tmp callbacks, no longer necessary |
| 192 | if (instance_data->num_tmp_callbacks > 0) { |
| 193 | layer_disable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks, instance_data->tmp_callbacks); |
| 194 | layer_free_tmp_callbacks(instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks); |
| 195 | instance_data->num_tmp_callbacks = 0; |
| 196 | } |
| 197 | |
| 198 | return result; |
| 199 | } |
| 200 | |
| 201 | VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
| 202 | dispatch_key key = get_dispatch_key(instance); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 203 | layer_data *instance_data = GetLayerDataPtr(key, layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 204 | VkLayerInstanceDispatchTable *disp_table = instance_data->instance_dispatch_table; |
| 205 | instance_ext_map.erase(disp_table); |
| 206 | disp_table->DestroyInstance(instance, pAllocator); |
| 207 | |
| 208 | // Clean up logging callback, if any |
| 209 | while (instance_data->logging_callback.size() > 0) { |
| 210 | VkDebugReportCallbackEXT callback = instance_data->logging_callback.back(); |
| 211 | layer_destroy_msg_callback(instance_data->report_data, callback, pAllocator); |
| 212 | instance_data->logging_callback.pop_back(); |
| 213 | } |
| 214 | |
| 215 | layer_debug_report_destroy_instance(instance_data->report_data); |
| 216 | layer_data_map.erase(key); |
| 217 | } |
| 218 | |
| 219 | VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 220 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 221 | layer_data *my_instance_data = GetLayerDataPtr(get_dispatch_key(gpu), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 222 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 223 | |
| 224 | assert(chain_info->u.pLayerInfo); |
| 225 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 226 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
| 227 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); |
| 228 | if (fpCreateDevice == NULL) { |
| 229 | return VK_ERROR_INITIALIZATION_FAILED; |
| 230 | } |
| 231 | |
| 232 | // Advance the link info for the next element on the chain |
| 233 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 234 | |
| 235 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| 236 | if (result != VK_SUCCESS) { |
| 237 | return result; |
| 238 | } |
| 239 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 240 | layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 241 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
| 242 | |
| 243 | // Setup layer's device dispatch table |
| 244 | my_device_data->device_dispatch_table = new VkLayerDispatchTable; |
| 245 | layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); |
| 246 | |
| 247 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
| 248 | // Set gpu for this device in order to get at any objects mapped at instance level |
| 249 | |
| 250 | my_device_data->gpu = gpu; |
| 251 | |
| 252 | return result; |
| 253 | } |
| 254 | |
| 255 | VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
| 256 | dispatch_key key = get_dispatch_key(device); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 257 | layer_data *dev_data = GetLayerDataPtr(key, layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 258 | |
| 259 | layer_debug_report_destroy_device(device); |
| 260 | dev_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
| 261 | layer_data_map.erase(key); |
| 262 | } |
| 263 | |
| 264 | static const VkLayerProperties globalLayerProps = {"VK_LAYER_GOOGLE_unique_objects", |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 265 | VK_LAYER_API_VERSION, // specVersion |
| 266 | 1, // implementationVersion |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 267 | "Google Validation Layer"}; |
| 268 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 269 | /// Declare prototype for these functions |
| 270 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName); |
| 271 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 272 | static inline PFN_vkVoidFunction layer_intercept_proc(const char *name) { |
Jamie Madill | 6069c82 | 2016-12-15 09:35:36 -0500 | [diff] [blame] | 273 | for (unsigned int i = 0; i < sizeof(procmap) / sizeof(procmap[0]); i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 274 | if (!strcmp(name, procmap[i].name)) return procmap[i].pFunc; |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 275 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 276 | if (0 == strcmp(name, "vk_layerGetPhysicalDeviceProcAddr")) { |
| 277 | return (PFN_vkVoidFunction)GetPhysicalDeviceProcAddr; |
| 278 | } |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 279 | return NULL; |
| 280 | } |
| 281 | |
| 282 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
| 283 | return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties); |
| 284 | } |
| 285 | |
| 286 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 287 | VkLayerProperties *pProperties) { |
| 288 | return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties); |
| 289 | } |
| 290 | |
| 291 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 292 | VkExtensionProperties *pProperties) { |
| 293 | if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName)) |
| 294 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 295 | |
| 296 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 297 | } |
| 298 | |
| 299 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 300 | uint32_t *pCount, VkExtensionProperties *pProperties) { |
| 301 | if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName)) |
| 302 | return util_GetExtensionProperties(0, nullptr, pCount, pProperties); |
| 303 | |
| 304 | assert(physicalDevice); |
| 305 | |
| 306 | dispatch_key key = get_dispatch_key(physicalDevice); |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 307 | layer_data *instance_data = GetLayerDataPtr(key, layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 308 | return instance_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
| 309 | } |
| 310 | |
| 311 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { |
| 312 | PFN_vkVoidFunction addr; |
| 313 | assert(device); |
| 314 | addr = layer_intercept_proc(funcName); |
| 315 | if (addr) { |
| 316 | return addr; |
| 317 | } |
| 318 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 319 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 320 | VkLayerDispatchTable *disp_table = dev_data->device_dispatch_table; |
| 321 | if (disp_table->GetDeviceProcAddr == NULL) { |
| 322 | return NULL; |
| 323 | } |
| 324 | return disp_table->GetDeviceProcAddr(device, funcName); |
| 325 | } |
| 326 | |
| 327 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { |
| 328 | PFN_vkVoidFunction addr; |
| 329 | |
| 330 | addr = layer_intercept_proc(funcName); |
| 331 | if (addr) { |
| 332 | return addr; |
| 333 | } |
| 334 | assert(instance); |
| 335 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 336 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 337 | addr = debug_report_get_instance_proc_addr(instance_data->report_data, funcName); |
| 338 | if (addr) { |
| 339 | return addr; |
| 340 | } |
| 341 | |
| 342 | VkLayerInstanceDispatchTable *disp_table = instance_data->instance_dispatch_table; |
| 343 | if (disp_table->GetInstanceProcAddr == NULL) { |
| 344 | return NULL; |
| 345 | } |
| 346 | return disp_table->GetInstanceProcAddr(instance, funcName); |
| 347 | } |
| 348 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 349 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { |
| 350 | assert(instance); |
| 351 | |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 352 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 353 | VkLayerInstanceDispatchTable *disp_table = instance_data->instance_dispatch_table; |
| 354 | if (disp_table->GetPhysicalDeviceProcAddr == NULL) { |
| 355 | return NULL; |
| 356 | } |
| 357 | return disp_table->GetPhysicalDeviceProcAddr(instance, funcName); |
| 358 | } |
| 359 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 360 | VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, |
| 361 | const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory) { |
| 362 | const VkMemoryAllocateInfo *input_allocate_info = pAllocateInfo; |
| 363 | std::unique_ptr<safe_VkMemoryAllocateInfo> safe_allocate_info; |
Mark Lobodzinski | d244322 | 2016-10-07 14:13:38 -0600 | [diff] [blame] | 364 | std::unique_ptr<safe_VkDedicatedAllocationMemoryAllocateInfoNV> safe_dedicated_allocate_info; |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 365 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 366 | |
| 367 | if ((pAllocateInfo != nullptr) && |
| 368 | ContainsExtStruct(pAllocateInfo, VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV)) { |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 369 | // Assuming there is only one extension struct of this type in the list for now |
| 370 | safe_dedicated_allocate_info = |
| 371 | std::unique_ptr<safe_VkDedicatedAllocationMemoryAllocateInfoNV>(new safe_VkDedicatedAllocationMemoryAllocateInfoNV); |
| 372 | safe_allocate_info = std::unique_ptr<safe_VkMemoryAllocateInfo>(new safe_VkMemoryAllocateInfo(pAllocateInfo)); |
| 373 | input_allocate_info = reinterpret_cast<const VkMemoryAllocateInfo *>(safe_allocate_info.get()); |
| 374 | |
| 375 | const GenericHeader *orig_pnext = reinterpret_cast<const GenericHeader *>(pAllocateInfo->pNext); |
| 376 | GenericHeader *input_pnext = reinterpret_cast<GenericHeader *>(safe_allocate_info.get()); |
| 377 | while (orig_pnext != nullptr) { |
| 378 | if (orig_pnext->sType == VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV) { |
| 379 | safe_dedicated_allocate_info->initialize( |
| 380 | reinterpret_cast<const VkDedicatedAllocationMemoryAllocateInfoNV *>(orig_pnext)); |
| 381 | |
| 382 | std::unique_lock<std::mutex> lock(global_lock); |
| 383 | |
| 384 | if (safe_dedicated_allocate_info->buffer != VK_NULL_HANDLE) { |
| 385 | uint64_t local_buffer = reinterpret_cast<uint64_t &>(safe_dedicated_allocate_info->buffer); |
| 386 | safe_dedicated_allocate_info->buffer = |
| 387 | reinterpret_cast<VkBuffer &>(device_data->unique_id_mapping[local_buffer]); |
| 388 | } |
| 389 | |
| 390 | if (safe_dedicated_allocate_info->image != VK_NULL_HANDLE) { |
| 391 | uint64_t local_image = reinterpret_cast<uint64_t &>(safe_dedicated_allocate_info->image); |
| 392 | safe_dedicated_allocate_info->image = reinterpret_cast<VkImage &>(device_data->unique_id_mapping[local_image]); |
| 393 | } |
| 394 | |
| 395 | lock.unlock(); |
| 396 | |
| 397 | input_pnext->pNext = reinterpret_cast<GenericHeader *>(safe_dedicated_allocate_info.get()); |
| 398 | input_pnext = reinterpret_cast<GenericHeader *>(input_pnext->pNext); |
| 399 | } else { |
| 400 | // TODO: generic handling of pNext copies |
| 401 | } |
| 402 | |
| 403 | orig_pnext = reinterpret_cast<const GenericHeader *>(orig_pnext->pNext); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | VkResult result = device_data->device_dispatch_table->AllocateMemory(device, input_allocate_info, pAllocator, pMemory); |
| 408 | |
| 409 | if (VK_SUCCESS == result) { |
| 410 | std::lock_guard<std::mutex> lock(global_lock); |
| 411 | uint64_t unique_id = global_unique_id++; |
| 412 | device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*pMemory); |
| 413 | *pMemory = reinterpret_cast<VkDeviceMemory &>(unique_id); |
| 414 | } |
| 415 | |
| 416 | return result; |
| 417 | } |
| 418 | |
| 419 | VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 420 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 421 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 422 | layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 423 | safe_VkComputePipelineCreateInfo *local_pCreateInfos = NULL; |
| 424 | if (pCreateInfos) { |
| 425 | std::lock_guard<std::mutex> lock(global_lock); |
| 426 | local_pCreateInfos = new safe_VkComputePipelineCreateInfo[createInfoCount]; |
| 427 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
| 428 | local_pCreateInfos[idx0].initialize(&pCreateInfos[idx0]); |
| 429 | if (pCreateInfos[idx0].basePipelineHandle) { |
| 430 | local_pCreateInfos[idx0].basePipelineHandle = |
| 431 | (VkPipeline)my_device_data |
| 432 | ->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].basePipelineHandle)]; |
| 433 | } |
| 434 | if (pCreateInfos[idx0].layout) { |
| 435 | local_pCreateInfos[idx0].layout = |
| 436 | (VkPipelineLayout) |
| 437 | my_device_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].layout)]; |
| 438 | } |
| 439 | if (pCreateInfos[idx0].stage.module) { |
| 440 | local_pCreateInfos[idx0].stage.module = |
| 441 | (VkShaderModule) |
| 442 | my_device_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].stage.module)]; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | if (pipelineCache) { |
| 447 | std::lock_guard<std::mutex> lock(global_lock); |
| 448 | pipelineCache = (VkPipelineCache)my_device_data->unique_id_mapping[reinterpret_cast<uint64_t &>(pipelineCache)]; |
| 449 | } |
| 450 | |
| 451 | VkResult result = my_device_data->device_dispatch_table->CreateComputePipelines( |
| 452 | device, pipelineCache, createInfoCount, (const VkComputePipelineCreateInfo *)local_pCreateInfos, pAllocator, pPipelines); |
| 453 | delete[] local_pCreateInfos; |
Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 454 | { |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 455 | uint64_t unique_id = 0; |
| 456 | std::lock_guard<std::mutex> lock(global_lock); |
| 457 | for (uint32_t i = 0; i < createInfoCount; ++i) { |
Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 458 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 459 | unique_id = global_unique_id++; |
| 460 | my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pPipelines[i]); |
| 461 | pPipelines[i] = reinterpret_cast<VkPipeline &>(unique_id); |
| 462 | } |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | return result; |
| 466 | } |
| 467 | |
| 468 | VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 469 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 470 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 471 | layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 472 | safe_VkGraphicsPipelineCreateInfo *local_pCreateInfos = NULL; |
| 473 | if (pCreateInfos) { |
| 474 | local_pCreateInfos = new safe_VkGraphicsPipelineCreateInfo[createInfoCount]; |
| 475 | std::lock_guard<std::mutex> lock(global_lock); |
| 476 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
| 477 | local_pCreateInfos[idx0].initialize(&pCreateInfos[idx0]); |
| 478 | if (pCreateInfos[idx0].basePipelineHandle) { |
| 479 | local_pCreateInfos[idx0].basePipelineHandle = |
| 480 | (VkPipeline)my_device_data |
| 481 | ->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].basePipelineHandle)]; |
| 482 | } |
| 483 | if (pCreateInfos[idx0].layout) { |
| 484 | local_pCreateInfos[idx0].layout = |
| 485 | (VkPipelineLayout) |
| 486 | my_device_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].layout)]; |
| 487 | } |
| 488 | if (pCreateInfos[idx0].pStages) { |
| 489 | for (uint32_t idx1 = 0; idx1 < pCreateInfos[idx0].stageCount; ++idx1) { |
| 490 | if (pCreateInfos[idx0].pStages[idx1].module) { |
| 491 | local_pCreateInfos[idx0].pStages[idx1].module = |
| 492 | (VkShaderModule)my_device_data |
| 493 | ->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].pStages[idx1].module)]; |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | if (pCreateInfos[idx0].renderPass) { |
| 498 | local_pCreateInfos[idx0].renderPass = |
| 499 | (VkRenderPass) |
| 500 | my_device_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].renderPass)]; |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | if (pipelineCache) { |
| 505 | std::lock_guard<std::mutex> lock(global_lock); |
| 506 | pipelineCache = (VkPipelineCache)my_device_data->unique_id_mapping[reinterpret_cast<uint64_t &>(pipelineCache)]; |
| 507 | } |
| 508 | |
| 509 | VkResult result = my_device_data->device_dispatch_table->CreateGraphicsPipelines( |
| 510 | device, pipelineCache, createInfoCount, (const VkGraphicsPipelineCreateInfo *)local_pCreateInfos, pAllocator, pPipelines); |
| 511 | delete[] local_pCreateInfos; |
Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 512 | { |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 513 | uint64_t unique_id = 0; |
| 514 | std::lock_guard<std::mutex> lock(global_lock); |
| 515 | for (uint32_t i = 0; i < createInfoCount; ++i) { |
Maciej Jesionowski | 4220070 | 2016-11-23 10:44:34 +0100 | [diff] [blame] | 516 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 517 | unique_id = global_unique_id++; |
| 518 | my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pPipelines[i]); |
| 519 | pPipelines[i] = reinterpret_cast<VkPipeline &>(unique_id); |
| 520 | } |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | return result; |
| 524 | } |
| 525 | |
| 526 | VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance, |
| 527 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 528 | const VkAllocationCallbacks *pAllocator, |
| 529 | VkDebugReportCallbackEXT *pMsgCallback) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 530 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 531 | VkResult result = |
| 532 | instance_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
| 533 | |
| 534 | if (VK_SUCCESS == result) { |
| 535 | result = layer_create_msg_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback); |
| 536 | } |
| 537 | return result; |
| 538 | } |
| 539 | |
| 540 | VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, |
| 541 | const VkAllocationCallbacks *pAllocator) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 542 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 543 | instance_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, callback, pAllocator); |
| 544 | layer_destroy_msg_callback(instance_data->report_data, callback, pAllocator); |
| 545 | } |
| 546 | |
| 547 | VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 548 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 549 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 550 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 551 | instance_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, |
| 552 | pMsg); |
| 553 | } |
| 554 | |
| 555 | VKAPI_ATTR VkResult VKAPI_CALL CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 556 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 557 | 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] | 558 | safe_VkSwapchainCreateInfoKHR *local_pCreateInfo = NULL; |
| 559 | if (pCreateInfo) { |
| 560 | std::lock_guard<std::mutex> lock(global_lock); |
| 561 | local_pCreateInfo = new safe_VkSwapchainCreateInfoKHR(pCreateInfo); |
| 562 | local_pCreateInfo->oldSwapchain = |
| 563 | (VkSwapchainKHR)my_map_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfo->oldSwapchain)]; |
| 564 | // Need to pull surface mapping from the instance-level map |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 565 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(my_map_data->gpu), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 566 | local_pCreateInfo->surface = |
| 567 | (VkSurfaceKHR)instance_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfo->surface)]; |
| 568 | } |
| 569 | |
| 570 | VkResult result = my_map_data->device_dispatch_table->CreateSwapchainKHR( |
| 571 | device, (const VkSwapchainCreateInfoKHR *)local_pCreateInfo, pAllocator, pSwapchain); |
| 572 | if (local_pCreateInfo) { |
| 573 | delete local_pCreateInfo; |
| 574 | } |
| 575 | if (VK_SUCCESS == result) { |
| 576 | std::lock_guard<std::mutex> lock(global_lock); |
| 577 | uint64_t unique_id = global_unique_id++; |
| 578 | my_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*pSwapchain); |
| 579 | *pSwapchain = reinterpret_cast<VkSwapchainKHR &>(unique_id); |
| 580 | } |
| 581 | return result; |
| 582 | } |
| 583 | |
Dustin Graves | 9a6eb05 | 2017-03-28 14:18:54 -0600 | [diff] [blame] | 584 | VKAPI_ATTR VkResult VKAPI_CALL CreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 585 | const VkSwapchainCreateInfoKHR *pCreateInfos, |
| 586 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchains) { |
| 587 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 588 | safe_VkSwapchainCreateInfoKHR *local_pCreateInfos = NULL; |
| 589 | { |
| 590 | std::lock_guard<std::mutex> lock(global_lock); |
| 591 | if (pCreateInfos) { |
| 592 | // Need to pull surface mapping from the instance-level map |
| 593 | layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(dev_data->gpu), layer_data_map); |
| 594 | local_pCreateInfos = new safe_VkSwapchainCreateInfoKHR[swapchainCount]; |
| 595 | for (uint32_t i = 0; i < swapchainCount; ++i) { |
| 596 | local_pCreateInfos[i].initialize(&pCreateInfos[i]); |
| 597 | if (pCreateInfos[i].surface) { |
| 598 | local_pCreateInfos[i].surface = |
| 599 | (VkSurfaceKHR)instance_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[i].surface)]; |
| 600 | } |
| 601 | if (pCreateInfos[i].oldSwapchain) { |
| 602 | local_pCreateInfos[i].oldSwapchain = |
| 603 | (VkSwapchainKHR) |
| 604 | dev_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[i].oldSwapchain)]; |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | VkResult result = dev_data->device_dispatch_table->CreateSharedSwapchainsKHR( |
| 610 | device, swapchainCount, (const VkSwapchainCreateInfoKHR *)local_pCreateInfos, pAllocator, pSwapchains); |
| 611 | if (local_pCreateInfos) delete[] local_pCreateInfos; |
| 612 | if (VK_SUCCESS == result) { |
| 613 | std::lock_guard<std::mutex> lock(global_lock); |
| 614 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 615 | uint64_t unique_id = global_unique_id++; |
| 616 | dev_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pSwapchains[i]); |
| 617 | pSwapchains[i] = reinterpret_cast<VkSwapchainKHR &>(unique_id); |
| 618 | } |
| 619 | } |
| 620 | return result; |
| 621 | } |
| 622 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 623 | VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, |
| 624 | VkImage *pSwapchainImages) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 625 | layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 626 | if (VK_NULL_HANDLE != swapchain) { |
| 627 | std::lock_guard<std::mutex> lock(global_lock); |
| 628 | swapchain = (VkSwapchainKHR)my_device_data->unique_id_mapping[reinterpret_cast<uint64_t &>(swapchain)]; |
| 629 | } |
| 630 | VkResult result = |
| 631 | my_device_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); |
| 632 | // TODO : Need to add corresponding code to delete these images |
| 633 | if (VK_SUCCESS == result) { |
| 634 | if ((*pSwapchainImageCount > 0) && pSwapchainImages) { |
| 635 | uint64_t unique_id = 0; |
| 636 | std::lock_guard<std::mutex> lock(global_lock); |
| 637 | for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) { |
| 638 | unique_id = global_unique_id++; |
| 639 | my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pSwapchainImages[i]); |
| 640 | pSwapchainImages[i] = reinterpret_cast<VkImage &>(unique_id); |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | return result; |
| 645 | } |
| 646 | |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 647 | VKAPI_ATTR VkResult VKAPI_CALL CreateDescriptorUpdateTemplateKHR(VkDevice device, |
| 648 | const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, |
| 649 | const VkAllocationCallbacks *pAllocator, |
| 650 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate) { |
| 651 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 652 | safe_VkDescriptorUpdateTemplateCreateInfoKHR *local_create_info = NULL; |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 653 | { |
| 654 | std::lock_guard<std::mutex> lock(global_lock); |
| 655 | if (pCreateInfo) { |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 656 | local_create_info = new safe_VkDescriptorUpdateTemplateCreateInfoKHR(pCreateInfo); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 657 | if (pCreateInfo->descriptorSetLayout) { |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 658 | local_create_info->descriptorSetLayout = |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 659 | (VkDescriptorSetLayout) |
| 660 | dev_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfo->descriptorSetLayout)]; |
| 661 | } |
| 662 | if (pCreateInfo->pipelineLayout) { |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 663 | local_create_info->pipelineLayout = |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 664 | (VkPipelineLayout)dev_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfo->pipelineLayout)]; |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | VkResult result = dev_data->device_dispatch_table->CreateDescriptorUpdateTemplateKHR( |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 669 | device, (const VkDescriptorUpdateTemplateCreateInfoKHR *)local_create_info, pAllocator, pDescriptorUpdateTemplate); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 670 | if (VK_SUCCESS == result) { |
| 671 | std::lock_guard<std::mutex> lock(global_lock); |
| 672 | uint64_t unique_id = global_unique_id++; |
| 673 | dev_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*pDescriptorUpdateTemplate); |
| 674 | *pDescriptorUpdateTemplate = reinterpret_cast<VkDescriptorUpdateTemplateKHR &>(unique_id); |
Mark Lobodzinski | 4f3ce67 | 2017-03-03 10:28:21 -0700 | [diff] [blame] | 675 | |
| 676 | // Shadow template createInfo for later updates |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 677 | std::unique_ptr<TEMPLATE_STATE> template_state(new TEMPLATE_STATE(*pDescriptorUpdateTemplate, local_create_info)); |
Mark Lobodzinski | 4f3ce67 | 2017-03-03 10:28:21 -0700 | [diff] [blame] | 678 | dev_data->desc_template_map[unique_id] = std::move(template_state); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 679 | } |
| 680 | return result; |
| 681 | } |
| 682 | |
| 683 | VKAPI_ATTR void VKAPI_CALL DestroyDescriptorUpdateTemplateKHR(VkDevice device, |
| 684 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 685 | const VkAllocationCallbacks *pAllocator) { |
| 686 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 687 | std::unique_lock<std::mutex> lock(global_lock); |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 688 | uint64_t descriptor_update_template_id = reinterpret_cast<uint64_t &>(descriptorUpdateTemplate); |
| 689 | dev_data->desc_template_map.erase(descriptor_update_template_id); |
| 690 | descriptorUpdateTemplate = (VkDescriptorUpdateTemplateKHR)dev_data->unique_id_mapping[descriptor_update_template_id]; |
| 691 | dev_data->unique_id_mapping.erase(descriptor_update_template_id); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 692 | lock.unlock(); |
| 693 | dev_data->device_dispatch_table->DestroyDescriptorUpdateTemplateKHR(device, descriptorUpdateTemplate, pAllocator); |
| 694 | } |
| 695 | |
Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 696 | void *BuildUnwrappedUpdateTemplateBuffer(layer_data *dev_data, uint64_t descriptorUpdateTemplate, const void *pData) { |
| 697 | auto const template_map_entry = dev_data->desc_template_map.find(descriptorUpdateTemplate); |
| 698 | if (template_map_entry == dev_data->desc_template_map.end()) { |
| 699 | assert(0); |
| 700 | } |
| 701 | auto const &create_info = template_map_entry->second->create_info; |
| 702 | size_t allocation_size = 0; |
| 703 | std::vector<std::tuple<size_t, VkDebugReportObjectTypeEXT, void *>> template_entries; |
| 704 | |
| 705 | for (uint32_t i = 0; i < create_info.descriptorUpdateEntryCount; i++) { |
| 706 | for (uint32_t j = 0; j < create_info.pDescriptorUpdateEntries[i].descriptorCount; j++) { |
| 707 | size_t offset = create_info.pDescriptorUpdateEntries[i].offset + j * create_info.pDescriptorUpdateEntries[i].stride; |
| 708 | char *update_entry = (char *)(pData) + offset; |
| 709 | |
| 710 | switch (create_info.pDescriptorUpdateEntries[i].descriptorType) { |
| 711 | case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 712 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 713 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 714 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 715 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: { |
| 716 | auto image_entry = reinterpret_cast<VkDescriptorImageInfo *>(update_entry); |
| 717 | allocation_size = std::max(allocation_size, offset + sizeof(VkDescriptorImageInfo)); |
| 718 | |
| 719 | VkDescriptorImageInfo *wrapped_entry = new VkDescriptorImageInfo(*image_entry); |
| 720 | wrapped_entry->sampler = reinterpret_cast<VkSampler &>( |
| 721 | dev_data->unique_id_mapping[reinterpret_cast<uint64_t &>(image_entry->sampler)]); |
| 722 | wrapped_entry->imageView = reinterpret_cast<VkImageView &>( |
| 723 | dev_data->unique_id_mapping[reinterpret_cast<uint64_t &>(image_entry->imageView)]); |
| 724 | template_entries.emplace_back(offset, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 725 | reinterpret_cast<void *>(wrapped_entry)); |
| 726 | } break; |
| 727 | |
| 728 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 729 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 730 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 731 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { |
| 732 | auto buffer_entry = reinterpret_cast<VkDescriptorBufferInfo *>(update_entry); |
| 733 | allocation_size = std::max(allocation_size, offset + sizeof(VkDescriptorBufferInfo)); |
| 734 | |
| 735 | VkDescriptorBufferInfo *wrapped_entry = new VkDescriptorBufferInfo(*buffer_entry); |
Mark Lobodzinski | d5197d0 | 2017-03-15 13:13:49 -0600 | [diff] [blame] | 736 | wrapped_entry->buffer = reinterpret_cast<VkBuffer &>( |
| 737 | dev_data->unique_id_mapping[reinterpret_cast<uint64_t &>(buffer_entry->buffer)]); |
Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 738 | template_entries.emplace_back(offset, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 739 | reinterpret_cast<void *>(wrapped_entry)); |
| 740 | } break; |
| 741 | |
| 742 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 743 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: { |
Mark Lobodzinski | d5197d0 | 2017-03-15 13:13:49 -0600 | [diff] [blame] | 744 | auto buffer_view_handle = reinterpret_cast<uint64_t *>(update_entry); |
Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 745 | allocation_size = std::max(allocation_size, offset + sizeof(VkBufferView)); |
| 746 | |
Mark Lobodzinski | d5197d0 | 2017-03-15 13:13:49 -0600 | [diff] [blame] | 747 | uint64_t wrapped_entry = dev_data->unique_id_mapping[reinterpret_cast<uint64_t &>(*buffer_view_handle)]; |
Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 748 | template_entries.emplace_back(offset, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, |
| 749 | reinterpret_cast<void *>(wrapped_entry)); |
| 750 | } break; |
| 751 | default: |
| 752 | assert(0); |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | // Allocate required buffer size and populate with source/unwrapped data |
| 758 | void *unwrapped_data = malloc(allocation_size); |
| 759 | for (auto &this_entry : template_entries) { |
| 760 | VkDebugReportObjectTypeEXT type = std::get<1>(this_entry); |
| 761 | void *destination = (char *)unwrapped_data + std::get<0>(this_entry); |
| 762 | void *source = (char *)std::get<2>(this_entry); |
| 763 | |
| 764 | switch (type) { |
| 765 | case VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT: |
| 766 | *(reinterpret_cast<VkDescriptorImageInfo *>(destination)) = *(reinterpret_cast<VkDescriptorImageInfo *>(source)); |
| 767 | delete reinterpret_cast<VkDescriptorImageInfo *>(source); |
| 768 | break; |
| 769 | case VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT: |
| 770 | *(reinterpret_cast<VkDescriptorBufferInfo *>(destination)) = *(reinterpret_cast<VkDescriptorBufferInfo *>(source)); |
| 771 | delete reinterpret_cast<VkDescriptorBufferInfo *>(source); |
| 772 | break; |
| 773 | case VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT: |
Mark Lobodzinski | d5197d0 | 2017-03-15 13:13:49 -0600 | [diff] [blame] | 774 | *(reinterpret_cast<VkBufferView *>(destination)) = reinterpret_cast<VkBufferView>(source); |
Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 775 | break; |
| 776 | default: |
| 777 | assert(0); |
| 778 | break; |
| 779 | } |
| 780 | } |
| 781 | return (void *)unwrapped_data; |
| 782 | } |
| 783 | |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 784 | VKAPI_ATTR void VKAPI_CALL UpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet, |
| 785 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 786 | const void *pData) { |
| 787 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 788 | uint64_t template_handle = reinterpret_cast<uint64_t &>(descriptorUpdateTemplate); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 789 | { |
| 790 | std::lock_guard<std::mutex> lock(global_lock); |
| 791 | descriptorSet = (VkDescriptorSet)dev_data->unique_id_mapping[reinterpret_cast<uint64_t &>(descriptorSet)]; |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 792 | descriptorUpdateTemplate = (VkDescriptorUpdateTemplateKHR)dev_data->unique_id_mapping[template_handle]; |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 793 | } |
Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 794 | void *unwrapped_buffer = nullptr; |
Mark Lobodzinski | 94d9e8c | 2017-03-06 16:18:19 -0700 | [diff] [blame] | 795 | unwrapped_buffer = BuildUnwrappedUpdateTemplateBuffer(dev_data, template_handle, pData); |
Mark Lobodzinski | b523f7c | 2017-03-06 09:00:21 -0700 | [diff] [blame] | 796 | dev_data->device_dispatch_table->UpdateDescriptorSetWithTemplateKHR(device, descriptorSet, descriptorUpdateTemplate, |
| 797 | unwrapped_buffer); |
| 798 | free(unwrapped_buffer); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer, |
| 802 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 803 | VkPipelineLayout layout, uint32_t set, const void *pData) { |
| 804 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map); |
Mark Lobodzinski | 1c47126 | 2017-03-28 16:22:56 -0600 | [diff] [blame^] | 805 | uint64_t template_handle = reinterpret_cast<uint64_t &>(descriptorUpdateTemplate); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 806 | { |
| 807 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | 1c47126 | 2017-03-28 16:22:56 -0600 | [diff] [blame^] | 808 | descriptorUpdateTemplate = (VkDescriptorUpdateTemplateKHR)dev_data->unique_id_mapping[template_handle]; |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 809 | layout = (VkPipelineLayout)dev_data->unique_id_mapping[reinterpret_cast<uint64_t &>(layout)]; |
| 810 | } |
Mark Lobodzinski | 1c47126 | 2017-03-28 16:22:56 -0600 | [diff] [blame^] | 811 | void *unwrapped_buffer = BuildUnwrappedUpdateTemplateBuffer(dev_data, template_handle, pData); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 812 | dev_data->device_dispatch_table->CmdPushDescriptorSetWithTemplateKHR(commandBuffer, descriptorUpdateTemplate, layout, set, |
Mark Lobodzinski | 1c47126 | 2017-03-28 16:22:56 -0600 | [diff] [blame^] | 813 | unwrapped_buffer); |
| 814 | free(unwrapped_buffer); |
Mark Lobodzinski | 71703a5 | 2017-03-03 08:40:16 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 817 | #ifndef __ANDROID__ |
| 818 | VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 819 | VkDisplayPropertiesKHR *pProperties) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 820 | layer_data *my_map_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 821 | safe_VkDisplayPropertiesKHR *local_pProperties = NULL; |
| 822 | { |
| 823 | std::lock_guard<std::mutex> lock(global_lock); |
| 824 | if (pProperties) { |
| 825 | local_pProperties = new safe_VkDisplayPropertiesKHR[*pPropertyCount]; |
| 826 | for (uint32_t idx0 = 0; idx0 < *pPropertyCount; ++idx0) { |
| 827 | local_pProperties[idx0].initialize(&pProperties[idx0]); |
| 828 | if (pProperties[idx0].display) { |
| 829 | local_pProperties[idx0].display = |
| 830 | (VkDisplayKHR)my_map_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pProperties[idx0].display)]; |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | VkResult result = my_map_data->instance_dispatch_table->GetPhysicalDeviceDisplayPropertiesKHR( |
| 837 | physicalDevice, pPropertyCount, (VkDisplayPropertiesKHR *)local_pProperties); |
| 838 | if (result == VK_SUCCESS && pProperties) { |
| 839 | for (uint32_t idx0 = 0; idx0 < *pPropertyCount; ++idx0) { |
| 840 | std::lock_guard<std::mutex> lock(global_lock); |
| 841 | |
| 842 | uint64_t unique_id = global_unique_id++; |
| 843 | my_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(local_pProperties[idx0].display); |
| 844 | pProperties[idx0].display = reinterpret_cast<VkDisplayKHR &>(unique_id); |
| 845 | pProperties[idx0].displayName = local_pProperties[idx0].displayName; |
| 846 | pProperties[idx0].physicalDimensions = local_pProperties[idx0].physicalDimensions; |
| 847 | pProperties[idx0].physicalResolution = local_pProperties[idx0].physicalResolution; |
| 848 | pProperties[idx0].supportedTransforms = local_pProperties[idx0].supportedTransforms; |
| 849 | pProperties[idx0].planeReorderPossible = local_pProperties[idx0].planeReorderPossible; |
| 850 | pProperties[idx0].persistentContent = local_pProperties[idx0].persistentContent; |
| 851 | } |
| 852 | } |
| 853 | if (local_pProperties) { |
| 854 | delete[] local_pProperties; |
| 855 | } |
| 856 | return result; |
| 857 | } |
| 858 | |
| 859 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
| 860 | uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 861 | layer_data *my_map_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 862 | VkResult result = my_map_data->instance_dispatch_table->GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, |
| 863 | pDisplayCount, pDisplays); |
| 864 | if (VK_SUCCESS == result) { |
| 865 | if ((*pDisplayCount > 0) && pDisplays) { |
| 866 | std::lock_guard<std::mutex> lock(global_lock); |
| 867 | for (uint32_t i = 0; i < *pDisplayCount; i++) { |
| 868 | auto it = my_map_data->unique_id_mapping.find(reinterpret_cast<const uint64_t &>(pDisplays[i])); |
| 869 | assert(it != my_map_data->unique_id_mapping.end()); |
| 870 | pDisplays[i] = reinterpret_cast<VkDisplayKHR &>(it->second); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | return result; |
| 875 | } |
| 876 | |
| 877 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, |
| 878 | uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 879 | layer_data *my_map_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Mark Lobodzinski | f0650ff | 2017-01-03 08:52:14 -0700 | [diff] [blame] | 880 | VkDisplayModePropertiesKHR *local_pProperties = NULL; |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 881 | { |
| 882 | std::lock_guard<std::mutex> lock(global_lock); |
| 883 | display = (VkDisplayKHR)my_map_data->unique_id_mapping[reinterpret_cast<uint64_t &>(display)]; |
| 884 | if (pProperties) { |
Mark Lobodzinski | f0650ff | 2017-01-03 08:52:14 -0700 | [diff] [blame] | 885 | local_pProperties = new VkDisplayModePropertiesKHR[*pPropertyCount]; |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
| 889 | VkResult result = my_map_data->instance_dispatch_table->GetDisplayModePropertiesKHR( |
| 890 | physicalDevice, display, pPropertyCount, (VkDisplayModePropertiesKHR *)local_pProperties); |
| 891 | if (result == VK_SUCCESS && pProperties) { |
| 892 | for (uint32_t idx0 = 0; idx0 < *pPropertyCount; ++idx0) { |
| 893 | std::lock_guard<std::mutex> lock(global_lock); |
| 894 | |
| 895 | uint64_t unique_id = global_unique_id++; |
| 896 | my_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(local_pProperties[idx0].displayMode); |
| 897 | pProperties[idx0].displayMode = reinterpret_cast<VkDisplayModeKHR &>(unique_id); |
| 898 | pProperties[idx0].parameters.visibleRegion.width = local_pProperties[idx0].parameters.visibleRegion.width; |
| 899 | pProperties[idx0].parameters.visibleRegion.height = local_pProperties[idx0].parameters.visibleRegion.height; |
| 900 | pProperties[idx0].parameters.refreshRate = local_pProperties[idx0].parameters.refreshRate; |
| 901 | } |
| 902 | } |
| 903 | if (local_pProperties) { |
| 904 | delete[] local_pProperties; |
| 905 | } |
| 906 | return result; |
| 907 | } |
Norbert Nopper | 1dec9a5 | 2016-11-25 07:55:13 +0100 | [diff] [blame] | 908 | |
| 909 | VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 910 | uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR *pCapabilities) { |
Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 911 | layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
Norbert Nopper | 1dec9a5 | 2016-11-25 07:55:13 +0100 | [diff] [blame] | 912 | { |
| 913 | std::lock_guard<std::mutex> lock(global_lock); |
| 914 | auto it = dev_data->unique_id_mapping.find(reinterpret_cast<uint64_t &>(mode)); |
| 915 | if (it == dev_data->unique_id_mapping.end()) { |
| 916 | uint64_t unique_id = global_unique_id++; |
| 917 | dev_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(mode); |
| 918 | |
| 919 | mode = reinterpret_cast<VkDisplayModeKHR &>(unique_id); |
| 920 | } else { |
| 921 | mode = reinterpret_cast<VkDisplayModeKHR &>(it->second); |
| 922 | } |
| 923 | } |
| 924 | VkResult result = |
| 925 | dev_data->instance_dispatch_table->GetDisplayPlaneCapabilitiesKHR(physicalDevice, mode, planeIndex, pCapabilities); |
| 926 | return result; |
| 927 | } |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 928 | #endif |
| 929 | |
Mark Lobodzinski | a096c12 | 2017-03-16 11:54:35 -0600 | [diff] [blame] | 930 | VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectTagEXT(VkDevice device, VkDebugMarkerObjectTagInfoEXT *pTagInfo) { |
| 931 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 932 | auto local_tag_info = new safe_VkDebugMarkerObjectTagInfoEXT(pTagInfo); |
| 933 | { |
| 934 | std::lock_guard<std::mutex> lock(global_lock); |
| 935 | auto it = device_data->unique_id_mapping.find(reinterpret_cast<uint64_t &>(local_tag_info->object)); |
| 936 | if (it != device_data->unique_id_mapping.end()) { |
| 937 | local_tag_info->object = it->second; |
| 938 | } |
| 939 | } |
| 940 | VkResult result = device_data->device_dispatch_table->DebugMarkerSetObjectTagEXT( |
| 941 | device, reinterpret_cast<VkDebugMarkerObjectTagInfoEXT *>(local_tag_info)); |
| 942 | return result; |
| 943 | } |
| 944 | |
| 945 | VKAPI_ATTR VkResult VKAPI_CALL DebugMarkerSetObjectNameEXT(VkDevice device, VkDebugMarkerObjectNameInfoEXT *pNameInfo) { |
| 946 | layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 947 | auto local_name_info = new safe_VkDebugMarkerObjectNameInfoEXT(pNameInfo); |
| 948 | { |
| 949 | std::lock_guard<std::mutex> lock(global_lock); |
| 950 | auto it = device_data->unique_id_mapping.find(reinterpret_cast<uint64_t &>(local_name_info->object)); |
| 951 | if (it != device_data->unique_id_mapping.end()) { |
| 952 | local_name_info->object = it->second; |
| 953 | } |
| 954 | } |
| 955 | VkResult result = device_data->device_dispatch_table->DebugMarkerSetObjectNameEXT( |
| 956 | device, reinterpret_cast<VkDebugMarkerObjectNameInfoEXT *>(local_name_info)); |
| 957 | return result; |
| 958 | } |
| 959 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 960 | } // namespace unique_objects |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame] | 961 | |
| 962 | // vk_layer_logging.h expects these to be defined |
| 963 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance, |
| 964 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 965 | const VkAllocationCallbacks *pAllocator, |
| 966 | VkDebugReportCallbackEXT *pMsgCallback) { |
| 967 | return unique_objects::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
| 968 | } |
| 969 | |
| 970 | VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, |
| 971 | const VkAllocationCallbacks *pAllocator) { |
| 972 | unique_objects::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
| 973 | } |
| 974 | |
| 975 | VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 976 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 977 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
| 978 | unique_objects::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
| 979 | } |
| 980 | |
| 981 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 982 | VkExtensionProperties *pProperties) { |
| 983 | return unique_objects::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); |
| 984 | } |
| 985 | |
| 986 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, |
| 987 | VkLayerProperties *pProperties) { |
| 988 | return unique_objects::EnumerateInstanceLayerProperties(pCount, pProperties); |
| 989 | } |
| 990 | |
| 991 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 992 | VkLayerProperties *pProperties) { |
| 993 | assert(physicalDevice == VK_NULL_HANDLE); |
| 994 | return unique_objects::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); |
| 995 | } |
| 996 | |
| 997 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) { |
| 998 | return unique_objects::GetDeviceProcAddr(dev, funcName); |
| 999 | } |
| 1000 | |
| 1001 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { |
| 1002 | return unique_objects::GetInstanceProcAddr(instance, funcName); |
| 1003 | } |
| 1004 | |
| 1005 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 1006 | const char *pLayerName, uint32_t *pCount, |
| 1007 | VkExtensionProperties *pProperties) { |
| 1008 | assert(physicalDevice == VK_NULL_HANDLE); |
| 1009 | return unique_objects::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
| 1010 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1011 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1012 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance, |
| 1013 | const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1014 | return unique_objects::GetPhysicalDeviceProcAddr(instance, funcName); |
| 1015 | } |
| 1016 | |
| 1017 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) { |
| 1018 | assert(pVersionStruct != NULL); |
| 1019 | assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT); |
| 1020 | |
| 1021 | // Fill in the function pointers if our version is at least capable of having the structure contain them. |
| 1022 | if (pVersionStruct->loaderLayerInterfaceVersion >= 2) { |
| 1023 | pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr; |
| 1024 | pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr; |
| 1025 | pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr; |
| 1026 | } |
| 1027 | |
| 1028 | if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 1029 | unique_objects::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion; |
| 1030 | } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) { |
| 1031 | pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
| 1032 | } |
| 1033 | |
| 1034 | return VK_SUCCESS; |
| 1035 | } |