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