diff options
Diffstat (limited to 'examples/example-base')
| -rw-r--r-- | examples/example-base/example-base.cpp | 15 | ||||
| -rw-r--r-- | examples/example-base/example-base.h | 38 |
2 files changed, 53 insertions, 0 deletions
diff --git a/examples/example-base/example-base.cpp b/examples/example-base/example-base.cpp index b06bbdf7e..09891e555 100644 --- a/examples/example-base/example-base.cpp +++ b/examples/example-base/example-base.cpp @@ -1,4 +1,10 @@ #include "example-base.h" +#include <chrono> + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <Windows.h> +#endif using namespace Slang; using namespace gfx; @@ -20,6 +26,7 @@ Slang::Result WindowedAppBase::initializeBase(const char* title, int width, int // Initialize the rendering layer. IDevice::Desc deviceDesc = {}; + // deviceDesc.slang.targetFlags = SLANG_TARGET_FLAG_DUMP_IR; gfx::Result res = gfxCreateDevice(&deviceDesc, gDevice.writeRef()); if (SLANG_FAILED(res)) return res; @@ -158,3 +165,11 @@ void WindowedAppBase::windowSizeChanged() } } } + +int64_t getCurrentTime() { return std::chrono::high_resolution_clock::now().time_since_epoch().count(); } + +int64_t getTimerFrequency() { return std::chrono::high_resolution_clock::period::den; } + +#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 ab7522f06..67f722c11 100644 --- a/examples/example-base/example-base.h +++ b/examples/example-base/example-base.h @@ -4,6 +4,10 @@ #include "tools/platform/window.h" #include "source/core/slang-basic.h" +#ifdef _WIN32 +void _Win32OutputDebugString(const char* str); +#endif + struct WindowedAppBase { protected: @@ -35,6 +39,40 @@ public: virtual void finalize() { gQueue->wait(); } }; +int64_t getCurrentTime(); +int64_t getTimerFrequency(); + +template<typename ... TArgs> inline void reportError(const char* format, TArgs... args) +{ + printf(format, args...); +#ifdef _WIN32 + char buffer[4096]; + sprintf_s(buffer, format, args...); + _Win32OutputDebugString(buffer); +#endif +} + +template <typename... TArgs> inline void log(const char* format, TArgs... args) +{ + reportError(format, args...); +} + +// Many Slang API functions return detailed diagnostic information +// (error messages, warnings, etc.) as a "blob" of data, or return +// a null blob pointer instead if there were no issues. +// +// For convenience, we define a subroutine that will dump the information +// in a diagnostic blob if one is produced, and skip it otherwise. +// +inline void diagnoseIfNeeded(slang::IBlob* diagnosticsBlob) +{ + if (diagnosticsBlob != nullptr) + { + reportError("%s", (const char*)diagnosticsBlob->getBufferPointer()); + } +} + + template<typename TApp> int innerMain() { |
