/src/vulkan-loader/loader/debug_utils.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2015-2021 The Khronos Group Inc. |
3 | | * Copyright (c) 2015-2021 Valve Corporation |
4 | | * Copyright (c) 2015-2021 LunarG, Inc. |
5 | | * Copyright (C) 2015-2016 Google Inc. |
6 | | * |
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 |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
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. |
18 | | * |
19 | | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
20 | | * Author: Jon Ashburn <jon@LunarG.com> |
21 | | * Author: Mark Young <marky@lunarg.com> |
22 | | * Author: Charles Giessen <charles@lunarg.com> |
23 | | * |
24 | | */ |
25 | | |
26 | | #include <inttypes.h> |
27 | | #include <stdio.h> |
28 | | #include <stdlib.h> |
29 | | #include <string.h> |
30 | | #if !defined(WIN32) |
31 | | #include <signal.h> |
32 | | #endif |
33 | | |
34 | | #include "vulkan/vk_layer.h" |
35 | | #include "vk_object_types.h" |
36 | | |
37 | | #include "allocation.h" |
38 | | #include "debug_utils.h" |
39 | | #include "log.h" |
40 | | #include "loader.h" |
41 | | #include "vk_loader_platform.h" |
42 | | |
43 | | // VK_EXT_debug_report related items |
44 | | |
45 | | VkResult util_CreateDebugUtilsMessenger(struct loader_instance *inst, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, |
46 | 0 | const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT messenger) { |
47 | 0 | VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL; |
48 | |
|
49 | 0 | pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_calloc_with_instance_fallback( |
50 | 0 | pAllocator, inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
51 | |
|
52 | 0 | if (!pNewDbgFuncNode) { |
53 | 0 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
54 | 0 | } |
55 | | |
56 | 0 | pNewDbgFuncNode->is_messenger = true; |
57 | 0 | pNewDbgFuncNode->messenger.messenger = messenger; |
58 | 0 | pNewDbgFuncNode->messenger.pfnUserCallback = pCreateInfo->pfnUserCallback; |
59 | 0 | pNewDbgFuncNode->messenger.messageSeverity = pCreateInfo->messageSeverity; |
60 | 0 | pNewDbgFuncNode->messenger.messageType = pCreateInfo->messageType; |
61 | 0 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
62 | 0 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
63 | 0 | inst->DbgFunctionHead = pNewDbgFuncNode; |
64 | |
|
65 | 0 | return VK_SUCCESS; |
66 | 0 | } |
67 | | |
68 | | VKAPI_ATTR VkResult VKAPI_CALL debug_utils_CreateDebugUtilsMessengerEXT(VkInstance instance, |
69 | | const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, |
70 | | const VkAllocationCallbacks *pAllocator, |
71 | 0 | VkDebugUtilsMessengerEXT *pMessenger) { |
72 | 0 | struct loader_instance *inst = loader_get_instance(instance); |
73 | 0 | loader_platform_thread_lock_mutex(&loader_lock); |
74 | 0 | VkResult result = inst->disp->layer_inst_disp.CreateDebugUtilsMessengerEXT(inst->instance, pCreateInfo, pAllocator, pMessenger); |
75 | 0 | loader_platform_thread_unlock_mutex(&loader_lock); |
76 | 0 | return result; |
77 | 0 | } |
78 | | |
79 | | VkBool32 util_SubmitDebugUtilsMessageEXT(const struct loader_instance *inst, VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, |
80 | | VkDebugUtilsMessageTypeFlagsEXT messageTypes, |
81 | 0 | const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData) { |
82 | 0 | VkBool32 bail = false; |
83 | |
|
84 | 0 | if (NULL != pCallbackData) { |
85 | 0 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
86 | 0 | VkDebugReportObjectTypeEXT object_type = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT; |
87 | 0 | VkDebugReportFlagsEXT object_flags = 0; |
88 | 0 | uint64_t object_handle = 0; |
89 | |
|
90 | 0 | debug_utils_AnnotFlagsToReportFlags(messageSeverity, messageTypes, &object_flags); |
91 | 0 | if (0 < pCallbackData->objectCount) { |
92 | 0 | debug_utils_AnnotObjectToDebugReportObject(pCallbackData->pObjects, &object_type, &object_handle); |
93 | 0 | } |
94 | |
|
95 | 0 | while (pTrav) { |
96 | 0 | if (pTrav->is_messenger && (pTrav->messenger.messageSeverity & messageSeverity) && |
97 | 0 | (pTrav->messenger.messageType & messageTypes)) { |
98 | 0 | if (pTrav->messenger.pfnUserCallback(messageSeverity, messageTypes, pCallbackData, pTrav->pUserData)) { |
99 | 0 | bail = true; |
100 | 0 | } |
101 | 0 | } |
102 | 0 | if (!pTrav->is_messenger && pTrav->report.msgFlags & object_flags) { |
103 | 0 | if (pTrav->report.pfnMsgCallback(object_flags, object_type, object_handle, 0, pCallbackData->messageIdNumber, |
104 | 0 | pCallbackData->pMessageIdName, pCallbackData->pMessage, pTrav->pUserData)) { |
105 | 0 | bail = true; |
106 | 0 | } |
107 | 0 | } |
108 | |
|
109 | 0 | pTrav = pTrav->pNext; |
110 | 0 | } |
111 | 0 | } |
112 | |
|
113 | 0 | return bail; |
114 | 0 | } |
115 | | |
116 | | void util_DestroyDebugUtilsMessenger(struct loader_instance *inst, VkDebugUtilsMessengerEXT messenger, |
117 | 0 | const VkAllocationCallbacks *pAllocator) { |
118 | 0 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
119 | 0 | VkLayerDbgFunctionNode *pPrev = pTrav; |
120 | |
|
121 | 0 | while (pTrav) { |
122 | 0 | if (pTrav->is_messenger && pTrav->messenger.messenger == messenger) { |
123 | 0 | pPrev->pNext = pTrav->pNext; |
124 | 0 | if (inst->DbgFunctionHead == pTrav) inst->DbgFunctionHead = pTrav->pNext; |
125 | 0 | loader_free_with_instance_fallback(pAllocator, inst, pTrav); |
126 | 0 | break; |
127 | 0 | } |
128 | 0 | pPrev = pTrav; |
129 | 0 | pTrav = pTrav->pNext; |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | | VkResult util_CreateDebugUtilsMessengers(struct loader_instance *inst, const void *pChain, |
134 | 0 | const VkAllocationCallbacks *pAllocator) { |
135 | 0 | const void *pNext = pChain; |
136 | 0 | while (pNext) { |
137 | 0 | if (((const VkBaseInStructure *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT) { |
138 | | // Assign a unique handle to each messenger (just use the address of the VkDebugUtilsMessengerCreateInfoEXT) |
139 | | // This is only being used this way due to it being for an 'anonymous' callback during instance creation |
140 | 0 | VkDebugUtilsMessengerEXT messenger_handle = (VkDebugUtilsMessengerEXT)(uintptr_t)pNext; |
141 | 0 | VkResult ret = util_CreateDebugUtilsMessenger(inst, (const VkDebugUtilsMessengerCreateInfoEXT *)pNext, pAllocator, |
142 | 0 | messenger_handle); |
143 | 0 | if (ret != VK_SUCCESS) { |
144 | 0 | return ret; |
145 | 0 | } |
146 | 0 | } |
147 | 0 | pNext = (void *)((VkBaseInStructure *)pNext)->pNext; |
148 | 0 | } |
149 | 0 | return VK_SUCCESS; |
150 | 0 | } |
151 | | |
152 | | VKAPI_ATTR void VKAPI_CALL debug_utils_SubmitDebugUtilsMessageEXT(VkInstance instance, |
153 | | VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, |
154 | | VkDebugUtilsMessageTypeFlagsEXT messageTypes, |
155 | 0 | const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData) { |
156 | 0 | struct loader_instance *inst = loader_get_instance(instance); |
157 | |
|
158 | 0 | inst->disp->layer_inst_disp.SubmitDebugUtilsMessageEXT(inst->instance, messageSeverity, messageTypes, pCallbackData); |
159 | 0 | } |
160 | | |
161 | | VKAPI_ATTR void VKAPI_CALL debug_utils_DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, |
162 | 0 | const VkAllocationCallbacks *pAllocator) { |
163 | 0 | struct loader_instance *inst = loader_get_instance(instance); |
164 | 0 | loader_platform_thread_lock_mutex(&loader_lock); |
165 | |
|
166 | 0 | inst->disp->layer_inst_disp.DestroyDebugUtilsMessengerEXT(inst->instance, messenger, pAllocator); |
167 | |
|
168 | 0 | loader_platform_thread_unlock_mutex(&loader_lock); |
169 | 0 | } |
170 | | |
171 | | // This is the instance chain terminator function for CreateDebugUtilsMessenger |
172 | | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDebugUtilsMessengerEXT(VkInstance instance, |
173 | | const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, |
174 | | const VkAllocationCallbacks *pAllocator, |
175 | 0 | VkDebugUtilsMessengerEXT *pMessenger) { |
176 | 0 | VkDebugUtilsMessengerEXT *icd_info = NULL; |
177 | 0 | const struct loader_icd_term *icd_term; |
178 | 0 | struct loader_instance *inst = (struct loader_instance *)instance; |
179 | 0 | VkResult res = VK_SUCCESS; |
180 | 0 | uint32_t storage_idx; |
181 | 0 | VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL; |
182 | |
|
183 | 0 | icd_info = (VkDebugUtilsMessengerEXT *)loader_calloc_with_instance_fallback( |
184 | 0 | pAllocator, inst, inst->total_icd_count * sizeof(VkDebugUtilsMessengerEXT), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
185 | |
|
186 | 0 | if (!icd_info) { |
187 | 0 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
188 | 0 | goto out; |
189 | 0 | } |
190 | | |
191 | 0 | storage_idx = 0; |
192 | 0 | for (icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
193 | 0 | if (!icd_term->dispatch.CreateDebugUtilsMessengerEXT) { |
194 | 0 | continue; |
195 | 0 | } |
196 | | |
197 | 0 | res = icd_term->dispatch.CreateDebugUtilsMessengerEXT(icd_term->instance, pCreateInfo, pAllocator, &icd_info[storage_idx]); |
198 | |
|
199 | 0 | if (res != VK_SUCCESS) { |
200 | 0 | goto out; |
201 | 0 | } |
202 | 0 | storage_idx++; |
203 | 0 | } |
204 | | |
205 | | // Setup the debug report callback in the terminator since a layer may want |
206 | | // to grab the information itself (RenderDoc) and then return back to the |
207 | | // user callback a sub-set of the messages. |
208 | 0 | pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_calloc_with_instance_fallback( |
209 | 0 | pAllocator, inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
210 | 0 | if (!pNewDbgFuncNode) { |
211 | 0 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
212 | 0 | goto out; |
213 | 0 | } |
214 | | |
215 | 0 | pNewDbgFuncNode->is_messenger = true; |
216 | 0 | pNewDbgFuncNode->messenger.pfnUserCallback = pCreateInfo->pfnUserCallback; |
217 | 0 | pNewDbgFuncNode->messenger.messageSeverity = pCreateInfo->messageSeverity; |
218 | 0 | pNewDbgFuncNode->messenger.messageType = pCreateInfo->messageType; |
219 | 0 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
220 | 0 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
221 | 0 | inst->DbgFunctionHead = pNewDbgFuncNode; |
222 | |
|
223 | 0 | *(VkDebugUtilsMessengerEXT **)pMessenger = icd_info; |
224 | 0 | pNewDbgFuncNode->messenger.messenger = *pMessenger; |
225 | |
|
226 | 0 | out: |
227 | | |
228 | | // Roll back on errors |
229 | 0 | if (VK_SUCCESS != res) { |
230 | 0 | storage_idx = 0; |
231 | 0 | for (icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
232 | 0 | if (NULL == icd_term->dispatch.DestroyDebugUtilsMessengerEXT) { |
233 | 0 | continue; |
234 | 0 | } |
235 | | |
236 | 0 | if (icd_info && icd_info[storage_idx]) { |
237 | 0 | icd_term->dispatch.DestroyDebugUtilsMessengerEXT(icd_term->instance, icd_info[storage_idx], pAllocator); |
238 | 0 | } |
239 | 0 | storage_idx++; |
240 | 0 | } |
241 | 0 | loader_free_with_instance_fallback(pAllocator, inst, pNewDbgFuncNode); |
242 | 0 | loader_free_with_instance_fallback(pAllocator, inst, icd_info); |
243 | 0 | } |
244 | |
|
245 | 0 | return res; |
246 | 0 | } |
247 | | |
248 | | // This is the instance chain terminator function for DestroyDebugUtilsMessenger |
249 | | VKAPI_ATTR void VKAPI_CALL terminator_DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, |
250 | 0 | const VkAllocationCallbacks *pAllocator) { |
251 | 0 | uint32_t storage_idx; |
252 | 0 | VkDebugUtilsMessengerEXT *icd_info; |
253 | 0 | const struct loader_icd_term *icd_term; |
254 | |
|
255 | 0 | struct loader_instance *inst = (struct loader_instance *)instance; |
256 | 0 | icd_info = *(VkDebugUtilsMessengerEXT **)&messenger; |
257 | 0 | storage_idx = 0; |
258 | 0 | for (icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
259 | 0 | if (NULL == icd_term->dispatch.DestroyDebugUtilsMessengerEXT) { |
260 | 0 | continue; |
261 | 0 | } |
262 | | |
263 | 0 | if (icd_info && icd_info[storage_idx]) { |
264 | 0 | icd_term->dispatch.DestroyDebugUtilsMessengerEXT(icd_term->instance, icd_info[storage_idx], pAllocator); |
265 | 0 | } |
266 | 0 | storage_idx++; |
267 | 0 | } |
268 | |
|
269 | 0 | util_DestroyDebugUtilsMessenger(inst, messenger, pAllocator); |
270 | |
|
271 | 0 | loader_free_with_instance_fallback(pAllocator, inst, icd_info); |
272 | 0 | } |
273 | | |
274 | | // This is the instance chain terminator function for SubmitDebugUtilsMessageEXT |
275 | | VKAPI_ATTR void VKAPI_CALL terminator_SubmitDebugUtilsMessageEXT(VkInstance instance, |
276 | | VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, |
277 | | VkDebugUtilsMessageTypeFlagsEXT messageTypes, |
278 | 0 | const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData) { |
279 | 0 | loader_platform_thread_lock_mutex(&loader_lock); |
280 | | // NOTE: Just make the callback ourselves because there could be one or more ICDs that support this extension |
281 | | // and each one will trigger the callback to the user. This would result in multiple callback triggers |
282 | | // per message. Instead, if we get a messaged up to here, then just trigger the message ourselves and |
283 | | // return. This would still allow the ICDs to trigger their own messages, but won't get any external ones. |
284 | 0 | struct loader_instance *inst = (struct loader_instance *)instance; |
285 | 0 | util_SubmitDebugUtilsMessageEXT(inst, messageSeverity, messageTypes, pCallbackData); |
286 | 0 | loader_platform_thread_unlock_mutex(&loader_lock); |
287 | 0 | } |
288 | | |
289 | | // VK_EXT_debug_report related items |
290 | | |
291 | | VkResult util_CreateDebugReportCallback(struct loader_instance *inst, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
292 | 0 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT callback) { |
293 | 0 | VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL; |
294 | |
|
295 | 0 | pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_calloc_with_instance_fallback( |
296 | 0 | pAllocator, inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
297 | 0 | if (!pNewDbgFuncNode) { |
298 | 0 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
299 | 0 | } |
300 | | |
301 | 0 | pNewDbgFuncNode->is_messenger = false; |
302 | 0 | pNewDbgFuncNode->report.msgCallback = callback; |
303 | 0 | pNewDbgFuncNode->report.pfnMsgCallback = pCreateInfo->pfnCallback; |
304 | 0 | pNewDbgFuncNode->report.msgFlags = pCreateInfo->flags; |
305 | 0 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
306 | 0 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
307 | 0 | inst->DbgFunctionHead = pNewDbgFuncNode; |
308 | |
|
309 | 0 | return VK_SUCCESS; |
310 | 0 | } |
311 | | |
312 | | VKAPI_ATTR VkResult VKAPI_CALL debug_utils_CreateDebugReportCallbackEXT(VkInstance instance, |
313 | | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
314 | | const VkAllocationCallbacks *pAllocator, |
315 | 0 | VkDebugReportCallbackEXT *pCallback) { |
316 | 0 | struct loader_instance *inst = loader_get_instance(instance); |
317 | 0 | loader_platform_thread_lock_mutex(&loader_lock); |
318 | 0 | VkResult result = inst->disp->layer_inst_disp.CreateDebugReportCallbackEXT(inst->instance, pCreateInfo, pAllocator, pCallback); |
319 | 0 | loader_platform_thread_unlock_mutex(&loader_lock); |
320 | 0 | return result; |
321 | 0 | } |
322 | | |
323 | | // Utility function to handle reporting |
324 | | VkBool32 util_DebugReportMessage(const struct loader_instance *inst, VkFlags msgFlags, VkDebugReportObjectTypeEXT objectType, |
325 | 0 | uint64_t srcObject, size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
326 | 0 | VkBool32 bail = false; |
327 | 0 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
328 | 0 | VkDebugUtilsMessageSeverityFlagBitsEXT severity; |
329 | 0 | VkDebugUtilsMessageTypeFlagsEXT types; |
330 | 0 | VkDebugUtilsMessengerCallbackDataEXT callback_data; |
331 | 0 | VkDebugUtilsObjectNameInfoEXT object_name; |
332 | |
|
333 | 0 | debug_utils_ReportFlagsToAnnotFlags(msgFlags, false, &severity, &types); |
334 | 0 | debug_utils_ReportObjectToAnnotObject(objectType, srcObject, &object_name); |
335 | |
|
336 | 0 | callback_data.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT; |
337 | 0 | callback_data.pNext = NULL; |
338 | 0 | callback_data.flags = 0; |
339 | 0 | callback_data.pMessageIdName = pLayerPrefix; |
340 | 0 | callback_data.messageIdNumber = msgCode; |
341 | 0 | callback_data.pMessage = pMsg; |
342 | 0 | callback_data.cmdBufLabelCount = 0; |
343 | 0 | callback_data.pCmdBufLabels = NULL; |
344 | 0 | callback_data.queueLabelCount = 0; |
345 | 0 | callback_data.pQueueLabels = NULL; |
346 | 0 | callback_data.objectCount = 1; |
347 | 0 | callback_data.pObjects = &object_name; |
348 | |
|
349 | 0 | while (pTrav) { |
350 | 0 | if (!pTrav->is_messenger && pTrav->report.msgFlags & msgFlags) { |
351 | 0 | if (pTrav->report.pfnMsgCallback(msgFlags, objectType, srcObject, location, msgCode, pLayerPrefix, pMsg, |
352 | 0 | pTrav->pUserData)) { |
353 | 0 | bail = true; |
354 | 0 | } |
355 | 0 | } |
356 | 0 | if (pTrav->is_messenger && (pTrav->messenger.messageSeverity & severity) && (pTrav->messenger.messageType & types)) { |
357 | 0 | if (pTrav->messenger.pfnUserCallback(severity, types, &callback_data, pTrav->pUserData)) { |
358 | 0 | bail = true; |
359 | 0 | } |
360 | 0 | } |
361 | |
|
362 | 0 | pTrav = pTrav->pNext; |
363 | 0 | } |
364 | |
|
365 | 0 | return bail; |
366 | 0 | } |
367 | | |
368 | | void util_DestroyDebugReportCallback(struct loader_instance *inst, VkDebugReportCallbackEXT callback, |
369 | 0 | const VkAllocationCallbacks *pAllocator) { |
370 | 0 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
371 | 0 | VkLayerDbgFunctionNode *pPrev = pTrav; |
372 | |
|
373 | 0 | while (pTrav) { |
374 | 0 | if (!pTrav->is_messenger && pTrav->report.msgCallback == callback) { |
375 | 0 | pPrev->pNext = pTrav->pNext; |
376 | 0 | if (inst->DbgFunctionHead == pTrav) inst->DbgFunctionHead = pTrav->pNext; |
377 | 0 | loader_free_with_instance_fallback(pAllocator, inst, pTrav); |
378 | 0 | break; |
379 | 0 | } |
380 | 0 | pPrev = pTrav; |
381 | 0 | pTrav = pTrav->pNext; |
382 | 0 | } |
383 | 0 | } |
384 | | |
385 | | VkResult util_CreateDebugReportCallbacks(struct loader_instance *inst, const void *pChain, |
386 | 0 | const VkAllocationCallbacks *pAllocator) { |
387 | 0 | const void *pNext = pChain; |
388 | 0 | while (pNext) { |
389 | 0 | if (((VkBaseInStructure *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
390 | | // Assign a unique handle to each callback (just use the address of the VkDebugReportCallbackCreateInfoEXT): |
391 | | // This is only being used this way due to it being for an 'anonymous' callback during instance creation |
392 | 0 | VkDebugReportCallbackEXT report_handle = (VkDebugReportCallbackEXT)(uintptr_t)pNext; |
393 | 0 | VkResult ret = |
394 | 0 | util_CreateDebugReportCallback(inst, (const VkDebugReportCallbackCreateInfoEXT *)pNext, pAllocator, report_handle); |
395 | 0 | if (ret != VK_SUCCESS) { |
396 | 0 | return ret; |
397 | 0 | } |
398 | 0 | } |
399 | 0 | pNext = (void *)((VkBaseInStructure *)pNext)->pNext; |
400 | 0 | } |
401 | 0 | return VK_SUCCESS; |
402 | 0 | } |
403 | | |
404 | | VKAPI_ATTR void VKAPI_CALL debug_utils_DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, |
405 | 0 | const VkAllocationCallbacks *pAllocator) { |
406 | 0 | struct loader_instance *inst = loader_get_instance(instance); |
407 | 0 | loader_platform_thread_lock_mutex(&loader_lock); |
408 | |
|
409 | 0 | inst->disp->layer_inst_disp.DestroyDebugReportCallbackEXT(inst->instance, callback, pAllocator); |
410 | |
|
411 | 0 | loader_platform_thread_unlock_mutex(&loader_lock); |
412 | 0 | } |
413 | | |
414 | | VKAPI_ATTR void VKAPI_CALL debug_utils_DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
415 | | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
416 | 0 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
417 | 0 | struct loader_instance *inst = loader_get_instance(instance); |
418 | |
|
419 | 0 | inst->disp->layer_inst_disp.DebugReportMessageEXT(inst->instance, flags, objType, object, location, msgCode, pLayerPrefix, |
420 | 0 | pMsg); |
421 | 0 | } |
422 | | |
423 | | // This is the instance chain terminator function |
424 | | // for CreateDebugReportCallback |
425 | | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDebugReportCallbackEXT(VkInstance instance, |
426 | | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
427 | | const VkAllocationCallbacks *pAllocator, |
428 | 0 | VkDebugReportCallbackEXT *pCallback) { |
429 | 0 | VkDebugReportCallbackEXT *icd_info = NULL; |
430 | 0 | const struct loader_icd_term *icd_term; |
431 | 0 | struct loader_instance *inst = (struct loader_instance *)instance; |
432 | 0 | VkResult res = VK_SUCCESS; |
433 | 0 | uint32_t storage_idx; |
434 | 0 | VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL; |
435 | |
|
436 | 0 | icd_info = ((VkDebugReportCallbackEXT *)loader_calloc_with_instance_fallback( |
437 | 0 | pAllocator, inst, inst->total_icd_count * sizeof(VkDebugReportCallbackEXT), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)); |
438 | 0 | if (!icd_info) { |
439 | 0 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
440 | 0 | goto out; |
441 | 0 | } |
442 | | |
443 | 0 | storage_idx = 0; |
444 | 0 | for (icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
445 | 0 | if (!icd_term->dispatch.CreateDebugReportCallbackEXT) { |
446 | 0 | continue; |
447 | 0 | } |
448 | | |
449 | 0 | res = icd_term->dispatch.CreateDebugReportCallbackEXT(icd_term->instance, pCreateInfo, pAllocator, &icd_info[storage_idx]); |
450 | |
|
451 | 0 | if (res != VK_SUCCESS) { |
452 | 0 | goto out; |
453 | 0 | } |
454 | 0 | storage_idx++; |
455 | 0 | } |
456 | | |
457 | | // Setup the debug report callback in the terminator since a layer may want |
458 | | // to grab the information itself (RenderDoc) and then return back to the |
459 | | // user callback a sub-set of the messages. |
460 | 0 | pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_calloc_with_instance_fallback( |
461 | 0 | pAllocator, inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
462 | |
|
463 | 0 | if (!pNewDbgFuncNode) { |
464 | 0 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
465 | 0 | goto out; |
466 | 0 | } |
467 | | |
468 | 0 | pNewDbgFuncNode->is_messenger = false; |
469 | 0 | pNewDbgFuncNode->report.pfnMsgCallback = pCreateInfo->pfnCallback; |
470 | 0 | pNewDbgFuncNode->report.msgFlags = pCreateInfo->flags; |
471 | 0 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
472 | 0 | pNewDbgFuncNode->pNext = inst->DbgFunctionHead; |
473 | 0 | inst->DbgFunctionHead = pNewDbgFuncNode; |
474 | |
|
475 | 0 | *(VkDebugReportCallbackEXT **)pCallback = icd_info; |
476 | 0 | pNewDbgFuncNode->report.msgCallback = *pCallback; |
477 | |
|
478 | 0 | out: |
479 | | |
480 | | // Roll back on errors |
481 | 0 | if (VK_SUCCESS != res) { |
482 | 0 | storage_idx = 0; |
483 | 0 | for (icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
484 | 0 | if (NULL == icd_term->dispatch.DestroyDebugReportCallbackEXT) { |
485 | 0 | continue; |
486 | 0 | } |
487 | | |
488 | 0 | if (icd_info && icd_info[storage_idx]) { |
489 | 0 | icd_term->dispatch.DestroyDebugReportCallbackEXT(icd_term->instance, icd_info[storage_idx], pAllocator); |
490 | 0 | } |
491 | 0 | storage_idx++; |
492 | 0 | } |
493 | 0 | loader_free_with_instance_fallback(pAllocator, inst, pNewDbgFuncNode); |
494 | 0 | loader_free_with_instance_fallback(pAllocator, inst, icd_info); |
495 | 0 | } |
496 | |
|
497 | 0 | return res; |
498 | 0 | } |
499 | | |
500 | | // This is the instance chain terminator function for DestroyDebugReportCallback |
501 | | VKAPI_ATTR void VKAPI_CALL terminator_DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, |
502 | 0 | const VkAllocationCallbacks *pAllocator) { |
503 | 0 | uint32_t storage_idx; |
504 | 0 | VkDebugReportCallbackEXT *icd_info; |
505 | 0 | const struct loader_icd_term *icd_term; |
506 | |
|
507 | 0 | struct loader_instance *inst = (struct loader_instance *)instance; |
508 | 0 | icd_info = *(VkDebugReportCallbackEXT **)&callback; |
509 | 0 | storage_idx = 0; |
510 | 0 | for (icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
511 | 0 | if (NULL == icd_term->dispatch.DestroyDebugReportCallbackEXT) { |
512 | 0 | continue; |
513 | 0 | } |
514 | | |
515 | 0 | if (icd_info[storage_idx]) { |
516 | 0 | icd_term->dispatch.DestroyDebugReportCallbackEXT(icd_term->instance, icd_info[storage_idx], pAllocator); |
517 | 0 | } |
518 | 0 | storage_idx++; |
519 | 0 | } |
520 | |
|
521 | 0 | util_DestroyDebugReportCallback(inst, callback, pAllocator); |
522 | |
|
523 | 0 | loader_free_with_instance_fallback(pAllocator, inst, icd_info); |
524 | 0 | } |
525 | | |
526 | | // This is the instance chain terminator function for DebugReportMessage |
527 | | VKAPI_ATTR void VKAPI_CALL terminator_DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, |
528 | | VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, |
529 | 0 | int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
530 | 0 | const struct loader_icd_term *icd_term; |
531 | |
|
532 | 0 | struct loader_instance *inst = (struct loader_instance *)instance; |
533 | |
|
534 | 0 | loader_platform_thread_lock_mutex(&loader_lock); |
535 | 0 | for (icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
536 | 0 | if (icd_term->dispatch.DebugReportMessageEXT != NULL) { |
537 | 0 | icd_term->dispatch.DebugReportMessageEXT(icd_term->instance, flags, objType, object, location, msgCode, pLayerPrefix, |
538 | 0 | pMsg); |
539 | 0 | } |
540 | 0 | } |
541 | | |
542 | | // Now that all ICDs have seen the message, call the necessary callbacks. Ignoring "bail" return value |
543 | | // as there is nothing to bail from at this point. |
544 | |
|
545 | 0 | util_DebugReportMessage(inst, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
546 | |
|
547 | 0 | loader_platform_thread_unlock_mutex(&loader_lock); |
548 | 0 | } |
549 | | |
550 | | // General utilities |
551 | | |
552 | | const VkExtensionProperties debug_utils_extension_info[] = { |
553 | | {VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}, |
554 | | {VK_EXT_DEBUG_UTILS_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_SPEC_VERSION}, |
555 | | }; |
556 | | |
557 | 0 | void destroy_debug_callbacks_chain(struct loader_instance *inst, const VkAllocationCallbacks *pAllocator) { |
558 | 0 | VkLayerDbgFunctionNode *pTrav = inst->DbgFunctionHead; |
559 | 0 | VkLayerDbgFunctionNode *pNext = NULL; |
560 | 0 | while (pTrav) { |
561 | 0 | pNext = pTrav->pNext; |
562 | 0 | loader_free_with_instance_fallback(pAllocator, inst, pTrav); |
563 | 0 | pTrav = pNext; |
564 | 0 | } |
565 | 0 | inst->DbgFunctionHead = NULL; |
566 | 0 | } |
567 | | |
568 | 0 | VkResult add_debug_extensions_to_ext_list(const struct loader_instance *inst, struct loader_extension_list *ext_list) { |
569 | 0 | return loader_add_to_ext_list(inst, ext_list, sizeof(debug_utils_extension_info) / sizeof(VkExtensionProperties), |
570 | 0 | debug_utils_extension_info); |
571 | 0 | } |
572 | | |
573 | 0 | void check_for_enabled_debug_extensions(struct loader_instance *ptr_instance, const VkInstanceCreateInfo *pCreateInfo) { |
574 | 0 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
575 | 0 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0) { |
576 | 0 | ptr_instance->enabled_known_extensions.ext_debug_report = 1; |
577 | 0 | } else if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0) { |
578 | 0 | ptr_instance->enabled_known_extensions.ext_debug_utils = 1; |
579 | 0 | } |
580 | 0 | } |
581 | 0 | } |
582 | | |
583 | 0 | bool debug_extensions_InstanceGpa(struct loader_instance *ptr_instance, const char *name, void **addr) { |
584 | 0 | bool ret_type = false; |
585 | |
|
586 | 0 | *addr = NULL; |
587 | |
|
588 | 0 | if (!strcmp("vkCreateDebugReportCallbackEXT", name)) { |
589 | 0 | *addr = |
590 | 0 | ptr_instance->enabled_known_extensions.ext_debug_report == 1 ? (void *)debug_utils_CreateDebugReportCallbackEXT : NULL; |
591 | 0 | ret_type = true; |
592 | 0 | } else if (!strcmp("vkDestroyDebugReportCallbackEXT", name)) { |
593 | 0 | *addr = |
594 | 0 | ptr_instance->enabled_known_extensions.ext_debug_report == 1 ? (void *)debug_utils_DestroyDebugReportCallbackEXT : NULL; |
595 | 0 | ret_type = true; |
596 | 0 | } else if (!strcmp("vkDebugReportMessageEXT", name)) { |
597 | 0 | *addr = ptr_instance->enabled_known_extensions.ext_debug_report == 1 ? (void *)debug_utils_DebugReportMessageEXT : NULL; |
598 | 0 | return true; |
599 | 0 | } |
600 | 0 | if (!strcmp("vkCreateDebugUtilsMessengerEXT", name)) { |
601 | 0 | *addr = |
602 | 0 | ptr_instance->enabled_known_extensions.ext_debug_utils == 1 ? (void *)debug_utils_CreateDebugUtilsMessengerEXT : NULL; |
603 | 0 | ret_type = true; |
604 | 0 | } else if (!strcmp("vkDestroyDebugUtilsMessengerEXT", name)) { |
605 | 0 | *addr = |
606 | 0 | ptr_instance->enabled_known_extensions.ext_debug_utils == 1 ? (void *)debug_utils_DestroyDebugUtilsMessengerEXT : NULL; |
607 | 0 | ret_type = true; |
608 | 0 | } else if (!strcmp("vkSubmitDebugUtilsMessageEXT", name)) { |
609 | 0 | *addr = ptr_instance->enabled_known_extensions.ext_debug_utils == 1 ? (void *)debug_utils_SubmitDebugUtilsMessageEXT : NULL; |
610 | 0 | ret_type = true; |
611 | 0 | } |
612 | |
|
613 | 0 | return ret_type; |
614 | 0 | } |
615 | | |
616 | | bool debug_utils_ReportFlagsToAnnotFlags(VkDebugReportFlagsEXT dr_flags, bool default_flag_is_spec, |
617 | | VkDebugUtilsMessageSeverityFlagBitsEXT *da_severity, |
618 | 0 | VkDebugUtilsMessageTypeFlagsEXT *da_type) { |
619 | 0 | bool type_set = false; |
620 | 0 | if (NULL == da_severity || NULL == da_type) { |
621 | 0 | return false; |
622 | 0 | } |
623 | 0 | *da_type = 0; |
624 | 0 | *da_severity = 0; |
625 | |
|
626 | 0 | if ((dr_flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) != 0) { |
627 | 0 | *da_severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT; |
628 | 0 | *da_type |= VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT; |
629 | 0 | type_set = true; |
630 | 0 | } else if ((dr_flags & (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)) != 0) { |
631 | 0 | *da_severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT; |
632 | 0 | } else if ((dr_flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) != 0) { |
633 | 0 | *da_severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; |
634 | 0 | } else if ((dr_flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) != 0) { |
635 | 0 | *da_severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT; |
636 | 0 | *da_type |= VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT; |
637 | 0 | type_set = true; |
638 | 0 | } |
639 | |
|
640 | 0 | if ((dr_flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) != 0) { |
641 | 0 | *da_type |= VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; |
642 | 0 | } else if (!type_set) { |
643 | 0 | if (default_flag_is_spec) { |
644 | 0 | *da_type |= VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT; |
645 | 0 | } else { |
646 | 0 | *da_type |= VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT; |
647 | 0 | } |
648 | 0 | } |
649 | |
|
650 | 0 | return true; |
651 | 0 | } |
652 | | |
653 | | bool debug_utils_AnnotFlagsToReportFlags(VkDebugUtilsMessageSeverityFlagBitsEXT da_severity, |
654 | 0 | VkDebugUtilsMessageTypeFlagsEXT da_type, VkDebugReportFlagsEXT *dr_flags) { |
655 | 0 | if (NULL == dr_flags) { |
656 | 0 | return false; |
657 | 0 | } |
658 | | |
659 | 0 | *dr_flags = 0; |
660 | |
|
661 | 0 | if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) != 0) { |
662 | 0 | *dr_flags |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
663 | 0 | } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) != 0) { |
664 | 0 | if ((da_type & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) != 0) { |
665 | 0 | *dr_flags |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
666 | 0 | } else { |
667 | 0 | *dr_flags |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
668 | 0 | } |
669 | 0 | } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) != 0) { |
670 | 0 | *dr_flags |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
671 | 0 | } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) != 0) { |
672 | 0 | *dr_flags |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
673 | 0 | } |
674 | |
|
675 | 0 | return true; |
676 | 0 | } |
677 | | |
678 | | bool debug_utils_ReportObjectToAnnotObject(VkDebugReportObjectTypeEXT dr_object_type, uint64_t object_handle, |
679 | 0 | VkDebugUtilsObjectNameInfoEXT *da_object_name_info) { |
680 | 0 | if (NULL == da_object_name_info) { |
681 | 0 | return false; |
682 | 0 | } |
683 | 0 | da_object_name_info->sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; |
684 | 0 | da_object_name_info->pNext = NULL; |
685 | 0 | da_object_name_info->objectHandle = (uint64_t)(uintptr_t)object_handle; |
686 | 0 | da_object_name_info->pObjectName = NULL; |
687 | 0 | da_object_name_info->objectType = convertDebugReportObjectToCoreObject(dr_object_type); |
688 | 0 | return true; |
689 | 0 | } |
690 | | |
691 | | bool debug_utils_AnnotObjectToDebugReportObject(const VkDebugUtilsObjectNameInfoEXT *da_object_name_info, |
692 | 0 | VkDebugReportObjectTypeEXT *dr_object_type, uint64_t *dr_object_handle) { |
693 | 0 | if (NULL == da_object_name_info || NULL == dr_object_type || NULL == dr_object_handle) { |
694 | 0 | return false; |
695 | 0 | } |
696 | 0 | *dr_object_type = convertCoreObjectToDebugReportObject(da_object_name_info->objectType); |
697 | 0 | *dr_object_handle = da_object_name_info->objectHandle; |
698 | 0 | return true; |
699 | 0 | } |