From b3cbe36c08b830963e09752763df66dc3d281cd3 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 21 Jun 2023 16:33:06 +0200 Subject: [PATCH] [dxvk] Apply frame rate limit on presentation timeline This may reduce latency as we no longer end up stalling subsequent GPU submissions. --- src/dxvk/dxvk_presenter.cpp | 17 +++++++++++++---- src/dxvk/dxvk_presenter.h | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/dxvk/dxvk_presenter.cpp b/src/dxvk/dxvk_presenter.cpp index 857ecf57..10f13da2 100644 --- a/src/dxvk/dxvk_presenter.cpp +++ b/src/dxvk/dxvk_presenter.cpp @@ -108,10 +108,6 @@ namespace dxvk { m_swapchain, std::numeric_limits::max(), sync.acquire, VK_NULL_HANDLE, &m_imageIndex); - bool vsync = mode == VK_PRESENT_MODE_FIFO_KHR - || mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR; - - m_fpsLimiter.delay(vsync); return status; } @@ -134,6 +130,7 @@ namespace dxvk { m_frameQueue.push(frame); m_frameCond.notify_one(); } else { + applyFrameRateLimit(mode); m_signal->signal(frameId); } @@ -648,6 +645,14 @@ namespace dxvk { } + void Presenter::applyFrameRateLimit(VkPresentModeKHR mode) { + bool vsync = mode == VK_PRESENT_MODE_FIFO_KHR + || mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR; + + m_fpsLimiter.delay(vsync); + } + + void Presenter::runFrameThread() { env::setThreadName("dxvk-frame"); @@ -667,6 +672,10 @@ namespace dxvk { if (!frame.frameId) return; + // Apply the FPS limiter before signaling the frame event in + // order to reduce latency if the app uses it for frame pacing. + applyFrameRateLimit(frame.mode); + // If the present operation has succeeded, actually wait for it to complete. // Don't bother with it on MAILBOX / IMMEDIATE modes since doing so would // restrict us to the display refresh rate on some platforms (XWayland). diff --git a/src/dxvk/dxvk_presenter.h b/src/dxvk/dxvk_presenter.h index 30247796..c5ba1273 100644 --- a/src/dxvk/dxvk_presenter.h +++ b/src/dxvk/dxvk_presenter.h @@ -294,6 +294,9 @@ namespace dxvk { void destroySurface(); + void applyFrameRateLimit( + VkPresentModeKHR mode); + void runFrameThread(); };