diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/example-base/example-base.cpp | 51 | ||||
| -rw-r--r-- | examples/example-base/example-base.h | 3 | ||||
| -rw-r--r-- | examples/gpu-printing/gpu-printing.cpp | 2 | ||||
| -rw-r--r-- | examples/hello-world/main.cpp | 1 |
4 files changed, 56 insertions, 1 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())) diff --git a/examples/gpu-printing/gpu-printing.cpp b/examples/gpu-printing/gpu-printing.cpp index f1e842e95..aeca7aa9a 100644 --- a/examples/gpu-printing/gpu-printing.cpp +++ b/examples/gpu-printing/gpu-printing.cpp @@ -156,7 +156,7 @@ void GPUPrinting::processGPUPrintCommands(const void* data, size_t dataSize) // that the buffer is corrupted or invalid, but we will try to // soldier on and process further commands. // - fprintf(stderr, "error: unexpected GPU printing op %d\n", op); + fprintf(stderr, "error: unexpected GPU printing op %d\n", (int)op); break; case GPUPrintingOp::Nop: diff --git a/examples/hello-world/main.cpp b/examples/hello-world/main.cpp index da149a8e0..e635b3a48 100644 --- a/examples/hello-world/main.cpp +++ b/examples/hello-world/main.cpp @@ -66,6 +66,7 @@ struct HelloWorldExample int main() { + initDebugCallback(); HelloWorldExample example; return example.run(); } |
