diff --git a/src/graphics/guest_gpu/graphicsRun.cpp b/src/graphics/guest_gpu/graphicsRun.cpp index 77ad9045f..cf738df3a 100644 --- a/src/graphics/guest_gpu/graphicsRun.cpp +++ b/src/graphics/guest_gpu/graphicsRun.cpp @@ -199,17 +199,6 @@ void GuestGpu::Done() { if (!IsGpuThread()) { WaitForIdle(); } - if (RenderDocCaptureInProgress()) { - SendCommandSync([this] { - Common::LockGuard render_lock(m_renderer.GetMutex()); - RenderDocEndCapture(); - }); - } else if (RenderDocCaptureRequested()) { - SendCommandSync([this] { - Common::LockGuard render_lock(m_renderer.GetMutex()); - RenderDocStartCapture(); - }); - } m_graphics_done = true; m_done_num++; } @@ -571,6 +560,10 @@ void GuestGpu::ThreadRun(void* data) { bool GuestGpu::Process(Submission& submission) { const bool first_slice = !submission.started; + if (first_slice && RenderDocCaptureRequested()) { + Common::LockGuard render_lock(m_renderer.GetMutex()); + RenderDocStartCapture(); + } auto& cp = GetProcessor(submission.queue_id); if (first_slice && submission.reset_processor) { diff --git a/src/graphics/presentation/renderDoc.cpp b/src/graphics/presentation/renderDoc.cpp index 07e139277..0bf7d7c7d 100644 --- a/src/graphics/presentation/renderDoc.cpp +++ b/src/graphics/presentation/renderDoc.cpp @@ -25,11 +25,13 @@ namespace Libs::Graphics { enum class RenderDocState : uint32_t { Idle, Requested, + Starting, Capturing, }; static RENDERDOC_API_1_6_0* g_api = nullptr; static std::atomic g_state = RenderDocState::Idle; +static std::atomic_uint32_t g_captured_flips = 0; static std::atomic_bool g_unavailable_log = false; #if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS @@ -140,7 +142,7 @@ bool RenderDocCaptureInProgress() { void RenderDocStartCapture() { RenderDocState expected = RenderDocState::Requested; - if (g_api == nullptr || !g_state.compare_exchange_strong(expected, RenderDocState::Capturing, + if (g_api == nullptr || !g_state.compare_exchange_strong(expected, RenderDocState::Starting, std::memory_order_acq_rel)) { return; } @@ -162,6 +164,8 @@ void RenderDocStartCapture() { LOGF("RenderDoc: capture failed to start\n"); return; } + g_captured_flips.store(0, std::memory_order_release); + g_state.store(RenderDocState::Capturing, std::memory_order_release); LOGF("RenderDoc: capture started\n"); } @@ -175,4 +179,15 @@ void RenderDocEndCapture() { LOGF(ok != 0 ? "RenderDoc: capture finished\n" : "RenderDoc: capture failed\n"); } +void RenderDocOnGuestFlip() { + if (!RenderDocCaptureInProgress()) { + return; + } + const auto flip = g_captured_flips.fetch_add(1, std::memory_order_acq_rel) + 1; + LOGF("RenderDoc: captured guest flip %u/2\n", flip); + if (flip >= 2) { + RenderDocEndCapture(); + } +} + } // namespace Libs::Graphics diff --git a/src/graphics/presentation/renderDoc.h b/src/graphics/presentation/renderDoc.h index f9ab9007b..28e67aea2 100644 --- a/src/graphics/presentation/renderDoc.h +++ b/src/graphics/presentation/renderDoc.h @@ -7,6 +7,7 @@ void RenderDocInit(); void RenderDocRequestCapture(); void RenderDocStartCapture(); void RenderDocEndCapture(); +void RenderDocOnGuestFlip(); [[nodiscard]] bool RenderDocCaptureRequested(); [[nodiscard]] bool RenderDocCaptureInProgress(); diff --git a/src/graphics/presentation/videoOut.cpp b/src/graphics/presentation/videoOut.cpp index fa0fc3963..c8b047a0a 100644 --- a/src/graphics/presentation/videoOut.cpp +++ b/src/graphics/presentation/videoOut.cpp @@ -16,6 +16,7 @@ #include "graphics/host_gpu/renderer/render.h" #include "graphics/host_gpu/renderer/renderContext.h" #include "graphics/presentation/presenter.h" +#include "graphics/presentation/renderDoc.h" #include "kernel/pthread.h" #include "libs/errno.h" #include "libs/libs.h" @@ -1127,6 +1128,7 @@ bool FlipQueue::Flip(uint32_t micros) { m_mutex.Unlock(); m_presenter.Present(*r.frame); + Graphics::RenderDocOnGuestFlip(); m_mutex.Lock(); if (m_requests.empty() || m_requests.front().id != r.id ||