Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 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 | #include <stdio.h> |
Jon Ashburn | e472239 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 25 | #include <stdbool.h> |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 26 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 27 | static VK_LAYER_DBG_FUNCTION_NODE *g_pDbgFunctionHead = NULL; |
| 28 | static VK_LAYER_DBG_REPORT_LEVEL g_reportingLevel = VK_DBG_LAYER_LEVEL_INFO; |
| 29 | static VK_LAYER_DBG_ACTION g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG; |
Jon Ashburn | e472239 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 30 | static bool g_actionIsDefault = true; |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 31 | static FILE *g_logFile = NULL; |
| 32 | |
| 33 | // Utility function to handle reporting |
| 34 | // If callbacks are enabled, use them, otherwise use printf |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 35 | static void layerCbMsg(VK_DBG_MSG_TYPE msgType, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 36 | VkValidationLevel validationLevel, |
| 37 | VkBaseObject srcObject, |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 38 | size_t location, |
| 39 | int32_t msgCode, |
| 40 | const char* pLayerPrefix, |
| 41 | const char* pMsg) |
| 42 | { |
Courtney Goeltzenleuchter | d661a82 | 2015-02-22 16:15:32 -0700 | [diff] [blame] | 43 | if (g_logFile == NULL) { |
| 44 | g_logFile = stdout; |
| 45 | } |
| 46 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 47 | if (g_debugAction & (VK_DBG_LAYER_ACTION_LOG_MSG | VK_DBG_LAYER_ACTION_CALLBACK)) { |
| 48 | VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead; |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 49 | switch (msgType) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 50 | 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 Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 53 | fprintf(g_logFile, "{%s}ERROR : %s\n", pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 0c7be30 | 2015-02-25 16:56:00 -0700 | [diff] [blame] | 54 | fflush(g_logFile); |
| 55 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 56 | if (g_debugAction & VK_DBG_LAYER_ACTION_CALLBACK) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 57 | while (pTrav) { |
| 58 | pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData); |
| 59 | pTrav = pTrav->pNext; |
| 60 | } |
| 61 | } |
| 62 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 63 | 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 Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 66 | fprintf(g_logFile, "{%s}WARN : %s\n", pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 67 | if (g_debugAction & VK_DBG_LAYER_ACTION_CALLBACK) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 68 | while (pTrav) { |
| 69 | pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData); |
| 70 | pTrav = pTrav->pNext; |
| 71 | } |
| 72 | } |
| 73 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 74 | 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 Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 77 | fprintf(g_logFile, "{%s}PERF_WARN : %s\n", pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 78 | if (g_debugAction & VK_DBG_LAYER_ACTION_CALLBACK) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 79 | while (pTrav) { |
| 80 | pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData); |
| 81 | pTrav = pTrav->pNext; |
| 82 | } |
| 83 | } |
| 84 | break; |
| 85 | default: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 86 | if (g_reportingLevel <= VK_DBG_LAYER_LEVEL_INFO) { |
| 87 | if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 88 | fprintf(g_logFile, "{%s}INFO : %s\n", pLayerPrefix, pMsg); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 89 | if (g_debugAction & VK_DBG_LAYER_ACTION_CALLBACK) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 90 | while (pTrav) { |
| 91 | pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData); |
| 92 | pTrav = pTrav->pNext; |
| 93 | } |
| 94 | } |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } |