blob: 3cd5a0c2131712af70875ee49347d7bca2910928 [file] [log] [blame]
Jon Ashburn21001f62015-02-16 08:26:50 -07001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Jon Ashburn21001f62015-02-16 08:26:50 -07003 *
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#include <stdio.h>
Jon Ashburne4722392015-03-03 15:07:15 -070025#include <stdbool.h>
Jon Ashburn21001f62015-02-16 08:26:50 -070026
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060027static VK_LAYER_DBG_FUNCTION_NODE *g_pDbgFunctionHead = NULL;
28static VK_LAYER_DBG_REPORT_LEVEL g_reportingLevel = VK_DBG_LAYER_LEVEL_INFO;
29static VK_LAYER_DBG_ACTION g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Jon Ashburne4722392015-03-03 15:07:15 -070030static bool g_actionIsDefault = true;
Jon Ashburn21001f62015-02-16 08:26:50 -070031static FILE *g_logFile = NULL;
32
33// Utility function to handle reporting
34// If callbacks are enabled, use them, otherwise use printf
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060035static void layerCbMsg(VK_DBG_MSG_TYPE msgType,
Mike Stroyan230e6252015-04-17 12:36:38 -060036 VkValidationLevel validationLevel,
37 VkObject srcObject,
Jon Ashburn21001f62015-02-16 08:26:50 -070038 size_t location,
39 int32_t msgCode,
40 const char* pLayerPrefix,
41 const char* pMsg)
42{
Courtney Goeltzenleuchterd661a822015-02-22 16:15:32 -070043 if (g_logFile == NULL) {
44 g_logFile = stdout;
45 }
46
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060047 if (g_debugAction & (VK_DBG_LAYER_ACTION_LOG_MSG | VK_DBG_LAYER_ACTION_CALLBACK)) {
48 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
Jon Ashburn21001f62015-02-16 08:26:50 -070049 switch (msgType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060050 case VK_DBG_MSG_ERROR:
51 if (g_reportingLevel <= VK_DBG_LAYER_LEVEL_ERROR) {
52 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG) {
Jon Ashburn21001f62015-02-16 08:26:50 -070053 fprintf(g_logFile, "{%s}ERROR : %s\n", pLayerPrefix, pMsg);
Courtney Goeltzenleuchter0c7be302015-02-25 16:56:00 -070054 fflush(g_logFile);
55 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060056 if (g_debugAction & VK_DBG_LAYER_ACTION_CALLBACK)
Jon Ashburn21001f62015-02-16 08:26:50 -070057 while (pTrav) {
58 pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);
59 pTrav = pTrav->pNext;
60 }
61 }
62 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063 case VK_DBG_MSG_WARNING:
64 if (g_reportingLevel <= VK_DBG_LAYER_LEVEL_WARN) {
65 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburn21001f62015-02-16 08:26:50 -070066 fprintf(g_logFile, "{%s}WARN : %s\n", pLayerPrefix, pMsg);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060067 if (g_debugAction & VK_DBG_LAYER_ACTION_CALLBACK)
Jon Ashburn21001f62015-02-16 08:26:50 -070068 while (pTrav) {
69 pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);
70 pTrav = pTrav->pNext;
71 }
72 }
73 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060074 case VK_DBG_MSG_PERF_WARNING:
75 if (g_reportingLevel <= VK_DBG_LAYER_LEVEL_PERF_WARN) {
76 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburn21001f62015-02-16 08:26:50 -070077 fprintf(g_logFile, "{%s}PERF_WARN : %s\n", pLayerPrefix, pMsg);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060078 if (g_debugAction & VK_DBG_LAYER_ACTION_CALLBACK)
Jon Ashburn21001f62015-02-16 08:26:50 -070079 while (pTrav) {
80 pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);
81 pTrav = pTrav->pNext;
82 }
83 }
84 break;
85 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060086 if (g_reportingLevel <= VK_DBG_LAYER_LEVEL_INFO) {
87 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburn21001f62015-02-16 08:26:50 -070088 fprintf(g_logFile, "{%s}INFO : %s\n", pLayerPrefix, pMsg);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060089 if (g_debugAction & VK_DBG_LAYER_ACTION_CALLBACK)
Jon Ashburn21001f62015-02-16 08:26:50 -070090 while (pTrav) {
91 pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);
92 pTrav = pTrav->pNext;
93 }
94 }
95 break;
96 }
97 }
98}