summaryrefslogtreecommitdiffstats
path: root/examples/example-base
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2025-08-01 10:13:00 -0700
committerGitHub <noreply@github.com>2025-08-01 17:13:00 +0000
commitef743e7166d3e6ada04c1ac9f68c05abe6884c0a (patch)
treef4ce6dbc12b6f8c9bb6d1b0fa2e5e002436c7a42 /examples/example-base
parenta660640d41eba1392c2fbc16ab9ff3661f82b0f9 (diff)
Enable debug-layers for examples when not using test-mode (#8024)
* Enable debug-layers for examples when not using test-mode * simplify in test mode * format code (#83) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'examples/example-base')
-rw-r--r--examples/example-base/example-base.cpp95
1 files changed, 52 insertions, 43 deletions
diff --git a/examples/example-base/example-base.cpp b/examples/example-base/example-base.cpp
index 95864b0af..34103b804 100644
--- a/examples/example-base/example-base.cpp
+++ b/examples/example-base/example-base.cpp
@@ -14,6 +14,50 @@
using namespace Slang;
using namespace rhi;
+class DebugCallback : public rhi::IDebugCallback
+{
+public:
+ virtual SLANG_NO_THROW void SLANG_MCALL handleMessage(
+ rhi::DebugMessageType type,
+ rhi::DebugMessageSource source,
+ const char* message) override
+ {
+ const char* typeStr = "";
+ switch (type)
+ {
+ case rhi::DebugMessageType::Info:
+ typeStr = "INFO: ";
+ break;
+ case rhi::DebugMessageType::Warning:
+ typeStr = "WARNING: ";
+ break;
+ case rhi::DebugMessageType::Error:
+ typeStr = "ERROR: ";
+ break;
+ default:
+ break;
+ }
+ const char* sourceStr = "[GraphicsLayer]: ";
+ switch (source)
+ {
+ case rhi::DebugMessageSource::Slang:
+ sourceStr = "[Slang]: ";
+ break;
+ case rhi::DebugMessageSource::Driver:
+ sourceStr = "[Driver]: ";
+ break;
+ }
+ printf("%s%s%s\n", sourceStr, typeStr, message);
+#ifdef _WIN32
+ OutputDebugStringA(sourceStr);
+ OutputDebugStringA(typeStr);
+ OutputDebugStringW(String(message).toWString());
+ OutputDebugStringW(L"\n");
+#endif
+ }
+};
+
+
Slang::Result WindowedAppBase::initializeBase(
const char* title,
int width,
@@ -22,15 +66,20 @@ Slang::Result WindowedAppBase::initializeBase(
{
DeviceDesc deviceDesc = {};
deviceDesc.deviceType = deviceType;
-#ifdef _DEBUG
- deviceDesc.enableValidation = true;
-#endif
+
+ // Enable validation when not in test mode to avoid output pollution during testing
+ deviceDesc.enableValidation = !isTestMode();
+
+ // Set debug callback (only used when validation is enabled, i.e., non-test mode)
+ static DebugCallback debugCallback;
+ deviceDesc.debugCallback = &debugCallback;
slang::CompilerOptionEntry slangOptions[] = {
{slang::CompilerOptionName::EmitSpirvDirectly, {slang::CompilerOptionValueKind::Int, 1}},
{slang::CompilerOptionName::DebugInformation,
{slang::CompilerOptionValueKind::Int, SLANG_DEBUG_INFO_LEVEL_STANDARD}}};
deviceDesc.slang.compilerOptionEntries = slangOptions;
+
// When in test mode, don't include debug information to avoid altering hash values during
// testing Otherwise, include debug information for better debugging experience
deviceDesc.slang.compilerOptionEntryCount = isTestMode() ? 1 : 2;
@@ -222,46 +271,6 @@ int64_t getTimerFrequency()
return std::chrono::high_resolution_clock::period::den;
}
-class DebugCallback : public IDebugCallback
-{
-public:
- virtual SLANG_NO_THROW void SLANG_MCALL
- handleMessage(DebugMessageType type, DebugMessageSource source, const char* message) override
- {
- const char* typeStr = "";
- switch (type)
- {
- case DebugMessageType::Info:
- typeStr = "INFO: ";
- break;
- case DebugMessageType::Warning:
- typeStr = "WARNING: ";
- break;
- case DebugMessageType::Error:
- typeStr = "ERROR: ";
- break;
- default:
- break;
- }
- const char* sourceStr = "[GraphicsLayer]: ";
- switch (source)
- {
- case DebugMessageSource::Slang:
- sourceStr = "[Slang]: ";
- break;
- case DebugMessageSource::Driver:
- sourceStr = "[Driver]: ";
- break;
- }
- printf("%s%s%s\n", sourceStr, typeStr, message);
-#ifdef _WIN32
- OutputDebugStringA(sourceStr);
- OutputDebugStringA(typeStr);
- OutputDebugStringW(String(message).toWString());
- OutputDebugStringW(L"\n");
-#endif
- }
-};
#ifdef _WIN32
void _Win32OutputDebugString(const char* str)