Hi,
I am looking at the most basic Microsoft's samples for DX12 and I was wondering about the way they use fences for forcing a wait after the call to "Present".
Isn't "Present" already doing that for us?
I mean, if not, why do we have to pass in a command queue when we create the swap chain?
// ...
// Present the frame.
ThrowIfFailed(m_swapChain->Present(0, 0));
MoveToNextFrame();
// ...
void D3D12Fullscreen::MoveToNextFrame()
{
// Schedule a Signal command in the queue.
const UINT64 currentFenceValue = m_fenceValues[m_frameIndex];
ThrowIfFailed(m_commandQueue->Signal(m_fence.Get(), currentFenceValue));
// Update the frame index.
m_frameIndex = m_swapChain->GetCurrentBackBufferIndex();
// If the next frame is not ready to be rendered yet, wait until it is ready.
if (m_fence->GetCompletedValue() < m_fenceValues[m_frameIndex])
{
ThrowIfFailed(m_fence->SetEventOnCompletion(m_fenceValues[m_frameIndex], m_fenceEvent));
WaitForSingleObjectEx(m_fenceEvent, INFINITE, FALSE);
}
// Set the fence value for the next frame.
m_fenceValues[m_frameIndex] = currentFenceValue + 1;
}
Maybe I missed something but I placed a breakpoint in the "if (m_fenceCompletedValue < m_fenceValues[m_frameIndex])" and never reached it presumably because "Present" already blocked until a buffer was ready.
Thanks & Cheers,
Shnoutz