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