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