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