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 <andy.nichols@qt.io>
This commit is contained in:
Laszlo Agocs 2025-03-20 18:41:30 +01:00 committed by Laszlo Agocs
parent 66fae045cd
commit f2437c9d8c
2 changed files with 9 additions and 2 deletions

View File

@ -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;

View File

@ -626,6 +626,7 @@ struct QD3D11SwapChain : public QRhiSwapChain
QD3D11SwapChainTimestamps timestamps;
int currentTimestampPairIndex = 0;
HANDLE frameLatencyWaitableObject = nullptr;
int lastFrameLatencyWaitSlot = -1;
};
class QD3D11Adapter : public QRhiAdapter