From 7cd1dbce12b56afb35989292c96893c594f713bf Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 21 Mar 2025 14:13:03 +0100 Subject: [PATCH] rhi: d3d12: Avoid 1 sec timeout when skipping present Follow the d3d11 change. Pick-to: 6.8 Change-Id: I06ef9e64f37fba72c2ab6adc84ad9058f22ae1e4 Reviewed-by: Andy Nichols (cherry picked from commit d8fb42bb790f468ad1b5304b743dbff297582ddd) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhid3d12.cpp | 10 ++++++++-- src/gui/rhi/qrhid3d12_p.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index 8a14755c9a1..7fad954da18 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -1647,8 +1647,13 @@ QRhi::FrameOpResult QRhiD3D12::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginF for (QD3D12SwapChain *sc : std::as_const(swapchains)) sc->waitCommandCompletionForFrameSlot(currentFrameSlot); // note: swapChainD->currentFrameSlot, not sc's - 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; + } + } HRESULT hr = cmdAllocators[currentFrameSlot]->Reset(); if (FAILED(hr)) { @@ -6759,6 +6764,7 @@ bool QD3D12SwapChain::createOrResize() currentBackBufferIndex = swapChain->GetCurrentBackBufferIndex(); currentFrameSlot = 0; + lastFrameLatencyWaitSlot = -1; // wait already in the first frame, as instructed in the dxgi docs rtWrapper.setRenderPassDescriptor(m_renderPassDesc); // for the public getter in QRhiRenderTarget QD3D12SwapChainRenderTarget *rtD = QRHI_RES(QD3D12SwapChainRenderTarget, &rtWrapper); diff --git a/src/gui/rhi/qrhid3d12_p.h b/src/gui/rhi/qrhid3d12_p.h index c009b6dd26f..460031e30cf 100644 --- a/src/gui/rhi/qrhid3d12_p.h +++ b/src/gui/rhi/qrhid3d12_p.h @@ -1079,6 +1079,7 @@ struct QD3D12SwapChain : public QRhiSwapChain } frameRes[QD3D12_FRAMES_IN_FLIGHT]; int currentFrameSlot = 0; // index in frameRes + int lastFrameLatencyWaitSlot = -1; }; template