From f2437c9d8ca0d4b4af7e917ff18cd0bc6ca83bcc Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 20 Mar 2025 18:41:30 +0100 Subject: [PATCH] rhi: d3d11: Avoid 1 sec timeout when skipping present endFrame(SkipPresent) followed by beginFrame() would sometimes end up waiting up to a second. We should not wait at all in this case. D3D12 patch will follow separately. Pick-to: 6.9 6.8 Change-Id: I3a5605c3fb672f9d68f2afb69645c5c47a5214b3 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhid3d11.cpp | 10 ++++++++-- src/gui/rhi/qrhid3d11_p.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index da27500995b..b79a1b9b8a9 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -1439,8 +1439,13 @@ QRhi::FrameOpResult QRhiD3D11::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginF const int currentFrameSlot = swapChainD->currentFrameSlot; // if we have a waitable object, now is the time to wait on it - if (swapChainD->frameLatencyWaitableObject) - WaitForSingleObjectEx(swapChainD->frameLatencyWaitableObject, 1000, true); + if (swapChainD->frameLatencyWaitableObject) { + // only wait when endFrame() called Present(), otherwise this would become a 1 sec timeout + if (swapChainD->lastFrameLatencyWaitSlot != currentFrameSlot) { + WaitForSingleObjectEx(swapChainD->frameLatencyWaitableObject, 1000, true); + swapChainD->lastFrameLatencyWaitSlot = currentFrameSlot; + } + } swapChainD->cb.resetState(); @@ -5499,6 +5504,7 @@ bool QD3D11SwapChain::createOrResize() } currentFrameSlot = 0; + lastFrameLatencyWaitSlot = -1; // wait already in the first frame, as instructed in the dxgi docs frameCount = 0; ds = m_depthStencil ? QRHI_RES(QD3D11RenderBuffer, m_depthStencil) : nullptr; diff --git a/src/gui/rhi/qrhid3d11_p.h b/src/gui/rhi/qrhid3d11_p.h index 11927a5a3bb..48f99280c7a 100644 --- a/src/gui/rhi/qrhid3d11_p.h +++ b/src/gui/rhi/qrhid3d11_p.h @@ -626,6 +626,7 @@ struct QD3D11SwapChain : public QRhiSwapChain QD3D11SwapChainTimestamps timestamps; int currentTimestampPairIndex = 0; HANDLE frameLatencyWaitableObject = nullptr; + int lastFrameLatencyWaitSlot = -1; }; class QD3D11Adapter : public QRhiAdapter