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