Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 4 | * |
Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | * of this software and/or associated documentation files (the "Materials"), to |
| 7 | * deal in the Materials without restriction, including without limitation the |
| 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 | * sell copies of the Materials, and to permit persons to whom the Materials |
| 10 | * are furnished to do so, subject to the following conditions: |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 11 | * |
Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 12 | * The above copyright notice(s) and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Materials. |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 14 | * |
Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * |
| 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 22 | * USE OR OTHER DEALINGS IN THE MATERIALS |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 23 | * |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 24 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 25 | * Author: Tobin Ehlis <tobin@lunarg.com> |
| 26 | * |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #ifndef LAYER_LOGGING_H |
| 30 | #define LAYER_LOGGING_H |
| 31 | |
| 32 | #include <stdio.h> |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 33 | #include <stdarg.h> |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 34 | #include <stdbool.h> |
| 35 | #include <unordered_map> |
Tobin Ehlis | 1dce5f1 | 2015-07-07 10:42:20 -0600 | [diff] [blame] | 36 | #include <inttypes.h> |
Tobin Ehlis | c8d7593 | 2015-11-02 15:45:19 -0700 | [diff] [blame] | 37 | #include "vk_loader_platform.h" |
David Pinedo | 329ca9e | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 38 | #include "vulkan/vk_layer.h" |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 39 | #include "vk_layer_data.h" |
| 40 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 41 | |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 42 | typedef struct _debug_report_data { |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 43 | VkLayerDbgFunctionNode *g_pDbgFunctionHead; |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 44 | VkFlags active_flags; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 45 | bool g_DEBUG_REPORT; |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 46 | } debug_report_data; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 47 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 48 | template debug_report_data *get_my_data_ptr<debug_report_data>(void *data_key, |
| 49 | std::unordered_map<void *, debug_report_data *> &data_map); |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 50 | |
| 51 | // Utility function to handle reporting |
Dustin Graves | e331918 | 2016-04-05 09:41:17 -0600 | [diff] [blame] | 52 | static inline bool debug_report_log_msg(debug_report_data *debug_data, VkFlags msgFlags, VkDebugReportObjectTypeEXT objectType, |
| 53 | uint64_t srcObject, size_t location, int32_t msgCode, const char *pLayerPrefix, |
| 54 | const char *pMsg) { |
| 55 | bool bail = false; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 56 | VkLayerDbgFunctionNode *pTrav = debug_data->g_pDbgFunctionHead; |
| 57 | while (pTrav) { |
| 58 | if (pTrav->msgFlags & msgFlags) { |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 59 | if (pTrav->pfnMsgCallback(msgFlags, objectType, srcObject, location, msgCode, pLayerPrefix, pMsg, pTrav->pUserData)) { |
Courtney Goeltzenleuchter | 0d6857f | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 60 | bail = true; |
| 61 | } |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 62 | } |
| 63 | pTrav = pTrav->pNext; |
| 64 | } |
Courtney Goeltzenleuchter | 0d6857f | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 65 | |
| 66 | return bail; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 67 | } |
| 68 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 69 | static inline debug_report_data * |
| 70 | debug_report_create_instance(VkLayerInstanceDispatchTable *table, VkInstance inst, uint32_t extension_count, |
| 71 | const char *const *ppEnabledExtensions) // layer or extension name to be enabled |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 72 | { |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 73 | debug_report_data *debug_data; |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 74 | PFN_vkGetInstanceProcAddr gpa = table->GetInstanceProcAddr; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 75 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 76 | table->CreateDebugReportCallbackEXT = (PFN_vkCreateDebugReportCallbackEXT)gpa(inst, "vkCreateDebugReportCallbackEXT"); |
| 77 | table->DestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT)gpa(inst, "vkDestroyDebugReportCallbackEXT"); |
| 78 | table->DebugReportMessageEXT = (PFN_vkDebugReportMessageEXT)gpa(inst, "vkDebugReportMessageEXT"); |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 79 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 80 | debug_data = (debug_report_data *)malloc(sizeof(debug_report_data)); |
| 81 | if (!debug_data) |
| 82 | return NULL; |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 83 | |
| 84 | memset(debug_data, 0, sizeof(debug_report_data)); |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 85 | for (uint32_t i = 0; i < extension_count; i++) { |
| 86 | /* TODO: Check other property fields */ |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 87 | if (strcmp(ppEnabledExtensions[i], VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0) { |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 88 | debug_data->g_DEBUG_REPORT = true; |
| 89 | } |
| 90 | } |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 91 | return debug_data; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 94 | static inline void layer_debug_report_destroy_instance(debug_report_data *debug_data) { |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 95 | VkLayerDbgFunctionNode *pTrav; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 96 | VkLayerDbgFunctionNode *pTravNext; |
| 97 | |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 98 | if (!debug_data) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | pTrav = debug_data->g_pDbgFunctionHead; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 103 | /* Clear out any leftover callbacks */ |
| 104 | while (pTrav) { |
| 105 | pTravNext = pTrav->pNext; |
| 106 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 107 | debug_report_log_msg(debug_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, |
| 108 | (uint64_t)pTrav->msgCallback, 0, VK_DEBUG_REPORT_ERROR_CALLBACK_REF_EXT, "DebugReport", |
| 109 | "Debug Report callbacks not removed before DestroyInstance"); |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 110 | |
| 111 | free(pTrav); |
| 112 | pTrav = pTravNext; |
| 113 | } |
| 114 | debug_data->g_pDbgFunctionHead = NULL; |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 115 | |
| 116 | free(debug_data); |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 117 | } |
| 118 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 119 | static inline debug_report_data *layer_debug_report_create_device(debug_report_data *instance_debug_data, VkDevice device) { |
Courtney Goeltzenleuchter | 7ad921d | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 120 | /* DEBUG_REPORT shares data between Instance and Device, |
| 121 | * so just return instance's data pointer */ |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 122 | return instance_debug_data; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 123 | } |
| 124 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 125 | static inline void layer_debug_report_destroy_device(VkDevice device) { /* Nothing to do since we're using instance data record */ } |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 126 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 127 | static inline VkResult layer_create_msg_callback(debug_report_data *debug_data, |
| 128 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 129 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback) { |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 130 | /* TODO: Use app allocator */ |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 131 | VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode *)malloc(sizeof(VkLayerDbgFunctionNode)); |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 132 | if (!pNewDbgFuncNode) |
| 133 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 134 | |
Tobin Ehlis | 44f667b | 2015-09-21 09:36:47 -0600 | [diff] [blame] | 135 | // Handle of 0 is logging_callback so use allocated Node address as unique handle |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 136 | if (!(*pCallback)) |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 137 | *pCallback = (VkDebugReportCallbackEXT)pNewDbgFuncNode; |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 138 | pNewDbgFuncNode->msgCallback = *pCallback; |
| 139 | pNewDbgFuncNode->pfnMsgCallback = pCreateInfo->pfnCallback; |
| 140 | pNewDbgFuncNode->msgFlags = pCreateInfo->flags; |
| 141 | pNewDbgFuncNode->pUserData = pCreateInfo->pUserData; |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 142 | pNewDbgFuncNode->pNext = debug_data->g_pDbgFunctionHead; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 143 | |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 144 | debug_data->g_pDbgFunctionHead = pNewDbgFuncNode; |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 145 | debug_data->active_flags |= pCreateInfo->flags; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 146 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 147 | debug_report_log_msg(debug_data, VK_DEBUG_REPORT_DEBUG_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, |
| 148 | (uint64_t)*pCallback, 0, VK_DEBUG_REPORT_ERROR_CALLBACK_REF_EXT, "DebugReport", "Added callback"); |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 149 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 150 | } |
| 151 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 152 | static inline void layer_destroy_msg_callback(debug_report_data *debug_data, VkDebugReportCallbackEXT callback, |
| 153 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 154 | VkLayerDbgFunctionNode *pTrav = debug_data->g_pDbgFunctionHead; |
| 155 | VkLayerDbgFunctionNode *pPrev = pTrav; |
Mike Stroyan | 0a78bcc | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 156 | bool matched; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 157 | |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 158 | debug_data->active_flags = 0; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 159 | while (pTrav) { |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 160 | if (pTrav->msgCallback == callback) { |
Mike Stroyan | 0a78bcc | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 161 | matched = true; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 162 | pPrev->pNext = pTrav->pNext; |
| 163 | if (debug_data->g_pDbgFunctionHead == pTrav) { |
| 164 | debug_data->g_pDbgFunctionHead = pTrav->pNext; |
| 165 | } |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 166 | debug_report_log_msg(debug_data, VK_DEBUG_REPORT_DEBUG_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, |
| 167 | (uint64_t)pTrav->msgCallback, 0, VK_DEBUG_REPORT_ERROR_CALLBACK_REF_EXT, "DebugReport", |
| 168 | "Destroyed callback"); |
Mike Stroyan | 0a78bcc | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 169 | } else { |
| 170 | matched = false; |
Mike Stroyan | f8155e4 | 2015-08-10 16:14:18 -0600 | [diff] [blame] | 171 | debug_data->active_flags |= pTrav->msgFlags; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 172 | } |
| 173 | pPrev = pTrav; |
| 174 | pTrav = pTrav->pNext; |
Mike Stroyan | 0a78bcc | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 175 | if (matched) { |
Courtney Goeltzenleuchter | f6a6e22 | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 176 | /* TODO: Use pAllocator */ |
Mike Stroyan | 0a78bcc | 2015-07-31 16:20:39 -0600 | [diff] [blame] | 177 | free(pPrev); |
| 178 | } |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 179 | } |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 180 | } |
| 181 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 182 | static inline PFN_vkVoidFunction debug_report_get_instance_proc_addr(debug_report_data *debug_data, const char *funcName) { |
Courtney Goeltzenleuchter | 1f1fbbd | 2015-06-14 12:03:26 -0600 | [diff] [blame] | 183 | if (!debug_data || !debug_data->g_DEBUG_REPORT) { |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 184 | return NULL; |
| 185 | } |
| 186 | |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 187 | if (!strcmp(funcName, "vkCreateDebugReportCallbackEXT")) { |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 188 | return (PFN_vkVoidFunction)vkCreateDebugReportCallbackEXT; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 189 | } |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 190 | if (!strcmp(funcName, "vkDestroyDebugReportCallbackEXT")) { |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 191 | return (PFN_vkVoidFunction)vkDestroyDebugReportCallbackEXT; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 192 | } |
| 193 | |
Courtney Goeltzenleuchter | acb1359 | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 194 | if (!strcmp(funcName, "vkDebugReportMessageEXT")) { |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 195 | return (PFN_vkVoidFunction)vkDebugReportMessageEXT; |
Courtney Goeltzenleuchter | 6175e4b | 2015-11-30 15:28:25 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 198 | return NULL; |
| 199 | } |
| 200 | |
| 201 | /* |
Courtney Goeltzenleuchter | ee8d581 | 2015-09-18 16:30:24 -0600 | [diff] [blame] | 202 | * Checks if the message will get logged. |
| 203 | * Allows layer to defer collecting & formating data if the |
| 204 | * message will be discarded. |
| 205 | */ |
Dustin Graves | e331918 | 2016-04-05 09:41:17 -0600 | [diff] [blame] | 206 | static inline bool will_log_msg(debug_report_data *debug_data, VkFlags msgFlags) { |
Courtney Goeltzenleuchter | ee8d581 | 2015-09-18 16:30:24 -0600 | [diff] [blame] | 207 | if (!debug_data || !(debug_data->active_flags & msgFlags)) { |
| 208 | /* message is not wanted */ |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | return true; |
| 213 | } |
| 214 | |
Chris Forbes | 16058d1 | 2016-03-24 12:06:35 +1300 | [diff] [blame] | 215 | #ifdef WIN32 |
| 216 | static inline int vasprintf(char **strp, char const *fmt, va_list ap) { |
| 217 | *strp = nullptr; |
| 218 | int size = _vscprintf(fmt, ap); |
| 219 | if (size >= 0) { |
| 220 | *strp = (char *)malloc(size+1); |
| 221 | if (!*strp) { |
| 222 | return -1; |
| 223 | } |
| 224 | _vsnprintf(*strp, size+1, fmt, ap); |
| 225 | } |
| 226 | return size; |
| 227 | } |
| 228 | #endif |
| 229 | |
Courtney Goeltzenleuchter | ee8d581 | 2015-09-18 16:30:24 -0600 | [diff] [blame] | 230 | /* |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 231 | * Output log message via DEBUG_REPORT |
| 232 | * Takes format and variable arg list so that output string |
| 233 | * is only computed if a message needs to be logged |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 234 | */ |
Michael Lentine | cbc4a5e | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 235 | #ifndef WIN32 |
Dustin Graves | e331918 | 2016-04-05 09:41:17 -0600 | [diff] [blame] | 236 | static inline bool log_msg(debug_report_data *debug_data, VkFlags msgFlags, VkDebugReportObjectTypeEXT objectType, |
| 237 | uint64_t srcObject, size_t location, int32_t msgCode, const char *pLayerPrefix, const char *format, ...) |
| 238 | __attribute__((format(printf, 8, 9))); |
Michael Lentine | cbc4a5e | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 239 | #endif |
Dustin Graves | e331918 | 2016-04-05 09:41:17 -0600 | [diff] [blame] | 240 | static inline bool log_msg(debug_report_data *debug_data, VkFlags msgFlags, VkDebugReportObjectTypeEXT objectType, |
| 241 | uint64_t srcObject, size_t location, int32_t msgCode, const char *pLayerPrefix, const char *format, |
| 242 | ...) { |
Courtney Goeltzenleuchter | 5914019 | 2015-06-26 15:14:50 -0600 | [diff] [blame] | 243 | if (!debug_data || !(debug_data->active_flags & msgFlags)) { |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 244 | /* message is not wanted */ |
Courtney Goeltzenleuchter | 0d6857f | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 245 | return false; |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 246 | } |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 247 | |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 248 | va_list argptr; |
| 249 | va_start(argptr, format); |
Chris Forbes | 16058d1 | 2016-03-24 12:06:35 +1300 | [diff] [blame] | 250 | char *str; |
| 251 | vasprintf(&str, format, argptr); |
Courtney Goeltzenleuchter | 3e19bf6 | 2015-06-14 09:50:18 -0600 | [diff] [blame] | 252 | va_end(argptr); |
Dustin Graves | e331918 | 2016-04-05 09:41:17 -0600 | [diff] [blame] | 253 | bool result = debug_report_log_msg(debug_data, msgFlags, objectType, srcObject, location, msgCode, pLayerPrefix, str); |
Chris Forbes | 16058d1 | 2016-03-24 12:06:35 +1300 | [diff] [blame] | 254 | free(str); |
| 255 | return result; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 256 | } |
| 257 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 258 | static inline VKAPI_ATTR VkBool32 VKAPI_CALL log_callback(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject, |
| 259 | size_t location, int32_t msgCode, const char *pLayerPrefix, |
| 260 | const char *pMsg, void *pUserData) { |
Courtney Goeltzenleuchter | 7ad921d | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 261 | char msg_flags[30]; |
Courtney Goeltzenleuchter | 41fa5b0 | 2015-06-11 15:58:51 -0600 | [diff] [blame] | 262 | |
Courtney Goeltzenleuchter | 7ad921d | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 263 | print_msg_flags(msgFlags, msg_flags); |
| 264 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 265 | fprintf((FILE *)pUserData, "%s(%s): object: %#" PRIx64 " type: %d location: %lu msgCode: %d: %s\n", pLayerPrefix, msg_flags, |
| 266 | srcObject, objType, (unsigned long)location, msgCode, pMsg); |
| 267 | fflush((FILE *)pUserData); |
Courtney Goeltzenleuchter | 0d6857f | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 268 | |
| 269 | return false; |
Courtney Goeltzenleuchter | 7ad921d | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 270 | } |
Courtney Goeltzenleuchter | b94f051 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 271 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 272 | static inline VKAPI_ATTR VkBool32 VKAPI_CALL win32_debug_output_msg(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 273 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 274 | const char *pLayerPrefix, const char *pMsg, void *pUserData) { |
Courtney Goeltzenleuchter | b94f051 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 275 | #ifdef WIN32 |
| 276 | char msg_flags[30]; |
| 277 | char buf[2048]; |
| 278 | |
| 279 | print_msg_flags(msgFlags, msg_flags); |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 280 | _snprintf(buf, sizeof(buf) - 1, |
| 281 | "%s (%s): object: 0x%" PRIxPTR " type: %d location: " PRINTF_SIZE_T_SPECIFIER " msgCode: %d: %s\n", pLayerPrefix, |
| 282 | msg_flags, (size_t)srcObject, objType, location, msgCode, pMsg); |
Courtney Goeltzenleuchter | b94f051 | 2015-10-05 14:41:34 -0600 | [diff] [blame] | 283 | |
| 284 | OutputDebugString(buf); |
| 285 | #endif |
| 286 | |
| 287 | return false; |
| 288 | } |
| 289 | |
Courtney Goeltzenleuchter | 7ad921d | 2015-06-14 11:29:24 -0600 | [diff] [blame] | 290 | #endif // LAYER_LOGGING_H |