From 2ee5f76185fec3332f4e9665d7fa96b9cd2a63ff Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 21 Feb 2017 21:51:43 +0000 Subject: [PATCH] Add clamp on extra descriptors in D3D12 for CBV/SRV/UAV heap. Refs #518 * We need extra descriptors during some analysis events for patching e.g shaders for overlays and things. This is because D3D12 only allows one heap of any given time bound at once. * D3D12 also limits the size of that heap, and the limit is not queryable so the application can make a heap of maximum size that it uses all of. * There's no solution for this, in this case we just can't add more descriptors and when we try to use the last one for our own purposes we stand a small chance of stomping an important descriptor. --- renderdoc/driver/d3d12/d3d12_device.cpp | 4 ++++ renderdoc/driver/d3d12/d3d12_device.h | 1 + renderdoc/driver/d3d12/d3d12_device_wrap.cpp | 10 +++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 1d3207ccf..670a94c9c 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -179,6 +179,10 @@ WrappedID3D12Device::WrappedID3D12Device(ID3D12Device *realDevice, D3D12InitPara m_DescriptorIncrements[i] = realDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE(i)); + RDCEraseEl(m_D3D12Opts); + + realDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &m_D3D12Opts, sizeof(m_D3D12Opts)); + WrappedID3D12Resource::m_List = NULL; // refcounters implicitly construct with one reference, but we don't start with any soft diff --git a/renderdoc/driver/d3d12/d3d12_device.h b/renderdoc/driver/d3d12/d3d12_device.h index 91e708cba..92e3f0856 100644 --- a/renderdoc/driver/d3d12/d3d12_device.h +++ b/renderdoc/driver/d3d12/d3d12_device.h @@ -333,6 +333,7 @@ private: WrappedIDXGISwapChain4 *m_LastSwap; + D3D12_FEATURE_DATA_D3D12_OPTIONS m_D3D12Opts; UINT m_DescriptorIncrements[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES]; void Serialise_CaptureScope(uint64_t offset); diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index c80ae4ef6..e0e01500b 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -447,7 +447,15 @@ bool WrappedID3D12Device::Serialise_CreateDescriptorHeap( // while patching, because DX12 has a stupid limitation to not be able // to set multiple descriptor heaps at once of the same type if(Descriptor.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) - Descriptor.NumDescriptors += 16; + { + if(m_D3D12Opts.ResourceBindingTier == D3D12_RESOURCE_BINDING_TIER_3 || + Descriptor.NumDescriptors + 16 <= 1000000) + Descriptor.NumDescriptors += 16; + else + RDCERR( + "RenderDoc needs extra descriptors for patching during analysis," + "but heap is already at binding tier limit"); + } ID3D12DescriptorHeap *ret = NULL; HRESULT hr = m_pDevice->CreateDescriptorHeap(&Descriptor, guid, (void **)&ret);