Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Vulkan |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #ifndef LAYER_LOGGING_H |
| 29 | #define LAYER_LOGGING_H |
| 30 | |
| 31 | #include <stdio.h> |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 32 | #include <stdarg.h> |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 33 | #include <stdbool.h> |
| 34 | #include <unordered_map> |
Tobin Ehlis | 60a9b4f | 2015-07-07 10:42:20 -0600 | [diff] [blame] | 35 | #include <inttypes.h> |
Tobin Ehlis | 890adf1 | 2015-11-02 15:45:19 -0700 | [diff] [blame^] | 36 | #include "vk_loader_platform.h" |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 37 | #include "vk_layer.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 38 | #include "vk_layer_data.h" |
| 39 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 40 | |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 41 | typedef struct _debug_report_data { |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 42 | VkLayerDbgFunctionNode *g_pDbgFunctionHead; |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 43 | VkFlags active_flags; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 44 | bool g_DEBUG_REPORT; |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 45 | } debug_report_data; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 46 | |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 47 | template debug_report_data *get_my_data_ptr<debug_report_data>( |
Courtney Goeltzenleuchter | 7dcc6a7 | 2015-06-11 16:01:11 -0600 | [diff] [blame] | 48 | void *data_key, |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 49 | std::unordered_map<void *, debug_report_data *> &data_map); |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 50 | |
| 51 | // Utility function to handle reporting |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 52 | static inline VkBool32 debug_report_log_msg( |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 53 | debug_report_data *debug_data, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 54 | VkFlags msgFlags, |
Tobin Ehlis | 60a9b4f | 2015-07-07 10:42:20 -0600 | [diff] [blame] | 55 | VkDbgObjectType objectType, |
| 56 | uint64_t srcObject, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 57 | size_t location, |
| 58 | int32_t msgCode, |
| 59 | const char* pLayerPrefix, |
| 60 | const char* pMsg) |
| 61 | { |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 62 | VkBool32 bail = false; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 63 | VkLayerDbgFunctionNode *pTrav = debug_data->g_pDbgFunctionHead; |
| 64 | while (pTrav) { |
| 65 | if (pTrav->msgFlags & msgFlags) { |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 66 | if (pTrav->pfnMsgCallback(msgFlags, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 67 | objectType, srcObject, |
| 68 | location, |
| 69 | msgCode, |
| 70 | pLayerPrefix, |
| 71 | pMsg, |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 72 | (void *) pTrav->pUserData)) { |
| 73 | bail = true; |
| 74 | } |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 75 | } |
| 76 | pTrav = pTrav->pNext; |
| 77 | } |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 78 | |
| 79 | return bail; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 80 | } |
| 81 | |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 82 | static inline debug_report_data *debug_report_create_instance( |
| 83 | VkLayerInstanceDispatchTable *table, |
| 84 | VkInstance inst, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 85 | uint32_t extension_count, |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 86 | const char*const* ppEnabledExtensions) // layer or extension name to be enabled |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 87 | { |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 88 | debug_report_data *debug_data; |
| 89 | PFN_vkGetInstanceProcAddr gpa = table->GetInstanceProcAddr; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 90 | |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 91 | table->DbgCreateMsgCallback = (PFN_vkDbgCreateMsgCallback) gpa(inst, "vkDbgCreateMsgCallback"); |
| 92 | table->DbgDestroyMsgCallback = (PFN_vkDbgDestroyMsgCallback) gpa(inst, "vkDbgDestroyMsgCallback"); |
| 93 | |
| 94 | debug_data = (debug_report_data *) malloc(sizeof(debug_report_data)); |
| 95 | if (!debug_data) return NULL; |
| 96 | |
| 97 | memset(debug_data, 0, sizeof(debug_report_data)); |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 98 | for (uint32_t i = 0; i < extension_count; i++) { |
| 99 | /* TODO: Check other property fields */ |
Courtney Goeltzenleuchter | 05159a9 | 2015-07-30 11:32:46 -0600 | [diff] [blame] | 100 | if (strcmp(ppEnabledExtensions[i], VK_DEBUG_REPORT_EXTENSION_NAME) == 0) { |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 101 | debug_data->g_DEBUG_REPORT = true; |
| 102 | } |
| 103 | } |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 104 | return debug_data; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 105 | } |
| 106 | |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 107 | static inline void layer_debug_report_destroy_instance(debug_report_data *debug_data) |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 108 | { |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 109 | VkLayerDbgFunctionNode *pTrav; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 110 | VkLayerDbgFunctionNode *pTravNext; |
| 111 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 112 | if (!debug_data) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | pTrav = debug_data->g_pDbgFunctionHead; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 117 | /* Clear out any leftover callbacks */ |
| 118 | while (pTrav) { |
| 119 | pTravNext = pTrav->pNext; |
| 120 | |
| 121 | debug_report_log_msg( |
| 122 | debug_data, VK_DBG_REPORT_WARN_BIT, |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 123 | VK_OBJECT_TYPE_MSG_CALLBACK, (uint64_t) pTrav->msgCallback, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 124 | 0, DEBUG_REPORT_CALLBACK_REF, |
| 125 | "DebugReport", |
| 126 | "Debug Report callbacks not removed before DestroyInstance"); |
| 127 | |
| 128 | free(pTrav); |
| 129 | pTrav = pTravNext; |
| 130 | } |
| 131 | debug_data->g_pDbgFunctionHead = NULL; |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 132 | |
| 133 | free(debug_data); |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 134 | } |
| 135 | |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 136 | static inline debug_report_data *layer_debug_report_create_device( |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 137 | debug_report_data *instance_debug_data, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 138 | VkDevice device) |
| 139 | { |
Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 140 | /* DEBUG_REPORT shares data between Instance and Device, |
| 141 | * so just return instance's data pointer */ |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 142 | return instance_debug_data; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static inline void layer_debug_report_destroy_device(VkDevice device) |
| 146 | { |
Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 147 | /* Nothing to do since we're using instance data record */ |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static inline VkResult layer_create_msg_callback( |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 151 | debug_report_data *debug_data, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 152 | VkFlags msgFlags, |
| 153 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
| 154 | void *pUserData, |
| 155 | VkDbgMsgCallback *pMsgCallback) |
| 156 | { |
| 157 | VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode*)malloc(sizeof(VkLayerDbgFunctionNode)); |
| 158 | if (!pNewDbgFuncNode) |
| 159 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 160 | |
Tobin Ehlis | eb7715d | 2015-09-21 09:36:47 -0600 | [diff] [blame] | 161 | // Handle of 0 is logging_callback so use allocated Node address as unique handle |
| 162 | if (!(*pMsgCallback)) |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 163 | *pMsgCallback = (VkDbgMsgCallback) pNewDbgFuncNode; |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 164 | pNewDbgFuncNode->msgCallback = *pMsgCallback; |
| 165 | pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback; |
| 166 | pNewDbgFuncNode->msgFlags = msgFlags; |
| 167 | pNewDbgFuncNode->pUserData = pUserData; |
| 168 | pNewDbgFuncNode->pNext = debug_data->g_pDbgFunctionHead; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 169 | |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 170 | debug_data->g_pDbgFunctionHead = pNewDbgFuncNode; |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 171 | debug_data->active_flags |= msgFlags; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 172 | |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 173 | debug_report_log_msg( |
| 174 | debug_data, VK_DBG_REPORT_DEBUG_BIT, |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 175 | VK_OBJECT_TYPE_MSG_CALLBACK, (uint64_t) *pMsgCallback, |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 176 | 0, DEBUG_REPORT_CALLBACK_REF, |
| 177 | "DebugReport", |
| 178 | "Added callback"); |
| 179 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 180 | } |
| 181 | |
Courtney Goeltzenleuchter | 37d482d | 2015-06-14 11:28:24 -0600 | [diff] [blame] | 182 | static inline void layer_destroy_msg_callback( |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 183 | debug_report_data *debug_data, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 184 | VkDbgMsgCallback msg_callback) |
| 185 | { |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 186 | VkLayerDbgFunctionNode *pTrav = debug_data->g_pDbgFunctionHead; |
| 187 | VkLayerDbgFunctionNode *pPrev = pTrav; |
Mike Stroyan | 14a57e7 | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 188 | bool matched; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 189 | |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 190 | debug_data->active_flags = 0; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 191 | while (pTrav) { |
| 192 | if (pTrav->msgCallback == msg_callback) { |
Mike Stroyan | 14a57e7 | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 193 | matched = true; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 194 | pPrev->pNext = pTrav->pNext; |
| 195 | if (debug_data->g_pDbgFunctionHead == pTrav) { |
| 196 | debug_data->g_pDbgFunctionHead = pTrav->pNext; |
| 197 | } |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 198 | debug_report_log_msg( |
| 199 | debug_data, VK_DBG_REPORT_DEBUG_BIT, |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 200 | VK_OBJECT_TYPE_MSG_CALLBACK, (uint64_t) pTrav->msgCallback, |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 201 | 0, DEBUG_REPORT_NONE, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 202 | "DebugReport", |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 203 | "Destroyed callback"); |
Mike Stroyan | 14a57e7 | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 204 | } else { |
| 205 | matched = false; |
Mike Stroyan | 22ff502 | 2015-08-10 16:14:18 -0600 | [diff] [blame] | 206 | debug_data->active_flags |= pTrav->msgFlags; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 207 | } |
| 208 | pPrev = pTrav; |
| 209 | pTrav = pTrav->pNext; |
Mike Stroyan | 14a57e7 | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 210 | if (matched) { |
| 211 | free(pPrev); |
| 212 | } |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 213 | } |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 214 | } |
| 215 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 216 | static inline PFN_vkVoidFunction debug_report_get_instance_proc_addr( |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 217 | debug_report_data *debug_data, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 218 | const char *funcName) |
| 219 | { |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 220 | if (!debug_data || !debug_data->g_DEBUG_REPORT) { |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 221 | return NULL; |
| 222 | } |
| 223 | |
| 224 | if (!strcmp(funcName, "vkDbgCreateMsgCallback")) { |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 225 | return (PFN_vkVoidFunction) vkDbgCreateMsgCallback; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 226 | } |
| 227 | if (!strcmp(funcName, "vkDbgDestroyMsgCallback")) { |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 228 | return (PFN_vkVoidFunction) vkDbgDestroyMsgCallback; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | return NULL; |
| 232 | } |
| 233 | |
| 234 | /* |
Courtney Goeltzenleuchter | 6a564a1 | 2015-09-18 16:30:24 -0600 | [diff] [blame] | 235 | * Checks if the message will get logged. |
| 236 | * Allows layer to defer collecting & formating data if the |
| 237 | * message will be discarded. |
| 238 | */ |
| 239 | static inline VkBool32 will_log_msg( |
| 240 | debug_report_data *debug_data, |
| 241 | VkFlags msgFlags) |
| 242 | { |
| 243 | if (!debug_data || !(debug_data->active_flags & msgFlags)) { |
| 244 | /* message is not wanted */ |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | return true; |
| 249 | } |
| 250 | |
| 251 | /* |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 252 | * Output log message via DEBUG_REPORT |
| 253 | * Takes format and variable arg list so that output string |
| 254 | * is only computed if a message needs to be logged |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 255 | */ |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 256 | static inline VkBool32 log_msg( |
Courtney Goeltzenleuchter | e45acec | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 257 | debug_report_data *debug_data, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 258 | VkFlags msgFlags, |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 259 | VkDbgObjectType objectType, |
| 260 | uint64_t srcObject, |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 261 | size_t location, |
| 262 | int32_t msgCode, |
| 263 | const char* pLayerPrefix, |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 264 | const char* format, |
| 265 | ...) |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 266 | { |
Courtney Goeltzenleuchter | 61cb70a | 2015-06-26 15:14:50 -0600 | [diff] [blame] | 267 | if (!debug_data || !(debug_data->active_flags & msgFlags)) { |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 268 | /* message is not wanted */ |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 269 | return false; |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 270 | } |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 271 | |
Courtney Goeltzenleuchter | b9f0bf3 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 272 | char str[1024]; |
| 273 | va_list argptr; |
| 274 | va_start(argptr, format); |
| 275 | vsnprintf(str, 1024, format, argptr); |
| 276 | va_end(argptr); |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 277 | return debug_report_log_msg( |
| 278 | debug_data, msgFlags, objectType, |
| 279 | srcObject, location, msgCode, |
| 280 | pLayerPrefix, str); |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 281 | } |
| 282 | |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 283 | static inline VkBool32 VKAPI log_callback( |
Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 284 | VkFlags msgFlags, |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 285 | VkDbgObjectType objType, |
| 286 | uint64_t srcObject, |
Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 287 | size_t location, |
| 288 | int32_t msgCode, |
| 289 | const char* pLayerPrefix, |
| 290 | const char* pMsg, |
| 291 | void* pUserData) |
| 292 | { |
| 293 | char msg_flags[30]; |
Courtney Goeltzenleuchter | 7d8503b | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 294 | |
Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 295 | print_msg_flags(msgFlags, msg_flags); |
| 296 | |
Mark Lobodzinski | a145649 | 2015-10-06 09:57:52 -0600 | [diff] [blame] | 297 | fprintf((FILE *) pUserData, "%s(%s): object: %#" PRIx64 " type: %d location: %lu msgCode: %d: %s\n", |
| 298 | pLayerPrefix, msg_flags, srcObject, objType, (unsigned long)location, msgCode, pMsg); |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 299 | fflush((FILE *) pUserData); |
| 300 | |
| 301 | return false; |
Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 302 | } |
Courtney Goeltzenleuchter | 5907ac4 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 303 | |
| 304 | static inline VkBool32 VKAPI win32_debug_output_msg( |
| 305 | VkFlags msgFlags, |
| 306 | VkDbgObjectType objType, |
| 307 | uint64_t srcObject, |
| 308 | size_t location, |
| 309 | int32_t msgCode, |
| 310 | const char* pLayerPrefix, |
| 311 | const char* pMsg, |
| 312 | void* pUserData) |
| 313 | { |
| 314 | #ifdef WIN32 |
| 315 | char msg_flags[30]; |
| 316 | char buf[2048]; |
| 317 | |
| 318 | print_msg_flags(msgFlags, msg_flags); |
Courtney Goeltzenleuchter | 22d8d79 | 2015-10-07 17:03:42 -0600 | [diff] [blame] | 319 | _snprintf(buf, sizeof(buf) - 1, "%s (%s): object: 0x%" PRIxPTR " type: %d location: " PRINTF_SIZE_T_SPECIFIER " msgCode: %d: %s\n", |
Courtney Goeltzenleuchter | 5907ac4 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 320 | pLayerPrefix, msg_flags, srcObject, objType, location, msgCode, pMsg); |
| 321 | |
| 322 | OutputDebugString(buf); |
| 323 | #endif |
| 324 | |
| 325 | return false; |
| 326 | } |
| 327 | |
Courtney Goeltzenleuchter | 2f25bb4 | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 328 | #endif // LAYER_LOGGING_H |