From e07ef1ec4046b521e4cbc46a64d7936751ba1dd9 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 29 Aug 2019 18:25:41 +0200 Subject: [PATCH] [d3d11] Resolve pipeline hazards when binding render targets --- src/d3d11/d3d11_context.cpp | 49 +++++++++++++++++++++++++++++++++++++ src/d3d11/d3d11_context.h | 6 +++++ 2 files changed, 55 insertions(+) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 01405cd27..c27580972 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -2640,6 +2640,9 @@ namespace dxvk { m_state.om.renderTargetViews[i] = rtv; needsUpdate = true; TestOmSrvHazards(rtv); + + if (NumUAVs == D3D11_KEEP_UNORDERED_ACCESS_VIEWS) + TestOmUavHazards(rtv); } } @@ -2680,6 +2683,9 @@ namespace dxvk { TestOmSrvHazards(uav); + if (NumRTVs == D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL) + needsUpdate |= TestOmRtvHazards(uav); + needsSpill = true; } } @@ -3829,6 +3835,49 @@ namespace dxvk { } + bool D3D11DeviceContext::TestOmRtvHazards( + D3D11UnorderedAccessView* pView) { + if (!pView || !pView->HasBindFlag(D3D11_BIND_RENDER_TARGET)) + return false; + + bool hazard = false; + + if (CheckViewOverlap(pView, m_state.om.depthStencilView.ptr())) { + m_state.om.depthStencilView = nullptr; + hazard = true; + } + + for (uint32_t i = 0; i < m_state.om.maxRtv; i++) { + if (CheckViewOverlap(pView, m_state.om.renderTargetViews[i].ptr())) { + m_state.om.renderTargetViews[i] = nullptr; + hazard = true; + } + } + + return hazard; + } + + + void D3D11DeviceContext::TestOmUavHazards( + D3D11RenderTargetView* pView) { + if (!pView || !pView->HasBindFlag(D3D11_BIND_UNORDERED_ACCESS)) + return; + + uint32_t uavSlotId = computeUavBinding (DxbcProgramType::PixelShader, 0); + uint32_t ctrSlotId = computeUavCounterBinding(DxbcProgramType::PixelShader, 0); + + for (uint32_t i = 0; i < m_state.om.maxUav; i++) { + if (CheckViewOverlap(pView, m_state.ps.unorderedAccessViews[i].ptr())) { + m_state.ps.unorderedAccessViews[i] = nullptr; + + BindUnorderedAccessView( + uavSlotId + i, nullptr, + ctrSlotId + i, ~0u); + } + } + } + + template void D3D11DeviceContext::TestCsSrvHazards( T* pView) { diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 868995763..e07ad1307 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -813,6 +813,12 @@ namespace dxvk { void TestOmSrvHazards( T* pView); + bool TestOmRtvHazards( + D3D11UnorderedAccessView* pView); + + void TestOmUavHazards( + D3D11RenderTargetView* pView); + template void TestCsSrvHazards( T* pView);