diff --git a/engine/include/XCEngine/Debug/RenderDocCapture.h b/engine/include/XCEngine/Debug/RenderDocCapture.h index b681c957..4f9e7add 100644 --- a/engine/include/XCEngine/Debug/RenderDocCapture.h +++ b/engine/include/XCEngine/Debug/RenderDocCapture.h @@ -8,24 +8,35 @@ namespace Debug { #define RENDERDOC_CC __cdecl +struct RenderDocCaptureInfo { + char filename[256]; + uint32_t length; + uint64_t timestamp; +}; + class RenderDocCapture { public: static RenderDocCapture& Get(); - bool Initialize(void* device, void* window = nullptr); + bool Initialize(void* device = nullptr, void* window = nullptr); void Shutdown(); void SetDevice(void* device); + void SetWindow(void* window); bool IsLoaded() const { return m_isLoaded; } bool IsCapturing() const; uint32_t GetNumCaptures() const; + bool GetCapture(uint32_t index, RenderDocCaptureInfo* info) const; - void BeginCapture(const char* title = nullptr); - void EndCapture(); + bool BeginCapture(const char* title = nullptr); + bool EndCapture(); void TriggerCapture(); void SetCaptureFilePath(const char* path); void SetCaptureComments(const char* comments); + void SetCaptureOptionU32(uint32_t option, uint32_t value); + + bool LaunchReplayUI(uint32_t connect = 1, const char* cmdline = nullptr); private: RenderDocCapture() = default; diff --git a/engine/src/Debug/RenderDocCapture.cpp b/engine/src/Debug/RenderDocCapture.cpp index 1e32dfc9..62b23903 100644 --- a/engine/src/Debug/RenderDocCapture.cpp +++ b/engine/src/Debug/RenderDocCapture.cpp @@ -50,6 +50,10 @@ void RenderDocCapture::SetDevice(void* device) { m_device = device; } +void RenderDocCapture::SetWindow(void* window) { + m_window = window; +} + bool RenderDocCapture::LoadRenderDoc() { char exePath[MAX_PATH]; GetModuleFileNameA(NULL, exePath, MAX_PATH); @@ -115,10 +119,32 @@ uint32_t RenderDocCapture::GetNumCaptures() const { return m_api->GetNumCaptures(); } -void RenderDocCapture::BeginCapture(const char* title) { - if (!m_isLoaded || !m_api) { - return; +bool RenderDocCapture::GetCapture(uint32_t index, RenderDocCaptureInfo* info) const { + if (!m_isLoaded || !m_api || !info) { + return false; } + uint32_t length = 0; + uint64_t timestamp = 0; + uint32_t result = m_api->GetCapture(index, info->filename, &length, ×tamp); + info->length = length; + info->timestamp = timestamp; + return result == 1; +} + +bool RenderDocCapture::BeginCapture(const char* title) { + if (!m_isLoaded || !m_api) { + Logger::Get().Warning(LogCategory::General, "BeginCapture called but RenderDoc not loaded"); + return false; + } + if (IsCapturing()) { + Logger::Get().Warning(LogCategory::General, "BeginCapture called while already capturing"); + return false; + } + if (!m_device || !m_window) { + Logger::Get().Warning(LogCategory::General, "BeginCapture called with null device or window"); + return false; + } + if (title) { m_api->SetCaptureTitle(title); } @@ -128,13 +154,22 @@ void RenderDocCapture::BeginCapture(const char* title) { m_api->SetActiveWindow(m_device, m_window); m_api->StartFrameCapture(m_device, m_window); + + return true; } -void RenderDocCapture::EndCapture() { +bool RenderDocCapture::EndCapture() { if (!m_isLoaded || !m_api) { - return; + Logger::Get().Warning(LogCategory::General, "EndCapture called but RenderDoc not loaded"); + return false; } + if (!IsCapturing()) { + Logger::Get().Warning(LogCategory::General, "EndCapture called but not currently capturing"); + return false; + } + m_api->EndFrameCapture(m_device, m_window); + return true; } void RenderDocCapture::TriggerCapture() { @@ -158,5 +193,21 @@ void RenderDocCapture::SetCaptureComments(const char* comments) { m_api->SetCaptureFileComments(nullptr, comments); } +void RenderDocCapture::SetCaptureOptionU32(uint32_t option, uint32_t value) { + if (!m_isLoaded || !m_api) { + return; + } + m_api->SetCaptureOptionU32(option, value); +} + +bool RenderDocCapture::LaunchReplayUI(uint32_t connect, const char* cmdline) { + if (!m_isLoaded || !m_api) { + Logger::Get().Warning(LogCategory::General, "LaunchReplayUI called but RenderDoc not loaded"); + return false; + } + m_api->LaunchReplayUI(connect, cmdline); + return true; +} + } // namespace Debug } // namespace XCEngine