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