From 8d24385f15a2fc5fc548573720ba7c287c794a31 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Tue, 3 Dec 2024 07:29:15 +0000 Subject: [PATCH] D3D12ShaderDebug support for direct heap access bindings Added: D3D12Descriptor FindDescriptor(WrappedID3D12Device *device, const DXDebug::HeapDescriptorType heapType, uint32_t descriptorIndex); --- renderdoc/driver/d3d12/d3d12_shaderdebug.cpp | 52 ++++++++++++++++++++ renderdoc/driver/d3d12/d3d12_shaderdebug.h | 3 ++ 2 files changed, 55 insertions(+) diff --git a/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp b/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp index c0a6b368b..ab48c47a8 100644 --- a/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp +++ b/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp @@ -425,6 +425,53 @@ bool D3D12ShaderDebug::CalculateSampleGather( return true; } +D3D12Descriptor D3D12ShaderDebug::FindDescriptor(WrappedID3D12Device *device, + const DXDebug::HeapDescriptorType heapType, + uint32_t descriptorIndex) +{ + RDCASSERT(heapType != HeapDescriptorType::NoHeap); + + const D3D12RenderState &rs = device->GetQueue()->GetCommandData()->m_RenderState; + D3D12ResourceManager *rm = device->GetResourceManager(); + // Fetch the correct heap sampler and resource descriptor heaps + WrappedID3D12DescriptorHeap *descHeap = NULL; + + rdcarray descHeaps = rs.heaps; + for(ResourceId heapId : descHeaps) + { + WrappedID3D12DescriptorHeap *pD3D12Heap = rm->GetCurrentAs(heapId); + D3D12_DESCRIPTOR_HEAP_DESC heapDesc = pD3D12Heap->GetDesc(); + if(heapDesc.Type == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER) + { + if((heapType == HeapDescriptorType::Sampler) && (descHeap == NULL)) + descHeap = pD3D12Heap; + } + else + { + RDCASSERT(heapDesc.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + if((heapType == HeapDescriptorType::CBV_SRV_UAV) && (descHeap == NULL)) + descHeap = pD3D12Heap; + } + } + + if(descHeap == NULL) + { + RDCERR("Couldn't find descriptor heap type %u", heapType); + return D3D12Descriptor(); + } + + D3D12Descriptor *desc = (D3D12Descriptor *)descHeap->GetCPUDescriptorHandleForHeapStart().ptr; + if(descriptorIndex >= descHeap->GetNumDescriptors()) + { + RDCERR("Descriptor index %u out of bounds Max:%u", descriptorIndex, + descHeap->GetNumDescriptors()); + return D3D12Descriptor(); + } + + desc += descriptorIndex; + return *desc; +} + D3D12Descriptor D3D12ShaderDebug::FindDescriptor(WrappedID3D12Device *device, D3D12_DESCRIPTOR_RANGE_TYPE descType, const BindingSlot &slot, @@ -432,6 +479,11 @@ D3D12Descriptor D3D12ShaderDebug::FindDescriptor(WrappedID3D12Device *device, { D3D12Descriptor descriptor; + if(slot.heapType != DXDebug::HeapDescriptorType::NoHeap) + { + return FindDescriptor(device, slot.heapType, slot.descriptorIndex); + } + const D3D12RenderState &rs = device->GetQueue()->GetCommandData()->m_RenderState; D3D12ResourceManager *rm = device->GetResourceManager(); diff --git a/renderdoc/driver/d3d12/d3d12_shaderdebug.h b/renderdoc/driver/d3d12/d3d12_shaderdebug.h index d810ae5dd..550dc903b 100644 --- a/renderdoc/driver/d3d12/d3d12_shaderdebug.h +++ b/renderdoc/driver/d3d12/d3d12_shaderdebug.h @@ -52,6 +52,9 @@ bool CalculateSampleGather(bool dxil, WrappedID3D12Device *device, int sampleOp, GatherChannel gatherChannel, const DXBC::ShaderType shaderType, uint32_t instruction, const char *opString, ShaderVariable &output); +D3D12Descriptor FindDescriptor(WrappedID3D12Device *device, + const DXDebug::HeapDescriptorType heapType, uint32_t descriptorIndex); + D3D12Descriptor FindDescriptor(WrappedID3D12Device *device, D3D12_DESCRIPTOR_RANGE_TYPE descType, const DXDebug::BindingSlot &slot, const DXBC::ShaderType shaderType);