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