From 5b07286c65a9ceec3a704f94dfc251f6dd64f543 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 29 Mar 2025 22:29:47 +0000 Subject: [PATCH] [idd] driver: report we are finished with the frame earlier `IddCxSwapChainFinishedProcessingFrame` must be called after every frame, but we should do it as early as possible once all commands are queued that use the frame. --- idd/LGIdd/CSwapChainProcessor.cpp | 30 ++++++++++++++++++++---------- idd/LGIdd/CSwapChainProcessor.h | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/idd/LGIdd/CSwapChainProcessor.cpp b/idd/LGIdd/CSwapChainProcessor.cpp index eec3afde..a9833733 100644 --- a/idd/LGIdd/CSwapChainProcessor.cpp +++ b/idd/LGIdd/CSwapChainProcessor.cpp @@ -134,12 +134,9 @@ void CSwapChainProcessor::SwapChainThreadCore() if (buffer.MetaData.PresentationFrameNumber != lastFrameNumber) { lastFrameNumber = buffer.MetaData.PresentationFrameNumber; - SwapChainNewFrame(buffer.MetaData.pSurface); + if (!SwapChainNewFrame(buffer.MetaData.pSurface)) + break; } - - hr = IddCxSwapChainFinishedProcessingFrame(m_hSwapChain); - if (FAILED(hr)) - break; } else { @@ -148,21 +145,21 @@ void CSwapChainProcessor::SwapChainThreadCore() } } -void CSwapChainProcessor::SwapChainNewFrame(ComPtr acquiredBuffer) +bool CSwapChainProcessor::SwapChainNewFrame(ComPtr acquiredBuffer) { ComPtr texture; HRESULT hr = acquiredBuffer.As(&texture); if (FAILED(hr)) { DEBUG_ERROR_HR(hr, "Failed to obtain the ID3D11Texture2D from the acquiredBuffer"); - return; + return false; } CInteropResource * srcRes = m_resPool.Get(texture); if (!srcRes) { DEBUG_ERROR("Failed to get a CInteropResource from the pool"); - return; + return false; } /** @@ -182,7 +179,7 @@ void CSwapChainProcessor::SwapChainNewFrame(ComPtr acquiredBuffer srcRes->GetFormat().Format); if (!buffer.mem) - return; + return false; CFrameBufferResource * fbRes = m_fbPool.Get(buffer, ((size_t)srcRes->GetFormat().Width * 4) * srcRes->GetFormat().Height); @@ -190,7 +187,7 @@ void CSwapChainProcessor::SwapChainNewFrame(ComPtr acquiredBuffer if (!fbRes) { DEBUG_ERROR("Failed to get a CFrameBufferResource from the pool"); - return; + return false; } D3D12_TEXTURE_COPY_LOCATION srcLoc = {}; @@ -213,12 +210,25 @@ void CSwapChainProcessor::SwapChainNewFrame(ComPtr acquiredBuffer &dstLoc, 0, 0, 0, &srcLoc, NULL); m_dx12Device->GetCopyQueue().Execute(); + + // report that all GPU processing for this frame has been queued + hr = IddCxSwapChainFinishedProcessingFrame(m_hSwapChain); + if (FAILED(hr)) + { + DEBUG_ERROR_HR(hr, "IddCxSwapChainFinishedProcessingFrame Failed"); + return false; + } + + // wait for the completion m_dx12Device->GetCopyQueue().Wait(); m_dx12Device->GetCopyQueue().Reset(); + // copy/finialize if (m_dx12Device->IsIndirectCopy()) m_devContext->WriteFrameBuffer( fbRes->GetMap(), 0, fbRes->GetFrameSize(), true); else m_devContext->FinalizeFrameBuffer(); + + return true; } \ No newline at end of file diff --git a/idd/LGIdd/CSwapChainProcessor.h b/idd/LGIdd/CSwapChainProcessor.h index deab8af7..f7d51177 100644 --- a/idd/LGIdd/CSwapChainProcessor.h +++ b/idd/LGIdd/CSwapChainProcessor.h @@ -54,7 +54,7 @@ private: void SwapChainThread(); void SwapChainThreadCore(); - void SwapChainNewFrame(ComPtr acquiredBuffer); + bool SwapChainNewFrame(ComPtr acquiredBuffer); public: CSwapChainProcessor(CIndirectDeviceContext * devContext, IDDCX_SWAPCHAIN hSwapChain,