From MS dx12 docs, I found out these barrier flags: D3D12_RESOURCE_BARRIER_FLAG_BEGIN_ONLY D3D12_RESOURCE_BARRIER_FLAG_END_ONLY, and they are described as:
This starts a barrier transition in a new state, putting a resource in a temporary no-access condition.
D3D12_RESOURCE_BARRIER_FLAG_END_ONLYThis barrier completes a transition, setting a new state and restoring active access to a resource.
curious about in what scenarios could we use it, I find out this
Example of split barriers
The following example shows how to use a split barrier to reduce pipeline stalls. The code that follows does not use split barriers:
BarrierDesc.Type = D3D12_RESOURCE_BARRIER_TRANSITION;
BarrierDesc.Flags = D3D12_RESOURCE_BARRIER_NONE;
BarrierDesc.Transition.pResource = pResource;
BarrierDesc.Transition.Subresource = 0;
BarrierDesc.Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;
BarrierDesc.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
pCommandList->ResourceBarrier( 1, &BarrierDesc );
Write(pResource); // ... render to pResource
OtherStuff(); // .. other gpu work
// Transition pResource to PIXEL_SHADER_RESOURCE
BarrierDesc.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
BarrierDesc.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
pCommandList->ResourceBarrier( 1, &BarrierDesc );
Read(pResource); // ... read from pResource
The following code uses split barriers:
BarrierDesc.Type = D3D12_RESOURCE_BARRIER_TRANSITION;
BarrierDesc.Flags = D3D12_RESOURCE_BARRIER_NONE;
BarrierDesc.Transition.pResource = pResource;
BarrierDesc.Transition.Subresource = 0;
BarrierDesc.Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;
BarrierDesc.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
pCommandList->ResourceBarrier( 1, &BarrierDesc );
Write(pResource); // ... render to pResource
// Done writing to pResource. Start barrier to PIXEL_SHADER_RESOURCE and
// then do other work
BarrierDesc.Flags = D3D12_RESOURCE_BARRIER_BEGIN_ONLY;
BarrierDesc.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
BarrierDesc.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
pCommandList->ResourceBarrier( 1, &BarrierDesc );
OtherStuff(); // .. other gpu work
// Need to read from pResource so end barrier
BarrierDesc.Flags = D3D12_RESOURCE_BARRIER_END_ONLY;
pCommandList->ResourceBarrier( 1, &BarrierDesc );
Read(pResource); // ... read from pResource
But still not quite get it that how could split barriers reduce pipeline stalls....
Any comments will be greatly appreciated