From 3c8ef6d2120e1de22ff05334f9db0a121c6c2cad Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 15 Apr 2015 06:59:41 +1200 Subject: [PATCH] shader_checker: add plumbing for debug --- layers/shader_checker.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/layers/shader_checker.cpp b/layers/shader_checker.cpp index 8b49660..835a334 100644 --- a/layers/shader_checker.cpp +++ b/layers/shader_checker.cpp @@ -31,14 +31,17 @@ #include "loader_platform.h" #include "vk_dispatch_table_helper.h" #include "vkLayer.h" +#include "layers_config.h" +#include "layers_msg.h" // The following is #included again to catch certain OS-specific functions // being used: #include "loader_platform.h" #include "SPIRV/spirv.h" -static std::unordered_map tableMap; +static std::unordered_map tableMap; +static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce); static void @@ -103,6 +106,27 @@ struct shader_source { static std::unordered_map shader_map; +static void +initLayer() +{ + const char *strOpt; + // initialize ShaderChecker options + getLayerOptionEnum("ShaderCheckerReportLevel", (uint32_t *) &g_reportingLevel); + g_actionIsDefault = getLayerOptionEnum("ShaderCheckerDebugAction", (uint32_t *) &g_debugAction); + + if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG) + { + strOpt = getLayerOption("ShaderCheckerLogFilename"); + if (strOpt) + { + g_logFile = fopen(strOpt, "w"); + } + if (g_logFile == NULL) + g_logFile = stdout; + } +} + + static VkLayerDispatchTable * initLayerTable(const VkBaseLayerObject *gpuw) { VkLayerDispatchTable *pTable; @@ -128,6 +152,8 @@ VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceC { VkLayerDispatchTable* pTable = tableMap[gpu]; VkResult result = pTable->CreateDevice(gpu, pCreateInfo, pDevice); + + loader_platform_thread_once(&g_initOnce, initLayer); // create a mapping for the device object into the dispatch table tableMap.emplace(*pDevice, pTable); return result; @@ -727,6 +753,8 @@ VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char* pName) initLayerTable((const VkBaseLayerObject *) gpu); + loader_platform_thread_once(&g_initOnce, initLayer); + #define ADD_HOOK(fn) \ if (!strncmp(#fn, pName, sizeof(#fn))) \ return (void *) fn -- 2.7.4