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