Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Vulkan |
| 3 | * |
| 4 | * Copyright (C) 2015 Valve, Inc. |
| 5 | * Copyright (C) 2016 Google, Inc. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
| 24 | */ |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <unordered_map> |
| 29 | #include <list> |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 30 | |
Dustin Graves | 899960f | 2016-02-05 15:53:12 -0700 | [diff] [blame] | 31 | #include "vk_loader_platform.h" |
Mike Stroyan | 3409fcd | 2016-01-29 15:11:28 -0700 | [diff] [blame] | 32 | #include "vulkan/vk_layer.h" |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 33 | #include "vk_layer_config.h" |
| 34 | #include "vk_layer_extension_utils.h" |
| 35 | #include "vk_layer_utils.h" |
| 36 | #include "vk_enum_validate_helper.h" |
| 37 | #include "vk_struct_validate_helper.h" |
| 38 | #include "vk_layer_table.h" |
| 39 | #include "vk_layer_logging.h" |
| 40 | #include "threading.h" |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 41 | #include "vk_dispatch_table_helper.h" |
| 42 | #include "vk_struct_string_helper_cpp.h" |
| 43 | #include "vk_layer_data.h" |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 44 | #include "vk_layer_utils.h" |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 45 | |
| 46 | #include "thread_check.h" |
| 47 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 48 | static void initThreading(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 49 | |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 50 | layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "google_threading"); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 51 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 52 | if (!threadingLockInitialized) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 53 | loader_platform_thread_create_mutex(&threadingLock); |
| 54 | loader_platform_thread_init_cond(&threadingCond); |
| 55 | threadingLockInitialized = 1; |
| 56 | } |
| 57 | } |
| 58 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 59 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 60 | vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 61 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 62 | |
| 63 | assert(chain_info->u.pLayerInfo); |
| 64 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 65 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 66 | if (fpCreateInstance == NULL) { |
| 67 | return VK_ERROR_INITIALIZATION_FAILED; |
| 68 | } |
| 69 | |
| 70 | // Advance the link info for the next element on the chain |
| 71 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 72 | |
| 73 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 74 | if (result != VK_SUCCESS) |
| 75 | return result; |
| 76 | |
| 77 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 78 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
| 79 | layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); |
| 80 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 81 | my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance, |
| 82 | pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 83 | initThreading(my_data, pAllocator); |
| 84 | return result; |
| 85 | } |
| 86 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 87 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 88 | dispatch_key key = get_dispatch_key(instance); |
| 89 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 90 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Mike Stroyan | a7bf328 | 2016-02-04 16:39:53 -0700 | [diff] [blame] | 91 | startWriteObject(my_data, instance); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 92 | pTable->DestroyInstance(instance, pAllocator); |
Mike Stroyan | a7bf328 | 2016-02-04 16:39:53 -0700 | [diff] [blame] | 93 | finishWriteObject(my_data, instance); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 94 | |
| 95 | // Clean up logging callback, if any |
| 96 | while (my_data->logging_callback.size() > 0) { |
| 97 | VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); |
| 98 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
| 99 | my_data->logging_callback.pop_back(); |
| 100 | } |
| 101 | |
| 102 | layer_debug_report_destroy_instance(my_data->report_data); |
| 103 | delete my_data->instance_dispatch_table; |
| 104 | layer_data_map.erase(key); |
| 105 | |
| 106 | if (layer_data_map.empty()) { |
| 107 | // Release mutex when destroying last instance. |
| 108 | loader_platform_thread_delete_mutex(&threadingLock); |
| 109 | threadingLockInitialized = 0; |
| 110 | } |
| 111 | } |
| 112 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 113 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 114 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 115 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| 116 | |
| 117 | assert(chain_info->u.pLayerInfo); |
| 118 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 119 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 120 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice"); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 121 | if (fpCreateDevice == NULL) { |
| 122 | return VK_ERROR_INITIALIZATION_FAILED; |
| 123 | } |
| 124 | |
| 125 | // Advance the link info for the next element on the chain |
| 126 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 127 | |
| 128 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| 129 | if (result != VK_SUCCESS) { |
| 130 | return result; |
| 131 | } |
| 132 | |
| 133 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
| 134 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 135 | |
| 136 | // Setup device dispatch table |
| 137 | my_device_data->device_dispatch_table = new VkLayerDispatchTable; |
| 138 | layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); |
| 139 | |
| 140 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
| 141 | return result; |
| 142 | } |
| 143 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 144 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 145 | dispatch_key key = get_dispatch_key(device); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 146 | layer_data *dev_data = get_my_data_ptr(key, layer_data_map); |
Mike Stroyan | a7bf328 | 2016-02-04 16:39:53 -0700 | [diff] [blame] | 147 | startWriteObject(dev_data, device); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 148 | dev_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
Mike Stroyan | a7bf328 | 2016-02-04 16:39:53 -0700 | [diff] [blame] | 149 | finishWriteObject(dev_data, device); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 150 | layer_data_map.erase(key); |
| 151 | } |
| 152 | |
Courtney Goeltzenleuchter | f3d3970 | 2016-02-12 13:30:20 -0700 | [diff] [blame] | 153 | static const VkExtensionProperties threading_extensions[] = { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 154 | {VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}}; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 155 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 156 | VK_LAYER_EXPORT VkResult VKAPI_CALL |
| 157 | vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) { |
Courtney Goeltzenleuchter | f3d3970 | 2016-02-12 13:30:20 -0700 | [diff] [blame] | 158 | return util_GetExtensionProperties(ARRAY_SIZE(threading_extensions), threading_extensions, pCount, pProperties); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 161 | static const VkLayerProperties globalLayerProps[] = {{ |
| 162 | "VK_LAYER_GOOGLE_threading", |
Jon Ashburn | dc9111c | 2016-03-22 12:57:13 -0600 | [diff] [blame] | 163 | VK_LAYER_API_VERSION, // specVersion |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 164 | 1, "Google Validation Layer", |
| 165 | }}; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 166 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 167 | VK_LAYER_EXPORT VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 168 | return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties); |
| 169 | } |
| 170 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 171 | static const VkLayerProperties deviceLayerProps[] = {{ |
| 172 | "VK_LAYER_GOOGLE_threading", |
Jon Ashburn | dc9111c | 2016-03-22 12:57:13 -0600 | [diff] [blame] | 173 | VK_LAYER_API_VERSION, // specVersion |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 174 | 1, "Google Validation Layer", |
| 175 | }}; |
Courtney Goeltzenleuchter | a4784fb | 2016-02-12 13:22:04 -0700 | [diff] [blame] | 176 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 177 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 178 | const char *pLayerName, uint32_t *pCount, |
| 179 | VkExtensionProperties *pProperties) { |
Courtney Goeltzenleuchter | f3d3970 | 2016-02-12 13:30:20 -0700 | [diff] [blame] | 180 | if (pLayerName == NULL) { |
| 181 | dispatch_key key = get_dispatch_key(physicalDevice); |
| 182 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 183 | return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
Courtney Goeltzenleuchter | f3d3970 | 2016-02-12 13:30:20 -0700 | [diff] [blame] | 184 | } else { |
| 185 | // Threading layer does not have any device extensions |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 186 | return util_GetExtensionProperties(0, nullptr, pCount, pProperties); |
Courtney Goeltzenleuchter | f3d3970 | 2016-02-12 13:30:20 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 190 | VK_LAYER_EXPORT VkResult VKAPI_CALL |
| 191 | vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 192 | return util_GetLayerProperties(ARRAY_SIZE(deviceLayerProps), deviceLayerProps, pCount, pProperties); |
| 193 | } |
| 194 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 195 | static inline PFN_vkVoidFunction layer_intercept_proc(const char *name) { |
| 196 | for (int i = 0; i < sizeof(procmap) / sizeof(procmap[0]); i++) { |
| 197 | if (!strcmp(name, procmap[i].name)) |
| 198 | return procmap[i].pFunc; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 199 | } |
| 200 | return NULL; |
| 201 | } |
| 202 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 203 | static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 204 | if (!name || name[0] != 'v' || name[1] != 'k') |
| 205 | return NULL; |
| 206 | |
| 207 | name += 2; |
| 208 | if (!strcmp(name, "CreateInstance")) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 209 | return (PFN_vkVoidFunction)vkCreateInstance; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 210 | if (!strcmp(name, "DestroyInstance")) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 211 | return (PFN_vkVoidFunction)vkDestroyInstance; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 212 | if (!strcmp(name, "EnumerateInstanceExtensionProperties")) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 213 | return (PFN_vkVoidFunction)vkEnumerateInstanceExtensionProperties; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 214 | if (!strcmp(name, "EnumerateInstanceLayerProperties")) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 215 | return (PFN_vkVoidFunction)vkEnumerateInstanceLayerProperties; |
Courtney Goeltzenleuchter | f3d3970 | 2016-02-12 13:30:20 -0700 | [diff] [blame] | 216 | if (!strcmp(name, "EnumerateDeviceExtensionProperties")) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 217 | return (PFN_vkVoidFunction)vkEnumerateDeviceExtensionProperties; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 218 | if (!strcmp(name, "EnumerateDeviceLayerProperties")) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 219 | return (PFN_vkVoidFunction)vkEnumerateDeviceLayerProperties; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 220 | if (!strcmp(name, "CreateDevice")) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 221 | return (PFN_vkVoidFunction)vkCreateDevice; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 222 | if (!strcmp(name, "GetInstanceProcAddr")) |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 223 | return (PFN_vkVoidFunction)vkGetInstanceProcAddr; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 224 | |
| 225 | return NULL; |
| 226 | } |
| 227 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 228 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 229 | PFN_vkVoidFunction addr; |
| 230 | layer_data *dev_data; |
| 231 | if (device == VK_NULL_HANDLE) { |
| 232 | return NULL; |
| 233 | } |
| 234 | |
| 235 | addr = layer_intercept_proc(funcName); |
| 236 | if (addr) |
| 237 | return addr; |
| 238 | |
| 239 | dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 240 | VkLayerDispatchTable *pTable = dev_data->device_dispatch_table; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 241 | |
| 242 | if (pTable->GetDeviceProcAddr == NULL) |
| 243 | return NULL; |
| 244 | return pTable->GetDeviceProcAddr(device, funcName); |
| 245 | } |
| 246 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 247 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 248 | PFN_vkVoidFunction addr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 249 | layer_data *my_data; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 250 | |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 251 | addr = layer_intercept_instance_proc(funcName); |
| 252 | if (addr) { |
| 253 | return addr; |
| 254 | } |
| 255 | |
Karl Schultz | 929f879 | 2016-02-07 15:17:26 -0700 | [diff] [blame] | 256 | if (instance == VK_NULL_HANDLE) { |
| 257 | return NULL; |
| 258 | } |
| 259 | |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 260 | my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 261 | addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
| 262 | if (addr) { |
| 263 | return addr; |
| 264 | } |
| 265 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 266 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 267 | if (pTable->GetInstanceProcAddr == NULL) { |
| 268 | return NULL; |
| 269 | } |
| 270 | return pTable->GetInstanceProcAddr(instance, funcName); |
| 271 | } |
| 272 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 273 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 274 | vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 275 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 276 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 277 | startReadObject(my_data, instance); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 278 | VkResult result = |
| 279 | my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 280 | if (VK_SUCCESS == result) { |
| 281 | result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback); |
| 282 | } |
| 283 | finishReadObject(my_data, instance); |
| 284 | return result; |
| 285 | } |
| 286 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 287 | VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL |
| 288 | vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks *pAllocator) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 289 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 290 | startReadObject(my_data, instance); |
| 291 | startWriteObject(my_data, callback); |
| 292 | my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, callback, pAllocator); |
| 293 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
| 294 | finishReadObject(my_data, instance); |
| 295 | finishWriteObject(my_data, callback); |
| 296 | } |
| 297 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 298 | VkResult VKAPI_CALL |
| 299 | vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 300 | dispatch_key key = get_dispatch_key(device); |
| 301 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 302 | VkLayerDispatchTable *pTable = my_data->device_dispatch_table; |
| 303 | VkResult result; |
| 304 | startReadObject(my_data, device); |
| 305 | startWriteObject(my_data, pAllocateInfo->commandPool); |
| 306 | |
| 307 | result = pTable->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers); |
| 308 | finishReadObject(my_data, device); |
| 309 | finishWriteObject(my_data, pAllocateInfo->commandPool); |
| 310 | |
| 311 | // Record mapping from command buffer to command pool |
| 312 | if (VK_SUCCESS == result) { |
Michael Mc Donnell | 75ecdb7 | 2016-04-03 14:47:51 -0700 | [diff] [blame] | 313 | for (uint32_t index = 0; index < pAllocateInfo->commandBufferCount; index++) { |
Mike Stroyan | ae8e8a7 | 2016-02-08 10:27:55 -0700 | [diff] [blame] | 314 | loader_platform_thread_lock_mutex(&threadingLock); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 315 | command_pool_map[pCommandBuffers[index]] = pAllocateInfo->commandPool; |
Mike Stroyan | ae8e8a7 | 2016-02-08 10:27:55 -0700 | [diff] [blame] | 316 | loader_platform_thread_unlock_mutex(&threadingLock); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | return result; |
| 321 | } |
| 322 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 323 | void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, |
| 324 | const VkCommandBuffer *pCommandBuffers) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 325 | dispatch_key key = get_dispatch_key(device); |
| 326 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 327 | VkLayerDispatchTable *pTable = my_data->device_dispatch_table; |
| 328 | const bool lockCommandPool = false; // pool is already directly locked |
| 329 | startReadObject(my_data, device); |
| 330 | startWriteObject(my_data, commandPool); |
Michael Mc Donnell | 75ecdb7 | 2016-04-03 14:47:51 -0700 | [diff] [blame] | 331 | for (uint32_t index = 0; index < commandBufferCount; index++) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 332 | startWriteObject(my_data, pCommandBuffers[index], lockCommandPool); |
| 333 | } |
| 334 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 335 | pTable->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 336 | finishReadObject(my_data, device); |
| 337 | finishWriteObject(my_data, commandPool); |
Michael Mc Donnell | 75ecdb7 | 2016-04-03 14:47:51 -0700 | [diff] [blame] | 338 | for (uint32_t index = 0; index < commandBufferCount; index++) { |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 339 | finishWriteObject(my_data, pCommandBuffers[index], lockCommandPool); |
Mike Stroyan | ae8e8a7 | 2016-02-08 10:27:55 -0700 | [diff] [blame] | 340 | loader_platform_thread_lock_mutex(&threadingLock); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 341 | command_pool_map.erase(pCommandBuffers[index]); |
Mike Stroyan | ae8e8a7 | 2016-02-08 10:27:55 -0700 | [diff] [blame] | 342 | loader_platform_thread_unlock_mutex(&threadingLock); |
Mike Stroyan | 845bdc4 | 2015-11-02 15:30:20 -0700 | [diff] [blame] | 343 | } |
| 344 | } |