In dx12 we have to manage resource before/after state ourselves, but all the dx12 docs sample code uses the same commandlist to call resourcebarrier. in my program, I use a computeCommandList to update a volume buffer and then use graphicCommandList to visualize the volume every frame. So for the volume buffer resource state I have the following state change flow:
void CreateResource(...){
...
UpdateSubresources( m_graphicCmdList.Get(), m_volumeBuffer.Get(), volumeBufferUploadHeap.Get(), 0, 0, 1, &volumeBufferData );
m_graphicCmdList->ResourceBarrier( 1, &CD3DX12_RESOURCE_BARRIER::Transition( m_volumeBuffer.Get(),
D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE ) );
VRET( m_graphicCmdList->Close() );
ID3D12CommandList* ppCommandLists[] = { m_graphicCmdList.Get() };
m_graphicCmdQueue->ExecuteCommandLists( _countof( ppCommandLists), ppCommandLists);
...
}
void Update(...){
...
!! m_computeCmdList->ResourceBarrier( 1, &CD3DX12_RESOURCE_BARRIER::Transition( m_volumeBuffer.Get(),
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS ) );
...
m_computeCmdList->Dispatch(...);
...
m_computeCmdList->ResourceBarrier( 1, &CD3DX12_RESOURCE_BARRIER::Transition( m_volumeBuffer.Get(),
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE) );
...
}
Any idea? Thanks