From a362e42124af56dd85cb9bc32838779a5a329fd5 Mon Sep 17 00:00:00 2001 From: Jonathan Glines Date: Thu, 29 Dec 2022 14:48:39 -0500 Subject: [PATCH] Add custom logging callback mechanism to NvPerfUtility This is needed to send log messages to the RenderDoc UI rather than to stderr. --- .../redist/NvPerfUtility/include/NvPerfInit.h | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/renderdoc/driver/ihv/nv/official/PerfSDK/redist/NvPerfUtility/include/NvPerfInit.h b/renderdoc/driver/ihv/nv/official/PerfSDK/redist/NvPerfUtility/include/NvPerfInit.h index 015d128b0..0b86394fd 100644 --- a/renderdoc/driver/ihv/nv/official/PerfSDK/redist/NvPerfUtility/include/NvPerfInit.h +++ b/renderdoc/driver/ihv/nv/official/PerfSDK/redist/NvPerfUtility/include/NvPerfInit.h @@ -174,6 +174,15 @@ namespace nv { namespace perf { COUNT }; + using WriteCustomLogCallbackFn = void (*)( + const char* /* pPrefix */, + const char* /* pDate */, + const char* /* pTime */, + const char* /* pFunctionName */, + const char* /* pMessage */, + void* /* pData */ + ); + struct LogSettings { uint32_t volumeLevels[(unsigned)LogSeverity::COUNT] = { 50, 50, 50 }; @@ -183,13 +192,15 @@ namespace nv { namespace perf { #else bool writePlatform = false; #endif - bool writeStderr = true; - FILE* writeFileFD = nullptr; - bool appendToFile = true; - LogSeverity flushFileSeverity = LogSeverity::Err; + bool writeStderr = true; + FILE* writeFileFD = nullptr; + bool appendToFile = true; + LogSeverity flushFileSeverity = LogSeverity::Err; + WriteCustomLogCallbackFn pFnWriteCustomCB = nullptr; + void* writeCustomData = nullptr; - bool logDate = true; - bool logTime = true; + bool logDate = true; + bool logTime = true; LogSettings() { @@ -327,6 +338,18 @@ namespace nv { namespace perf { return true; } + inline void UserLogEnableCustom(WriteCustomLogCallbackFn cb, void* data) + { + LogSettings* pSettings = GetLogSettingsStorage_(); + pSettings->pFnWriteCustomCB = cb; + pSettings->writeCustomData = data; + } + + inline void UserLogDisableCustom() + { + UserLogEnableCustom(nullptr, nullptr); + } + inline void UserLogImplStderr(const char* pMessage) { fprintf(stderr, "%s", pMessage); @@ -446,6 +469,17 @@ namespace nv { namespace perf { UserLogImplFileFlush(settings.writeFileFD); } } + if (settings.pFnWriteCustomCB) + { + settings.pFnWriteCustomCB( + pPrefix, + settings.logDate ? datebuf : nullptr, + settings.logTime ? timebuf : nullptr, + pFunctionName, + str.c_str(), + settings.writeCustomData + ); + } } inline bool InitializeNvPerf()