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) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 52 | ptr_instance->debug_report_enabled = false; |
| 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) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 57 | ptr_instance->debug_report_enabled = true; |
| 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) { |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 68 | VkLayerDbgFunctionNode *pNewDbgFuncNode; |
| 69 | if (pAllocator != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 70 | pNewDbgFuncNode = (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation( |
| 71 | pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode), |
| 72 | sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 73 | } else { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 74 | pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_heap_alloc( |
| 75 | inst, sizeof(VkLayerDbgFunctionNode), |
| 76 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 77 | } |
| 78 | if (!pNewDbgFuncNode) |
| 79 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 80 | |
| 81 | pNewDbgFuncNode->msgCallback = callback; |
| 82 | pNewDbgFuncNode->pfnMsgCallback = pCreateInfo->pfnCallback; |
| 83 | pNewDbgFuncNode->msgFlags = pCreateInfo->flags; |
| 84 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
| 85 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
| 86 | inst->DbgFunctionHead = pNewDbgFuncNode; |
| 87 | |
| 88 | return VK_SUCCESS; |
| 89 | } |
| 90 | |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 91 | static VKAPI_ATTR VkResult VKAPI_CALL debug_report_CreateDebugReportCallback( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 92 | VkInstance instance, VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 93 | VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 94 | struct loader_instance *inst = loader_get_instance(instance); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 95 | loader_platform_thread_lock_mutex(&loader_lock); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 96 | VkResult result = inst->disp->CreateDebugReportCallbackEXT( |
| 97 | instance, pCreateInfo, pAllocator, pCallback); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 98 | if (result == VK_SUCCESS) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 99 | result = util_CreateDebugReportCallback(inst, pCreateInfo, pAllocator, |
| 100 | *pCallback); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 101 | } |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 102 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 103 | return result; |
| 104 | } |
| 105 | |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 106 | // Utility function to handle reporting |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 107 | VkBool32 util_DebugReportMessage(const struct loader_instance *inst, |
| 108 | VkFlags msgFlags, |
| 109 | VkDebugReportObjectTypeEXT objectType, |
| 110 | uint64_t srcObject, size_t location, |
| 111 | int32_t msgCode, const char *pLayerPrefix, |
| 112 | const char *pMsg) { |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 113 | VkBool32 bail = false; |
| 114 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
| 115 | while (pTrav) { |
| 116 | if (pTrav->msgFlags & msgFlags) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 117 | if (pTrav->pfnMsgCallback(msgFlags, objectType, srcObject, location, |
| 118 | msgCode, pLayerPrefix, pMsg, |
| 119 | pTrav->pUserData)) { |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 120 | bail = true; |
| 121 | } |
| 122 | } |
| 123 | pTrav = pTrav->pNext; |
| 124 | } |
| 125 | |
| 126 | return bail; |
| 127 | } |
| 128 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 129 | void util_DestroyDebugReportCallback(struct loader_instance *inst, |
| 130 | VkDebugReportCallbackEXT callback, |
| 131 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 132 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
| 133 | VkLayerDbgFunctionNode *pPrev = pTrav; |
| 134 | |
| 135 | while (pTrav) { |
| 136 | if (pTrav->msgCallback == callback) { |
| 137 | pPrev->pNext = pTrav->pNext; |
| 138 | if (inst->DbgFunctionHead == pTrav) |
| 139 | inst->DbgFunctionHead = pTrav->pNext; |
| 140 | if (pAllocator != NULL) { |
| 141 | pAllocator->pfnFree(pAllocator->pUserData, pTrav); |
| 142 | } else { |
| 143 | loader_heap_free(inst, pTrav); |
| 144 | } |
| 145 | break; |
| 146 | } |
| 147 | pPrev = pTrav; |
| 148 | pTrav = pTrav->pNext; |
| 149 | } |
| 150 | } |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 151 | |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 152 | // This utility (used by vkInstanceCreateInfo(), looks at a pNext chain. It |
| 153 | // counts any VkDebugReportCallbackCreateInfoEXT structs that it finds. It |
| 154 | // then allocates array that can hold that many structs, as well as that many |
| 155 | // VkDebugReportCallbackEXT handles. It then copies each |
| 156 | // VkDebugReportCallbackCreateInfoEXT, and initializes each handle. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 157 | VkResult util_CopyDebugReportCreateInfos( |
| 158 | const void *pChain, const VkAllocationCallbacks *pAllocator, |
| 159 | uint32_t *num_callbacks, VkDebugReportCallbackCreateInfoEXT **infos, |
| 160 | VkDebugReportCallbackEXT **callbacks) { |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 161 | uint32_t n = *num_callbacks = 0; |
| 162 | |
| 163 | // NOTE: The loader is not using pAllocator, and so this function doesn't |
| 164 | // either. |
| 165 | |
| 166 | const void *pNext = pChain; |
| 167 | while (pNext) { |
| 168 | // 1st, count the number VkDebugReportCallbackCreateInfoEXT: |
| 169 | if (((VkDebugReportCallbackCreateInfoEXT *)pNext)->sType == |
| 170 | VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
| 171 | n++; |
| 172 | } |
| 173 | pNext = (void *)((VkDebugReportCallbackCreateInfoEXT *)pNext)->pNext; |
| 174 | } |
| 175 | if (n == 0) { |
| 176 | return VK_SUCCESS; |
| 177 | } |
| 178 | |
| 179 | // 2nd, allocate memory for each VkDebugReportCallbackCreateInfoEXT: |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 180 | VkDebugReportCallbackCreateInfoEXT *pInfos = *infos = |
| 181 | ((VkDebugReportCallbackCreateInfoEXT *)malloc( |
| 182 | n * sizeof(VkDebugReportCallbackCreateInfoEXT))); |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 183 | if (!pInfos) { |
| 184 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 185 | } |
| 186 | // 3rd, allocate memory for a unique handle for each callback: |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 187 | VkDebugReportCallbackEXT *pCallbacks = *callbacks = |
| 188 | ((VkDebugReportCallbackEXT *)malloc(n * |
| 189 | sizeof(VkDebugReportCallbackEXT))); |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 190 | if (!pCallbacks) { |
| 191 | free(pInfos); |
| 192 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 193 | } |
| 194 | // 4th, copy each VkDebugReportCallbackCreateInfoEXT for use by |
| 195 | // vkDestroyInstance, and assign a unique handle to each callback (just |
| 196 | // use the address of the copied VkDebugReportCallbackCreateInfoEXT): |
| 197 | pNext = pChain; |
| 198 | while (pNext) { |
| 199 | if (((VkInstanceCreateInfo *)pNext)->sType == |
| 200 | VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 201 | memcpy(pInfos, pNext, sizeof(VkDebugReportCallbackCreateInfoEXT)); |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 202 | *pCallbacks++ = (VkDebugReportCallbackEXT)pInfos++; |
| 203 | } |
| 204 | pNext = (void *)((VkInstanceCreateInfo *)pNext)->pNext; |
| 205 | } |
| 206 | |
| 207 | *num_callbacks = n; |
| 208 | return VK_SUCCESS; |
| 209 | } |
| 210 | |
| 211 | void util_FreeDebugReportCreateInfos(const VkAllocationCallbacks *pAllocator, |
| 212 | VkDebugReportCallbackCreateInfoEXT *infos, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 213 | VkDebugReportCallbackEXT *callbacks) { |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 214 | free(infos); |
| 215 | free(callbacks); |
| 216 | } |
| 217 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 218 | VkResult util_CreateDebugReportCallbacks( |
| 219 | struct loader_instance *inst, const VkAllocationCallbacks *pAllocator, |
| 220 | uint32_t num_callbacks, VkDebugReportCallbackCreateInfoEXT *infos, |
| 221 | VkDebugReportCallbackEXT *callbacks) { |
Jamie Madill | 2b6b8d5 | 2016-04-04 15:09:51 -0400 | [diff] [blame] | 222 | VkResult rtn = VK_SUCCESS; |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 223 | for (uint32_t i = 0; i < num_callbacks; i++) { |
| 224 | rtn = util_CreateDebugReportCallback(inst, &infos[i], pAllocator, |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 225 | callbacks[i]); |
| 226 | if (rtn != VK_SUCCESS) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 227 | for (uint32_t j = 0; j < i; j++) { |
| 228 | util_DestroyDebugReportCallback(inst, callbacks[j], pAllocator); |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 229 | } |
| 230 | return rtn; |
| 231 | } |
| 232 | } |
| 233 | return rtn; |
| 234 | } |
| 235 | |
| 236 | void util_DestroyDebugReportCallbacks(struct loader_instance *inst, |
| 237 | const VkAllocationCallbacks *pAllocator, |
| 238 | uint32_t num_callbacks, |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 239 | VkDebugReportCallbackEXT *callbacks) { |
| 240 | for (uint32_t i = 0; i < num_callbacks; i++) { |
| 241 | util_DestroyDebugReportCallback(inst, callbacks[i], pAllocator); |
Ian Elliott | ad6300f | 2016-03-31 10:48:19 -0600 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 245 | static VKAPI_ATTR void VKAPI_CALL |
| 246 | debug_report_DestroyDebugReportCallback(VkInstance instance, |
| 247 | VkDebugReportCallbackEXT callback, |
| 248 | VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 249 | struct loader_instance *inst = loader_get_instance(instance); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 250 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 251 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 252 | inst->disp->DestroyDebugReportCallbackEXT(instance, callback, pAllocator); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 253 | |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 254 | util_DestroyDebugReportCallback(inst, callback, pAllocator); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 255 | |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 256 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 257 | } |
| 258 | |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 259 | static VKAPI_ATTR void VKAPI_CALL debug_report_DebugReportMessage( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 260 | VkInstance instance, VkDebugReportFlagsEXT flags, |
| 261 | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
| 262 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 263 | struct loader_instance *inst = loader_get_instance(instance); |
| 264 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 265 | inst->disp->DebugReportMessageEXT(instance, flags, objType, object, |
| 266 | location, msgCode, pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 267 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 268 | |
| 269 | /* |
| 270 | * This is the instance chain terminator function |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 271 | * for CreateDebugReportCallback |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 272 | */ |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 273 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 274 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDebugReportCallback( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 275 | VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 276 | const VkAllocationCallbacks *pAllocator, |
| 277 | VkDebugReportCallbackEXT *pCallback) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 278 | VkDebugReportCallbackEXT *icd_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 279 | const struct loader_icd *icd; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 280 | struct loader_instance *inst = (struct loader_instance *)instance; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 281 | VkResult res = VK_SUCCESS; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 282 | uint32_t storage_idx; |
| 283 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 284 | icd_info = calloc(sizeof(VkDebugReportCallbackEXT), inst->total_icd_count); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 285 | if (!icd_info) { |
| 286 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 287 | } |
| 288 | |
| 289 | storage_idx = 0; |
| 290 | for (icd = inst->icds; icd; icd = icd->next) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 291 | if (!icd->CreateDebugReportCallbackEXT) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 292 | continue; |
| 293 | } |
| 294 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 295 | res = icd->CreateDebugReportCallbackEXT( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 296 | icd->instance, pCreateInfo, pAllocator, &icd_info[storage_idx]); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 297 | |
| 298 | if (res != VK_SUCCESS) { |
| 299 | break; |
| 300 | } |
| 301 | storage_idx++; |
| 302 | } |
| 303 | |
| 304 | /* roll back on errors */ |
| 305 | if (icd) { |
| 306 | storage_idx = 0; |
| 307 | for (icd = inst->icds; icd; icd = icd->next) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 308 | if (icd_info[storage_idx]) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 309 | icd->DestroyDebugReportCallbackEXT( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 310 | icd->instance, icd_info[storage_idx], pAllocator); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 311 | } |
| 312 | storage_idx++; |
| 313 | } |
| 314 | |
| 315 | return res; |
| 316 | } |
| 317 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 318 | *(VkDebugReportCallbackEXT **)pCallback = icd_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 319 | |
| 320 | return VK_SUCCESS; |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * This is the instance chain terminator function |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 325 | * for DestroyDebugReportCallback |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 326 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 327 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 328 | terminator_DestroyDebugReportCallback(VkInstance instance, |
| 329 | VkDebugReportCallbackEXT callback, |
| 330 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 331 | uint32_t storage_idx; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 332 | VkDebugReportCallbackEXT *icd_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 333 | const struct loader_icd *icd; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 334 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 335 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 336 | icd_info = *(VkDebugReportCallbackEXT **)&callback; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 337 | storage_idx = 0; |
| 338 | for (icd = inst->icds; icd; icd = icd->next) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 339 | if (icd_info[storage_idx]) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 340 | icd->DestroyDebugReportCallbackEXT( |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 341 | icd->instance, icd_info[storage_idx], pAllocator); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 342 | } |
| 343 | storage_idx++; |
| 344 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 345 | } |
| 346 | |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 347 | /* |
| 348 | * This is the instance chain terminator function |
| 349 | * for DebugReportMessage |
| 350 | */ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 351 | VKAPI_ATTR void VKAPI_CALL |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 352 | terminator_DebugReportMessage(VkInstance instance, VkDebugReportFlagsEXT flags, |
| 353 | VkDebugReportObjectTypeEXT objType, |
| 354 | uint64_t object, size_t location, int32_t msgCode, |
| 355 | const char *pLayerPrefix, const char *pMsg) { |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 356 | const struct loader_icd *icd; |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 357 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 358 | struct loader_instance *inst = (struct loader_instance *)instance; |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 359 | |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 360 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 361 | for (icd = inst->icds; icd; icd = icd->next) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 362 | if (icd->DebugReportMessageEXT != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 363 | icd->DebugReportMessageEXT(icd->instance, flags, objType, object, |
| 364 | location, msgCode, pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Now that all ICDs have seen the message, call the necessary callbacks. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 370 | * Ignoring "bail" return value as there is nothing to bail from at this |
| 371 | * point. |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 372 | */ |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 373 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 374 | util_DebugReportMessage(inst, flags, objType, object, location, msgCode, |
| 375 | pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 8288727 | 2015-12-02 15:29:33 -0700 | [diff] [blame] | 376 | |
| 377 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 380 | bool debug_report_instance_gpa(struct loader_instance *ptr_instance, |
| 381 | const char *name, void **addr) { |
Jon Ashburn | 8a39efc | 2015-11-06 11:02:40 -0700 | [diff] [blame] | 382 | // debug_report is currently advertised to be supported by the loader, |
| 383 | // 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] | 384 | *addr = NULL; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 385 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 386 | if (!strcmp("vkCreateDebugReportCallbackEXT", name)) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 387 | *addr = ptr_instance->debug_report_enabled |
| 388 | ? (void *)debug_report_CreateDebugReportCallback |
| 389 | : NULL; |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 390 | return true; |
| 391 | } |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 392 | if (!strcmp("vkDestroyDebugReportCallbackEXT", name)) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 393 | *addr = ptr_instance->debug_report_enabled |
| 394 | ? (void *)debug_report_DestroyDebugReportCallback |
| 395 | : NULL; |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 396 | return true; |
| 397 | } |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 398 | if (!strcmp("vkDebugReportMessageEXT", name)) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 399 | *addr = ptr_instance->debug_report_enabled |
| 400 | ? (void *)debug_report_DebugReportMessage |
| 401 | : NULL; |
Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 402 | return true; |
| 403 | } |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 404 | return false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 405 | } |