Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1 | /* |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 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. |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 6 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | * of this software and/or associated documentation files (the "Materials"), to |
| 9 | * deal in the Materials without restriction, including without limitation the |
| 10 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 11 | * sell copies of the Materials, and to permit persons to whom the Materials are |
| 12 | * furnished to do so, subject to the following conditions: |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 13 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 14 | * The above copyright notice(s) and this permission notice shall be included in |
| 15 | * all copies or substantial portions of the Materials. |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 16 | * |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 17 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * |
| 21 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 24 | * USE OR OTHER DEALINGS IN THE MATERIALS. |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 25 | * |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 26 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 27 | * Author: Jon Ashburn <jon@LunarG.com> |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 28 | * |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 29 | */ |
| 30 | |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 31 | #define _GNU_SOURCE |
Courtney Goeltzenleuchter | f1eb249 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 32 | #include <stdio.h> |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 33 | #include <string.h> |
| 34 | #include <stdlib.h> |
Courtney Goeltzenleuchter | f1eb249 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 35 | #include <inttypes.h> |
Tony Barbour | 6969851 | 2015-06-18 16:29:32 -0600 | [diff] [blame] | 36 | #ifndef WIN32 |
Courtney Goeltzenleuchter | c3c1f01 | 2015-07-22 11:01:53 -0600 | [diff] [blame] | 37 | #include <signal.h> |
| 38 | #else |
Tony Barbour | 6969851 | 2015-06-18 16:29:32 -0600 | [diff] [blame] | 39 | #endif |
Jon Ashburn | 6fb9a53 | 2015-08-28 14:58:46 -0700 | [diff] [blame] | 40 | #include "vk_loader_platform.h" |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 41 | #include "debug_report.h" |
David Pinedo | 329ca9e | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 42 | #include "vulkan/vk_layer.h" |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 43 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 44 | typedef void(VKAPI_PTR *PFN_stringCallback)(char *message); |
Courtney Goeltzenleuchter | f1eb249 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 45 | |
Jon Ashburn | c4748dc | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 46 | static const VkExtensionProperties debug_report_extension_info = { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 47 | .extensionName = VK_EXT_DEBUG_REPORT_EXTENSION_NAME, |
| 48 | .specVersion = VK_EXT_DEBUG_REPORT_SPEC_VERSION, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | void debug_report_add_instance_extensions( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 52 | const struct loader_instance *inst, |
| 53 | struct loader_extension_list *ext_list) { |
Jon Ashburn | e58f1a3 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 54 | loader_add_to_ext_list(inst, ext_list, 1, &debug_report_extension_info); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 55 | } |
| 56 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 57 | void debug_report_create_instance(struct loader_instance *ptr_instance, |
| 58 | const VkInstanceCreateInfo *pCreateInfo) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 59 | ptr_instance->debug_report_enabled = false; |
| 60 | |
Jon Ashburn | a4ae48b | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 61 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 62 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 63 | VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 64 | ptr_instance->debug_report_enabled = true; |
| 65 | return; |
| 66 | } |
| 67 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 68 | } |
| 69 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 70 | VkResult |
| 71 | util_CreateDebugReportCallback(struct loader_instance *inst, |
| 72 | VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 73 | const VkAllocationCallbacks *pAllocator, |
| 74 | VkDebugReportCallbackEXT callback) { |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 75 | VkLayerDbgFunctionNode *pNewDbgFuncNode; |
| 76 | if (pAllocator != NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 77 | pNewDbgFuncNode = (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation( |
| 78 | pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode), |
| 79 | sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 80 | } else { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 81 | pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_heap_alloc( |
| 82 | inst, sizeof(VkLayerDbgFunctionNode), |
| 83 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 84 | } |
| 85 | if (!pNewDbgFuncNode) |
| 86 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 87 | |
| 88 | pNewDbgFuncNode->msgCallback = callback; |
| 89 | pNewDbgFuncNode->pfnMsgCallback = pCreateInfo->pfnCallback; |
| 90 | pNewDbgFuncNode->msgFlags = pCreateInfo->flags; |
| 91 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
| 92 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
| 93 | inst->DbgFunctionHead = pNewDbgFuncNode; |
| 94 | |
| 95 | return VK_SUCCESS; |
| 96 | } |
| 97 | |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 98 | static VKAPI_ATTR VkResult VKAPI_CALL debug_report_CreateDebugReportCallback( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 99 | VkInstance instance, VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 100 | VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback) { |
Jon Ashburn | 0c5eea2 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 101 | struct loader_instance *inst = loader_get_instance(instance); |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 102 | loader_platform_thread_lock_mutex(&loader_lock); |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 103 | VkResult result = inst->disp->CreateDebugReportCallbackEXT( |
| 104 | instance, pCreateInfo, pAllocator, pCallback); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 105 | if (result == VK_SUCCESS) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 106 | result = util_CreateDebugReportCallback(inst, pCreateInfo, pAllocator, |
| 107 | *pCallback); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 108 | } |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 109 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 110 | return result; |
| 111 | } |
| 112 | |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 113 | // Utility function to handle reporting |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 114 | VkBool32 util_DebugReportMessage(const struct loader_instance *inst, |
| 115 | VkFlags msgFlags, |
| 116 | VkDebugReportObjectTypeEXT objectType, |
| 117 | uint64_t srcObject, size_t location, |
| 118 | int32_t msgCode, const char *pLayerPrefix, |
| 119 | const char *pMsg) { |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 120 | VkBool32 bail = false; |
| 121 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
| 122 | while (pTrav) { |
| 123 | if (pTrav->msgFlags & msgFlags) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 124 | if (pTrav->pfnMsgCallback(msgFlags, objectType, srcObject, location, |
| 125 | msgCode, pLayerPrefix, pMsg, |
| 126 | pTrav->pUserData)) { |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 127 | bail = true; |
| 128 | } |
| 129 | } |
| 130 | pTrav = pTrav->pNext; |
| 131 | } |
| 132 | |
| 133 | return bail; |
| 134 | } |
| 135 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 136 | void util_DestroyDebugReportCallback(struct loader_instance *inst, |
| 137 | VkDebugReportCallbackEXT callback, |
| 138 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 139 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
| 140 | VkLayerDbgFunctionNode *pPrev = pTrav; |
| 141 | |
| 142 | while (pTrav) { |
| 143 | if (pTrav->msgCallback == callback) { |
| 144 | pPrev->pNext = pTrav->pNext; |
| 145 | if (inst->DbgFunctionHead == pTrav) |
| 146 | inst->DbgFunctionHead = pTrav->pNext; |
| 147 | if (pAllocator != NULL) { |
| 148 | pAllocator->pfnFree(pAllocator->pUserData, pTrav); |
| 149 | } else { |
| 150 | loader_heap_free(inst, pTrav); |
| 151 | } |
| 152 | break; |
| 153 | } |
| 154 | pPrev = pTrav; |
| 155 | pTrav = pTrav->pNext; |
| 156 | } |
| 157 | } |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 158 | |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 159 | // This utility (used by vkInstanceCreateInfo(), looks at a pNext chain. It |
| 160 | // counts any VkDebugReportCallbackCreateInfoEXT structs that it finds. It |
| 161 | // then allocates array that can hold that many structs, as well as that many |
| 162 | // VkDebugReportCallbackEXT handles. It then copies each |
| 163 | // VkDebugReportCallbackCreateInfoEXT, and initializes each handle. |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 164 | VkResult util_CopyDebugReportCreateInfos( |
| 165 | const void *pChain, const VkAllocationCallbacks *pAllocator, |
| 166 | uint32_t *num_callbacks, VkDebugReportCallbackCreateInfoEXT **infos, |
| 167 | VkDebugReportCallbackEXT **callbacks) { |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 168 | uint32_t n = *num_callbacks = 0; |
| 169 | |
| 170 | // NOTE: The loader is not using pAllocator, and so this function doesn't |
| 171 | // either. |
| 172 | |
| 173 | const void *pNext = pChain; |
| 174 | while (pNext) { |
| 175 | // 1st, count the number VkDebugReportCallbackCreateInfoEXT: |
| 176 | if (((VkDebugReportCallbackCreateInfoEXT *)pNext)->sType == |
| 177 | VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
| 178 | n++; |
| 179 | } |
| 180 | pNext = (void *)((VkDebugReportCallbackCreateInfoEXT *)pNext)->pNext; |
| 181 | } |
| 182 | if (n == 0) { |
| 183 | return VK_SUCCESS; |
| 184 | } |
| 185 | |
| 186 | // 2nd, allocate memory for each VkDebugReportCallbackCreateInfoEXT: |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 187 | VkDebugReportCallbackCreateInfoEXT *pInfos = *infos = |
| 188 | ((VkDebugReportCallbackCreateInfoEXT *)malloc( |
| 189 | n * sizeof(VkDebugReportCallbackCreateInfoEXT))); |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 190 | if (!pInfos) { |
| 191 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 192 | } |
| 193 | // 3rd, allocate memory for a unique handle for each callback: |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 194 | VkDebugReportCallbackEXT *pCallbacks = *callbacks = |
| 195 | ((VkDebugReportCallbackEXT *)malloc(n * |
| 196 | sizeof(VkDebugReportCallbackEXT))); |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 197 | if (!pCallbacks) { |
| 198 | free(pInfos); |
| 199 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 200 | } |
| 201 | // 4th, copy each VkDebugReportCallbackCreateInfoEXT for use by |
| 202 | // vkDestroyInstance, and assign a unique handle to each callback (just |
| 203 | // use the address of the copied VkDebugReportCallbackCreateInfoEXT): |
| 204 | pNext = pChain; |
| 205 | while (pNext) { |
| 206 | if (((VkInstanceCreateInfo *)pNext)->sType == |
| 207 | VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 208 | memcpy(pInfos, pNext, sizeof(VkDebugReportCallbackCreateInfoEXT)); |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 209 | *pCallbacks++ = (VkDebugReportCallbackEXT)pInfos++; |
| 210 | } |
| 211 | pNext = (void *)((VkInstanceCreateInfo *)pNext)->pNext; |
| 212 | } |
| 213 | |
| 214 | *num_callbacks = n; |
| 215 | return VK_SUCCESS; |
| 216 | } |
| 217 | |
| 218 | void util_FreeDebugReportCreateInfos(const VkAllocationCallbacks *pAllocator, |
| 219 | VkDebugReportCallbackCreateInfoEXT *infos, |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 220 | VkDebugReportCallbackEXT *callbacks) { |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 221 | free(infos); |
| 222 | free(callbacks); |
| 223 | } |
| 224 | |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 225 | VkResult util_CreateDebugReportCallbacks( |
| 226 | struct loader_instance *inst, const VkAllocationCallbacks *pAllocator, |
| 227 | uint32_t num_callbacks, VkDebugReportCallbackCreateInfoEXT *infos, |
| 228 | VkDebugReportCallbackEXT *callbacks) { |
Jamie Madill | 1d5109d | 2016-04-04 15:09:51 -0400 | [diff] [blame] | 229 | VkResult rtn = VK_SUCCESS; |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 230 | for (uint32_t i = 0; i < num_callbacks; i++) { |
| 231 | rtn = util_CreateDebugReportCallback(inst, &infos[i], pAllocator, |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 232 | callbacks[i]); |
| 233 | if (rtn != VK_SUCCESS) { |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 234 | for (uint32_t j = 0; j < i; j++) { |
| 235 | util_DestroyDebugReportCallback(inst, callbacks[j], pAllocator); |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 236 | } |
| 237 | return rtn; |
| 238 | } |
| 239 | } |
| 240 | return rtn; |
| 241 | } |
| 242 | |
| 243 | void util_DestroyDebugReportCallbacks(struct loader_instance *inst, |
| 244 | const VkAllocationCallbacks *pAllocator, |
| 245 | uint32_t num_callbacks, |
Jon Ashburn | 9b2a8c9 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 246 | VkDebugReportCallbackEXT *callbacks) { |
| 247 | for (uint32_t i = 0; i < num_callbacks; i++) { |
| 248 | util_DestroyDebugReportCallback(inst, callbacks[i], pAllocator); |
Ian Elliott | 01b7832 | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 252 | static VKAPI_ATTR void VKAPI_CALL |
| 253 | debug_report_DestroyDebugReportCallback(VkInstance instance, |
| 254 | VkDebugReportCallbackEXT callback, |
| 255 | VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 0c5eea2 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 256 | struct loader_instance *inst = loader_get_instance(instance); |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 257 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 258 | |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 259 | inst->disp->DestroyDebugReportCallbackEXT(instance, callback, pAllocator); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 260 | |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 261 | util_DestroyDebugReportCallback(inst, callback, pAllocator); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 262 | |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 263 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 264 | } |
| 265 | |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 266 | static VKAPI_ATTR void VKAPI_CALL debug_report_DebugReportMessage( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 267 | VkInstance instance, VkDebugReportFlagsEXT flags, |
| 268 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 269 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 270 | struct loader_instance *inst = loader_get_instance(instance); |
| 271 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 272 | inst->disp->DebugReportMessageEXT(instance, flags, objType, object, |
| 273 | location, msgCode, pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 274 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 275 | |
| 276 | /* |
| 277 | * This is the instance chain terminator function |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 278 | * for CreateDebugReportCallback |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 279 | */ |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 280 | |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 281 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDebugReportCallback( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 282 | VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 283 | const VkAllocationCallbacks *pAllocator, |
| 284 | VkDebugReportCallbackEXT *pCallback) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 285 | VkDebugReportCallbackEXT *icd_info; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 286 | const struct loader_icd *icd; |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 287 | struct loader_instance *inst = (struct loader_instance *)instance; |
Karl Schultz | c50a598 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 288 | VkResult res = VK_SUCCESS; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 289 | uint32_t storage_idx; |
| 290 | |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 291 | icd_info = calloc(sizeof(VkDebugReportCallbackEXT), inst->total_icd_count); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 292 | if (!icd_info) { |
| 293 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 294 | } |
| 295 | |
| 296 | storage_idx = 0; |
| 297 | for (icd = inst->icds; icd; icd = icd->next) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 298 | if (!icd->CreateDebugReportCallbackEXT) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 299 | continue; |
| 300 | } |
| 301 | |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 302 | res = icd->CreateDebugReportCallbackEXT( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 303 | icd->instance, pCreateInfo, pAllocator, &icd_info[storage_idx]); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 304 | |
| 305 | if (res != VK_SUCCESS) { |
| 306 | break; |
| 307 | } |
| 308 | storage_idx++; |
| 309 | } |
| 310 | |
| 311 | /* roll back on errors */ |
| 312 | if (icd) { |
| 313 | storage_idx = 0; |
| 314 | for (icd = inst->icds; icd; icd = icd->next) { |
Chia-I Wu | e420a33 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 315 | if (icd_info[storage_idx]) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 316 | icd->DestroyDebugReportCallbackEXT( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 317 | icd->instance, icd_info[storage_idx], pAllocator); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 318 | } |
| 319 | storage_idx++; |
| 320 | } |
| 321 | |
| 322 | return res; |
| 323 | } |
| 324 | |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 325 | *(VkDebugReportCallbackEXT **)pCallback = icd_info; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 326 | |
| 327 | return VK_SUCCESS; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * This is the instance chain terminator function |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 332 | * for DestroyDebugReportCallback |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 333 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 334 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 335 | terminator_DestroyDebugReportCallback(VkInstance instance, |
| 336 | VkDebugReportCallbackEXT callback, |
| 337 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 338 | uint32_t storage_idx; |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 339 | VkDebugReportCallbackEXT *icd_info; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 340 | const struct loader_icd *icd; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 341 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 342 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 343 | icd_info = *(VkDebugReportCallbackEXT **)&callback; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 344 | storage_idx = 0; |
| 345 | for (icd = inst->icds; icd; icd = icd->next) { |
Chia-I Wu | e420a33 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 346 | if (icd_info[storage_idx]) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 347 | icd->DestroyDebugReportCallbackEXT( |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 348 | icd->instance, icd_info[storage_idx], pAllocator); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 349 | } |
| 350 | storage_idx++; |
| 351 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 352 | } |
| 353 | |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 354 | /* |
| 355 | * This is the instance chain terminator function |
| 356 | * for DebugReportMessage |
| 357 | */ |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 358 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | a9c4a57 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 359 | terminator_DebugReportMessage(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 360 | VkDebugReportObjectTypeEXT objType, |
| 361 | uint64_t object, size_t location, int32_t msgCode, |
| 362 | const char *pLayerPrefix, const char *pMsg) { |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 363 | const struct loader_icd *icd; |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 364 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 365 | struct loader_instance *inst = (struct loader_instance *)instance; |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 366 | |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 367 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 368 | for (icd = inst->icds; icd; icd = icd->next) { |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 369 | if (icd->DebugReportMessageEXT != NULL) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 370 | icd->DebugReportMessageEXT(icd->instance, flags, objType, object, |
| 371 | location, msgCode, pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | * Now that all ICDs have seen the message, call the necessary callbacks. |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 377 | * Ignoring "bail" return value as there is nothing to bail from at this |
| 378 | * point. |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 379 | */ |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 380 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 381 | util_DebugReportMessage(inst, flags, objType, object, location, msgCode, |
| 382 | pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 15436c1 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 383 | |
| 384 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 387 | bool debug_report_instance_gpa(struct loader_instance *ptr_instance, |
| 388 | const char *name, void **addr) { |
Jon Ashburn | 9945600 | 2015-11-06 11:02:40 -0700 | [diff] [blame] | 389 | // debug_report is currently advertised to be supported by the loader, |
| 390 | // so always return the entry points if name matches and it's enabled |
Jon Ashburn | 05b4ec6 | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 391 | *addr = NULL; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 392 | |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 393 | if (!strcmp("vkCreateDebugReportCallbackEXT", name)) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 394 | *addr = ptr_instance->debug_report_enabled |
| 395 | ? (void *)debug_report_CreateDebugReportCallback |
| 396 | : NULL; |
Jon Ashburn | 05b4ec6 | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 397 | return true; |
| 398 | } |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 399 | if (!strcmp("vkDestroyDebugReportCallbackEXT", name)) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 400 | *addr = ptr_instance->debug_report_enabled |
| 401 | ? (void *)debug_report_DestroyDebugReportCallback |
| 402 | : NULL; |
Jon Ashburn | 05b4ec6 | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 403 | return true; |
| 404 | } |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 405 | if (!strcmp("vkDebugReportMessageEXT", name)) { |
Jon Ashburn | 44aed66 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 406 | *addr = ptr_instance->debug_report_enabled |
| 407 | ? (void *)debug_report_DebugReportMessage |
| 408 | : NULL; |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 409 | return true; |
| 410 | } |
Jon Ashburn | 05b4ec6 | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 411 | return false; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 412 | } |