rhi: d3d12: Avoid 1 sec timeout when skipping present

Follow the d3d11 change.

Change-Id: I06ef9e64f37fba72c2ab6adc84ad9058f22ae1e4
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
(cherry picked from commit d8fb42bb790f468ad1b5304b743dbff297582ddd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 7cd1dbce12b56afb35989292c96893c594f713bf)
This commit is contained in:
Laszlo Agocs 2025-03-21 14:13:03 +01:00 committed by Qt Cherry-pick Bot
parent 779dcc9a34
commit a4a98a74ca
2 changed files with 9 additions and 2 deletions

View File

@ -1536,8 +1536,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)) {
@ -6578,6 +6583,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);

View File

@ -1054,6 +1054,7 @@ struct QD3D12SwapChain : public QRhiSwapChain
} frameRes[QD3D12_FRAMES_IN_FLIGHT];
int currentFrameSlot = 0; // index in frameRes
int lastFrameLatencyWaitSlot = -1;
};
template<typename T, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type>