Monday, December 31, 2018

Studying D3D12HelloFrameBuffer desktop project


DirectX-Graphics-Samples-master\Samples\Desktop\D3D12HelloWorld\src\HelloFrameBuffering

Shows optimal vsync waiting. Should investigate in detail.

Difference from HelloTriangle sample

 
D3D12HelloFrameBuffering.h
ComPtr<ID3D12CommandAllocator> m_commandAllocators[FrameCount];
Two command allocators. Note m_commandList is still one instance.
UINT64 m_fenceValues[FrameCount];
There are two fences are used. m_fence is one instance.
void MoveToNextFrame();
add Signal() with m_fence to m_commandQueue  and set completion event and wait until the signal of previous MoveToNextFrame() is processed on GPU. If previous MoveToNextFrame() signal is already reached, this function does not block.
void WaitForGpu();
add Signal() with m_fence to m_commandQueue and set completion event and wait until this signal is processed on GPU. This function always blocks.

Double buffering of draw commands

 
There are two commandAllocators and command list is double buffered, one frame time of delay is acceptable.

m_fence is only one instance while m_fenceValues has two integer value to remember previous fence value.

m_fenceValues[] Initialized with zeros on constructor.

LoadAssets() increments m_fenceValues[0] twice and the value becomes 2, m_fenceValues[1] remains 0;

On the first MoveToNextFrame()

m_fenceValues[0] is 2. currentFenceValue :=2  and m_fence is passed to commandQueue->Signal()

m_frameIndex changes from 0 to 1

Function never blocks

m_fenceValues[1] := 3;

GPU executes commandList and redraw buffer 0 and when GPU reaches signal command, m_fence completed value will become 2.

Second MoveNextFrame() call

m_fenceValues[1] is 3 and currentFenceValue :=3 and m_fence is passed to commandQueue->Signal(). after previous commandList execution is finished, GPU will executes commandList and redraw buffer 1.

m_frameIndex changes from 1 to 0. If commandQueue does not reach to previous MoveToNextFrame() Signal value (==2), block until m_fence value becomes 2.




No comments:

Post a Comment