diff options
| author | Yong He <yonghe@outlook.com> | 2021-04-29 14:19:51 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-29 14:19:51 -0700 |
| commit | 2482271fffbe85efc1bd7efcf74a76f6ed436012 (patch) | |
| tree | 707da083c8eda527b7c548d636cb884cf53c53eb /examples/example-base | |
| parent | ad6f3070251f25cf022c231b8567d78e98061127 (diff) | |
`gfx` DebugCallback and debug layer. (#1822)
* `gfx` DebugCallback and debug layer.
Diffstat (limited to 'examples/example-base')
| -rw-r--r-- | examples/example-base/example-base.cpp | 51 | ||||
| -rw-r--r-- | examples/example-base/example-base.h | 3 |
2 files changed, 54 insertions, 0 deletions
diff --git a/examples/example-base/example-base.cpp b/examples/example-base/example-base.cpp index a75ddf247..04f938697 100644 --- a/examples/example-base/example-base.cpp +++ b/examples/example-base/example-base.cpp @@ -25,6 +25,10 @@ Slang::Result WindowedAppBase::initializeBase(const char* title, int width, int gWindow->events.sizeChanged = Slang::Action<>(this, &WindowedAppBase::windowSizeChanged); // Initialize the rendering layer. +#ifdef _DEBUG + // Enable debug layer in debug config. + gfxEnableDebugLayer(); +#endif IDevice::Desc deviceDesc = {}; // deviceDesc.slang.targetFlags = SLANG_TARGET_FLAG_DUMP_IR; gfx::Result res = gfxCreateDevice(&deviceDesc, gDevice.writeRef()); @@ -170,6 +174,53 @@ int64_t getCurrentTime() { return std::chrono::high_resolution_clock::now().time 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 + } +}; + +void initDebugCallback() +{ + static DebugCallback callback = {}; + gfxSetDebugCallback(&callback); +} + #ifdef _WIN32 void _Win32OutputDebugString(const char* str) { OutputDebugStringW(Slang::String(str).toWString().begin()); } #endif diff --git a/examples/example-base/example-base.h b/examples/example-base/example-base.h index 67f722c11..a1c46aa53 100644 --- a/examples/example-base/example-base.h +++ b/examples/example-base/example-base.h @@ -72,10 +72,13 @@ inline void diagnoseIfNeeded(slang::IBlob* diagnosticsBlob) } } +void initDebugCallback(); template<typename TApp> int innerMain() { + initDebugCallback(); + TApp app; if (SLANG_FAILED(app.initialize())) |
