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