From 6be124e2cd215b29474be3b0767e0d759100113e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 29 Aug 2019 18:40:56 +0200 Subject: [PATCH] [d3d11] Check for conflicts withing RTV and UAV lists upon binding them --- 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 c27580972..842e20b6a 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -2477,6 +2477,9 @@ namespace dxvk { ID3D11UnorderedAccessView* const* ppUnorderedAccessViews, const UINT* pUAVInitialCounts) { D3D10DeviceLock lock = LockContext(); + + if (TestRtvUavHazards(0, nullptr, NumUAVs, ppUnorderedAccessViews)) + return; // Unbind previously bound conflicting UAVs uint32_t uavSlotId = computeUavBinding (DxbcProgramType::ComputeShader, 0); @@ -2622,6 +2625,9 @@ namespace dxvk { const UINT* pUAVInitialCounts) { D3D10DeviceLock lock = LockContext(); + if (TestRtvUavHazards(NumRTVs, ppRenderTargetViews, NumUAVs, ppUnorderedAccessViews)) + return; + bool needsUpdate = false; bool needsSpill = false; @@ -3768,6 +3774,49 @@ namespace dxvk { } + bool D3D11DeviceContext::TestRtvUavHazards( + UINT NumRTVs, + ID3D11RenderTargetView* const* ppRTVs, + UINT NumUAVs, + ID3D11UnorderedAccessView* const* ppUAVs) { + if (NumRTVs == D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL) NumRTVs = 0; + if (NumUAVs == D3D11_KEEP_UNORDERED_ACCESS_VIEWS) NumUAVs = 0; + + for (uint32_t i = 0; i < NumRTVs; i++) { + auto rtv = static_cast(ppRTVs[i]); + + if (!rtv) + continue; + + for (uint32_t j = 0; j < i; j++) { + if (CheckViewOverlap(rtv, static_cast(ppRTVs[j]))) + return true; + } + + if (rtv->HasBindFlag(D3D11_BIND_UNORDERED_ACCESS)) { + for (uint32_t j = 0; j < NumUAVs; j++) { + if (CheckViewOverlap(rtv, static_cast(ppUAVs[j]))) + return true; + } + } + } + + for (uint32_t i = 0; i < NumUAVs; i++) { + auto uav = static_cast(ppUAVs[i]); + + if (!uav) + continue; + + for (uint32_t j = 0; j < i; j++) { + if (CheckViewOverlap(uav, static_cast(ppUAVs[j]))) + return true; + } + } + + return false; + } + + template bool D3D11DeviceContext::TestSrvHazards( D3D11ShaderResourceView* pView) { diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index e07ad1307..0684c9218 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -800,6 +800,12 @@ namespace dxvk { const D3D11CommonTexture* pTexture, VkImageSubresource Subresource); + bool TestRtvUavHazards( + UINT NumRTVs, + ID3D11RenderTargetView* const* ppRTVs, + UINT NumUAVs, + ID3D11UnorderedAccessView* const* ppUAVs); + template bool TestSrvHazards( D3D11ShaderResourceView* pView);