Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1 | /* |
Jon Ashburn | 23d36b1 | 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 | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 6 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 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 |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 10 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 12 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 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. |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 18 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 19 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 20 | * Author: Jon Ashburn <jon@LunarG.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 21 | * |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 22 | */ |
| 23 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 24 | #define _GNU_SOURCE |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 25 | #include <stdio.h> |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 28 | #include <inttypes.h> |
Tony Barbour | 1d825c7 | 2015-06-18 16:29:32 -0600 | [diff] [blame] | 29 | #ifndef WIN32 |
Courtney Goeltzenleuchter | 03663d0 | 2015-07-22 11:01:53 -0600 | [diff] [blame] | 30 | #include <signal.h> |
| 31 | #else |
Tony Barbour | 1d825c7 | 2015-06-18 16:29:32 -0600 | [diff] [blame] | 32 | #endif |
Jon Ashburn | 480a50a | 2015-08-28 14:58:46 -0700 | [diff] [blame] | 33 | #include "vk_loader_platform.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 34 | #include "debug_report.h" |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 35 | #include "vulkan/vk_layer.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 36 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 37 | typedef void(VKAPI_PTR *PFN_stringCallback)(char *message); |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 38 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 39 | static const VkExtensionProperties debug_report_extension_info = { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 40 | .extensionName = VK_EXT_DEBUG_REPORT_EXTENSION_NAME, |
| 41 | .specVersion = VK_EXT_DEBUG_REPORT_SPEC_VERSION, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | void debug_report_add_instance_extensions( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 45 | const struct loader_instance *inst, |
| 46 | struct loader_extension_list *ext_list) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 47 | loader_add_to_ext_list(inst, ext_list, 1, &debug_report_extension_info); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 48 | } |
| 49 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 50 | void debug_report_create_instance(struct loader_instance *ptr_instance, |
| 51 | const VkInstanceCreateInfo *pCreateInfo) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 52 | ptr_instance->enabled_known_extensions.ext_debug_report = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 53 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 54 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 55 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 56 | VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 57 | ptr_instance->enabled_known_extensions.ext_debug_report = 1; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 58 | return; |
| 59 | } |
| 60 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 61 | } |
| 62 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 63 | VkResult |
| 64 | util_CreateDebugReportCallback(struct loader_instance *inst, |
| 65 | VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 66 | const VkAllocationCallbacks *pAllocator, |
| 67 | VkDebugReportCallbackEXT callback) { |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 68 | VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL; |
| 69 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 70 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 71 | { |
| 72 | #else |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 73 | if (pAllocator != NULL) { |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 74 | pNewDbgFuncNode = |
| 75 | (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation( |
| 76 | pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode), |
| 77 | sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 78 | } else { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 79 | #endif |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 80 | pNewDbgFuncNode = |
| 81 | (VkLayerDbgFunctionNode *)loader_instance_heap_alloc( |
| 82 | inst, sizeof(VkLayerDbgFunctionNode), |
| 83 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 84 | } |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 85 | if (!pNewDbgFuncNode) { |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 86 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 87 | } |
| 88 | memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode)); |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 89 | |
| 90 | pNewDbgFuncNode->msgCallback = callback; |
| 91 | pNewDbgFuncNode->pfnMsgCallback = pCreateInfo->pfnCallback; |
| 92 | pNewDbgFuncNode->msgFlags = pCreateInfo->flags; |
| 93 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
| 94 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
| 95 | inst->DbgFunctionHead = pNewDbgFuncNode; |
| 96 | |
| 97 | return VK_SUCCESS; |
| 98 | } |
| 99 | |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 100 | static VKAPI_ATTR VkResult VKAPI_CALL debug_report_CreateDebugReportCallbackEXT( |
| 101 | VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 102 | const VkAllocationCallbacks *pAllocator, |
| 103 | VkDebugReportCallbackEXT *pCallback) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 104 | struct loader_instance *inst = loader_get_instance(instance); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 105 | loader_platform_thread_lock_mutex(&loader_lock); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 106 | VkResult result = inst->disp->CreateDebugReportCallbackEXT( |
| 107 | instance, pCreateInfo, pAllocator, pCallback); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 108 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 109 | return result; |
| 110 | } |
| 111 | |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 112 | // Utility function to handle reporting |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 113 | VkBool32 util_DebugReportMessage(const struct loader_instance *inst, |
| 114 | VkFlags msgFlags, |
| 115 | VkDebugReportObjectTypeEXT objectType, |
| 116 | uint64_t srcObject, size_t location, |
| 117 | int32_t msgCode, const char *pLayerPrefix, |
| 118 | const char *pMsg) { |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 119 | VkBool32 bail = false; |
| 120 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
| 121 | while (pTrav) { |
| 122 | if (pTrav->msgFlags & msgFlags) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 123 | if (pTrav->pfnMsgCallback(msgFlags, objectType, srcObject, location, |
| 124 | msgCode, pLayerPrefix, pMsg, |
| 125 | pTrav->pUserData)) { |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 126 | bail = true; |
| 127 | } |
| 128 | } |
| 129 | pTrav = pTrav->pNext; |
| 130 | } |
| 131 | |
| 132 | return bail; |
| 133 | } |
| 134 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 135 | void util_DestroyDebugReportCallback(struct loader_instance *inst, |
| 136 | VkDebugReportCallbackEXT callback, |
| 137 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 138 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
| 139 | VkLayerDbgFunctionNode *pPrev = pTrav; |
| 140 | |
| 141 | while (pTrav) { |
| 142 | if (pTrav->msgCallback == callback) { |
| 143 | pPrev->pNext = pTrav->pNext; |
| 144 | if (inst->DbgFunctionHead == pTrav) |
| 145 | inst->DbgFunctionHead = pTrav->pNext; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 146 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 147 | { |
| 148 | #else |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 149 | if (pAllocator != NULL) { |
| 150 | pAllocator->pfnFree(pAllocator->pUserData, pTrav); |
| 151 | } else { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 152 | #endif |
| 153 | loader_instance_heap_free(inst, pTrav); |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 154 | } |
| 155 | break; |
| 156 | } |
| 157 | pPrev = pTrav; |
| 158 | pTrav = pTrav->pNext; |
| 159 | } |
| 160 | } |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 161 | |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 162 | // This utility (used by vkInstanceCreateInfo(), looks at a pNext chain. It |
| 163 | // counts any VkDebugReportCallbackCreateInfoEXT structs that it finds. It |
| 164 | // then allocates array that can hold that many structs, as well as that many |
| 165 | // VkDebugReportCallbackEXT handles. It then copies each |
| 166 | // VkDebugReportCallbackCreateInfoEXT, and initializes each handle. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 167 | VkResult util_CopyDebugReportCreateInfos( |
| 168 | const void *pChain, const VkAllocationCallbacks *pAllocator, |
| 169 | uint32_t *num_callbacks, VkDebugReportCallbackCreateInfoEXT **infos, |
| 170 | VkDebugReportCallbackEXT **callbacks) { |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 171 | uint32_t n = *num_callbacks = 0; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 172 | VkDebugReportCallbackCreateInfoEXT *pInfos = NULL; |
| 173 | VkDebugReportCallbackEXT *pCallbacks = NULL; |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 174 | |
| 175 | // NOTE: The loader is not using pAllocator, and so this function doesn't |
| 176 | // either. |
| 177 | |
| 178 | const void *pNext = pChain; |
| 179 | while (pNext) { |
| 180 | // 1st, count the number VkDebugReportCallbackCreateInfoEXT: |
| 181 | if (((VkDebugReportCallbackCreateInfoEXT *)pNext)->sType == |
| 182 | VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
| 183 | n++; |
| 184 | } |
| 185 | pNext = (void *)((VkDebugReportCallbackCreateInfoEXT *)pNext)->pNext; |
| 186 | } |
| 187 | if (n == 0) { |
| 188 | return VK_SUCCESS; |
| 189 | } |
| 190 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 191 | // 2nd, allocate memory for each VkDebugReportCallbackCreateInfoEXT: |
| 192 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 193 | { |
| 194 | #else |
| 195 | if (pAllocator != NULL) { |
| 196 | pInfos = *infos = |
| 197 | ((VkDebugReportCallbackCreateInfoEXT *)pAllocator->pfnAllocation( |
| 198 | pAllocator->pUserData, |
| 199 | n * sizeof(VkDebugReportCallbackCreateInfoEXT), sizeof(void *), |
| 200 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)); |
| 201 | } else { |
| 202 | #endif |
| 203 | pInfos = *infos = ((VkDebugReportCallbackCreateInfoEXT *)malloc( |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 204 | n * sizeof(VkDebugReportCallbackCreateInfoEXT))); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 205 | } |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 206 | if (!pInfos) { |
| 207 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 208 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 209 | // 3rd, allocate memory for a unique handle for each callback: |
| 210 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 211 | { |
| 212 | #else |
| 213 | if (pAllocator != NULL) { |
| 214 | pCallbacks = *callbacks = |
| 215 | ((VkDebugReportCallbackEXT *)pAllocator->pfnAllocation( |
| 216 | pAllocator->pUserData, n * sizeof(VkDebugReportCallbackEXT), |
| 217 | sizeof(void *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)); |
| 218 | } else { |
| 219 | #endif |
| 220 | pCallbacks = *callbacks = ((VkDebugReportCallbackEXT *)malloc( |
| 221 | n * sizeof(VkDebugReportCallbackEXT))); |
| 222 | } |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 223 | if (!pCallbacks) { |
| 224 | free(pInfos); |
| 225 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 226 | } |
| 227 | // 4th, copy each VkDebugReportCallbackCreateInfoEXT for use by |
| 228 | // vkDestroyInstance, and assign a unique handle to each callback (just |
| 229 | // use the address of the copied VkDebugReportCallbackCreateInfoEXT): |
| 230 | pNext = pChain; |
| 231 | while (pNext) { |
| 232 | if (((VkInstanceCreateInfo *)pNext)->sType == |
| 233 | VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 234 | memcpy(pInfos, pNext, sizeof(VkDebugReportCallbackCreateInfoEXT)); |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 235 | *pCallbacks++ = (VkDebugReportCallbackEXT)pInfos++; |
| 236 | } |
| 237 | pNext = (void *)((VkInstanceCreateInfo *)pNext)->pNext; |
| 238 | } |
| 239 | |
| 240 | *num_callbacks = n; |
| 241 | return VK_SUCCESS; |
| 242 | } |
| 243 | |
| 244 | void util_FreeDebugReportCreateInfos(const VkAllocationCallbacks *pAllocator, |
| 245 | VkDebugReportCallbackCreateInfoEXT *infos, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 246 | VkDebugReportCallbackEXT *callbacks) { |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 247 | free(infos); |
| 248 | free(callbacks); |
| 249 | } |
| 250 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 251 | VkResult util_CreateDebugReportCallbacks( |
| 252 | struct loader_instance *inst, const VkAllocationCallbacks *pAllocator, |
| 253 | uint32_t num_callbacks, VkDebugReportCallbackCreateInfoEXT *infos, |
| 254 | VkDebugReportCallbackEXT *callbacks) { |
Jamie Madill | 2b6b8d5 | 2016-04-04 15:09:51 -0400 | [diff] [blame] | 255 | VkResult rtn = VK_SUCCESS; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 256 | for (uint32_t i = 0; i < num_callbacks; i++) { |
| 257 | rtn = util_CreateDebugReportCallback(inst, &infos[i], pAllocator, |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 258 | callbacks[i]); |
| 259 | if (rtn != VK_SUCCESS) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 260 | for (uint32_t j = 0; j < i; j++) { |
| 261 | util_DestroyDebugReportCallback(inst, callbacks[j], pAllocator); |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 262 | } |
| 263 | return rtn; |
| 264 | } |
| 265 | } |
| 266 | return rtn; |
| 267 | } |
| 268 | |
| 269 | void util_DestroyDebugReportCallbacks(struct loader_instance *inst, |
| 270 | const VkAllocationCallbacks *pAllocator, |
| 271 | uint32_t num_callbacks, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 272 | VkDebugReportCallbackEXT *callbacks) { |
| 273 | for (uint32_t i = 0; i < num_callbacks; i++) { |
| 274 | util_DestroyDebugReportCallback(inst, callbacks[i], pAllocator); |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 278 | static VKAPI_ATTR void VKAPI_CALL |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 279 | debug_report_DestroyDebugReportCallbackEXT( |
| 280 | VkInstance instance, VkDebugReportCallbackEXT callback, |
| 281 | const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 282 | struct loader_instance *inst = loader_get_instance(instance); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 283 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 284 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 285 | inst->disp->DestroyDebugReportCallbackEXT(instance, callback, pAllocator); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 286 | |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 287 | util_DestroyDebugReportCallback(inst, callback, pAllocator); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 288 | |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 289 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 290 | } |
| 291 | |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 292 | static VKAPI_ATTR void VKAPI_CALL debug_report_DebugReportMessageEXT( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 293 | VkInstance instance, VkDebugReportFlagsEXT flags, |
| 294 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 295 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 296 | struct loader_instance *inst = loader_get_instance(instance); |
| 297 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 298 | inst->disp->DebugReportMessageEXT(instance, flags, objType, object, |
| 299 | location, msgCode, pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 300 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * This is the instance chain terminator function |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 304 | * for CreateDebugReportCallback |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 305 | */ |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 306 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 307 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDebugReportCallback( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 308 | VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 309 | const VkAllocationCallbacks *pAllocator, |
| 310 | VkDebugReportCallbackEXT *pCallback) { |
Mark Young | 9b0636f | 2016-10-13 10:51:14 -0600 | [diff] [blame] | 311 | VkDebugReportCallbackEXT *icd_info = NULL; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 312 | const struct loader_icd *icd; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 313 | struct loader_instance *inst = (struct loader_instance *)instance; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 314 | VkResult res = VK_SUCCESS; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 315 | uint32_t storage_idx; |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 316 | VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 317 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 318 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 319 | { |
| 320 | #else |
| 321 | if (pAllocator != NULL) { |
| 322 | icd_info = ((VkDebugReportCallbackEXT *)pAllocator->pfnAllocation( |
| 323 | pAllocator->pUserData, |
| 324 | inst->total_icd_count * sizeof(VkDebugReportCallbackEXT), |
| 325 | sizeof(void *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)); |
| 326 | memset(icd_info, 0, |
| 327 | inst->total_icd_count * sizeof(VkDebugReportCallbackEXT)); |
| 328 | } else { |
| 329 | #endif |
| 330 | icd_info = |
| 331 | calloc(sizeof(VkDebugReportCallbackEXT), inst->total_icd_count); |
| 332 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 333 | if (!icd_info) { |
Mark Young | 9b0636f | 2016-10-13 10:51:14 -0600 | [diff] [blame] | 334 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 335 | goto out; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | storage_idx = 0; |
| 339 | for (icd = inst->icds; icd; icd = icd->next) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 340 | if (!icd->CreateDebugReportCallbackEXT) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 341 | continue; |
| 342 | } |
| 343 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 344 | res = icd->CreateDebugReportCallbackEXT( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 345 | icd->instance, pCreateInfo, pAllocator, &icd_info[storage_idx]); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 346 | |
| 347 | if (res != VK_SUCCESS) { |
Mark Young | 9b0636f | 2016-10-13 10:51:14 -0600 | [diff] [blame] | 348 | goto out; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 349 | } |
| 350 | storage_idx++; |
| 351 | } |
| 352 | |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 353 | // Setup the debug report callback in the terminator since a layer may want |
| 354 | // to grab the information itself (RenderDoc) and then return back to the |
| 355 | // user callback a sub-set of the messages. |
| 356 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 0) |
| 357 | if (pAllocator != NULL) { |
| 358 | pNewDbgFuncNode = |
| 359 | (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation( |
| 360 | pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode), |
| 361 | sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
| 362 | } else { |
| 363 | #else |
| 364 | { |
| 365 | #endif |
| 366 | pNewDbgFuncNode = |
| 367 | (VkLayerDbgFunctionNode *)loader_instance_heap_alloc( |
| 368 | inst, sizeof(VkLayerDbgFunctionNode), |
| 369 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
| 370 | } |
| 371 | if (!pNewDbgFuncNode) { |
Mark Young | 9b0636f | 2016-10-13 10:51:14 -0600 | [diff] [blame] | 372 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 373 | goto out; |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 374 | } |
| 375 | memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode)); |
| 376 | |
Mark Young | 7e4da97 | 2016-08-25 14:54:58 -0600 | [diff] [blame] | 377 | pNewDbgFuncNode->pfnMsgCallback = pCreateInfo->pfnCallback; |
| 378 | pNewDbgFuncNode->msgFlags = pCreateInfo->flags; |
| 379 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
| 380 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
| 381 | inst->DbgFunctionHead = pNewDbgFuncNode; |
| 382 | |
Mark Young | 9b0636f | 2016-10-13 10:51:14 -0600 | [diff] [blame] | 383 | *(VkDebugReportCallbackEXT **)pCallback = icd_info; |
| 384 | pNewDbgFuncNode->msgCallback = *pCallback; |
| 385 | |
| 386 | out: |
| 387 | |
| 388 | // Roll back on errors |
Mark Young | d82497d | 2016-10-14 14:18:56 -0600 | [diff] [blame] | 389 | if (VK_SUCCESS != res) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 390 | storage_idx = 0; |
| 391 | for (icd = inst->icds; icd; icd = icd->next) { |
Mark Young | a26d47c | 2016-05-04 16:44:10 -0600 | [diff] [blame] | 392 | if (NULL == icd->DestroyDebugReportCallbackEXT) { |
| 393 | continue; |
| 394 | } |
| 395 | |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 396 | if (icd_info[storage_idx]) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 397 | icd->DestroyDebugReportCallbackEXT( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 398 | icd->instance, icd_info[storage_idx], pAllocator); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 399 | } |
| 400 | storage_idx++; |
| 401 | } |
| 402 | |
Mark Young | 9b0636f | 2016-10-13 10:51:14 -0600 | [diff] [blame] | 403 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 404 | { |
| 405 | #else |
| 406 | if (pAllocator != NULL) { |
| 407 | if (NULL != pNewDbgFuncNode) { |
| 408 | pAllocator->pfnFree(pAllocator->pUserData, pNewDbgFuncNode); |
| 409 | } |
| 410 | if (NULL != icd_info) { |
| 411 | pAllocator->pfnFree(pAllocator->pUserData, icd_info); |
| 412 | } |
| 413 | } else { |
| 414 | #endif |
| 415 | if (NULL != pNewDbgFuncNode) { |
| 416 | free(pNewDbgFuncNode); |
| 417 | } |
| 418 | if (NULL != icd_info) { |
| 419 | free(icd_info); |
| 420 | } |
| 421 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 422 | } |
| 423 | |
Mark Young | d82497d | 2016-10-14 14:18:56 -0600 | [diff] [blame] | 424 | return res; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /* |
| 428 | * This is the instance chain terminator function |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 429 | * for DestroyDebugReportCallback |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 430 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 431 | VKAPI_ATTR void VKAPI_CALL terminator_DestroyDebugReportCallback( |
| 432 | VkInstance instance, VkDebugReportCallbackEXT callback, |
| 433 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 434 | uint32_t storage_idx; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 435 | VkDebugReportCallbackEXT *icd_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 436 | const struct loader_icd *icd; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 437 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 438 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 439 | icd_info = *(VkDebugReportCallbackEXT **)&callback; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 440 | storage_idx = 0; |
| 441 | for (icd = inst->icds; icd; icd = icd->next) { |
Mark Young | a26d47c | 2016-05-04 16:44:10 -0600 | [diff] [blame] | 442 | if (NULL == icd->DestroyDebugReportCallbackEXT) { |
| 443 | continue; |
| 444 | } |
| 445 | |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 446 | if (icd_info[storage_idx]) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 447 | icd->DestroyDebugReportCallbackEXT( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 448 | icd->instance, icd_info[storage_idx], pAllocator); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 449 | } |
| 450 | storage_idx++; |
| 451 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 452 | } |
| 453 | |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 454 | /* |
| 455 | * This is the instance chain terminator function |
| 456 | * for DebugReportMessage |
| 457 | */ |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 458 | VKAPI_ATTR void VKAPI_CALL terminator_DebugReportMessage( |
| 459 | VkInstance instance, VkDebugReportFlagsEXT flags, |
| 460 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 461 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 462 | const struct loader_icd *icd; |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 463 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 464 | struct loader_instance *inst = (struct loader_instance *)instance; |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 465 | |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 466 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 467 | for (icd = inst->icds; icd; icd = icd->next) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 468 | if (icd->DebugReportMessageEXT != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 469 | icd->DebugReportMessageEXT(icd->instance, flags, objType, object, |
| 470 | location, msgCode, pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | |
| 474 | /* |
| 475 | * Now that all ICDs have seen the message, call the necessary callbacks. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 476 | * Ignoring "bail" return value as there is nothing to bail from at this |
| 477 | * point. |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 478 | */ |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 479 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 480 | util_DebugReportMessage(inst, flags, objType, object, location, msgCode, |
| 481 | pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 482 | |
| 483 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 486 | bool debug_report_instance_gpa(struct loader_instance *ptr_instance, |
| 487 | const char *name, void **addr) { |
Jon Ashburn | 8a39efc | 2015-11-06 11:02:40 -0700 | [diff] [blame] | 488 | // debug_report is currently advertised to be supported by the loader, |
| 489 | // so always return the entry points if name matches and it's enabled |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 490 | *addr = NULL; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 491 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 492 | if (!strcmp("vkCreateDebugReportCallbackEXT", name)) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 493 | *addr = (ptr_instance->enabled_known_extensions.ext_debug_report == 1) |
| 494 | ? (void *)debug_report_CreateDebugReportCallbackEXT |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 495 | : NULL; |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 496 | return true; |
| 497 | } |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 498 | if (!strcmp("vkDestroyDebugReportCallbackEXT", name)) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 499 | *addr = (ptr_instance->enabled_known_extensions.ext_debug_report == 1) |
| 500 | ? (void *)debug_report_DestroyDebugReportCallbackEXT |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 501 | : NULL; |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 502 | return true; |
| 503 | } |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 504 | if (!strcmp("vkDebugReportMessageEXT", name)) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 505 | *addr = (ptr_instance->enabled_known_extensions.ext_debug_report == 1) |
| 506 | ? (void *)debug_report_DebugReportMessageEXT |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 507 | : NULL; |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 508 | return true; |
| 509 | } |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 510 | return false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 511 | } |