From 57224d06b676ad640f5e097e260cee9ab9f50aed Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 21 Apr 2021 16:17:28 +0100 Subject: [PATCH] Force ref-all-resources when root signature looks to be bindless * This is required for the new heap-indexing bindless because we don't even have ranges to mark referenced, but for other cases ref-all resources tends to be more efficient especially when we're going to get to the same place (including all resources) via a less efficient mechanism. --- renderdoc/driver/d3d12/d3d12_device_wrap.cpp | 44 ++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index 86eb786b3..8301f9695 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -1034,6 +1034,50 @@ HRESULT WrappedID3D12Device::CreateRootSignature(UINT nodeMask, const void *pBlo wrapped->sig = GetShaderCache()->GetRootSig(pBlobWithRootSignature, blobLengthInBytes); + bool forceRefAll = false; + + // force ref-all-resources if the heap is directly indexed because we can't track resource + // access + if(wrapped->sig.Flags & (D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | + D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED)) + { + forceRefAll = true; + RDCDEBUG("Forcing Ref All Resources due to heap-indexing root signature flags"); + } + else + { + for(const D3D12RootSignatureParameter ¶m : wrapped->sig.Parameters) + { + if(param.ParameterType != D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) + continue; + + for(UINT r = 0; r < param.DescriptorTable.NumDescriptorRanges; r++) + { + const D3D12_DESCRIPTOR_RANGE1 &range = param.DescriptorTable.pDescriptorRanges[r]; + if(range.NumDescriptors > 100000) + { + forceRefAll = true; + RDCDEBUG( + "Forcing Ref All Resources due to large root signature range of %u descriptors " + "(space=%u, reg=%u, visibility=%s)", + range.NumDescriptors, range.RegisterSpace, range.BaseShaderRegister, + ToStr(param.ShaderVisibility).c_str()); + break; + } + } + + if(forceRefAll) + break; + } + } + + if(forceRefAll) + { + CaptureOptions opts = RenderDoc::Inst().GetCaptureOptions(); + opts.refAllResources = true; + RenderDoc::Inst().SetCaptureOptions(opts); + } + record->AddChunk(scope.Get()); } else