blob: bcc9b30102e4cee8941d1b02010fcc9f1c00c3ca [file] [log] [blame]
Mark Young6ba8abe2017-11-09 10:37:04 -07001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 LunarG, Inc.
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -06004 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -06008 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06009 * http://www.apache.org/licenses/LICENSE-2.0
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060016 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060017 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
18 * Author: Tobin Ehlis <tobin@lunarg.com>
Mark Young6ba8abe2017-11-09 10:37:04 -070019 * Author: Mark Young <marky@lunarg.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060020 *
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060021 */
22
23#ifndef LAYER_LOGGING_H
24#define LAYER_LOGGING_H
25
Mark Lobodzinskib87f9022016-05-24 16:04:56 -060026#include "vk_loader_layer.h"
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060027#include "vk_layer_config.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060028#include "vk_layer_data.h"
29#include "vk_layer_table.h"
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060030#include "vk_loader_platform.h"
31#include "vulkan/vk_layer.h"
Mark Young6ba8abe2017-11-09 10:37:04 -070032#include "vk_object_types.h"
Mark Lobodzinski487a0d12018-03-30 10:09:03 -060033#include "vk_validation_error_messages.h"
Mark Lobodzinskic9d81652017-08-10 11:01:17 -060034#include <signal.h>
Karl Schultzd7f37542016-05-10 11:36:08 -060035#include <cinttypes>
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060036#include <stdarg.h>
37#include <stdbool.h>
38#include <stdio.h>
39#include <unordered_map>
Mark Lobodzinski97c4d512016-05-19 15:27:18 -060040#include <vector>
Mark Young6ba8abe2017-11-09 10:37:04 -070041#include <sstream>
42#include <string>
43
44// TODO: Could be autogenerated for the specific handles for extra type safety...
45template <typename HANDLE_T>
46static inline uint64_t HandleToUint64(HANDLE_T *h) {
47 return reinterpret_cast<uint64_t>(h);
48}
49
50static inline uint64_t HandleToUint64(uint64_t h) { return h; }
51
52// Data we store per label for logging
53typedef struct _LoggingLabelData {
54 std::string name;
55 float color[4];
56} LoggingLabelData;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060057
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060058typedef struct _debug_report_data {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -060059 VkLayerDbgFunctionNode *debug_callback_list;
60 VkLayerDbgFunctionNode *default_debug_callback_list;
Mark Young6ba8abe2017-11-09 10:37:04 -070061 VkDebugUtilsMessageSeverityFlagsEXT active_severities;
62 VkDebugUtilsMessageTypeFlagsEXT active_types;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060063 bool g_DEBUG_REPORT;
Mark Young6ba8abe2017-11-09 10:37:04 -070064 bool g_DEBUG_UTILS;
Tony Barbour3431dac2017-06-19 16:50:37 -060065 std::unordered_map<uint64_t, std::string> *debugObjectNameMap;
Mark Young6ba8abe2017-11-09 10:37:04 -070066 std::unordered_map<uint64_t, std::string> *debugUtilsObjectNameMap;
67 std::unordered_map<VkQueue, std::vector<LoggingLabelData>> *debugUtilsQueueLabels;
68 bool queueLabelHasInsert;
69 std::unordered_map<VkCommandBuffer, std::vector<LoggingLabelData>> *debugUtilsCmdBufLabels;
70 bool cmdBufLabelHasInsert;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060071} debug_report_data;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060072
Tobin Ehlis8d6acde2017-02-08 07:40:40 -070073template debug_report_data *GetLayerDataPtr<debug_report_data>(void *data_key,
Jon Ashburn5484e0c2016-03-08 17:48:44 -070074 std::unordered_map<void *, debug_report_data *> &data_map);
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060075
Mark Young6ba8abe2017-11-09 10:37:04 -070076static inline void DebugReportFlagsToAnnotFlags(VkDebugReportFlagsEXT dr_flags, bool default_flag_is_spec,
77 VkDebugUtilsMessageSeverityFlagsEXT *da_severity,
78 VkDebugUtilsMessageTypeFlagsEXT *da_type) {
79 // All layer warnings are spec warnings currently. At least as far as anything not specifically
80 // called out. In the future, we'll label things using the new split severity and type values.
81 *da_type = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
82 *da_severity = 0;
83 if ((dr_flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) != 0) {
84 *da_severity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT;
85 *da_type |= VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT;
86 }
87 if ((dr_flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) != 0) {
88 *da_severity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT;
89 *da_type |= VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT;
90 }
91 if ((dr_flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) != 0) {
92 *da_severity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
93 *da_type |= VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
94 }
95 if ((dr_flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) != 0) {
96 *da_severity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
97 }
98 if ((dr_flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) != 0) {
99 *da_severity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
100 }
101}
102
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600103// Forward Declarations
Mark Young6ba8abe2017-11-09 10:37:04 -0700104static inline bool debug_log_msg(const debug_report_data *debug_data, VkFlags msg_flags, VkDebugReportObjectTypeEXT object_type,
105 uint64_t src_object, size_t location, int32_t msg_code, const char *layer_prefix,
106 const char *message);
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600107
108// Add a debug message callback node structure to the specified callback linked list
Mark Young6ba8abe2017-11-09 10:37:04 -0700109static inline void AddDebugCallbackNode(debug_report_data *debug_data, VkLayerDbgFunctionNode **list_head,
110 VkLayerDbgFunctionNode *new_node) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600111 new_node->pNext = *list_head;
112 *list_head = new_node;
113}
114
Mark Young6ba8abe2017-11-09 10:37:04 -0700115// Remove specified debug messenger node structure from the specified linked list
116static inline void RemoveDebugUtilsMessenger(debug_report_data *debug_data, VkLayerDbgFunctionNode **list_head,
117 VkDebugUtilsMessengerEXT messenger) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600118 VkLayerDbgFunctionNode *cur_callback = *list_head;
119 VkLayerDbgFunctionNode *prev_callback = cur_callback;
120 bool matched = false;
Mark Young6ba8abe2017-11-09 10:37:04 -0700121 VkFlags local_severities = 0;
122 VkFlags local_types = 0;
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600123
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600124 while (cur_callback) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700125 if (cur_callback->is_messenger && cur_callback->messenger.messenger == messenger) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600126 matched = true;
127 prev_callback->pNext = cur_callback->pNext;
128 if (*list_head == cur_callback) {
129 *list_head = cur_callback->pNext;
130 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700131 debug_log_msg(debug_data, VK_DEBUG_REPORT_DEBUG_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT,
132 reinterpret_cast<uint64_t &>(cur_callback->messenger.messenger), 0, 0, "DebugUtilsMessenger",
133 "Destroyed messenger\n");
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600134 } else {
135 matched = false;
Mark Young6ba8abe2017-11-09 10:37:04 -0700136 local_severities |= cur_callback->messenger.messageSeverity;
137 local_types |= cur_callback->messenger.messageType;
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600138 }
139 prev_callback = cur_callback;
140 cur_callback = cur_callback->pNext;
141 if (matched) {
142 free(prev_callback);
143 }
144 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700145 debug_data->active_severities = local_severities;
146 debug_data->active_types = local_types;
147}
148
149// Remove specified debug message callback node structure from the specified callback linked list
150static inline void RemoveDebugUtilsMessageCallback(debug_report_data *debug_data, VkLayerDbgFunctionNode **list_head,
151 VkDebugReportCallbackEXT callback) {
152 VkLayerDbgFunctionNode *cur_callback = *list_head;
153 VkLayerDbgFunctionNode *prev_callback = cur_callback;
154 bool matched = false;
155 VkFlags local_severities = 0;
156 VkFlags local_types = 0;
157
158 while (cur_callback) {
159 if (!cur_callback->is_messenger && cur_callback->report.msgCallback == callback) {
160 matched = true;
161 prev_callback->pNext = cur_callback->pNext;
162 if (*list_head == cur_callback) {
163 *list_head = cur_callback->pNext;
164 }
165 debug_log_msg(debug_data, VK_DEBUG_REPORT_DEBUG_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT,
166 reinterpret_cast<uint64_t &>(cur_callback->report.msgCallback), 0, 0, "DebugReport",
167 "Destroyed callback\n");
168 } else {
169 matched = false;
170 VkFlags this_severities = 0;
171 VkFlags this_types = 0;
172 DebugReportFlagsToAnnotFlags(cur_callback->report.msgFlags, true, &this_severities, &this_types);
173 local_severities |= this_severities;
174 local_types |= this_types;
175 }
176 prev_callback = cur_callback;
177 cur_callback = cur_callback->pNext;
178 if (matched) {
179 free(prev_callback);
180 }
181 }
182 debug_data->active_severities = local_severities;
183 debug_data->active_types = local_types;
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600184}
185
186// Removes all debug callback function nodes from the specified callback linked lists and frees their resources
187static inline void RemoveAllMessageCallbacks(debug_report_data *debug_data, VkLayerDbgFunctionNode **list_head) {
188 VkLayerDbgFunctionNode *current_callback = *list_head;
189 VkLayerDbgFunctionNode *prev_callback = current_callback;
190
191 while (current_callback) {
192 prev_callback = current_callback->pNext;
Mark Young6ba8abe2017-11-09 10:37:04 -0700193 if (!current_callback->is_messenger) {
194 debug_log_msg(debug_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT,
195 (uint64_t)current_callback->report.msgCallback, 0, 0, "DebugReport",
196 "Debug Report callbacks not removed before DestroyInstance");
197 } else {
198 debug_log_msg(debug_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT,
199 (uint64_t)current_callback->messenger.messenger, 0, 0, "Messenger",
200 "Debug messengers not removed before DestroyInstance");
201 }
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600202 free(current_callback);
203 current_callback = prev_callback;
204 }
205 *list_head = NULL;
206}
207
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600208// Utility function to handle reporting
Mark Young6ba8abe2017-11-09 10:37:04 -0700209static inline bool debug_log_msg(const debug_report_data *debug_data, VkFlags msg_flags, VkDebugReportObjectTypeEXT object_type,
210 uint64_t src_object, size_t location, int32_t msg_code, const char *layer_prefix,
211 const char *message) {
Dustin Graves8f1eab92016-04-05 09:41:17 -0600212 bool bail = false;
Mark Young6ba8abe2017-11-09 10:37:04 -0700213 VkLayerDbgFunctionNode *layer_dbg_node = NULL;
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600214
Mark Lobodzinski55a197f2016-06-21 15:54:57 -0600215 if (debug_data->debug_callback_list != NULL) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700216 layer_dbg_node = debug_data->debug_callback_list;
Mark Lobodzinski55a197f2016-06-21 15:54:57 -0600217 } else {
Mark Young6ba8abe2017-11-09 10:37:04 -0700218 layer_dbg_node = debug_data->default_debug_callback_list;
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600219 }
220
Mark Young6ba8abe2017-11-09 10:37:04 -0700221 VkDebugUtilsMessageSeverityFlagsEXT severity;
222 VkDebugUtilsMessageTypeFlagsEXT types;
223 VkDebugUtilsMessengerCallbackDataEXT callback_data;
224 VkDebugUtilsObjectNameInfoEXT object_name_info;
225
226 // Convert the info to the VK_EXT_debug_utils form in case we need it.
227 DebugReportFlagsToAnnotFlags(msg_flags, true, &severity, &types);
228 object_name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
229 object_name_info.pNext = NULL;
230 object_name_info.objectType = convertDebugReportObjectToCoreObject(object_type);
231 object_name_info.objectHandle = (uint64_t)(uintptr_t)src_object;
232 object_name_info.pObjectName = NULL;
233
234 callback_data.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT;
235 callback_data.pNext = NULL;
236 callback_data.flags = 0;
237 callback_data.pMessageIdName = layer_prefix;
238 callback_data.messageIdNumber = msg_code;
239 callback_data.pMessage = message;
240 callback_data.queueLabelCount = 0;
241 callback_data.pQueueLabels = NULL;
242 callback_data.cmdBufLabelCount = 0;
243 callback_data.pCmdBufLabels = NULL;
244 callback_data.objectCount = 1;
245 callback_data.pObjects = &object_name_info;
246
247 VkDebugUtilsLabelEXT *queue_labels = nullptr;
248 VkDebugUtilsLabelEXT *cmd_buf_labels = nullptr;
249 std::string new_debug_report_message = "";
250 std::ostringstream oss;
Mark Young6ba8abe2017-11-09 10:37:04 -0700251
252 if (0 != src_object) {
Mark Young8504ba62018-03-21 13:35:34 -0600253 oss << "Object: 0x" << std::hex << src_object;
Mark Young6ba8abe2017-11-09 10:37:04 -0700254 // If this is a queue, add any queue labels to the callback data.
255 if (VK_OBJECT_TYPE_QUEUE == object_name_info.objectType) {
256 auto label_iter = debug_data->debugUtilsQueueLabels->find(reinterpret_cast<VkQueue>(src_object));
257 if (label_iter != debug_data->debugUtilsQueueLabels->end()) {
258 queue_labels = new VkDebugUtilsLabelEXT[label_iter->second.size()];
259 if (nullptr != queue_labels) {
260 // Record the labels, but record them in reverse order since we want the
261 // most recent at the top.
262 uint32_t label_size = static_cast<uint32_t>(label_iter->second.size());
263 uint32_t last_index = label_size - 1;
264 for (uint32_t label = 0; label < label_size; ++label) {
265 queue_labels[last_index - label].sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
266 queue_labels[last_index - label].pNext = nullptr;
267 queue_labels[last_index - label].pLabelName = label_iter->second[label].name.c_str();
268 queue_labels[last_index - label].color[0] = label_iter->second[label].color[0];
269 queue_labels[last_index - label].color[1] = label_iter->second[label].color[1];
270 queue_labels[last_index - label].color[2] = label_iter->second[label].color[2];
271 queue_labels[last_index - label].color[3] = label_iter->second[label].color[3];
272 }
273 callback_data.queueLabelCount = label_size;
274 callback_data.pQueueLabels = queue_labels;
275 }
276 }
277 // If this is a command buffer, add any command buffer labels to the callback data.
278 } else if (VK_OBJECT_TYPE_COMMAND_BUFFER == object_name_info.objectType) {
279 auto label_iter = debug_data->debugUtilsCmdBufLabels->find(reinterpret_cast<VkCommandBuffer>(src_object));
280 if (label_iter != debug_data->debugUtilsCmdBufLabels->end()) {
281 cmd_buf_labels = new VkDebugUtilsLabelEXT[label_iter->second.size()];
282 if (nullptr != cmd_buf_labels) {
283 // Record the labels, but record them in reverse order since we want the
284 // most recent at the top.
285 uint32_t label_size = static_cast<uint32_t>(label_iter->second.size());
286 uint32_t last_index = label_size - 1;
287 for (uint32_t label = 0; label < label_size; ++label) {
288 cmd_buf_labels[last_index - label].sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
289 cmd_buf_labels[last_index - label].pNext = nullptr;
290 cmd_buf_labels[last_index - label].pLabelName = label_iter->second[label].name.c_str();
291 cmd_buf_labels[last_index - label].color[0] = label_iter->second[label].color[0];
292 cmd_buf_labels[last_index - label].color[1] = label_iter->second[label].color[1];
293 cmd_buf_labels[last_index - label].color[2] = label_iter->second[label].color[2];
294 cmd_buf_labels[last_index - label].color[3] = label_iter->second[label].color[3];
295 }
296 callback_data.cmdBufLabelCount = label_size;
297 callback_data.pCmdBufLabels = cmd_buf_labels;
298 }
299 }
300 }
301 // Look for any debug utils or marker names to use for this object
302 callback_data.pObjects[0].pObjectName = NULL;
303 auto utils_name_iter = debug_data->debugUtilsObjectNameMap->find(src_object);
304 if (utils_name_iter != debug_data->debugUtilsObjectNameMap->end()) {
305 callback_data.pObjects[0].pObjectName = utils_name_iter->second.c_str();
306 } else {
307 auto marker_name_iter = debug_data->debugObjectNameMap->find(src_object);
308 if (marker_name_iter != debug_data->debugObjectNameMap->end()) {
309 callback_data.pObjects[0].pObjectName = marker_name_iter->second.c_str();
310 }
311 }
312 if (NULL != callback_data.pObjects[0].pObjectName) {
Mark Young8504ba62018-03-21 13:35:34 -0600313 oss << " (Name = " << callback_data.pObjects[0].pObjectName << " : Type = ";
314 } else {
315 oss << " (Type = ";
Mark Young6ba8abe2017-11-09 10:37:04 -0700316 }
Mark Young8504ba62018-03-21 13:35:34 -0600317 oss << std::to_string(object_type) << ")";
318 } else {
319 oss << "Object: VK_NULL_HANDLE (Type = " << std::to_string(object_type) << ")";
Mark Young6ba8abe2017-11-09 10:37:04 -0700320 }
321 new_debug_report_message += oss.str();
322 new_debug_report_message += " | ";
323 new_debug_report_message += message;
324
325 while (layer_dbg_node) {
Mark Young8504ba62018-03-21 13:35:34 -0600326 // If the app uses the VK_EXT_debug_report extension, call all of those registered callbacks.
Mark Young6ba8abe2017-11-09 10:37:04 -0700327 if (!layer_dbg_node->is_messenger && (layer_dbg_node->report.msgFlags & msg_flags) &&
328 layer_dbg_node->report.pfnMsgCallback(msg_flags, object_type, src_object, location, msg_code, layer_prefix,
329 new_debug_report_message.c_str(), layer_dbg_node->pUserData)) {
330 bail = true;
Mark Young8504ba62018-03-21 13:35:34 -0600331 // If the app uses the VK_EXT_debug_utils extension, call all of those registered callbacks.
Mark Young6ba8abe2017-11-09 10:37:04 -0700332 } else if (layer_dbg_node->is_messenger && (layer_dbg_node->messenger.messageSeverity & severity) &&
333 (layer_dbg_node->messenger.messageType & types) &&
334 layer_dbg_node->messenger.pfnUserCallback(static_cast<VkDebugUtilsMessageSeverityFlagBitsEXT>(severity), types,
335 &callback_data, layer_dbg_node->pUserData)) {
336 bail = true;
337 }
338 layer_dbg_node = layer_dbg_node->pNext;
339 }
340
341 if (nullptr != queue_labels) {
342 delete[] queue_labels;
343 }
344 if (nullptr != cmd_buf_labels) {
345 delete[] cmd_buf_labels;
346 }
347
348 return bail;
349}
350
351static inline void DebugAnnotFlagsToReportFlags(VkDebugUtilsMessageSeverityFlagBitsEXT da_severity,
352 VkDebugUtilsMessageTypeFlagsEXT da_type, VkDebugReportFlagsEXT *dr_flags) {
353 *dr_flags = 0;
354
355 if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) != 0) {
356 *dr_flags |= VK_DEBUG_REPORT_ERROR_BIT_EXT;
357 } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) != 0) {
358 if ((da_type & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) != 0) {
359 *dr_flags |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
360 } else {
361 *dr_flags |= VK_DEBUG_REPORT_WARNING_BIT_EXT;
362 }
363 } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) != 0) {
364 *dr_flags |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
365 } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) != 0) {
366 *dr_flags |= VK_DEBUG_REPORT_DEBUG_BIT_EXT;
367 }
368}
369
370static inline bool debug_messenger_log_msg(const debug_report_data *debug_data,
371 VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
372 VkDebugUtilsMessageTypeFlagsEXT message_type,
373 VkDebugUtilsMessengerCallbackDataEXT *callback_data) {
374 bool bail = false;
375 VkLayerDbgFunctionNode *layer_dbg_node = NULL;
376
377 if (debug_data->debug_callback_list != NULL) {
378 layer_dbg_node = debug_data->debug_callback_list;
379 } else {
380 layer_dbg_node = debug_data->default_debug_callback_list;
381 }
382
383 VkDebugReportFlagsEXT object_flags = 0;
384
385 DebugAnnotFlagsToReportFlags(message_severity, message_type, &object_flags);
386
387 while (layer_dbg_node) {
388 if (layer_dbg_node->is_messenger && (layer_dbg_node->messenger.messageSeverity & message_severity) &&
389 (layer_dbg_node->messenger.messageType & message_type)) {
390 // Loop through each object and give it the proper name if it was set.
391 for (uint32_t obj = 0; obj < callback_data->objectCount; obj++) {
392 auto it = debug_data->debugUtilsObjectNameMap->find(callback_data->pObjects[obj].objectHandle);
393 if (it == debug_data->debugUtilsObjectNameMap->end()) {
394 continue;
395 }
396 callback_data->pObjects[obj].pObjectName = it->second.c_str();
397 }
398 if (layer_dbg_node->messenger.pfnUserCallback(message_severity, message_type, callback_data,
399 layer_dbg_node->pUserData)) {
400 bail = true;
401 }
402 } else if (!layer_dbg_node->is_messenger && layer_dbg_node->report.msgFlags & object_flags) {
403 auto it = debug_data->debugObjectNameMap->find(callback_data->pObjects[0].objectHandle);
404 VkDebugReportObjectTypeEXT object_type = get_debug_report_enum[callback_data->pObjects[0].objectType];
Tony Barbour3431dac2017-06-19 16:50:37 -0600405 if (it == debug_data->debugObjectNameMap->end()) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700406 if (layer_dbg_node->report.pfnMsgCallback(object_flags, object_type, callback_data->pObjects[0].objectHandle, 0,
407 callback_data->messageIdNumber, callback_data->pMessageIdName,
408 callback_data->pMessage, layer_dbg_node->pUserData)) {
Tony Barbour3431dac2017-06-19 16:50:37 -0600409 bail = true;
410 }
411 } else {
412 std::string newMsg = "SrcObject name = ";
413 newMsg.append(it->second.c_str());
414 newMsg.append(" ");
Mark Young6ba8abe2017-11-09 10:37:04 -0700415 newMsg.append(callback_data->pMessage);
416 if (layer_dbg_node->report.pfnMsgCallback(object_flags, object_type, callback_data->pObjects[0].objectHandle, 0,
417 callback_data->messageIdNumber, callback_data->pMessageIdName,
418 newMsg.c_str(), layer_dbg_node->pUserData)) {
Tony Barbour3431dac2017-06-19 16:50:37 -0600419 bail = true;
420 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600421 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600422 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700423 layer_dbg_node = layer_dbg_node->pNext;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600424 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600425
426 return bail;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600427}
428
Mark Young6ba8abe2017-11-09 10:37:04 -0700429static inline debug_report_data *debug_utils_create_instance(
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700430 VkLayerInstanceDispatchTable *table, VkInstance inst, uint32_t extension_count,
Mark Young6ba8abe2017-11-09 10:37:04 -0700431 const char *const *enabled_extensions) // layer or extension name to be enabled
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600432{
Mark Youngaa1aa3a2016-07-05 16:41:50 -0600433 debug_report_data *debug_data = (debug_report_data *)malloc(sizeof(debug_report_data));
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700434 if (!debug_data) return NULL;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600435
436 memset(debug_data, 0, sizeof(debug_report_data));
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600437 for (uint32_t i = 0; i < extension_count; i++) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600438 // TODO: Check other property fields
Mark Young6ba8abe2017-11-09 10:37:04 -0700439 if (strcmp(enabled_extensions[i], VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0) {
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600440 debug_data->g_DEBUG_REPORT = true;
Mark Young6ba8abe2017-11-09 10:37:04 -0700441 } else if (strcmp(enabled_extensions[i], VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0) {
442 debug_data->g_DEBUG_UTILS = true;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600443 }
444 }
Tony Barbour3431dac2017-06-19 16:50:37 -0600445 debug_data->debugObjectNameMap = new std::unordered_map<uint64_t, std::string>;
Mark Young6ba8abe2017-11-09 10:37:04 -0700446 debug_data->debugUtilsObjectNameMap = new std::unordered_map<uint64_t, std::string>;
447 debug_data->debugUtilsQueueLabels = new std::unordered_map<VkQueue, std::vector<LoggingLabelData>>;
448 debug_data->debugUtilsCmdBufLabels = new std::unordered_map<VkCommandBuffer, std::vector<LoggingLabelData>>;
449 debug_data->queueLabelHasInsert = false;
450 debug_data->cmdBufLabelHasInsert = false;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600451 return debug_data;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600452}
453
Mark Young6ba8abe2017-11-09 10:37:04 -0700454static inline void layer_debug_utils_destroy_instance(debug_report_data *debug_data) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600455 if (debug_data) {
456 RemoveAllMessageCallbacks(debug_data, &debug_data->default_debug_callback_list);
457 RemoveAllMessageCallbacks(debug_data, &debug_data->debug_callback_list);
Tony Barbour3431dac2017-06-19 16:50:37 -0600458 delete debug_data->debugObjectNameMap;
Mark Young6ba8abe2017-11-09 10:37:04 -0700459 delete debug_data->debugUtilsObjectNameMap;
460 delete debug_data->debugUtilsQueueLabels;
461 delete debug_data->debugUtilsCmdBufLabels;
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600462 free(debug_data);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600463 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600464}
465
Mark Young6ba8abe2017-11-09 10:37:04 -0700466static inline debug_report_data *layer_debug_utils_create_device(debug_report_data *instance_debug_data, VkDevice device) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600467 // DEBUG_REPORT shares data between Instance and Device,
468 // so just return instance's data pointer
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600469 return instance_debug_data;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600470}
471
Mark Young6ba8abe2017-11-09 10:37:04 -0700472static inline void layer_debug_utils_destroy_device(VkDevice device) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600473 // Nothing to do since we're using instance data record
474}
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600475
Mark Young6ba8abe2017-11-09 10:37:04 -0700476static inline void layer_destroy_messenger_callback(debug_report_data *debug_data, VkDebugUtilsMessengerEXT messenger,
477 const VkAllocationCallbacks *allocator) {
478 RemoveDebugUtilsMessenger(debug_data, &debug_data->debug_callback_list, messenger);
479 RemoveDebugUtilsMessenger(debug_data, &debug_data->default_debug_callback_list, messenger);
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600480}
481
Mark Young6ba8abe2017-11-09 10:37:04 -0700482static inline VkResult layer_create_messenger_callback(debug_report_data *debug_data, bool default_callback,
483 const VkDebugUtilsMessengerCreateInfoEXT *create_info,
484 const VkAllocationCallbacks *allocator,
485 VkDebugUtilsMessengerEXT *messenger) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700486 VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode *)malloc(sizeof(VkLayerDbgFunctionNode));
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700487 if (!pNewDbgFuncNode) return VK_ERROR_OUT_OF_HOST_MEMORY;
Mark Young6ba8abe2017-11-09 10:37:04 -0700488 memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode));
489 pNewDbgFuncNode->is_messenger = true;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600490
Tobin Ehliseb7715d2015-09-21 09:36:47 -0600491 // Handle of 0 is logging_callback so use allocated Node address as unique handle
Mark Young6ba8abe2017-11-09 10:37:04 -0700492 if (!(*messenger)) *messenger = (VkDebugUtilsMessengerEXT)pNewDbgFuncNode;
493 pNewDbgFuncNode->messenger.messenger = *messenger;
494 pNewDbgFuncNode->messenger.pfnUserCallback = create_info->pfnUserCallback;
495 pNewDbgFuncNode->messenger.messageSeverity = create_info->messageSeverity;
496 pNewDbgFuncNode->messenger.messageType = create_info->messageType;
497 pNewDbgFuncNode->pUserData = create_info->pUserData;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600498
Mark Young6ba8abe2017-11-09 10:37:04 -0700499 debug_data->active_severities |= create_info->messageSeverity;
500 debug_data->active_types |= create_info->messageType;
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600501 if (default_callback) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700502 AddDebugCallbackNode(debug_data, &debug_data->default_debug_callback_list, pNewDbgFuncNode);
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600503 } else {
Mark Young6ba8abe2017-11-09 10:37:04 -0700504 AddDebugCallbackNode(debug_data, &debug_data->debug_callback_list, pNewDbgFuncNode);
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600505 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600506
Mark Young6ba8abe2017-11-09 10:37:04 -0700507 VkDebugUtilsMessengerCallbackDataEXT callback_data = {};
508 VkDebugUtilsObjectNameInfoEXT blank_object = {};
509 callback_data.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT;
510 callback_data.pNext = NULL;
511 callback_data.flags = 0;
512 callback_data.pMessageIdName = "Layer Internal Message";
513 callback_data.messageIdNumber = 0;
514 callback_data.pMessage = "Added messenger";
515 callback_data.queueLabelCount = 0;
516 callback_data.pQueueLabels = NULL;
517 callback_data.cmdBufLabelCount = 0;
518 callback_data.pCmdBufLabels = NULL;
519 callback_data.objectCount = 1;
520 callback_data.pObjects = &blank_object;
521 blank_object.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
522 blank_object.pNext = NULL;
523 blank_object.objectType = VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT;
524 blank_object.objectHandle = HandleToUint64(*messenger);
525 blank_object.pObjectName = NULL;
526 debug_messenger_log_msg(debug_data, VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT,
527 VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT, &callback_data);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600528 return VK_SUCCESS;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600529}
530
Mark Young6ba8abe2017-11-09 10:37:04 -0700531static inline void layer_destroy_report_callback(debug_report_data *debug_data, VkDebugReportCallbackEXT callback,
532 const VkAllocationCallbacks *allocator) {
533 RemoveDebugUtilsMessageCallback(debug_data, &debug_data->debug_callback_list, callback);
534 RemoveDebugUtilsMessageCallback(debug_data, &debug_data->default_debug_callback_list, callback);
535}
536
537static inline VkResult layer_create_report_callback(debug_report_data *debug_data, bool default_callback,
538 const VkDebugReportCallbackCreateInfoEXT *create_info,
539 const VkAllocationCallbacks *allocator, VkDebugReportCallbackEXT *callback) {
540 VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode *)malloc(sizeof(VkLayerDbgFunctionNode));
541 if (!pNewDbgFuncNode) {
542 return VK_ERROR_OUT_OF_HOST_MEMORY;
543 }
544 memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode));
545 pNewDbgFuncNode->is_messenger = false;
546
547 // Handle of 0 is logging_callback so use allocated Node address as unique handle
548 if (!(*callback)) *callback = (VkDebugReportCallbackEXT)pNewDbgFuncNode;
549 pNewDbgFuncNode->report.msgCallback = *callback;
550 pNewDbgFuncNode->report.pfnMsgCallback = create_info->pfnCallback;
551 pNewDbgFuncNode->report.msgFlags = create_info->flags;
552 pNewDbgFuncNode->pUserData = create_info->pUserData;
553
554 VkFlags local_severity = 0;
555 VkFlags local_type = 0;
556 DebugReportFlagsToAnnotFlags(create_info->flags, true, &local_severity, &local_type);
557 debug_data->active_severities |= local_severity;
558 debug_data->active_types |= local_type;
559 if (default_callback) {
560 AddDebugCallbackNode(debug_data, &debug_data->default_debug_callback_list, pNewDbgFuncNode);
561 } else {
562 AddDebugCallbackNode(debug_data, &debug_data->debug_callback_list, pNewDbgFuncNode);
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600563 }
564
Mark Young6ba8abe2017-11-09 10:37:04 -0700565 debug_log_msg(debug_data, VK_DEBUG_REPORT_DEBUG_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, (uint64_t)*callback, 0,
566 0, "DebugReport", "Added callback");
567 return VK_SUCCESS;
568}
569
570static inline PFN_vkVoidFunction debug_utils_get_instance_proc_addr(debug_report_data *debug_data, const char *func_name) {
571 if (!debug_data) {
572 return NULL;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600573 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700574 if (debug_data->g_DEBUG_REPORT) {
575 if (!strcmp(func_name, "vkCreateDebugReportCallbackEXT")) {
576 return (PFN_vkVoidFunction)vkCreateDebugReportCallbackEXT;
577 }
578 if (!strcmp(func_name, "vkDestroyDebugReportCallbackEXT")) {
579 return (PFN_vkVoidFunction)vkDestroyDebugReportCallbackEXT;
580 }
581 if (!strcmp(func_name, "vkDebugReportMessageEXT")) {
582 return (PFN_vkVoidFunction)vkDebugReportMessageEXT;
583 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600584 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700585 if (debug_data->g_DEBUG_UTILS) {
586 if (!strcmp(func_name, "vkCreateDebugUtilsMessengerEXT")) {
587 return (PFN_vkVoidFunction)vkCreateDebugUtilsMessengerEXT;
588 }
589 if (!strcmp(func_name, "vkDestroyDebugUtilsMessengerEXT")) {
590 return (PFN_vkVoidFunction)vkDestroyDebugUtilsMessengerEXT;
591 }
592 if (!strcmp(func_name, "vkSubmitDebugUtilsMessageEXT")) {
593 return (PFN_vkVoidFunction)vkSubmitDebugUtilsMessageEXT;
594 }
Courtney Goeltzenleuchter822e8d72015-11-30 15:28:25 -0700595 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600596 return NULL;
597}
598
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600599// This utility (called at vkCreateInstance() time), looks at a pNext chain.
600// It counts any VkDebugReportCallbackCreateInfoEXT structs that it finds. It
601// then allocates an array that can hold that many structs, as well as that
602// many VkDebugReportCallbackEXT handles. It then copies each
603// VkDebugReportCallbackCreateInfoEXT, and initializes each handle.
Mark Young6ba8abe2017-11-09 10:37:04 -0700604static inline VkResult layer_copy_tmp_report_callbacks(const void *pChain, uint32_t *num_callbacks,
605 VkDebugReportCallbackCreateInfoEXT **infos,
606 VkDebugReportCallbackEXT **callbacks) {
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600607 uint32_t n = *num_callbacks = 0;
608
609 const void *pNext = pChain;
610 while (pNext) {
611 // 1st, count the number VkDebugReportCallbackCreateInfoEXT:
612 if (((VkDebugReportCallbackCreateInfoEXT *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) {
613 n++;
614 }
615 pNext = (void *)((VkDebugReportCallbackCreateInfoEXT *)pNext)->pNext;
616 }
617 if (n == 0) {
618 return VK_SUCCESS;
619 }
620
621 // 2nd, allocate memory for each VkDebugReportCallbackCreateInfoEXT:
622 VkDebugReportCallbackCreateInfoEXT *pInfos = *infos =
623 ((VkDebugReportCallbackCreateInfoEXT *)malloc(n * sizeof(VkDebugReportCallbackCreateInfoEXT)));
624 if (!pInfos) {
625 return VK_ERROR_OUT_OF_HOST_MEMORY;
626 }
627 // 3rd, allocate memory for a unique handle for each callback:
628 VkDebugReportCallbackEXT *pCallbacks = *callbacks = ((VkDebugReportCallbackEXT *)malloc(n * sizeof(VkDebugReportCallbackEXT)));
629 if (!pCallbacks) {
630 free(pInfos);
631 return VK_ERROR_OUT_OF_HOST_MEMORY;
632 }
633 // 4th, copy each VkDebugReportCallbackCreateInfoEXT for use by
634 // vkDestroyInstance, and assign a unique handle to each callback (just
635 // use the address of the copied VkDebugReportCallbackCreateInfoEXT):
636 pNext = pChain;
637 while (pNext) {
638 if (((VkInstanceCreateInfo *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) {
639 memcpy(pInfos, pNext, sizeof(VkDebugReportCallbackCreateInfoEXT));
640 *pCallbacks++ = (VkDebugReportCallbackEXT)pInfos++;
641 }
642 pNext = (void *)((VkInstanceCreateInfo *)pNext)->pNext;
643 }
644
645 *num_callbacks = n;
646 return VK_SUCCESS;
647}
648
Mark Young6ba8abe2017-11-09 10:37:04 -0700649// This utility frees the arrays allocated by layer_copy_tmp_report_callbacks()
650static inline void layer_free_tmp_report_callbacks(VkDebugReportCallbackCreateInfoEXT *infos, VkDebugReportCallbackEXT *callbacks) {
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600651 free(infos);
652 free(callbacks);
653}
654
655// This utility enables all of the VkDebugReportCallbackCreateInfoEXT structs
Mark Young6ba8abe2017-11-09 10:37:04 -0700656// that were copied by layer_copy_tmp_report_callbacks()
657static inline VkResult layer_enable_tmp_report_callbacks(debug_report_data *debug_data, uint32_t num_callbacks,
658 VkDebugReportCallbackCreateInfoEXT *infos,
659 VkDebugReportCallbackEXT *callbacks) {
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600660 VkResult rtn = VK_SUCCESS;
661 for (uint32_t i = 0; i < num_callbacks; i++) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700662 rtn = layer_create_report_callback(debug_data, false, &infos[i], NULL, &callbacks[i]);
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600663 if (rtn != VK_SUCCESS) {
664 for (uint32_t j = 0; j < i; j++) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700665 layer_destroy_report_callback(debug_data, callbacks[j], NULL);
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600666 }
667 return rtn;
668 }
669 }
670 return rtn;
671}
672
673// This utility disables all of the VkDebugReportCallbackCreateInfoEXT structs
Mark Young6ba8abe2017-11-09 10:37:04 -0700674// that were copied by layer_copy_tmp_report_callbacks()
675static inline void layer_disable_tmp_report_callbacks(debug_report_data *debug_data, uint32_t num_callbacks,
676 VkDebugReportCallbackEXT *callbacks) {
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600677 for (uint32_t i = 0; i < num_callbacks; i++) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700678 layer_destroy_report_callback(debug_data, callbacks[i], NULL);
679 }
680}
681
682// This utility (called at vkCreateInstance() time), looks at a pNext chain.
683// It counts any VkDebugUtilsMessengerCreateInfoEXT structs that it finds. It
684// then allocates an array that can hold that many structs, as well as that
685// many VkDebugUtilsMessengerEXT handles. It then copies each
686// VkDebugUtilsMessengerCreateInfoEXT, and initializes each handle.
Mark Young8504ba62018-03-21 13:35:34 -0600687static inline VkResult layer_copy_tmp_debug_messengers(const void *pChain, uint32_t *num_messengers,
688 VkDebugUtilsMessengerCreateInfoEXT **infos,
689 VkDebugUtilsMessengerEXT **messengers) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700690 uint32_t n = *num_messengers = 0;
691
692 const void *pNext = pChain;
693 while (pNext) {
694 // 1st, count the number VkDebugUtilsMessengerCreateInfoEXT:
695 if (((VkDebugUtilsMessengerCreateInfoEXT *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT) {
696 n++;
697 }
698 pNext = (void *)((VkDebugUtilsMessengerCreateInfoEXT *)pNext)->pNext;
699 }
700 if (n == 0) {
701 return VK_SUCCESS;
702 }
703
704 // 2nd, allocate memory for each VkDebugUtilsMessengerCreateInfoEXT:
705 VkDebugUtilsMessengerCreateInfoEXT *pInfos = *infos =
706 ((VkDebugUtilsMessengerCreateInfoEXT *)malloc(n * sizeof(VkDebugUtilsMessengerCreateInfoEXT)));
707 if (!pInfos) {
708 return VK_ERROR_OUT_OF_HOST_MEMORY;
709 }
710 // 3rd, allocate memory for a unique handle for each messenger:
711 VkDebugUtilsMessengerEXT *pMessengers = *messengers =
712 ((VkDebugUtilsMessengerEXT *)malloc(n * sizeof(VkDebugUtilsMessengerEXT)));
713 if (!pMessengers) {
714 free(pInfos);
715 return VK_ERROR_OUT_OF_HOST_MEMORY;
716 }
717 // 4th, copy each VkDebugUtilsMessengerCreateInfoEXT for use by
718 // vkDestroyInstance, and assign a unique handle to each callback (just
719 // use the address of the copied VkDebugUtilsMessengerCreateInfoEXT):
720 pNext = pChain;
721 while (pNext) {
722 if (((VkInstanceCreateInfo *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT) {
723 memcpy(pInfos, pNext, sizeof(VkDebugUtilsMessengerCreateInfoEXT));
724 *pMessengers++ = (VkDebugUtilsMessengerEXT)pInfos++;
725 }
726 pNext = (void *)((VkInstanceCreateInfo *)pNext)->pNext;
727 }
728
729 *num_messengers = n;
730 return VK_SUCCESS;
731}
732
733// This utility frees the arrays allocated by layer_copy_tmp_debug_messengers()
Mark Young8504ba62018-03-21 13:35:34 -0600734static inline void layer_free_tmp_debug_messengers(VkDebugUtilsMessengerCreateInfoEXT *infos,
735 VkDebugUtilsMessengerEXT *messengers) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700736 free(infos);
737 free(messengers);
738}
739
740// This utility enables all of the VkDebugUtilsMessengerCreateInfoEXT structs
741// that were copied by layer_copy_tmp_debug_messengers()
Mark Young8504ba62018-03-21 13:35:34 -0600742static inline VkResult layer_enable_tmp_debug_messengers(debug_report_data *debug_data, uint32_t num_messengers,
743 VkDebugUtilsMessengerCreateInfoEXT *infos,
744 VkDebugUtilsMessengerEXT *messengers) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700745 VkResult rtn = VK_SUCCESS;
746 for (uint32_t i = 0; i < num_messengers; i++) {
747 rtn = layer_create_messenger_callback(debug_data, false, &infos[i], NULL, &messengers[i]);
748 if (rtn != VK_SUCCESS) {
749 for (uint32_t j = 0; j < i; j++) {
750 layer_destroy_messenger_callback(debug_data, messengers[j], NULL);
751 }
752 return rtn;
753 }
754 }
755 return rtn;
756}
757
758// This utility disables all of the VkDebugUtilsMessengerCreateInfoEXT structs
759// that were copied by layer_copy_tmp_debug_messengers()
Mark Young8504ba62018-03-21 13:35:34 -0600760static inline void layer_disable_tmp_debug_messengers(debug_report_data *debug_data, uint32_t num_messengers,
761 VkDebugUtilsMessengerEXT *messengers) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700762 for (uint32_t i = 0; i < num_messengers; i++) {
763 layer_destroy_messenger_callback(debug_data, messengers[i], NULL);
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600764 }
765}
766
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600767// Checks if the message will get logged.
768// Allows layer to defer collecting & formating data if the
769// message will be discarded.
Mark Young6ba8abe2017-11-09 10:37:04 -0700770static inline bool will_log_msg(debug_report_data *debug_data, VkFlags msg_flags) {
771 VkFlags local_severity = 0;
772 VkFlags local_type = 0;
773 DebugReportFlagsToAnnotFlags(msg_flags, true, &local_severity, &local_type);
774 if (!debug_data || !(debug_data->active_severities & local_severity) || !(debug_data->active_types & local_type)) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600775 // Message is not wanted
Courtney Goeltzenleuchter6a564a12015-09-18 16:30:24 -0600776 return false;
777 }
778
779 return true;
780}
John Zulauf6664e272018-01-17 11:00:22 -0700781#ifndef WIN32
Mark Lobodzinski1bcbdf92018-02-07 10:00:22 -0700782static inline int string_sprintf(std::string *output, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
John Zulauf6664e272018-01-17 11:00:22 -0700783#endif
Mark Lobodzinski1bcbdf92018-02-07 10:00:22 -0700784static inline int string_sprintf(std::string *output, const char *fmt, ...) {
John Zulauf6664e272018-01-17 11:00:22 -0700785 std::string &formatted = *output;
786 va_list argptr;
787 va_start(argptr, fmt);
788 int reserve = vsnprintf(nullptr, 0, fmt, argptr);
789 va_end(argptr);
790 formatted.reserve(reserve + 1);
791 va_start(argptr, fmt);
792 int result = vsnprintf((char *)formatted.data(), formatted.capacity(), fmt, argptr);
793 va_end(argptr);
794 assert(result == reserve);
795 return result;
796}
Courtney Goeltzenleuchter6a564a12015-09-18 16:30:24 -0600797
Chris Forbes8a25bce2016-03-24 12:06:35 +1300798#ifdef WIN32
799static inline int vasprintf(char **strp, char const *fmt, va_list ap) {
800 *strp = nullptr;
801 int size = _vscprintf(fmt, ap);
802 if (size >= 0) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700803 *strp = (char *)malloc(size + 1);
Chris Forbes8a25bce2016-03-24 12:06:35 +1300804 if (!*strp) {
805 return -1;
806 }
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700807 _vsnprintf(*strp, size + 1, fmt, ap);
Chris Forbes8a25bce2016-03-24 12:06:35 +1300808 }
809 return size;
810}
811#endif
812
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600813// Output log message via DEBUG_REPORT
814// Takes format and variable arg list so that output string
815// is only computed if a message needs to be logged
Michael Lentine010f4692015-11-03 16:19:46 -0800816#ifndef WIN32
Mark Young6ba8abe2017-11-09 10:37:04 -0700817static inline bool log_msg(const debug_report_data *debug_data, VkFlags msg_flags, VkDebugReportObjectTypeEXT object_type,
818 uint64_t src_object, size_t location, int32_t msg_code, const char *layer_prefix, const char *format,
819 ...) __attribute__((format(printf, 8, 9)));
Michael Lentine010f4692015-11-03 16:19:46 -0800820#endif
Mark Young6ba8abe2017-11-09 10:37:04 -0700821static inline bool log_msg(const debug_report_data *debug_data, VkFlags msg_flags, VkDebugReportObjectTypeEXT object_type,
822 uint64_t src_object, size_t location, int32_t msg_code, const char *layer_prefix, const char *format,
Dustin Graves8f1eab92016-04-05 09:41:17 -0600823 ...) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700824 VkFlags local_severity = 0;
825 VkFlags local_type = 0;
826 DebugReportFlagsToAnnotFlags(msg_flags, true, &local_severity, &local_type);
827 if (!debug_data || !(debug_data->active_severities & local_severity) || !(debug_data->active_types & local_type)) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600828 // Message is not wanted
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600829 return false;
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600830 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600831
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600832 va_list argptr;
833 va_start(argptr, format);
Chris Forbes8a25bce2016-03-24 12:06:35 +1300834 char *str;
Chris Forbesed6a1b32016-04-28 14:27:19 +1200835 if (-1 == vasprintf(&str, format, argptr)) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600836 // On failure, glibc vasprintf leaves str undefined
Chris Forbesed6a1b32016-04-28 14:27:19 +1200837 str = nullptr;
838 }
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600839 va_end(argptr);
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600840
841 std::string str_plus_spec_text(str);
842
843 // If the msg_code is in the error map, tack on spec text to error message.
844 if (validation_error_map.find(msg_code) != validation_error_map.end()) {
845 str_plus_spec_text += " ";
846 str_plus_spec_text += validation_error_map[msg_code];
847 }
848
Mark Young6ba8abe2017-11-09 10:37:04 -0700849 bool result = debug_log_msg(debug_data, msg_flags, object_type, src_object, location, msg_code, layer_prefix,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600850 str_plus_spec_text.c_str() ? str_plus_spec_text.c_str() : "Allocation failure");
Chris Forbes8a25bce2016-03-24 12:06:35 +1300851 free(str);
852 return result;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600853}
854
Mark Young6ba8abe2017-11-09 10:37:04 -0700855static inline VKAPI_ATTR VkBool32 VKAPI_CALL report_log_callback(VkFlags msg_flags, VkDebugReportObjectTypeEXT obj_type,
856 uint64_t src_object, size_t location, int32_t msg_code,
857 const char *layer_prefix, const char *message, void *user_data) {
858 char msg_flag_string[30];
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600859
Mark Young6ba8abe2017-11-09 10:37:04 -0700860 PrintMessageFlags(msg_flags, msg_flag_string);
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600861
Mark Young8504ba62018-03-21 13:35:34 -0600862 fprintf((FILE *)user_data, "%s(%s): location: %lu msg_code: %d: %s\n", layer_prefix, msg_flag_string, (unsigned long)location,
863 msg_code, message);
Mark Young6ba8abe2017-11-09 10:37:04 -0700864 fflush((FILE *)user_data);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600865
866 return false;
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600867}
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600868
Mark Young6ba8abe2017-11-09 10:37:04 -0700869static inline VKAPI_ATTR VkBool32 VKAPI_CALL report_win32_debug_output_msg(VkFlags msg_flags, VkDebugReportObjectTypeEXT obj_type,
870 uint64_t src_object, size_t location, int32_t msg_code,
871 const char *layer_prefix, const char *message,
872 void *user_data) {
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600873#ifdef WIN32
Mark Young6ba8abe2017-11-09 10:37:04 -0700874 char msg_flag_string[30];
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600875 char buf[2048];
876
Mark Young6ba8abe2017-11-09 10:37:04 -0700877 PrintMessageFlags(msg_flags, msg_flag_string);
Mark Young8504ba62018-03-21 13:35:34 -0600878 _snprintf(buf, sizeof(buf) - 1, "%s (%s): location: " PRINTF_SIZE_T_SPECIFIER " msg_code: %d: %s\n", layer_prefix,
879 msg_flag_string, location, msg_code, message);
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600880
881 OutputDebugString(buf);
882#endif
883
884 return false;
885}
886
Mark Young6ba8abe2017-11-09 10:37:04 -0700887static inline VKAPI_ATTR VkBool32 VKAPI_CALL DebugBreakCallback(VkFlags msgFlags, VkDebugReportObjectTypeEXT obj_type,
888 uint64_t src_object, size_t location, int32_t msg_code,
889 const char *layer_prefix, const char *message, void *user_data) {
Mark Lobodzinskic9d81652017-08-10 11:01:17 -0600890#ifdef WIN32
891 DebugBreak();
892#else
893 raise(SIGTRAP);
894#endif
895
896 return false;
897}
898
Mark Young6ba8abe2017-11-09 10:37:04 -0700899static inline VKAPI_ATTR VkBool32 VKAPI_CALL messenger_log_callback(VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
900 VkDebugUtilsMessageTypeFlagsEXT message_type,
901 const VkDebugUtilsMessengerCallbackDataEXT *callback_data,
902 void *user_data) {
903 char msg_severity[30];
904 char msg_type[30];
905
906 PrintMessageSeverity(message_severity, msg_severity);
907 PrintMessageType(message_type, msg_type);
908
Mark Young8504ba62018-03-21 13:35:34 -0600909 fprintf((FILE *)user_data, "%s(%s / %s): msgNum: %d - %s\n", callback_data->pMessageIdName, msg_severity, msg_type,
Mark Young6ba8abe2017-11-09 10:37:04 -0700910 callback_data->messageIdNumber, callback_data->pMessage);
Mark Young8504ba62018-03-21 13:35:34 -0600911 fprintf((FILE *)user_data, " Objects: %d\n", callback_data->objectCount);
912 for (uint32_t obj = 0; obj < callback_data->objectCount; ++obj) {
913 fprintf((FILE *)user_data, " [%d] 0x%" PRIx64 ", type: %d, name: %s\n", obj,
914 callback_data->pObjects[obj].objectHandle, callback_data->pObjects[obj].objectType,
915 callback_data->pObjects[obj].pObjectName);
916 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700917 fflush((FILE *)user_data);
918
919 return false;
Petr Krause9388f62017-05-13 20:53:12 +0200920}
921
Mark Young6ba8abe2017-11-09 10:37:04 -0700922static inline VKAPI_ATTR VkBool32 VKAPI_CALL messenger_win32_debug_output_msg(
923 VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, VkDebugUtilsMessageTypeFlagsEXT message_type,
924 const VkDebugUtilsMessengerCallbackDataEXT *callback_data, void *user_data) {
925#ifdef WIN32
926 char buf[2048];
927 char msg_severity[30];
928 char msg_type[30];
Mark Lobodzinski863d5de2017-05-22 10:10:07 -0600929
Mark Young6ba8abe2017-11-09 10:37:04 -0700930 PrintMessageSeverity(message_severity, msg_severity);
931 PrintMessageType(message_type, msg_type);
932
Mark Young8504ba62018-03-21 13:35:34 -0600933 size_t buffer_space = sizeof(buf) - 1;
934 size_t remaining_space = buffer_space;
935 _snprintf(buf, sizeof(buf) - 1, "%s(%s / %s): msgNum: %d - %s\n", callback_data->pMessageIdName, msg_severity, msg_type,
936 callback_data->messageIdNumber, callback_data->pMessage);
937 remaining_space = buffer_space - strlen(buf);
938 _snprintf(buf, remaining_space, " Objects: %d\n", callback_data->objectCount);
939 for (uint32_t obj = 0; obj < callback_data->objectCount; ++obj) {
940 remaining_space = buffer_space - strlen(buf);
941 if (remaining_space > 0) {
942 _snprintf(buf, remaining_space, " [%d] 0x%" PRIx64 ", type: %d, name: %s\n", obj,
943 callback_data->pObjects[obj].objectHandle, callback_data->pObjects[obj].objectType,
944 callback_data->pObjects[obj].pObjectName);
945 }
946 }
Mark Young6ba8abe2017-11-09 10:37:04 -0700947 OutputDebugString(buf);
948#endif
949
950 return false;
951}
952
953// This utility converts from the VkDebugUtilsLabelEXT structure into the logging version of the structure.
954// In the logging version, we only record what we absolutely need to convey back to the callbacks.
955static inline void InsertLabelIntoLog(const VkDebugUtilsLabelEXT *utils_label, std::vector<LoggingLabelData> &log_vector) {
956 LoggingLabelData log_label_data = {};
957 log_label_data.name = utils_label->pLabelName;
958 log_label_data.color[0] = utils_label->color[0];
959 log_label_data.color[1] = utils_label->color[1];
960 log_label_data.color[2] = utils_label->color[2];
961 log_label_data.color[3] = utils_label->color[3];
962 log_vector.push_back(log_label_data);
963}
964
Mark Young8504ba62018-03-21 13:35:34 -0600965static inline void BeginQueueDebugUtilsLabel(debug_report_data *report_data, VkQueue queue,
966 const VkDebugUtilsLabelEXT *label_info) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700967 if (nullptr != label_info && nullptr != label_info->pLabelName) {
968 auto label_iter = report_data->debugUtilsQueueLabels->find(queue);
969 if (label_iter == report_data->debugUtilsQueueLabels->end()) {
970 std::vector<LoggingLabelData> new_queue_labels;
971 InsertLabelIntoLog(label_info, new_queue_labels);
972 report_data->debugUtilsQueueLabels->insert({queue, new_queue_labels});
973 } else {
974 // If the last thing was a label insert, we need to pop it off of the label vector before any
975 // changes. This is because a label added with "vkQueueInsertDebugUtilsLabelEXT" is only a
976 // temporary location that exists until the next operation occurs. In this case, a new
977 // "vkQueueBeginDebugUtilsLabelEXT" has occurred erasing the previous inserted label.
978 if (report_data->queueLabelHasInsert) {
979 report_data->queueLabelHasInsert = false;
980 label_iter->second.pop_back();
981 }
982 InsertLabelIntoLog(label_info, label_iter->second);
983 }
984 }
985}
986
Mark Young8504ba62018-03-21 13:35:34 -0600987static inline void EndQueueDebugUtilsLabel(debug_report_data *report_data, VkQueue queue) {
Mark Young6ba8abe2017-11-09 10:37:04 -0700988 auto label_iter = report_data->debugUtilsQueueLabels->find(queue);
989 if (label_iter != report_data->debugUtilsQueueLabels->end()) {
990 // If the last thing was a label insert, we need to pop it off of the label vector before any
991 // changes. This is because a label added with "vkQueueInsertDebugUtilsLabelEXT" is only a
992 // temporary location that exists until the next operation occurs. In this case, a
993 // "vkQueueEndDebugUtilsLabelEXT" has occurred erasing the inserted label.
994 if (report_data->queueLabelHasInsert) {
995 report_data->queueLabelHasInsert = false;
996 label_iter->second.pop_back();
997 }
998 // Now pop the normal item
999 label_iter->second.pop_back();
1000 }
1001}
1002
Mark Young8504ba62018-03-21 13:35:34 -06001003static inline void InsertQueueDebugUtilsLabel(debug_report_data *report_data, VkQueue queue,
1004 const VkDebugUtilsLabelEXT *label_info) {
Mark Young6ba8abe2017-11-09 10:37:04 -07001005 if (nullptr != label_info && nullptr != label_info->pLabelName) {
1006 auto label_iter = report_data->debugUtilsQueueLabels->find(queue);
1007 if (label_iter == report_data->debugUtilsQueueLabels->end()) {
1008 std::vector<LoggingLabelData> new_queue_labels;
1009 InsertLabelIntoLog(label_info, new_queue_labels);
1010 report_data->debugUtilsQueueLabels->insert({queue, new_queue_labels});
1011 } else {
1012 // If the last thing was a label insert, we need to pop it off of the label vector before any
1013 // changes. This is because a label added with "vkQueueInsertDebugUtilsLabelEXT" is only a
1014 // temporary location that exists until the next operation occurs. In this case, a new
1015 // "vkQueueInsertDebugUtilsLabelEXT" has occurred erasing the previous inserted label.
1016 if (report_data->queueLabelHasInsert) {
1017 label_iter->second.pop_back();
1018 }
1019 // Insert this new label and mark it as one that has been "inserted" so we can remove it on
1020 // the next queue label operation.
1021 InsertLabelIntoLog(label_info, label_iter->second);
1022 report_data->queueLabelHasInsert = true;
1023 }
1024 }
1025}
1026
Mark Young8504ba62018-03-21 13:35:34 -06001027static inline void BeginCmdDebugUtilsLabel(debug_report_data *report_data, VkCommandBuffer command_buffer,
1028 const VkDebugUtilsLabelEXT *label_info) {
Mark Young6ba8abe2017-11-09 10:37:04 -07001029 if (nullptr != label_info && nullptr != label_info->pLabelName) {
1030 auto label_iter = report_data->debugUtilsCmdBufLabels->find(command_buffer);
1031 if (label_iter == report_data->debugUtilsCmdBufLabels->end()) {
1032 std::vector<LoggingLabelData> new_cmdbuf_labels;
1033 InsertLabelIntoLog(label_info, new_cmdbuf_labels);
1034 report_data->debugUtilsCmdBufLabels->insert({command_buffer, new_cmdbuf_labels});
1035 } else {
1036 // If the last thing was a label insert, we need to pop it off of the label vector before any
1037 // changes. This is because a label added with "vkCmdInsertDebugUtilsLabelEXT" is only a
1038 // temporary location that exists until the next operation occurs. In this case, a
1039 // "vkCmdBeginDebugUtilsLabelEXT" has occurred erasing the inserted label.
1040 if (report_data->cmdBufLabelHasInsert) {
1041 report_data->cmdBufLabelHasInsert = false;
1042 label_iter->second.pop_back();
1043 }
1044 InsertLabelIntoLog(label_info, label_iter->second);
1045 }
1046 }
1047}
1048
Mark Young8504ba62018-03-21 13:35:34 -06001049static inline void EndCmdDebugUtilsLabel(debug_report_data *report_data, VkCommandBuffer command_buffer) {
Mark Young6ba8abe2017-11-09 10:37:04 -07001050 auto label_iter = report_data->debugUtilsCmdBufLabels->find(command_buffer);
1051 if (label_iter != report_data->debugUtilsCmdBufLabels->end()) {
1052 // If the last thing was a label insert, we need to pop it off of the label vector before any
1053 // changes. This is because a label added with "vkCmdInsertDebugUtilsLabelEXT" is only a
1054 // temporary location that exists until the next operation occurs. In this case, a
1055 // "vkCmdEndDebugUtilsLabelEXT" has occurred erasing the inserted label.
1056 if (report_data->cmdBufLabelHasInsert) {
1057 report_data->cmdBufLabelHasInsert = false;
1058 label_iter->second.pop_back();
1059 }
1060 // Now pop the normal item
1061 label_iter->second.pop_back();
1062 }
1063}
1064
Mark Young8504ba62018-03-21 13:35:34 -06001065static inline void InsertCmdDebugUtilsLabel(debug_report_data *report_data, VkCommandBuffer command_buffer,
1066 const VkDebugUtilsLabelEXT *label_info) {
Mark Young6ba8abe2017-11-09 10:37:04 -07001067 if (nullptr != label_info && nullptr != label_info->pLabelName) {
1068 auto label_iter = report_data->debugUtilsCmdBufLabels->find(command_buffer);
1069 if (label_iter == report_data->debugUtilsCmdBufLabels->end()) {
1070 std::vector<LoggingLabelData> new_cmdbuf_labels;
1071 InsertLabelIntoLog(label_info, new_cmdbuf_labels);
1072 report_data->debugUtilsCmdBufLabels->insert({command_buffer, new_cmdbuf_labels});
1073 } else {
1074 // If the last thing was a label insert, we need to pop it off of the label vector before any
1075 // changes. This is because a label added with "vkCmdInsertDebugUtilsLabelEXT" is only a
1076 // temporary location that exists until the next operation occurs. In this case, a new
1077 // "vkCmdInsertDebugUtilsLabelEXT" has occurred erasing the previous inserted label.
1078 if (report_data->cmdBufLabelHasInsert) {
1079 label_iter->second.pop_back();
1080 }
1081 // Insert this new label and mark it as one that has been "inserted" so we can remove it on
1082 // the next command buffer label operation.
1083 InsertLabelIntoLog(label_info, label_iter->second);
1084 report_data->cmdBufLabelHasInsert = true;
1085 }
1086 }
1087}
Mark Lobodzinski863d5de2017-05-22 10:10:07 -06001088
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001089#endif // LAYER_LOGGING_H