From 68929a567b80972e71b05a3750762941aecfa0d3 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sat, 2 Mar 2024 13:46:45 +0000 Subject: [PATCH] Work around D3D12 confusion where feature can be unsupported but used * Even if new barriers aren't supported, it's still possible to use the creation function and create them in any of the new layouts. In this case we can't use new barriers to transition them out of that state so we have to pretend they've already been moved out. --- renderdoc/driver/d3d12/d3d12_manager.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_manager.cpp b/renderdoc/driver/d3d12/d3d12_manager.cpp index 1261f94e2..0bfb1e41f 100644 --- a/renderdoc/driver/d3d12/d3d12_manager.cpp +++ b/renderdoc/driver/d3d12/d3d12_manager.cpp @@ -1473,11 +1473,29 @@ void D3D12ResourceManager::SerialiseResourceStates( for(size_t m = 0; m < States.size(); m++) { - const D3D12ResourceLayout srcState = states[liveid][m]; - const D3D12ResourceLayout dstState = States[m]; + D3D12ResourceLayout srcState = states[liveid][m]; + D3D12ResourceLayout dstState = States[m]; + + // because of some extreme ugliness on the D3D12 side, resources can be created in new + // layouts without the new barriers actually being supported. If that's the case, we just + // pretend they're in old COMMON to avoid doing the new barrier + if(!m_Device->GetOpts12().EnhancedBarriersSupported && srcState.IsLayout()) + { + RDCASSERT(srcState.ToLayout() == D3D12_BARRIER_LAYOUT_COMMON, srcState.ToLayout()); + srcState = D3D12ResourceLayout::FromStates(D3D12_RESOURCE_STATE_COMMON); + } + + if(!m_Device->GetOpts12().EnhancedBarriersSupported && dstState.IsLayout()) + { + RDCASSERT(dstState.ToLayout() == D3D12_BARRIER_LAYOUT_COMMON, dstState.ToLayout()); + dstState = D3D12ResourceLayout::FromStates(D3D12_RESOURCE_STATE_COMMON); + } + if(srcState != dstState) + { AddStateResetBarrier(srcState, dstState, (ID3D12Resource *)GetCurrentResource(liveid), (UINT)m, barriers); + } } }