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