From 1dee62ebfc4b21254b9d7cd0c58c3af52e062890 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 17 Jan 2025 22:20:35 +0100 Subject: [PATCH] [dxvk] Add latency tracker to context --- src/dxvk/dxvk_context.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/dxvk/dxvk_context.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index dfb7760b7..6cbfcf75b 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -110,9 +110,45 @@ namespace dxvk { } + void DxvkContext::beginLatencyTracking( + const Rc& tracker, + uint64_t frameId) { + if (tracker && !m_latencyTracker) { + tracker->notifyCsRenderBegin(frameId); + + m_latencyTracker = tracker; + m_latencyFrameId = frameId; + + m_endLatencyTracking = false; + } + } + + + void DxvkContext::endLatencyTracking( + const Rc& tracker) { + if (tracker && tracker == m_latencyTracker) + m_endLatencyTracking = true; + } + + void DxvkContext::flushCommandList(DxvkSubmitStatus* status) { + // Need to call this before submitting so that the last GPU + // submission does not happen before the render end signal. + if (m_endLatencyTracking && m_latencyTracker) + m_latencyTracker->notifyCsRenderEnd(m_latencyFrameId); + m_device->submitCommandList(this->endRecording(), - nullptr, 0, status); + m_latencyTracker, m_latencyFrameId, status); + + // Ensure that subsequent submissions do not see the tracker. + // It is important to hide certain internal submissions in + // case the application is CPU-bound. + if (m_endLatencyTracking) { + m_latencyTracker = nullptr; + m_latencyFrameId = 0u; + + m_endLatencyTracking = false; + } this->beginRecording( m_device->createCommandList()); diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index a978af177..cbeb51080 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -4,6 +4,7 @@ #include "dxvk_bind_mask.h" #include "dxvk_cmdlist.h" #include "dxvk_context_state.h" +#include "dxvk_latency.h" #include "dxvk_objects.h" #include "dxvk_queue.h" #include "dxvk_util.h" @@ -68,6 +69,30 @@ namespace dxvk { */ void endFrame(); + /** + * \brief Begins latency tracking + * + * Notifies the beginning of a frame on the CS timeline + * an ensures that subsequent submissions are associated + * with the correct frame ID. Only one tracker can be + * active at any given time. + * \param [in] tracker Latency tracker object + * \param [in] frameId Current frame ID + */ + void beginLatencyTracking( + const Rc& tracker, + uint64_t frameId); + + /** + * \brief Ends latency tracking + * + * Notifies the end of the frame. Ignored if the + * tracker is not currently active. + * \param [in] tracker Latency tracker object + */ + void endLatencyTracking( + const Rc& tracker); + /** * \brief Flushes command buffer * @@ -1421,6 +1446,10 @@ namespace dxvk { std::vector m_debugLabelStack; bool m_debugLabelInternalActive = false; + Rc m_latencyTracker; + uint64_t m_latencyFrameId = 0u; + bool m_endLatencyTracking = false; + void blitImageFb( Rc dstView, const VkOffset3D* dstOffsets,