d3d12: Factorize resource state change

This commit is contained in:
vlj 2015-05-28 23:12:16 +02:00 committed by Vincent Lejeune
commit af69803ee0
2 changed files with 15 additions and 15 deletions

View file

@ -89,4 +89,15 @@ D3D12_RESOURCE_DESC getTexture2DResourceDesc(size_t width, size_t height, DXGI_F
return result; return result;
} }
inline
D3D12_RESOURCE_BARRIER getResourceBarrierTransition(ID3D12Resource *res, D3D12_RESOURCE_STATES stateBefore, D3D12_RESOURCE_STATES stateAfter)
{
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Transition.pResource = res;
barrier.Transition.StateBefore = stateBefore;
barrier.Transition.StateAfter = stateAfter;
return barrier;
}
#endif #endif

View file

@ -679,7 +679,7 @@ void D3D12GSRender::ExecCMD()
commandList->SetDescriptorHeaps(1, &m_perFrameStorage.m_samplerDescriptorHeap); commandList->SetDescriptorHeaps(1, &m_perFrameStorage.m_samplerDescriptorHeap);
commandList->SetGraphicsRootDescriptorTable(3, Handle); commandList->SetGraphicsRootDescriptorTable(3, Handle);
m_perFrameStorage.m_currentTextureIndex += 16; m_perFrameStorage.m_currentTextureIndex += usedTexture;
InitDrawBuffers(); InitDrawBuffers();
@ -1241,12 +1241,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
// Convert // Convert
D3D12_RESOURCE_BARRIER barrier = {}; convertCommandList->ResourceBarrier(1, &getResourceBarrierTransition(m_fbo->getDepthStencilTexture(), D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Transition.pResource = m_fbo->getDepthStencilTexture();
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_DEPTH_WRITE;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_GENERIC_READ;
convertCommandList->ResourceBarrier(1, &barrier);
convertCommandList->SetPipelineState(m_convertPSO); convertCommandList->SetPipelineState(m_convertPSO);
convertCommandList->SetComputeRootSignature(m_convertRootSignature); convertCommandList->SetComputeRootSignature(m_convertRootSignature);
@ -1254,8 +1249,6 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
convertCommandList->SetComputeRootDescriptorTable(0, descriptorHeap->GetGPUDescriptorHandleForHeapStart()); convertCommandList->SetComputeRootDescriptorTable(0, descriptorHeap->GetGPUDescriptorHandleForHeapStart());
convertCommandList->Dispatch(RSXThread::m_width / 8, RSXThread::m_height / 8, 1); convertCommandList->Dispatch(RSXThread::m_width / 8, RSXThread::m_height / 8, 1);
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_GENERIC_READ;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_DEPTH_WRITE;
// Flush UAV // Flush UAV
D3D12_RESOURCE_BARRIER uavbarrier = {}; D3D12_RESOURCE_BARRIER uavbarrier = {};
uavbarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; uavbarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
@ -1263,15 +1256,11 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value)
D3D12_RESOURCE_BARRIER barriers[] = D3D12_RESOURCE_BARRIER barriers[] =
{ {
barrier, getResourceBarrierTransition(m_fbo->getDepthStencilTexture(), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_DEPTH_WRITE),
uavbarrier, uavbarrier,
}; };
convertCommandList->ResourceBarrier(2, barriers); convertCommandList->ResourceBarrier(2, barriers);
convertCommandList->ResourceBarrier(1, &getResourceBarrierTransition(depthConverted, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE));
barrier.Transition.pResource = depthConverted;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
convertCommandList->ResourceBarrier(1, &barrier);
convertCommandList->Close(); convertCommandList->Close();
m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&convertCommandList); m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&convertCommandList);