Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 23 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 24 | * |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 25 | */ |
| 26 | |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 27 | #define _GNU_SOURCE |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 28 | #include <stdio.h> |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <stdlib.h> |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 31 | #include <inttypes.h> |
Tony Barbour | 1d825c7 | 2015-06-18 16:29:32 -0600 | [diff] [blame] | 32 | #ifndef WIN32 |
Courtney Goeltzenleuchter | 03663d0 | 2015-07-22 11:01:53 -0600 | [diff] [blame] | 33 | #include <signal.h> |
| 34 | #else |
Tony Barbour | 1d825c7 | 2015-06-18 16:29:32 -0600 | [diff] [blame] | 35 | #endif |
Jon Ashburn | 480a50a | 2015-08-28 14:58:46 -0700 | [diff] [blame] | 36 | #include "vk_loader_platform.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 37 | #include "debug_report.h" |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 38 | #include "vulkan/vk_layer.h" |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 39 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 40 | typedef void (VKAPI_PTR *PFN_stringCallback)(char *message); |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 41 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 42 | static const VkExtensionProperties debug_report_extension_info = { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 43 | .extensionName = VK_DEBUG_REPORT_EXTENSION_NAME, |
Ian Elliott | 464e0b5 | 2015-09-04 14:14:35 -0600 | [diff] [blame] | 44 | .specVersion = VK_DEBUG_REPORT_EXTENSION_REVISION, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | void debug_report_add_instance_extensions( |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 48 | const struct loader_instance *inst, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 49 | struct loader_extension_list *ext_list) |
| 50 | { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 51 | 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] | 52 | } |
| 53 | |
| 54 | void debug_report_create_instance( |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 55 | struct loader_instance *ptr_instance, |
| 56 | const VkInstanceCreateInfo *pCreateInfo) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 57 | { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 58 | ptr_instance->debug_report_enabled = false; |
| 59 | |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 60 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
Courtney Goeltzenleuchter | 05159a9 | 2015-07-30 11:32:46 -0600 | [diff] [blame] | 61 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_DEBUG_REPORT_EXTENSION_NAME) == 0) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 62 | ptr_instance->debug_report_enabled = true; |
| 63 | return; |
| 64 | } |
| 65 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 66 | } |
| 67 | |
Jon Ashburn | 4f23258 | 2015-11-06 15:31:44 -0700 | [diff] [blame^] | 68 | static VKAPI_ATTR VkResult VKAPI_CALL debug_report_DbgCreateMsgCallback( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 69 | VkInstance instance, |
| 70 | VkFlags msgFlags, |
| 71 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
| 72 | void* pUserData, |
| 73 | VkDbgMsgCallback* pMsgCallback) |
| 74 | { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 75 | VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode *) loader_heap_alloc((struct loader_instance *)instance, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 76 | if (!pNewDbgFuncNode) |
| 77 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 78 | |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 79 | struct loader_instance *inst = loader_get_instance(instance); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 80 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 81 | VkResult result = inst->disp->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 82 | if (result == VK_SUCCESS) { |
| 83 | pNewDbgFuncNode->msgCallback = *pMsgCallback; |
| 84 | pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback; |
| 85 | pNewDbgFuncNode->msgFlags = msgFlags; |
| 86 | pNewDbgFuncNode->pUserData = pUserData; |
| 87 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
| 88 | inst->DbgFunctionHead = pNewDbgFuncNode; |
| 89 | } else { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 90 | loader_heap_free((struct loader_instance *) instance, pNewDbgFuncNode); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 91 | } |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 92 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 93 | return result; |
| 94 | } |
| 95 | |
Jon Ashburn | 4f23258 | 2015-11-06 15:31:44 -0700 | [diff] [blame^] | 96 | static VKAPI_ATTR VkResult VKAPI_CALL debug_report_DbgDestroyMsgCallback( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 97 | VkInstance instance, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 98 | VkDbgMsgCallback msg_callback) |
| 99 | { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 100 | struct loader_instance *inst = loader_get_instance(instance); |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 101 | loader_platform_thread_lock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 102 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
| 103 | VkLayerDbgFunctionNode *pPrev = pTrav; |
| 104 | |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 105 | VkResult result = inst->disp->DbgDestroyMsgCallback(instance, msg_callback); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 106 | |
| 107 | while (pTrav) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 108 | if (pTrav->msgCallback == msg_callback) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 109 | pPrev->pNext = pTrav->pNext; |
| 110 | if (inst->DbgFunctionHead == pTrav) |
| 111 | inst->DbgFunctionHead = pTrav->pNext; |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 112 | loader_heap_free((struct loader_instance *) instance, pTrav); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 113 | break; |
| 114 | } |
| 115 | pPrev = pTrav; |
| 116 | pTrav = pTrav->pNext; |
| 117 | } |
| 118 | |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 119 | loader_platform_thread_unlock_mutex(&loader_lock); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 120 | return result; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /* |
| 125 | * This is the instance chain terminator function |
| 126 | * for DbgCreateMsgCallback |
| 127 | */ |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 128 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 129 | VKAPI_ATTR VkResult VKAPI_CALL loader_DbgCreateMsgCallback( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 130 | VkInstance instance, |
| 131 | VkFlags msgFlags, |
| 132 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
Jon Ashburn | e67741a | 2015-08-06 13:56:43 -0600 | [diff] [blame] | 133 | void* pUserData, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 134 | VkDbgMsgCallback* pMsgCallback) |
| 135 | { |
| 136 | VkDbgMsgCallback *icd_info; |
| 137 | const struct loader_icd *icd; |
| 138 | struct loader_instance *inst; |
| 139 | VkResult res; |
| 140 | uint32_t storage_idx; |
| 141 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 142 | for (inst = loader.instances; inst; inst = inst->next) { |
| 143 | if ((VkInstance) inst == instance) |
| 144 | break; |
| 145 | } |
| 146 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 147 | icd_info = calloc(sizeof(VkDbgMsgCallback), inst->total_icd_count); |
| 148 | if (!icd_info) { |
| 149 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 150 | } |
| 151 | |
| 152 | storage_idx = 0; |
| 153 | for (icd = inst->icds; icd; icd = icd->next) { |
| 154 | if (!icd->DbgCreateMsgCallback) { |
| 155 | continue; |
| 156 | } |
| 157 | |
| 158 | res = icd->DbgCreateMsgCallback( |
| 159 | icd->instance, |
| 160 | msgFlags, |
| 161 | pfnMsgCallback, |
| 162 | pUserData, |
| 163 | &icd_info[storage_idx]); |
| 164 | |
| 165 | if (res != VK_SUCCESS) { |
| 166 | break; |
| 167 | } |
| 168 | storage_idx++; |
| 169 | } |
| 170 | |
| 171 | /* roll back on errors */ |
| 172 | if (icd) { |
| 173 | storage_idx = 0; |
| 174 | for (icd = inst->icds; icd; icd = icd->next) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 175 | if (icd_info[storage_idx]) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 176 | icd->DbgDestroyMsgCallback( |
| 177 | icd->instance, |
| 178 | icd_info[storage_idx]); |
| 179 | } |
| 180 | storage_idx++; |
| 181 | } |
| 182 | |
| 183 | return res; |
| 184 | } |
| 185 | |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 186 | *(VkDbgMsgCallback **)pMsgCallback = icd_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 187 | |
| 188 | return VK_SUCCESS; |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * This is the instance chain terminator function |
| 193 | * for DbgDestroyMsgCallback |
| 194 | */ |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 195 | VKAPI_ATTR VkResult VKAPI_CALL loader_DbgDestroyMsgCallback( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 196 | VkInstance instance, |
| 197 | VkDbgMsgCallback msgCallback) |
| 198 | { |
| 199 | uint32_t storage_idx; |
| 200 | VkDbgMsgCallback *icd_info; |
| 201 | const struct loader_icd *icd; |
| 202 | VkResult res = VK_SUCCESS; |
| 203 | struct loader_instance *inst; |
| 204 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 205 | for (inst = loader.instances; inst; inst = inst->next) { |
| 206 | if ((VkInstance) inst == instance) |
| 207 | break; |
| 208 | } |
| 209 | |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 210 | icd_info = *(VkDbgMsgCallback **) &msgCallback; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 211 | storage_idx = 0; |
| 212 | for (icd = inst->icds; icd; icd = icd->next) { |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 213 | if (icd_info[storage_idx]) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 214 | icd->DbgDestroyMsgCallback( |
Courtney Goeltzenleuchter | 7d0023c | 2015-06-08 15:09:22 -0600 | [diff] [blame] | 215 | icd->instance, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 216 | icd_info[storage_idx]); |
| 217 | } |
| 218 | storage_idx++; |
| 219 | } |
| 220 | return res; |
| 221 | } |
| 222 | |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 223 | static void print_msg_flags(VkFlags msgFlags, char *msg_flags) |
| 224 | { |
| 225 | bool separator = false; |
| 226 | |
| 227 | msg_flags[0] = 0; |
| 228 | if (msgFlags & VK_DBG_REPORT_DEBUG_BIT) { |
| 229 | strcat(msg_flags, "DEBUG"); |
| 230 | separator = true; |
| 231 | } |
| 232 | if (msgFlags & VK_DBG_REPORT_INFO_BIT) { |
| 233 | if (separator) strcat(msg_flags, ","); |
| 234 | strcat(msg_flags, "INFO"); |
| 235 | separator = true; |
| 236 | } |
| 237 | if (msgFlags & VK_DBG_REPORT_WARN_BIT) { |
| 238 | if (separator) strcat(msg_flags, ","); |
| 239 | strcat(msg_flags, "WARN"); |
| 240 | separator = true; |
| 241 | } |
| 242 | if (msgFlags & VK_DBG_REPORT_PERF_WARN_BIT) { |
| 243 | if (separator) strcat(msg_flags, ","); |
| 244 | strcat(msg_flags, "PERF"); |
| 245 | separator = true; |
| 246 | } |
| 247 | if (msgFlags & VK_DBG_REPORT_ERROR_BIT) { |
| 248 | if (separator) strcat(msg_flags, ","); |
| 249 | strcat(msg_flags, "ERROR"); |
| 250 | } |
| 251 | } |
| 252 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 253 | // DebugReport utility callback functions |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 254 | static VKAPI_ATTR void VKAPI_CALL StringCallback( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 255 | VkFlags msgFlags, |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 256 | VkDbgObjectType objType, |
| 257 | uint64_t srcObject, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 258 | size_t location, |
| 259 | int32_t msgCode, |
| 260 | const char* pLayerPrefix, |
| 261 | const char* pMsg, |
| 262 | void* pUserData) |
| 263 | { |
Jon Ashburn | 7242c67 | 2015-06-30 14:44:13 -0700 | [diff] [blame] | 264 | size_t buf_size; |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 265 | char *buf; |
| 266 | char msg_flags[30]; |
| 267 | PFN_stringCallback callback = (PFN_stringCallback) pUserData; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 268 | |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 269 | print_msg_flags(msgFlags, msg_flags); |
| 270 | |
| 271 | buf_size = strlen(msg_flags) + /* ReportFlags: i.e. (DEBUG,INFO,WARN,PERF,ERROR) */ |
| 272 | 20 + /* objType */ |
| 273 | 20 + /* srcObject */ |
| 274 | 20 + /* location */ |
| 275 | 20 + /* msgCode */ |
| 276 | strlen(pLayerPrefix) + |
| 277 | strlen(pMsg) + |
| 278 | 50 /* other / whitespace */; |
Jon Ashburn | 48091a3 | 2015-08-27 13:06:58 -0600 | [diff] [blame] | 279 | buf = loader_stack_alloc(buf_size); |
| 280 | |
Courtney Goeltzenleuchter | 22d8d79 | 2015-10-07 17:03:42 -0600 | [diff] [blame] | 281 | snprintf(buf, buf_size, "%s (%s): object: 0x%" PRIxLEAST64 " type: %d location: " PRINTF_SIZE_T_SPECIFIER " msgCode : %d : %s", |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 282 | pLayerPrefix, msg_flags, srcObject, objType, location, msgCode, pMsg); |
| 283 | callback(buf); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 284 | } |
| 285 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 286 | static VKAPI_ATTR void VKAPI_CALL StdioCallback( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 287 | VkFlags msgFlags, |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 288 | VkDbgObjectType objType, |
| 289 | uint64_t srcObject, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 290 | size_t location, |
| 291 | int32_t msgCode, |
| 292 | const char* pLayerPrefix, |
| 293 | const char* pMsg, |
| 294 | void* pUserData) |
| 295 | { |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 296 | char msg_flags[30]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 297 | |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 298 | print_msg_flags(msgFlags, msg_flags); |
| 299 | |
Courtney Goeltzenleuchter | 22d8d79 | 2015-10-07 17:03:42 -0600 | [diff] [blame] | 300 | fprintf((FILE *)pUserData, "%s(%s): object: 0x%" PRIxLEAST64 " type: %d location: " PRINTF_SIZE_T_SPECIFIER " msgCode : %d : %s", |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 301 | pLayerPrefix, msg_flags, srcObject, objType, location, msgCode, pMsg); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 302 | } |
| 303 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 304 | static VKAPI_ATTR void VKAPI_CALL BreakCallback( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 305 | VkFlags msgFlags, |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 306 | VkDbgObjectType objType, |
| 307 | uint64_t srcObject, |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 308 | size_t location, |
| 309 | int32_t msgCode, |
| 310 | const char* pLayerPrefix, |
| 311 | const char* pMsg, |
| 312 | void* pUserData) |
| 313 | { |
Courtney Goeltzenleuchter | 03663d0 | 2015-07-22 11:01:53 -0600 | [diff] [blame] | 314 | #ifndef WIN32 |
| 315 | raise(SIGTRAP); |
| 316 | #else |
| 317 | DebugBreak(); |
| 318 | #endif |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 319 | } |
| 320 | |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 321 | bool debug_report_instance_gpa( |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 322 | struct loader_instance *ptr_instance, |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 323 | const char* name, |
| 324 | void **addr) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 325 | { |
Jon Ashburn | 8a39efc | 2015-11-06 11:02:40 -0700 | [diff] [blame] | 326 | // debug_report is currently advertised to be supported by the loader, |
| 327 | // 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] | 328 | *addr = NULL; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 329 | |
Jon Ashburn | f7a48db | 2015-10-01 12:03:17 -0600 | [diff] [blame] | 330 | if (!strcmp("vkDbgCreateMsgCallback", name)) { |
| 331 | *addr = ptr_instance->debug_report_enabled ? (void *) debug_report_DbgCreateMsgCallback : NULL; |
| 332 | return true; |
| 333 | } |
| 334 | if (!strcmp("vkDbgDestroyMsgCallback", name)) { |
| 335 | *addr = ptr_instance->debug_report_enabled ? (void *) debug_report_DbgDestroyMsgCallback : NULL; |
| 336 | return true; |
| 337 | } |
| 338 | if (!strcmp("vkDbgStringCallback", name)) { |
| 339 | *addr = ptr_instance->debug_report_enabled ? (void *) StringCallback : NULL; |
| 340 | return true; |
| 341 | } |
| 342 | if (!strcmp("vkDbgStdioCallback", name)) { |
| 343 | *addr = ptr_instance->debug_report_enabled ? (void *) StdioCallback : NULL; |
| 344 | return true; |
| 345 | } |
| 346 | if (!strcmp("vkDbgBreakCallback", name)) { |
| 347 | *addr = ptr_instance->debug_report_enabled ? (void *) BreakCallback : NULL; |
| 348 | return true; |
| 349 | } |
| 350 | return false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 351 | } |