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