blob: b1f3ac425c45d81d6146f71f3f1b5cfe553932a8 [file] [log] [blame]
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -06001/*
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -06004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
24 * Author: Tobin Ehlis <tobin@lunarg.com>
25 *
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060026 */
27
28#ifndef LAYER_LOGGING_H
29#define LAYER_LOGGING_H
30
31#include <stdio.h>
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -060032#include <stdarg.h>
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060033#include <stdbool.h>
34#include <unordered_map>
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -060035#include <inttypes.h>
Tobin Ehlis890adf12015-11-02 15:45:19 -070036#include "vk_loader_platform.h"
David Pinedo9316d3b2015-11-06 12:54:48 -070037#include "vulkan/vk_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060038#include "vk_layer_data.h"
39#include "vk_layer_table.h"
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060040
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060041typedef struct _debug_report_data {
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060042 VkLayerDbgFunctionNode *g_pDbgFunctionHead;
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -060043 VkFlags active_flags;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060044 bool g_DEBUG_REPORT;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060045} debug_report_data;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060046
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060047template debug_report_data *get_my_data_ptr<debug_report_data>(
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -060048 void *data_key,
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060049 std::unordered_map<void *, debug_report_data *> &data_map);
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060050
51// Utility function to handle reporting
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -060052static inline VkBool32 debug_report_log_msg(
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060053 debug_report_data *debug_data,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060054 VkFlags msgFlags,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070055 VkDebugReportObjectTypeEXT objectType,
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -060056 uint64_t srcObject,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060057 size_t location,
58 int32_t msgCode,
59 const char* pLayerPrefix,
60 const char* pMsg)
61{
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -060062 VkBool32 bail = false;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060063 VkLayerDbgFunctionNode *pTrav = debug_data->g_pDbgFunctionHead;
64 while (pTrav) {
65 if (pTrav->msgFlags & msgFlags) {
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -060066 if (pTrav->pfnMsgCallback(msgFlags,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060067 objectType, srcObject,
68 location,
69 msgCode,
70 pLayerPrefix,
71 pMsg,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070072 pTrav->pUserData)) {
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -060073 bail = true;
74 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060075 }
76 pTrav = pTrav->pNext;
77 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -060078
79 return bail;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060080}
81
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060082static inline debug_report_data *debug_report_create_instance(
83 VkLayerInstanceDispatchTable *table,
84 VkInstance inst,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060085 uint32_t extension_count,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060086 const char*const* ppEnabledExtensions) // layer or extension name to be enabled
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060087{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060088 debug_report_data *debug_data;
89 PFN_vkGetInstanceProcAddr gpa = table->GetInstanceProcAddr;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060090
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070091 table->CreateDebugReportCallbackEXT = (PFN_vkCreateDebugReportCallbackEXT) gpa(inst, "vkCreateDebugReportCallbackEXT");
92 table->DestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT) gpa(inst, "vkDestroyDebugReportCallbackEXT");
93 table->DebugReportMessageEXT = (PFN_vkDebugReportMessageEXT) gpa(inst, "vkDebugReportMessageEXT");
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060094
95 debug_data = (debug_report_data *) malloc(sizeof(debug_report_data));
96 if (!debug_data) return NULL;
97
98 memset(debug_data, 0, sizeof(debug_report_data));
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -060099 for (uint32_t i = 0; i < extension_count; i++) {
100 /* TODO: Check other property fields */
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700101 if (strcmp(ppEnabledExtensions[i], VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0) {
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600102 debug_data->g_DEBUG_REPORT = true;
103 }
104 }
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600105 return debug_data;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600106}
107
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600108static inline void layer_debug_report_destroy_instance(debug_report_data *debug_data)
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600109{
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600110 VkLayerDbgFunctionNode *pTrav;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600111 VkLayerDbgFunctionNode *pTravNext;
112
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600113 if (!debug_data) {
114 return;
115 }
116
117 pTrav = debug_data->g_pDbgFunctionHead;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600118 /* Clear out any leftover callbacks */
119 while (pTrav) {
120 pTravNext = pTrav->pNext;
121
122 debug_report_log_msg(
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700123 debug_data, VK_DEBUG_REPORT_WARN_BIT_EXT,
124 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, (uint64_t) pTrav->msgCallback,
125 0, VK_DEBUG_REPORT_ERROR_CALLBACK_REF,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600126 "DebugReport",
127 "Debug Report callbacks not removed before DestroyInstance");
128
129 free(pTrav);
130 pTrav = pTravNext;
131 }
132 debug_data->g_pDbgFunctionHead = NULL;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600133
134 free(debug_data);
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600135}
136
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600137static inline debug_report_data *layer_debug_report_create_device(
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600138 debug_report_data *instance_debug_data,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600139 VkDevice device)
140{
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600141 /* DEBUG_REPORT shares data between Instance and Device,
142 * so just return instance's data pointer */
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600143 return instance_debug_data;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600144}
145
146static inline void layer_debug_report_destroy_device(VkDevice device)
147{
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600148 /* Nothing to do since we're using instance data record */
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600149}
150
151static inline VkResult layer_create_msg_callback(
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700152 debug_report_data *debug_data,
153 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
154 const VkAllocationCallbacks *pAllocator,
155 VkDebugReportCallbackEXT *pCallback)
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600156{
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700157 /* TODO: Use app allocator */
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600158 VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode*)malloc(sizeof(VkLayerDbgFunctionNode));
159 if (!pNewDbgFuncNode)
160 return VK_ERROR_OUT_OF_HOST_MEMORY;
161
Tobin Ehliseb7715d2015-09-21 09:36:47 -0600162 // Handle of 0 is logging_callback so use allocated Node address as unique handle
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700163 if (!(*pCallback))
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700164 *pCallback = (VkDebugReportCallbackEXT) pNewDbgFuncNode;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700165 pNewDbgFuncNode->msgCallback = *pCallback;
166 pNewDbgFuncNode->pfnMsgCallback = pCreateInfo->pfnCallback;
167 pNewDbgFuncNode->msgFlags = pCreateInfo->flags;
168 pNewDbgFuncNode->pUserData = pCreateInfo->pUserData;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600169 pNewDbgFuncNode->pNext = debug_data->g_pDbgFunctionHead;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600170
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600171 debug_data->g_pDbgFunctionHead = pNewDbgFuncNode;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700172 debug_data->active_flags |= pCreateInfo->flags;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600173
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600174 debug_report_log_msg(
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700175 debug_data, VK_DEBUG_REPORT_DEBUG_BIT_EXT,
176 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, (uint64_t) *pCallback,
177 0, VK_DEBUG_REPORT_ERROR_CALLBACK_REF,
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600178 "DebugReport",
179 "Added callback");
180 return VK_SUCCESS;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600181}
182
Courtney Goeltzenleuchter37d482d2015-06-14 11:28:24 -0600183static inline void layer_destroy_msg_callback(
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600184 debug_report_data *debug_data,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700185 VkDebugReportCallbackEXT callback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700186 const VkAllocationCallbacks *pAllocator)
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600187{
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600188 VkLayerDbgFunctionNode *pTrav = debug_data->g_pDbgFunctionHead;
189 VkLayerDbgFunctionNode *pPrev = pTrav;
Mike Stroyan14a57e72015-07-31 16:20:39 -0600190 bool matched;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600191
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600192 debug_data->active_flags = 0;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600193 while (pTrav) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700194 if (pTrav->msgCallback == callback) {
Mike Stroyan14a57e72015-07-31 16:20:39 -0600195 matched = true;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600196 pPrev->pNext = pTrav->pNext;
197 if (debug_data->g_pDbgFunctionHead == pTrav) {
198 debug_data->g_pDbgFunctionHead = pTrav->pNext;
199 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600200 debug_report_log_msg(
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700201 debug_data, VK_DEBUG_REPORT_DEBUG_BIT_EXT,
202 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, (uint64_t) pTrav->msgCallback,
203 0, VK_DEBUG_REPORT_ERROR_CALLBACK_REF,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600204 "DebugReport",
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600205 "Destroyed callback");
Mike Stroyan14a57e72015-07-31 16:20:39 -0600206 } else {
207 matched = false;
Mike Stroyan22ff5022015-08-10 16:14:18 -0600208 debug_data->active_flags |= pTrav->msgFlags;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600209 }
210 pPrev = pTrav;
211 pTrav = pTrav->pNext;
Mike Stroyan14a57e72015-07-31 16:20:39 -0600212 if (matched) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700213 /* TODO: Use pAllocator */
Mike Stroyan14a57e72015-07-31 16:20:39 -0600214 free(pPrev);
215 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600216 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600217}
218
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600219static inline PFN_vkVoidFunction debug_report_get_instance_proc_addr(
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600220 debug_report_data *debug_data,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600221 const char *funcName)
222{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600223 if (!debug_data || !debug_data->g_DEBUG_REPORT) {
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600224 return NULL;
225 }
226
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700227 if (!strcmp(funcName, "vkCreateDebugReportCallbackEXT")) {
228 return (PFN_vkVoidFunction) vkCreateDebugReportCallbackEXT;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600229 }
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700230 if (!strcmp(funcName, "vkDestroyDebugReportCallbackEXT")) {
231 return (PFN_vkVoidFunction) vkDestroyDebugReportCallbackEXT;
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600232 }
233
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700234 if (!strcmp(funcName, "vkDebugReportMessageEXT")) {
235 return (PFN_vkVoidFunction) vkDebugReportMessageEXT;
Courtney Goeltzenleuchter822e8d72015-11-30 15:28:25 -0700236 }
237
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600238 return NULL;
239}
240
241/*
Courtney Goeltzenleuchter6a564a12015-09-18 16:30:24 -0600242 * Checks if the message will get logged.
243 * Allows layer to defer collecting & formating data if the
244 * message will be discarded.
245 */
246static inline VkBool32 will_log_msg(
247 debug_report_data *debug_data,
248 VkFlags msgFlags)
249{
250 if (!debug_data || !(debug_data->active_flags & msgFlags)) {
251 /* message is not wanted */
252 return false;
253 }
254
255 return true;
256}
257
258/*
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600259 * Output log message via DEBUG_REPORT
260 * Takes format and variable arg list so that output string
261 * is only computed if a message needs to be logged
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600262 */
Michael Lentine010f4692015-11-03 16:19:46 -0800263#ifndef WIN32
264static inline VkBool32 log_msg(
265 debug_report_data *debug_data,
266 VkFlags msgFlags,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700267 VkDebugReportObjectTypeEXT objectType,
Michael Lentine010f4692015-11-03 16:19:46 -0800268 uint64_t srcObject,
269 size_t location,
270 int32_t msgCode,
271 const char* pLayerPrefix,
272 const char* format,
273 ...) __attribute__ ((format (printf, 8, 9)));
274#endif
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600275static inline VkBool32 log_msg(
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600276 debug_report_data *debug_data,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600277 VkFlags msgFlags,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700278 VkDebugReportObjectTypeEXT objectType,
Tony Barbour1d2cd3f2015-07-03 10:33:54 -0600279 uint64_t srcObject,
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600280 size_t location,
281 int32_t msgCode,
282 const char* pLayerPrefix,
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600283 const char* format,
284 ...)
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600285{
Courtney Goeltzenleuchter61cb70a2015-06-26 15:14:50 -0600286 if (!debug_data || !(debug_data->active_flags & msgFlags)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600287 /* message is not wanted */
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600288 return false;
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600289 }
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600290
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600291 char str[1024];
292 va_list argptr;
293 va_start(argptr, format);
294 vsnprintf(str, 1024, format, argptr);
295 va_end(argptr);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600296 return debug_report_log_msg(
297 debug_data, msgFlags, objectType,
298 srcObject, location, msgCode,
299 pLayerPrefix, str);
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600300}
301
Chia-I Wu9ab61502015-11-06 06:42:02 +0800302static inline VKAPI_ATTR VkBool32 VKAPI_CALL log_callback(
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600303 VkFlags msgFlags,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700304 VkDebugReportObjectTypeEXT objType,
Tony Barbour1d2cd3f2015-07-03 10:33:54 -0600305 uint64_t srcObject,
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600306 size_t location,
307 int32_t msgCode,
308 const char* pLayerPrefix,
309 const char* pMsg,
Courtney Goeltzenleuchteraf5e7552015-11-30 11:52:06 -0700310 const void* pUserData)
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600311{
312 char msg_flags[30];
Courtney Goeltzenleuchter7d8503b2015-06-11 15:58:51 -0600313
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600314 print_msg_flags(msgFlags, msg_flags);
315
Mark Lobodzinskia1456492015-10-06 09:57:52 -0600316 fprintf((FILE *) pUserData, "%s(%s): object: %#" PRIx64 " type: %d location: %lu msgCode: %d: %s\n",
317 pLayerPrefix, msg_flags, srcObject, objType, (unsigned long)location, msgCode, pMsg);
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600318 fflush((FILE *) pUserData);
319
320 return false;
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600321}
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600322
Chia-I Wu9ab61502015-11-06 06:42:02 +0800323static inline VKAPI_ATTR VkBool32 VKAPI_CALL win32_debug_output_msg(
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600324 VkFlags msgFlags,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600326 uint64_t srcObject,
327 size_t location,
328 int32_t msgCode,
329 const char* pLayerPrefix,
330 const char* pMsg,
Courtney Goeltzenleuchteraf5e7552015-11-30 11:52:06 -0700331 const void* pUserData)
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600332{
333#ifdef WIN32
334 char msg_flags[30];
335 char buf[2048];
336
337 print_msg_flags(msgFlags, msg_flags);
Courtney Goeltzenleuchter22d8d792015-10-07 17:03:42 -0600338 _snprintf(buf, sizeof(buf) - 1, "%s (%s): object: 0x%" PRIxPTR " type: %d location: " PRINTF_SIZE_T_SPECIFIER " msgCode: %d: %s\n",
Courtney Goeltzenleuchter5907ac42015-10-05 14:41:34 -0600339 pLayerPrefix, msg_flags, srcObject, objType, location, msgCode, pMsg);
340
341 OutputDebugString(buf);
342#endif
343
344 return false;
345}
346
Courtney Goeltzenleuchter2f25bb42015-06-14 11:29:24 -0600347#endif // LAYER_LOGGING_H