| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2017 Valve Corporation |
| 3 | * Copyright (c) 2015-2017 LunarG, Inc. |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 4 | * |
| Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 5 | * 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 Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 8 | * |
| Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 10 | * |
| Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * 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 Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 16 | * |
| Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 17 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 18 | * Author: Tobin Ehlis <tobin@lunarg.com> |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 19 | * Author: Mark Young <marky@lunarg.com> |
| Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 20 | * |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifndef LAYER_LOGGING_H |
| 24 | #define LAYER_LOGGING_H |
| 25 | |
| Mark Lobodzinski | b87f902 | 2016-05-24 16:04:56 -0600 | [diff] [blame] | 26 | #include "vk_loader_layer.h" |
| Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 27 | #include "vk_layer_config.h" |
| Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 28 | #include "vk_layer_data.h" |
| 29 | #include "vk_layer_table.h" |
| Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 30 | #include "vk_loader_platform.h" |
| 31 | #include "vulkan/vk_layer.h" |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 32 | #include "vk_object_types.h" |
| Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 33 | #include "vk_validation_error_messages.h" |
| Mark Lobodzinski | c9d8165 | 2017-08-10 11:01:17 -0600 | [diff] [blame] | 34 | #include <signal.h> |
| Karl Schultz | d7f3754 | 2016-05-10 11:36:08 -0600 | [diff] [blame] | 35 | #include <cinttypes> |
| Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 36 | #include <stdarg.h> |
| 37 | #include <stdbool.h> |
| 38 | #include <stdio.h> |
| 39 | #include <unordered_map> |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 40 | #include <vector> |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 41 | #include <sstream> |
| 42 | #include <string> |
| 43 | |
| 44 | // TODO: Could be autogenerated for the specific handles for extra type safety... |
| 45 | template <typename HANDLE_T> |
| 46 | static inline uint64_t HandleToUint64(HANDLE_T *h) { |
| 47 | return reinterpret_cast<uint64_t>(h); |
| 48 | } |
| 49 | |
| 50 | static inline uint64_t HandleToUint64(uint64_t h) { return h; } |
| 51 | |
| 52 | // Data we store per label for logging |
| 53 | typedef struct _LoggingLabelData { |
| 54 | std::string name; |
| 55 | float color[4]; |
| 56 | } LoggingLabelData; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 57 | |
| Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 58 | typedef struct _debug_report_data { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 59 | VkLayerDbgFunctionNode *debug_callback_list; |
| 60 | VkLayerDbgFunctionNode *default_debug_callback_list; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 61 | VkDebugUtilsMessageSeverityFlagsEXT active_severities; |
| 62 | VkDebugUtilsMessageTypeFlagsEXT active_types; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 63 | bool g_DEBUG_REPORT; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 64 | bool g_DEBUG_UTILS; |
| Tony Barbour | 3431dac | 2017-06-19 16:50:37 -0600 | [diff] [blame] | 65 | std::unordered_map<uint64_t, std::string> *debugObjectNameMap; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 66 | 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 Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 71 | } debug_report_data; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 72 | |
| Tobin Ehlis | 8d6acde | 2017-02-08 07:40:40 -0700 | [diff] [blame] | 73 | template debug_report_data *GetLayerDataPtr<debug_report_data>(void *data_key, |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 74 | std::unordered_map<void *, debug_report_data *> &data_map); |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 75 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 76 | static 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 Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 103 | // Forward Declarations |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 104 | static 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, |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 106 | const char *message, const char *text_vuid = NULL); |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 107 | |
| 108 | // Add a debug message callback node structure to the specified callback linked list |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 109 | static inline void AddDebugCallbackNode(debug_report_data *debug_data, VkLayerDbgFunctionNode **list_head, |
| 110 | VkLayerDbgFunctionNode *new_node) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 111 | new_node->pNext = *list_head; |
| 112 | *list_head = new_node; |
| 113 | } |
| 114 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 115 | // Remove specified debug messenger node structure from the specified linked list |
| 116 | static inline void RemoveDebugUtilsMessenger(debug_report_data *debug_data, VkLayerDbgFunctionNode **list_head, |
| 117 | VkDebugUtilsMessengerEXT messenger) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 118 | VkLayerDbgFunctionNode *cur_callback = *list_head; |
| 119 | VkLayerDbgFunctionNode *prev_callback = cur_callback; |
| 120 | bool matched = false; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 121 | VkFlags local_severities = 0; |
| 122 | VkFlags local_types = 0; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 123 | |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 124 | while (cur_callback) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 125 | if (cur_callback->is_messenger && cur_callback->messenger.messenger == messenger) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 126 | matched = true; |
| 127 | prev_callback->pNext = cur_callback->pNext; |
| 128 | if (*list_head == cur_callback) { |
| 129 | *list_head = cur_callback->pNext; |
| 130 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 131 | 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 Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 134 | } else { |
| 135 | matched = false; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 136 | local_severities |= cur_callback->messenger.messageSeverity; |
| 137 | local_types |= cur_callback->messenger.messageType; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 138 | } |
| 139 | prev_callback = cur_callback; |
| 140 | cur_callback = cur_callback->pNext; |
| 141 | if (matched) { |
| 142 | free(prev_callback); |
| 143 | } |
| 144 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 145 | 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 |
| 150 | static 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 Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | // Removes all debug callback function nodes from the specified callback linked lists and frees their resources |
| 187 | static 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 Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 193 | 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 Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 202 | free(current_callback); |
| 203 | current_callback = prev_callback; |
| 204 | } |
| 205 | *list_head = NULL; |
| 206 | } |
| 207 | |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 208 | // Note that text_vuid is a default parameter, and is optional. See the above forward declaration |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 209 | static 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, |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 211 | const char *message, const char *text_vuid) { |
| Dustin Graves | 8f1eab9 | 2016-04-05 09:41:17 -0600 | [diff] [blame] | 212 | bool bail = false; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 213 | VkLayerDbgFunctionNode *layer_dbg_node = NULL; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 214 | |
| Mark Lobodzinski | 55a197f | 2016-06-21 15:54:57 -0600 | [diff] [blame] | 215 | if (debug_data->debug_callback_list != NULL) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 216 | layer_dbg_node = debug_data->debug_callback_list; |
| Mark Lobodzinski | 55a197f | 2016-06-21 15:54:57 -0600 | [diff] [blame] | 217 | } else { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 218 | layer_dbg_node = debug_data->default_debug_callback_list; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 219 | } |
| 220 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 221 | 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; |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 237 | callback_data.pMessageIdName = text_vuid; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 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 Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 251 | |
| 252 | if (0 != src_object) { |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 253 | oss << "Object: 0x" << std::hex << src_object; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 254 | // 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 Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 313 | oss << " (Name = " << callback_data.pObjects[0].pObjectName << " : Type = "; |
| 314 | } else { |
| 315 | oss << " (Type = "; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 316 | } |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 317 | oss << std::to_string(object_type) << ")"; |
| 318 | } else { |
| 319 | oss << "Object: VK_NULL_HANDLE (Type = " << std::to_string(object_type) << ")"; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 320 | } |
| 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 Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 326 | // If the app uses the VK_EXT_debug_report extension, call all of those registered callbacks. |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 327 | if (!layer_dbg_node->is_messenger && (layer_dbg_node->report.msgFlags & msg_flags)) { |
| 328 | if (text_vuid != nullptr) { |
| 329 | // If a text vuid is supplied for the old debug report extension, prepend it to the message string |
| 330 | new_debug_report_message.insert(0, " ] "); |
| 331 | new_debug_report_message.insert(0, text_vuid); |
| 332 | new_debug_report_message.insert(0, " [ "); |
| 333 | } |
| 334 | |
| 335 | if (layer_dbg_node->report.pfnMsgCallback(msg_flags, object_type, src_object, location, msg_code, layer_prefix, |
| 336 | new_debug_report_message.c_str(), layer_dbg_node->pUserData)) { |
| 337 | bail = true; |
| 338 | } |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 339 | // If the app uses the VK_EXT_debug_utils extension, call all of those registered callbacks. |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 340 | } else if (layer_dbg_node->is_messenger && (layer_dbg_node->messenger.messageSeverity & severity) && |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 341 | (layer_dbg_node->messenger.messageType & types)) { |
| 342 | if (layer_dbg_node->messenger.pfnUserCallback(static_cast<VkDebugUtilsMessageSeverityFlagBitsEXT>(severity), types, |
| 343 | &callback_data, layer_dbg_node->pUserData)) { |
| 344 | bail = true; |
| 345 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 346 | } |
| 347 | layer_dbg_node = layer_dbg_node->pNext; |
| 348 | } |
| 349 | |
| 350 | if (nullptr != queue_labels) { |
| 351 | delete[] queue_labels; |
| 352 | } |
| 353 | if (nullptr != cmd_buf_labels) { |
| 354 | delete[] cmd_buf_labels; |
| 355 | } |
| 356 | |
| 357 | return bail; |
| 358 | } |
| 359 | |
| 360 | static inline void DebugAnnotFlagsToReportFlags(VkDebugUtilsMessageSeverityFlagBitsEXT da_severity, |
| 361 | VkDebugUtilsMessageTypeFlagsEXT da_type, VkDebugReportFlagsEXT *dr_flags) { |
| 362 | *dr_flags = 0; |
| 363 | |
| 364 | if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) != 0) { |
| 365 | *dr_flags |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
| 366 | } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) != 0) { |
| 367 | if ((da_type & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) != 0) { |
| 368 | *dr_flags |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
| 369 | } else { |
| 370 | *dr_flags |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
| 371 | } |
| 372 | } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) != 0) { |
| 373 | *dr_flags |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
| 374 | } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) != 0) { |
| 375 | *dr_flags |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | static inline bool debug_messenger_log_msg(const debug_report_data *debug_data, |
| 380 | VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, |
| 381 | VkDebugUtilsMessageTypeFlagsEXT message_type, |
| 382 | VkDebugUtilsMessengerCallbackDataEXT *callback_data) { |
| 383 | bool bail = false; |
| 384 | VkLayerDbgFunctionNode *layer_dbg_node = NULL; |
| 385 | |
| 386 | if (debug_data->debug_callback_list != NULL) { |
| 387 | layer_dbg_node = debug_data->debug_callback_list; |
| 388 | } else { |
| 389 | layer_dbg_node = debug_data->default_debug_callback_list; |
| 390 | } |
| 391 | |
| 392 | VkDebugReportFlagsEXT object_flags = 0; |
| 393 | |
| 394 | DebugAnnotFlagsToReportFlags(message_severity, message_type, &object_flags); |
| 395 | |
| 396 | while (layer_dbg_node) { |
| 397 | if (layer_dbg_node->is_messenger && (layer_dbg_node->messenger.messageSeverity & message_severity) && |
| 398 | (layer_dbg_node->messenger.messageType & message_type)) { |
| 399 | // Loop through each object and give it the proper name if it was set. |
| 400 | for (uint32_t obj = 0; obj < callback_data->objectCount; obj++) { |
| 401 | auto it = debug_data->debugUtilsObjectNameMap->find(callback_data->pObjects[obj].objectHandle); |
| 402 | if (it == debug_data->debugUtilsObjectNameMap->end()) { |
| 403 | continue; |
| 404 | } |
| 405 | callback_data->pObjects[obj].pObjectName = it->second.c_str(); |
| 406 | } |
| 407 | if (layer_dbg_node->messenger.pfnUserCallback(message_severity, message_type, callback_data, |
| 408 | layer_dbg_node->pUserData)) { |
| 409 | bail = true; |
| 410 | } |
| 411 | } else if (!layer_dbg_node->is_messenger && layer_dbg_node->report.msgFlags & object_flags) { |
| 412 | auto it = debug_data->debugObjectNameMap->find(callback_data->pObjects[0].objectHandle); |
| 413 | VkDebugReportObjectTypeEXT object_type = get_debug_report_enum[callback_data->pObjects[0].objectType]; |
| Tony Barbour | 3431dac | 2017-06-19 16:50:37 -0600 | [diff] [blame] | 414 | if (it == debug_data->debugObjectNameMap->end()) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 415 | if (layer_dbg_node->report.pfnMsgCallback(object_flags, object_type, callback_data->pObjects[0].objectHandle, 0, |
| 416 | callback_data->messageIdNumber, callback_data->pMessageIdName, |
| 417 | callback_data->pMessage, layer_dbg_node->pUserData)) { |
| Tony Barbour | 3431dac | 2017-06-19 16:50:37 -0600 | [diff] [blame] | 418 | bail = true; |
| 419 | } |
| 420 | } else { |
| 421 | std::string newMsg = "SrcObject name = "; |
| 422 | newMsg.append(it->second.c_str()); |
| 423 | newMsg.append(" "); |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 424 | newMsg.append(callback_data->pMessage); |
| 425 | if (layer_dbg_node->report.pfnMsgCallback(object_flags, object_type, callback_data->pObjects[0].objectHandle, 0, |
| 426 | callback_data->messageIdNumber, callback_data->pMessageIdName, |
| 427 | newMsg.c_str(), layer_dbg_node->pUserData)) { |
| Tony Barbour | 3431dac | 2017-06-19 16:50:37 -0600 | [diff] [blame] | 428 | bail = true; |
| 429 | } |
| Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 430 | } |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 431 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 432 | layer_dbg_node = layer_dbg_node->pNext; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 433 | } |
| Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 434 | |
| 435 | return bail; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 436 | } |
| 437 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 438 | static inline debug_report_data *debug_utils_create_instance( |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 439 | VkLayerInstanceDispatchTable *table, VkInstance inst, uint32_t extension_count, |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 440 | const char *const *enabled_extensions) // layer or extension name to be enabled |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 441 | { |
| Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 442 | debug_report_data *debug_data = (debug_report_data *)malloc(sizeof(debug_report_data)); |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 443 | if (!debug_data) return NULL; |
| Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 444 | |
| 445 | memset(debug_data, 0, sizeof(debug_report_data)); |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 446 | for (uint32_t i = 0; i < extension_count; i++) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 447 | // TODO: Check other property fields |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 448 | if (strcmp(enabled_extensions[i], VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0) { |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 449 | debug_data->g_DEBUG_REPORT = true; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 450 | } else if (strcmp(enabled_extensions[i], VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0) { |
| 451 | debug_data->g_DEBUG_UTILS = true; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 452 | } |
| 453 | } |
| Tony Barbour | 3431dac | 2017-06-19 16:50:37 -0600 | [diff] [blame] | 454 | debug_data->debugObjectNameMap = new std::unordered_map<uint64_t, std::string>; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 455 | debug_data->debugUtilsObjectNameMap = new std::unordered_map<uint64_t, std::string>; |
| 456 | debug_data->debugUtilsQueueLabels = new std::unordered_map<VkQueue, std::vector<LoggingLabelData>>; |
| 457 | debug_data->debugUtilsCmdBufLabels = new std::unordered_map<VkCommandBuffer, std::vector<LoggingLabelData>>; |
| 458 | debug_data->queueLabelHasInsert = false; |
| 459 | debug_data->cmdBufLabelHasInsert = false; |
| Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 460 | return debug_data; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 461 | } |
| 462 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 463 | static inline void layer_debug_utils_destroy_instance(debug_report_data *debug_data) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 464 | if (debug_data) { |
| 465 | RemoveAllMessageCallbacks(debug_data, &debug_data->default_debug_callback_list); |
| 466 | RemoveAllMessageCallbacks(debug_data, &debug_data->debug_callback_list); |
| Tony Barbour | 3431dac | 2017-06-19 16:50:37 -0600 | [diff] [blame] | 467 | delete debug_data->debugObjectNameMap; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 468 | delete debug_data->debugUtilsObjectNameMap; |
| 469 | delete debug_data->debugUtilsQueueLabels; |
| 470 | delete debug_data->debugUtilsCmdBufLabels; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 471 | free(debug_data); |
| Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 472 | } |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 473 | } |
| 474 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 475 | static inline debug_report_data *layer_debug_utils_create_device(debug_report_data *instance_debug_data, VkDevice device) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 476 | // DEBUG_REPORT shares data between Instance and Device, |
| 477 | // so just return instance's data pointer |
| Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 478 | return instance_debug_data; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 479 | } |
| 480 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 481 | static inline void layer_debug_utils_destroy_device(VkDevice device) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 482 | // Nothing to do since we're using instance data record |
| 483 | } |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 484 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 485 | static inline void layer_destroy_messenger_callback(debug_report_data *debug_data, VkDebugUtilsMessengerEXT messenger, |
| 486 | const VkAllocationCallbacks *allocator) { |
| 487 | RemoveDebugUtilsMessenger(debug_data, &debug_data->debug_callback_list, messenger); |
| 488 | RemoveDebugUtilsMessenger(debug_data, &debug_data->default_debug_callback_list, messenger); |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 489 | } |
| 490 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 491 | static inline VkResult layer_create_messenger_callback(debug_report_data *debug_data, bool default_callback, |
| 492 | const VkDebugUtilsMessengerCreateInfoEXT *create_info, |
| 493 | const VkAllocationCallbacks *allocator, |
| 494 | VkDebugUtilsMessengerEXT *messenger) { |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 495 | VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode *)malloc(sizeof(VkLayerDbgFunctionNode)); |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 496 | if (!pNewDbgFuncNode) return VK_ERROR_OUT_OF_HOST_MEMORY; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 497 | memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode)); |
| 498 | pNewDbgFuncNode->is_messenger = true; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 499 | |
| Tobin Ehlis | eb7715d | 2015-09-21 09:36:47 -0600 | [diff] [blame] | 500 | // Handle of 0 is logging_callback so use allocated Node address as unique handle |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 501 | if (!(*messenger)) *messenger = (VkDebugUtilsMessengerEXT)pNewDbgFuncNode; |
| 502 | pNewDbgFuncNode->messenger.messenger = *messenger; |
| 503 | pNewDbgFuncNode->messenger.pfnUserCallback = create_info->pfnUserCallback; |
| 504 | pNewDbgFuncNode->messenger.messageSeverity = create_info->messageSeverity; |
| 505 | pNewDbgFuncNode->messenger.messageType = create_info->messageType; |
| 506 | pNewDbgFuncNode->pUserData = create_info->pUserData; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 507 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 508 | debug_data->active_severities |= create_info->messageSeverity; |
| 509 | debug_data->active_types |= create_info->messageType; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 510 | if (default_callback) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 511 | AddDebugCallbackNode(debug_data, &debug_data->default_debug_callback_list, pNewDbgFuncNode); |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 512 | } else { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 513 | AddDebugCallbackNode(debug_data, &debug_data->debug_callback_list, pNewDbgFuncNode); |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 514 | } |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 515 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 516 | VkDebugUtilsMessengerCallbackDataEXT callback_data = {}; |
| 517 | VkDebugUtilsObjectNameInfoEXT blank_object = {}; |
| 518 | callback_data.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT; |
| 519 | callback_data.pNext = NULL; |
| 520 | callback_data.flags = 0; |
| 521 | callback_data.pMessageIdName = "Layer Internal Message"; |
| 522 | callback_data.messageIdNumber = 0; |
| 523 | callback_data.pMessage = "Added messenger"; |
| 524 | callback_data.queueLabelCount = 0; |
| 525 | callback_data.pQueueLabels = NULL; |
| 526 | callback_data.cmdBufLabelCount = 0; |
| 527 | callback_data.pCmdBufLabels = NULL; |
| 528 | callback_data.objectCount = 1; |
| 529 | callback_data.pObjects = &blank_object; |
| 530 | blank_object.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; |
| 531 | blank_object.pNext = NULL; |
| 532 | blank_object.objectType = VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT; |
| 533 | blank_object.objectHandle = HandleToUint64(*messenger); |
| 534 | blank_object.pObjectName = NULL; |
| 535 | debug_messenger_log_msg(debug_data, VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT, |
| 536 | VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT, &callback_data); |
| Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 537 | return VK_SUCCESS; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 538 | } |
| 539 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 540 | static inline void layer_destroy_report_callback(debug_report_data *debug_data, VkDebugReportCallbackEXT callback, |
| 541 | const VkAllocationCallbacks *allocator) { |
| 542 | RemoveDebugUtilsMessageCallback(debug_data, &debug_data->debug_callback_list, callback); |
| 543 | RemoveDebugUtilsMessageCallback(debug_data, &debug_data->default_debug_callback_list, callback); |
| 544 | } |
| 545 | |
| 546 | static inline VkResult layer_create_report_callback(debug_report_data *debug_data, bool default_callback, |
| 547 | const VkDebugReportCallbackCreateInfoEXT *create_info, |
| 548 | const VkAllocationCallbacks *allocator, VkDebugReportCallbackEXT *callback) { |
| 549 | VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode *)malloc(sizeof(VkLayerDbgFunctionNode)); |
| 550 | if (!pNewDbgFuncNode) { |
| 551 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 552 | } |
| 553 | memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode)); |
| 554 | pNewDbgFuncNode->is_messenger = false; |
| 555 | |
| 556 | // Handle of 0 is logging_callback so use allocated Node address as unique handle |
| 557 | if (!(*callback)) *callback = (VkDebugReportCallbackEXT)pNewDbgFuncNode; |
| 558 | pNewDbgFuncNode->report.msgCallback = *callback; |
| 559 | pNewDbgFuncNode->report.pfnMsgCallback = create_info->pfnCallback; |
| 560 | pNewDbgFuncNode->report.msgFlags = create_info->flags; |
| 561 | pNewDbgFuncNode->pUserData = create_info->pUserData; |
| 562 | |
| 563 | VkFlags local_severity = 0; |
| 564 | VkFlags local_type = 0; |
| 565 | DebugReportFlagsToAnnotFlags(create_info->flags, true, &local_severity, &local_type); |
| 566 | debug_data->active_severities |= local_severity; |
| 567 | debug_data->active_types |= local_type; |
| 568 | if (default_callback) { |
| 569 | AddDebugCallbackNode(debug_data, &debug_data->default_debug_callback_list, pNewDbgFuncNode); |
| 570 | } else { |
| 571 | AddDebugCallbackNode(debug_data, &debug_data->debug_callback_list, pNewDbgFuncNode); |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 572 | } |
| 573 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 574 | debug_log_msg(debug_data, VK_DEBUG_REPORT_DEBUG_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, (uint64_t)*callback, 0, |
| 575 | 0, "DebugReport", "Added callback"); |
| 576 | return VK_SUCCESS; |
| 577 | } |
| 578 | |
| 579 | static inline PFN_vkVoidFunction debug_utils_get_instance_proc_addr(debug_report_data *debug_data, const char *func_name) { |
| 580 | if (!debug_data) { |
| 581 | return NULL; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 582 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 583 | if (debug_data->g_DEBUG_REPORT) { |
| 584 | if (!strcmp(func_name, "vkCreateDebugReportCallbackEXT")) { |
| 585 | return (PFN_vkVoidFunction)vkCreateDebugReportCallbackEXT; |
| 586 | } |
| 587 | if (!strcmp(func_name, "vkDestroyDebugReportCallbackEXT")) { |
| 588 | return (PFN_vkVoidFunction)vkDestroyDebugReportCallbackEXT; |
| 589 | } |
| 590 | if (!strcmp(func_name, "vkDebugReportMessageEXT")) { |
| 591 | return (PFN_vkVoidFunction)vkDebugReportMessageEXT; |
| 592 | } |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 593 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 594 | if (debug_data->g_DEBUG_UTILS) { |
| 595 | if (!strcmp(func_name, "vkCreateDebugUtilsMessengerEXT")) { |
| 596 | return (PFN_vkVoidFunction)vkCreateDebugUtilsMessengerEXT; |
| 597 | } |
| 598 | if (!strcmp(func_name, "vkDestroyDebugUtilsMessengerEXT")) { |
| 599 | return (PFN_vkVoidFunction)vkDestroyDebugUtilsMessengerEXT; |
| 600 | } |
| 601 | if (!strcmp(func_name, "vkSubmitDebugUtilsMessageEXT")) { |
| 602 | return (PFN_vkVoidFunction)vkSubmitDebugUtilsMessageEXT; |
| 603 | } |
| Courtney Goeltzenleuchter | 822e8d7 | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 604 | } |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 605 | return NULL; |
| 606 | } |
| 607 | |
| Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 608 | // This utility (called at vkCreateInstance() time), looks at a pNext chain. |
| 609 | // It counts any VkDebugReportCallbackCreateInfoEXT structs that it finds. It |
| 610 | // then allocates an array that can hold that many structs, as well as that |
| 611 | // many VkDebugReportCallbackEXT handles. It then copies each |
| 612 | // VkDebugReportCallbackCreateInfoEXT, and initializes each handle. |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 613 | static inline VkResult layer_copy_tmp_report_callbacks(const void *pChain, uint32_t *num_callbacks, |
| 614 | VkDebugReportCallbackCreateInfoEXT **infos, |
| 615 | VkDebugReportCallbackEXT **callbacks) { |
| Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 616 | uint32_t n = *num_callbacks = 0; |
| 617 | |
| 618 | const void *pNext = pChain; |
| 619 | while (pNext) { |
| 620 | // 1st, count the number VkDebugReportCallbackCreateInfoEXT: |
| 621 | if (((VkDebugReportCallbackCreateInfoEXT *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
| 622 | n++; |
| 623 | } |
| 624 | pNext = (void *)((VkDebugReportCallbackCreateInfoEXT *)pNext)->pNext; |
| 625 | } |
| 626 | if (n == 0) { |
| 627 | return VK_SUCCESS; |
| 628 | } |
| 629 | |
| 630 | // 2nd, allocate memory for each VkDebugReportCallbackCreateInfoEXT: |
| 631 | VkDebugReportCallbackCreateInfoEXT *pInfos = *infos = |
| 632 | ((VkDebugReportCallbackCreateInfoEXT *)malloc(n * sizeof(VkDebugReportCallbackCreateInfoEXT))); |
| 633 | if (!pInfos) { |
| 634 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 635 | } |
| 636 | // 3rd, allocate memory for a unique handle for each callback: |
| 637 | VkDebugReportCallbackEXT *pCallbacks = *callbacks = ((VkDebugReportCallbackEXT *)malloc(n * sizeof(VkDebugReportCallbackEXT))); |
| 638 | if (!pCallbacks) { |
| 639 | free(pInfos); |
| 640 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 641 | } |
| 642 | // 4th, copy each VkDebugReportCallbackCreateInfoEXT for use by |
| 643 | // vkDestroyInstance, and assign a unique handle to each callback (just |
| 644 | // use the address of the copied VkDebugReportCallbackCreateInfoEXT): |
| 645 | pNext = pChain; |
| 646 | while (pNext) { |
| 647 | if (((VkInstanceCreateInfo *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { |
| 648 | memcpy(pInfos, pNext, sizeof(VkDebugReportCallbackCreateInfoEXT)); |
| 649 | *pCallbacks++ = (VkDebugReportCallbackEXT)pInfos++; |
| 650 | } |
| 651 | pNext = (void *)((VkInstanceCreateInfo *)pNext)->pNext; |
| 652 | } |
| 653 | |
| 654 | *num_callbacks = n; |
| 655 | return VK_SUCCESS; |
| 656 | } |
| 657 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 658 | // This utility frees the arrays allocated by layer_copy_tmp_report_callbacks() |
| 659 | static inline void layer_free_tmp_report_callbacks(VkDebugReportCallbackCreateInfoEXT *infos, VkDebugReportCallbackEXT *callbacks) { |
| Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 660 | free(infos); |
| 661 | free(callbacks); |
| 662 | } |
| 663 | |
| 664 | // This utility enables all of the VkDebugReportCallbackCreateInfoEXT structs |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 665 | // that were copied by layer_copy_tmp_report_callbacks() |
| 666 | static inline VkResult layer_enable_tmp_report_callbacks(debug_report_data *debug_data, uint32_t num_callbacks, |
| 667 | VkDebugReportCallbackCreateInfoEXT *infos, |
| 668 | VkDebugReportCallbackEXT *callbacks) { |
| Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 669 | VkResult rtn = VK_SUCCESS; |
| 670 | for (uint32_t i = 0; i < num_callbacks; i++) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 671 | rtn = layer_create_report_callback(debug_data, false, &infos[i], NULL, &callbacks[i]); |
| Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 672 | if (rtn != VK_SUCCESS) { |
| 673 | for (uint32_t j = 0; j < i; j++) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 674 | layer_destroy_report_callback(debug_data, callbacks[j], NULL); |
| Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 675 | } |
| 676 | return rtn; |
| 677 | } |
| 678 | } |
| 679 | return rtn; |
| 680 | } |
| 681 | |
| 682 | // This utility disables all of the VkDebugReportCallbackCreateInfoEXT structs |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 683 | // that were copied by layer_copy_tmp_report_callbacks() |
| 684 | static inline void layer_disable_tmp_report_callbacks(debug_report_data *debug_data, uint32_t num_callbacks, |
| 685 | VkDebugReportCallbackEXT *callbacks) { |
| Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 686 | for (uint32_t i = 0; i < num_callbacks; i++) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 687 | layer_destroy_report_callback(debug_data, callbacks[i], NULL); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | // This utility (called at vkCreateInstance() time), looks at a pNext chain. |
| 692 | // It counts any VkDebugUtilsMessengerCreateInfoEXT structs that it finds. It |
| 693 | // then allocates an array that can hold that many structs, as well as that |
| 694 | // many VkDebugUtilsMessengerEXT handles. It then copies each |
| 695 | // VkDebugUtilsMessengerCreateInfoEXT, and initializes each handle. |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 696 | static inline VkResult layer_copy_tmp_debug_messengers(const void *pChain, uint32_t *num_messengers, |
| 697 | VkDebugUtilsMessengerCreateInfoEXT **infos, |
| 698 | VkDebugUtilsMessengerEXT **messengers) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 699 | uint32_t n = *num_messengers = 0; |
| 700 | |
| 701 | const void *pNext = pChain; |
| 702 | while (pNext) { |
| 703 | // 1st, count the number VkDebugUtilsMessengerCreateInfoEXT: |
| 704 | if (((VkDebugUtilsMessengerCreateInfoEXT *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT) { |
| 705 | n++; |
| 706 | } |
| 707 | pNext = (void *)((VkDebugUtilsMessengerCreateInfoEXT *)pNext)->pNext; |
| 708 | } |
| 709 | if (n == 0) { |
| 710 | return VK_SUCCESS; |
| 711 | } |
| 712 | |
| 713 | // 2nd, allocate memory for each VkDebugUtilsMessengerCreateInfoEXT: |
| 714 | VkDebugUtilsMessengerCreateInfoEXT *pInfos = *infos = |
| 715 | ((VkDebugUtilsMessengerCreateInfoEXT *)malloc(n * sizeof(VkDebugUtilsMessengerCreateInfoEXT))); |
| 716 | if (!pInfos) { |
| 717 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 718 | } |
| 719 | // 3rd, allocate memory for a unique handle for each messenger: |
| 720 | VkDebugUtilsMessengerEXT *pMessengers = *messengers = |
| 721 | ((VkDebugUtilsMessengerEXT *)malloc(n * sizeof(VkDebugUtilsMessengerEXT))); |
| 722 | if (!pMessengers) { |
| 723 | free(pInfos); |
| 724 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 725 | } |
| 726 | // 4th, copy each VkDebugUtilsMessengerCreateInfoEXT for use by |
| 727 | // vkDestroyInstance, and assign a unique handle to each callback (just |
| 728 | // use the address of the copied VkDebugUtilsMessengerCreateInfoEXT): |
| 729 | pNext = pChain; |
| 730 | while (pNext) { |
| 731 | if (((VkInstanceCreateInfo *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT) { |
| 732 | memcpy(pInfos, pNext, sizeof(VkDebugUtilsMessengerCreateInfoEXT)); |
| 733 | *pMessengers++ = (VkDebugUtilsMessengerEXT)pInfos++; |
| 734 | } |
| 735 | pNext = (void *)((VkInstanceCreateInfo *)pNext)->pNext; |
| 736 | } |
| 737 | |
| 738 | *num_messengers = n; |
| 739 | return VK_SUCCESS; |
| 740 | } |
| 741 | |
| 742 | // This utility frees the arrays allocated by layer_copy_tmp_debug_messengers() |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 743 | static inline void layer_free_tmp_debug_messengers(VkDebugUtilsMessengerCreateInfoEXT *infos, |
| 744 | VkDebugUtilsMessengerEXT *messengers) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 745 | free(infos); |
| 746 | free(messengers); |
| 747 | } |
| 748 | |
| 749 | // This utility enables all of the VkDebugUtilsMessengerCreateInfoEXT structs |
| 750 | // that were copied by layer_copy_tmp_debug_messengers() |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 751 | static inline VkResult layer_enable_tmp_debug_messengers(debug_report_data *debug_data, uint32_t num_messengers, |
| 752 | VkDebugUtilsMessengerCreateInfoEXT *infos, |
| 753 | VkDebugUtilsMessengerEXT *messengers) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 754 | VkResult rtn = VK_SUCCESS; |
| 755 | for (uint32_t i = 0; i < num_messengers; i++) { |
| 756 | rtn = layer_create_messenger_callback(debug_data, false, &infos[i], NULL, &messengers[i]); |
| 757 | if (rtn != VK_SUCCESS) { |
| 758 | for (uint32_t j = 0; j < i; j++) { |
| 759 | layer_destroy_messenger_callback(debug_data, messengers[j], NULL); |
| 760 | } |
| 761 | return rtn; |
| 762 | } |
| 763 | } |
| 764 | return rtn; |
| 765 | } |
| 766 | |
| 767 | // This utility disables all of the VkDebugUtilsMessengerCreateInfoEXT structs |
| 768 | // that were copied by layer_copy_tmp_debug_messengers() |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 769 | static inline void layer_disable_tmp_debug_messengers(debug_report_data *debug_data, uint32_t num_messengers, |
| 770 | VkDebugUtilsMessengerEXT *messengers) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 771 | for (uint32_t i = 0; i < num_messengers; i++) { |
| 772 | layer_destroy_messenger_callback(debug_data, messengers[i], NULL); |
| Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 776 | // Checks if the message will get logged. |
| 777 | // Allows layer to defer collecting & formating data if the |
| 778 | // message will be discarded. |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 779 | static inline bool will_log_msg(debug_report_data *debug_data, VkFlags msg_flags) { |
| 780 | VkFlags local_severity = 0; |
| 781 | VkFlags local_type = 0; |
| 782 | DebugReportFlagsToAnnotFlags(msg_flags, true, &local_severity, &local_type); |
| 783 | if (!debug_data || !(debug_data->active_severities & local_severity) || !(debug_data->active_types & local_type)) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 784 | // Message is not wanted |
| Courtney Goeltzenleuchter | 6a564a1 | 2015-09-18 16:30:24 -0600 | [diff] [blame] | 785 | return false; |
| 786 | } |
| 787 | |
| 788 | return true; |
| 789 | } |
| John Zulauf | 6664e27 | 2018-01-17 11:00:22 -0700 | [diff] [blame] | 790 | #ifndef WIN32 |
| Mark Lobodzinski | 1bcbdf9 | 2018-02-07 10:00:22 -0700 | [diff] [blame] | 791 | static inline int string_sprintf(std::string *output, const char *fmt, ...) __attribute__((format(printf, 2, 3))); |
| John Zulauf | 6664e27 | 2018-01-17 11:00:22 -0700 | [diff] [blame] | 792 | #endif |
| Mark Lobodzinski | 1bcbdf9 | 2018-02-07 10:00:22 -0700 | [diff] [blame] | 793 | static inline int string_sprintf(std::string *output, const char *fmt, ...) { |
| John Zulauf | 6664e27 | 2018-01-17 11:00:22 -0700 | [diff] [blame] | 794 | std::string &formatted = *output; |
| 795 | va_list argptr; |
| 796 | va_start(argptr, fmt); |
| 797 | int reserve = vsnprintf(nullptr, 0, fmt, argptr); |
| 798 | va_end(argptr); |
| 799 | formatted.reserve(reserve + 1); |
| 800 | va_start(argptr, fmt); |
| 801 | int result = vsnprintf((char *)formatted.data(), formatted.capacity(), fmt, argptr); |
| 802 | va_end(argptr); |
| 803 | assert(result == reserve); |
| 804 | return result; |
| 805 | } |
| Courtney Goeltzenleuchter | 6a564a1 | 2015-09-18 16:30:24 -0600 | [diff] [blame] | 806 | |
| Chris Forbes | 8a25bce | 2016-03-24 12:06:35 +1300 | [diff] [blame] | 807 | #ifdef WIN32 |
| 808 | static inline int vasprintf(char **strp, char const *fmt, va_list ap) { |
| 809 | *strp = nullptr; |
| 810 | int size = _vscprintf(fmt, ap); |
| 811 | if (size >= 0) { |
| Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 812 | *strp = (char *)malloc(size + 1); |
| Chris Forbes | 8a25bce | 2016-03-24 12:06:35 +1300 | [diff] [blame] | 813 | if (!*strp) { |
| 814 | return -1; |
| 815 | } |
| Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 816 | _vsnprintf(*strp, size + 1, fmt, ap); |
| Chris Forbes | 8a25bce | 2016-03-24 12:06:35 +1300 | [diff] [blame] | 817 | } |
| 818 | return size; |
| 819 | } |
| 820 | #endif |
| 821 | |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 822 | // Output log message via DEBUG_REPORT. Takes format and variable arg list so that output string is only computed if a message |
| 823 | // needs to be logged |
| Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 824 | #ifndef WIN32 |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 825 | static inline bool log_msg(const debug_report_data *debug_data, VkFlags msg_flags, VkDebugReportObjectTypeEXT object_type, |
| Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 826 | uint64_t src_object, int32_t msg_code, const char *format, ...) __attribute__((format(printf, 6, 7))); |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 827 | static inline bool log_msg(const debug_report_data *debug_data, VkFlags msg_flags, VkDebugReportObjectTypeEXT object_type, |
| 828 | uint64_t src_object, std::string vuid_text, const char *format, ...) |
| 829 | __attribute__((format(printf, 6, 7))); |
| Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 830 | #endif |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 831 | static inline bool log_msg(const debug_report_data *debug_data, VkFlags msg_flags, VkDebugReportObjectTypeEXT object_type, |
| Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 832 | uint64_t src_object, int32_t msg_code, const char *format, ...) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 833 | VkFlags local_severity = 0; |
| 834 | VkFlags local_type = 0; |
| 835 | DebugReportFlagsToAnnotFlags(msg_flags, true, &local_severity, &local_type); |
| 836 | if (!debug_data || !(debug_data->active_severities & local_severity) || !(debug_data->active_types & local_type)) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 837 | // Message is not wanted |
| Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 838 | return false; |
| Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 839 | } |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 840 | |
| Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 841 | va_list argptr; |
| 842 | va_start(argptr, format); |
| Chris Forbes | 8a25bce | 2016-03-24 12:06:35 +1300 | [diff] [blame] | 843 | char *str; |
| Chris Forbes | ed6a1b3 | 2016-04-28 14:27:19 +1200 | [diff] [blame] | 844 | if (-1 == vasprintf(&str, format, argptr)) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 845 | // On failure, glibc vasprintf leaves str undefined |
| Chris Forbes | ed6a1b3 | 2016-04-28 14:27:19 +1200 | [diff] [blame] | 846 | str = nullptr; |
| 847 | } |
| Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 848 | va_end(argptr); |
| Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 849 | |
| 850 | std::string str_plus_spec_text(str); |
| 851 | |
| 852 | // If the msg_code is in the error map, tack on spec text to error message. |
| 853 | if (validation_error_map.find(msg_code) != validation_error_map.end()) { |
| 854 | str_plus_spec_text += " "; |
| 855 | str_plus_spec_text += validation_error_map[msg_code]; |
| 856 | } |
| 857 | |
| Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 858 | bool result = debug_log_msg(debug_data, msg_flags, object_type, src_object, 0, msg_code, "Validation", |
| Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 859 | str_plus_spec_text.c_str() ? str_plus_spec_text.c_str() : "Allocation failure"); |
| Chris Forbes | 8a25bce | 2016-03-24 12:06:35 +1300 | [diff] [blame] | 860 | free(str); |
| 861 | return result; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 862 | } |
| 863 | |
| Mark Lobodzinski | 316c18c | 2018-02-21 09:48:42 -0700 | [diff] [blame^] | 864 | // Overload of log_msg that takes a VUID string in place of a numerical VUID abstraction |
| 865 | static inline bool log_msg(const debug_report_data *debug_data, VkFlags msg_flags, VkDebugReportObjectTypeEXT object_type, |
| 866 | uint64_t src_object, std::string vuid_text, const char *format, ...) { |
| 867 | VkFlags local_severity = 0; |
| 868 | VkFlags local_type = 0; |
| 869 | DebugReportFlagsToAnnotFlags(msg_flags, true, &local_severity, &local_type); |
| 870 | if (!debug_data || !(debug_data->active_severities & local_severity) || !(debug_data->active_types & local_type)) { |
| 871 | // Message is not wanted |
| 872 | return false; |
| 873 | } |
| 874 | |
| 875 | va_list argptr; |
| 876 | va_start(argptr, format); |
| 877 | char *str; |
| 878 | if (-1 == vasprintf(&str, format, argptr)) { |
| 879 | // On failure, glibc vasprintf leaves str undefined |
| 880 | str = nullptr; |
| 881 | } |
| 882 | va_end(argptr); |
| 883 | |
| 884 | std::string str_plus_spec_text(str); |
| 885 | |
| 886 | // If the msg_code is in the error map, get ID, look up spec text, and tack it onto error message. |
| 887 | if (validation_error_text_map.find(vuid_text.c_str()) != validation_error_text_map.end()) { |
| 888 | str_plus_spec_text += " "; |
| 889 | str_plus_spec_text += validation_error_map[validation_error_text_map[vuid_text.c_str()]]; |
| 890 | } |
| 891 | |
| 892 | // Append layer prefix with VUID string, pass in UNDEFINED for numerical VUID |
| 893 | static const int UNDEFINED_VUID = -1; |
| 894 | bool result = debug_log_msg(debug_data, msg_flags, object_type, src_object, 0, UNDEFINED_VUID, "Validation", |
| 895 | str_plus_spec_text.c_str() ? str_plus_spec_text.c_str() : "Allocation failure", vuid_text.c_str()); |
| 896 | |
| 897 | free(str); |
| 898 | return result; |
| 899 | } |
| 900 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 901 | static inline VKAPI_ATTR VkBool32 VKAPI_CALL report_log_callback(VkFlags msg_flags, VkDebugReportObjectTypeEXT obj_type, |
| 902 | uint64_t src_object, size_t location, int32_t msg_code, |
| 903 | const char *layer_prefix, const char *message, void *user_data) { |
| 904 | char msg_flag_string[30]; |
| Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 905 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 906 | PrintMessageFlags(msg_flags, msg_flag_string); |
| Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 907 | |
| Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 908 | fprintf((FILE *)user_data, "%s(%s): msg_code: %d: %s\n", layer_prefix, msg_flag_string, msg_code, message); |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 909 | fflush((FILE *)user_data); |
| Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 910 | |
| 911 | return false; |
| Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 912 | } |
| Courtney Goeltzenleuchter | 5907ac4 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 913 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 914 | static inline VKAPI_ATTR VkBool32 VKAPI_CALL report_win32_debug_output_msg(VkFlags msg_flags, VkDebugReportObjectTypeEXT obj_type, |
| 915 | uint64_t src_object, size_t location, int32_t msg_code, |
| 916 | const char *layer_prefix, const char *message, |
| 917 | void *user_data) { |
| Courtney Goeltzenleuchter | 5907ac4 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 918 | #ifdef WIN32 |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 919 | char msg_flag_string[30]; |
| Courtney Goeltzenleuchter | 5907ac4 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 920 | char buf[2048]; |
| 921 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 922 | PrintMessageFlags(msg_flags, msg_flag_string); |
| Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 923 | _snprintf(buf, sizeof(buf) - 1, "%s (%s): msg_code: %d: %s\n", layer_prefix, msg_flag_string, msg_code, message); |
| Courtney Goeltzenleuchter | 5907ac4 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 924 | |
| 925 | OutputDebugString(buf); |
| 926 | #endif |
| 927 | |
| 928 | return false; |
| 929 | } |
| 930 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 931 | static inline VKAPI_ATTR VkBool32 VKAPI_CALL DebugBreakCallback(VkFlags msgFlags, VkDebugReportObjectTypeEXT obj_type, |
| 932 | uint64_t src_object, size_t location, int32_t msg_code, |
| 933 | const char *layer_prefix, const char *message, void *user_data) { |
| Mark Lobodzinski | c9d8165 | 2017-08-10 11:01:17 -0600 | [diff] [blame] | 934 | #ifdef WIN32 |
| 935 | DebugBreak(); |
| 936 | #else |
| 937 | raise(SIGTRAP); |
| 938 | #endif |
| 939 | |
| 940 | return false; |
| 941 | } |
| 942 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 943 | static inline VKAPI_ATTR VkBool32 VKAPI_CALL messenger_log_callback(VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, |
| 944 | VkDebugUtilsMessageTypeFlagsEXT message_type, |
| 945 | const VkDebugUtilsMessengerCallbackDataEXT *callback_data, |
| 946 | void *user_data) { |
| 947 | char msg_severity[30]; |
| 948 | char msg_type[30]; |
| 949 | |
| 950 | PrintMessageSeverity(message_severity, msg_severity); |
| 951 | PrintMessageType(message_type, msg_type); |
| 952 | |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 953 | fprintf((FILE *)user_data, "%s(%s / %s): msgNum: %d - %s\n", callback_data->pMessageIdName, msg_severity, msg_type, |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 954 | callback_data->messageIdNumber, callback_data->pMessage); |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 955 | fprintf((FILE *)user_data, " Objects: %d\n", callback_data->objectCount); |
| 956 | for (uint32_t obj = 0; obj < callback_data->objectCount; ++obj) { |
| 957 | fprintf((FILE *)user_data, " [%d] 0x%" PRIx64 ", type: %d, name: %s\n", obj, |
| 958 | callback_data->pObjects[obj].objectHandle, callback_data->pObjects[obj].objectType, |
| 959 | callback_data->pObjects[obj].pObjectName); |
| 960 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 961 | fflush((FILE *)user_data); |
| 962 | |
| 963 | return false; |
| Petr Kraus | e9388f6 | 2017-05-13 20:53:12 +0200 | [diff] [blame] | 964 | } |
| 965 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 966 | static inline VKAPI_ATTR VkBool32 VKAPI_CALL messenger_win32_debug_output_msg( |
| 967 | VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, VkDebugUtilsMessageTypeFlagsEXT message_type, |
| 968 | const VkDebugUtilsMessengerCallbackDataEXT *callback_data, void *user_data) { |
| 969 | #ifdef WIN32 |
| 970 | char buf[2048]; |
| 971 | char msg_severity[30]; |
| 972 | char msg_type[30]; |
| Mark Lobodzinski | 863d5de | 2017-05-22 10:10:07 -0600 | [diff] [blame] | 973 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 974 | PrintMessageSeverity(message_severity, msg_severity); |
| 975 | PrintMessageType(message_type, msg_type); |
| 976 | |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 977 | size_t buffer_space = sizeof(buf) - 1; |
| 978 | size_t remaining_space = buffer_space; |
| 979 | _snprintf(buf, sizeof(buf) - 1, "%s(%s / %s): msgNum: %d - %s\n", callback_data->pMessageIdName, msg_severity, msg_type, |
| 980 | callback_data->messageIdNumber, callback_data->pMessage); |
| 981 | remaining_space = buffer_space - strlen(buf); |
| 982 | _snprintf(buf, remaining_space, " Objects: %d\n", callback_data->objectCount); |
| 983 | for (uint32_t obj = 0; obj < callback_data->objectCount; ++obj) { |
| 984 | remaining_space = buffer_space - strlen(buf); |
| 985 | if (remaining_space > 0) { |
| 986 | _snprintf(buf, remaining_space, " [%d] 0x%" PRIx64 ", type: %d, name: %s\n", obj, |
| 987 | callback_data->pObjects[obj].objectHandle, callback_data->pObjects[obj].objectType, |
| 988 | callback_data->pObjects[obj].pObjectName); |
| 989 | } |
| 990 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 991 | OutputDebugString(buf); |
| 992 | #endif |
| 993 | |
| 994 | return false; |
| 995 | } |
| 996 | |
| 997 | // This utility converts from the VkDebugUtilsLabelEXT structure into the logging version of the structure. |
| 998 | // In the logging version, we only record what we absolutely need to convey back to the callbacks. |
| 999 | static inline void InsertLabelIntoLog(const VkDebugUtilsLabelEXT *utils_label, std::vector<LoggingLabelData> &log_vector) { |
| 1000 | LoggingLabelData log_label_data = {}; |
| 1001 | log_label_data.name = utils_label->pLabelName; |
| 1002 | log_label_data.color[0] = utils_label->color[0]; |
| 1003 | log_label_data.color[1] = utils_label->color[1]; |
| 1004 | log_label_data.color[2] = utils_label->color[2]; |
| 1005 | log_label_data.color[3] = utils_label->color[3]; |
| 1006 | log_vector.push_back(log_label_data); |
| 1007 | } |
| 1008 | |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 1009 | static inline void BeginQueueDebugUtilsLabel(debug_report_data *report_data, VkQueue queue, |
| 1010 | const VkDebugUtilsLabelEXT *label_info) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 1011 | if (nullptr != label_info && nullptr != label_info->pLabelName) { |
| 1012 | auto label_iter = report_data->debugUtilsQueueLabels->find(queue); |
| 1013 | if (label_iter == report_data->debugUtilsQueueLabels->end()) { |
| 1014 | std::vector<LoggingLabelData> new_queue_labels; |
| 1015 | InsertLabelIntoLog(label_info, new_queue_labels); |
| 1016 | report_data->debugUtilsQueueLabels->insert({queue, new_queue_labels}); |
| 1017 | } else { |
| 1018 | // If the last thing was a label insert, we need to pop it off of the label vector before any |
| 1019 | // changes. This is because a label added with "vkQueueInsertDebugUtilsLabelEXT" is only a |
| 1020 | // temporary location that exists until the next operation occurs. In this case, a new |
| 1021 | // "vkQueueBeginDebugUtilsLabelEXT" has occurred erasing the previous inserted label. |
| 1022 | if (report_data->queueLabelHasInsert) { |
| 1023 | report_data->queueLabelHasInsert = false; |
| 1024 | label_iter->second.pop_back(); |
| 1025 | } |
| 1026 | InsertLabelIntoLog(label_info, label_iter->second); |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 1031 | static inline void EndQueueDebugUtilsLabel(debug_report_data *report_data, VkQueue queue) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 1032 | auto label_iter = report_data->debugUtilsQueueLabels->find(queue); |
| 1033 | if (label_iter != report_data->debugUtilsQueueLabels->end()) { |
| 1034 | // If the last thing was a label insert, we need to pop it off of the label vector before any |
| 1035 | // changes. This is because a label added with "vkQueueInsertDebugUtilsLabelEXT" is only a |
| 1036 | // temporary location that exists until the next operation occurs. In this case, a |
| 1037 | // "vkQueueEndDebugUtilsLabelEXT" has occurred erasing the inserted label. |
| 1038 | if (report_data->queueLabelHasInsert) { |
| 1039 | report_data->queueLabelHasInsert = false; |
| 1040 | label_iter->second.pop_back(); |
| 1041 | } |
| 1042 | // Now pop the normal item |
| 1043 | label_iter->second.pop_back(); |
| 1044 | } |
| 1045 | } |
| 1046 | |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 1047 | static inline void InsertQueueDebugUtilsLabel(debug_report_data *report_data, VkQueue queue, |
| 1048 | const VkDebugUtilsLabelEXT *label_info) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 1049 | if (nullptr != label_info && nullptr != label_info->pLabelName) { |
| 1050 | auto label_iter = report_data->debugUtilsQueueLabels->find(queue); |
| 1051 | if (label_iter == report_data->debugUtilsQueueLabels->end()) { |
| 1052 | std::vector<LoggingLabelData> new_queue_labels; |
| 1053 | InsertLabelIntoLog(label_info, new_queue_labels); |
| 1054 | report_data->debugUtilsQueueLabels->insert({queue, new_queue_labels}); |
| 1055 | } else { |
| 1056 | // If the last thing was a label insert, we need to pop it off of the label vector before any |
| 1057 | // changes. This is because a label added with "vkQueueInsertDebugUtilsLabelEXT" is only a |
| 1058 | // temporary location that exists until the next operation occurs. In this case, a new |
| 1059 | // "vkQueueInsertDebugUtilsLabelEXT" has occurred erasing the previous inserted label. |
| 1060 | if (report_data->queueLabelHasInsert) { |
| 1061 | label_iter->second.pop_back(); |
| 1062 | } |
| 1063 | // Insert this new label and mark it as one that has been "inserted" so we can remove it on |
| 1064 | // the next queue label operation. |
| 1065 | InsertLabelIntoLog(label_info, label_iter->second); |
| 1066 | report_data->queueLabelHasInsert = true; |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 1071 | static inline void BeginCmdDebugUtilsLabel(debug_report_data *report_data, VkCommandBuffer command_buffer, |
| 1072 | const VkDebugUtilsLabelEXT *label_info) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 1073 | if (nullptr != label_info && nullptr != label_info->pLabelName) { |
| 1074 | auto label_iter = report_data->debugUtilsCmdBufLabels->find(command_buffer); |
| 1075 | if (label_iter == report_data->debugUtilsCmdBufLabels->end()) { |
| 1076 | std::vector<LoggingLabelData> new_cmdbuf_labels; |
| 1077 | InsertLabelIntoLog(label_info, new_cmdbuf_labels); |
| 1078 | report_data->debugUtilsCmdBufLabels->insert({command_buffer, new_cmdbuf_labels}); |
| 1079 | } else { |
| 1080 | // If the last thing was a label insert, we need to pop it off of the label vector before any |
| 1081 | // changes. This is because a label added with "vkCmdInsertDebugUtilsLabelEXT" is only a |
| 1082 | // temporary location that exists until the next operation occurs. In this case, a |
| 1083 | // "vkCmdBeginDebugUtilsLabelEXT" has occurred erasing the inserted label. |
| 1084 | if (report_data->cmdBufLabelHasInsert) { |
| 1085 | report_data->cmdBufLabelHasInsert = false; |
| 1086 | label_iter->second.pop_back(); |
| 1087 | } |
| 1088 | InsertLabelIntoLog(label_info, label_iter->second); |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 1093 | static inline void EndCmdDebugUtilsLabel(debug_report_data *report_data, VkCommandBuffer command_buffer) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 1094 | auto label_iter = report_data->debugUtilsCmdBufLabels->find(command_buffer); |
| 1095 | if (label_iter != report_data->debugUtilsCmdBufLabels->end()) { |
| 1096 | // If the last thing was a label insert, we need to pop it off of the label vector before any |
| 1097 | // changes. This is because a label added with "vkCmdInsertDebugUtilsLabelEXT" is only a |
| 1098 | // temporary location that exists until the next operation occurs. In this case, a |
| 1099 | // "vkCmdEndDebugUtilsLabelEXT" has occurred erasing the inserted label. |
| 1100 | if (report_data->cmdBufLabelHasInsert) { |
| 1101 | report_data->cmdBufLabelHasInsert = false; |
| 1102 | label_iter->second.pop_back(); |
| 1103 | } |
| 1104 | // Now pop the normal item |
| 1105 | label_iter->second.pop_back(); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| Mark Young | 8504ba6 | 2018-03-21 13:35:34 -0600 | [diff] [blame] | 1109 | static inline void InsertCmdDebugUtilsLabel(debug_report_data *report_data, VkCommandBuffer command_buffer, |
| 1110 | const VkDebugUtilsLabelEXT *label_info) { |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 1111 | if (nullptr != label_info && nullptr != label_info->pLabelName) { |
| 1112 | auto label_iter = report_data->debugUtilsCmdBufLabels->find(command_buffer); |
| 1113 | if (label_iter == report_data->debugUtilsCmdBufLabels->end()) { |
| 1114 | std::vector<LoggingLabelData> new_cmdbuf_labels; |
| 1115 | InsertLabelIntoLog(label_info, new_cmdbuf_labels); |
| 1116 | report_data->debugUtilsCmdBufLabels->insert({command_buffer, new_cmdbuf_labels}); |
| 1117 | } else { |
| 1118 | // If the last thing was a label insert, we need to pop it off of the label vector before any |
| 1119 | // changes. This is because a label added with "vkCmdInsertDebugUtilsLabelEXT" is only a |
| 1120 | // temporary location that exists until the next operation occurs. In this case, a new |
| 1121 | // "vkCmdInsertDebugUtilsLabelEXT" has occurred erasing the previous inserted label. |
| 1122 | if (report_data->cmdBufLabelHasInsert) { |
| 1123 | label_iter->second.pop_back(); |
| 1124 | } |
| 1125 | // Insert this new label and mark it as one that has been "inserted" so we can remove it on |
| 1126 | // the next command buffer label operation. |
| 1127 | InsertLabelIntoLog(label_info, label_iter->second); |
| 1128 | report_data->cmdBufLabelHasInsert = true; |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| Mark Lobodzinski | 863d5de | 2017-05-22 10:10:07 -0600 | [diff] [blame] | 1132 | |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1133 | #endif // LAYER_LOGGING_H |