diff --git a/renderdoc/driver/d3d12/d3d12_dxil_debug.cpp b/renderdoc/driver/d3d12/d3d12_dxil_debug.cpp index cc37a493b..37f1f221e 100644 --- a/renderdoc/driver/d3d12/d3d12_dxil_debug.cpp +++ b/renderdoc/driver/d3d12/d3d12_dxil_debug.cpp @@ -1138,4 +1138,46 @@ ResourceReferenceInfo D3D12APIWrapper::GetResourceReferenceInfo(const DXDebug::B } return resRefInfo; } + +ShaderDirectAccess D3D12APIWrapper::GetShaderDirectAccess(DescriptorCategory category, + const DXDebug::BindingSlot &slot) +{ + const HeapDescriptorType heapType = slot.heapType; + RDCASSERT(heapType != HeapDescriptorType::NoHeap); + uint32_t descriptorIndex = slot.descriptorIndex; + + const D3D12RenderState &rs = m_Device->GetQueue()->GetCommandData()->m_RenderState; + D3D12ResourceManager *rm = m_Device->GetResourceManager(); + + ShaderDirectAccess access; + uint32_t byteSize = DXILDebug::D3D12_DESCRIPTOR_BYTESIZE; + uint32_t byteOffset = descriptorIndex * byteSize; + + // Fetch the correct heap sampler and resource descriptor heap + 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) + { + RDCASSERTEQUAL(category, DescriptorCategory::Sampler); + return ShaderDirectAccess(category, rm->GetOriginalID(heapId), byteOffset, byteSize); + } + } + else + { + RDCASSERT(heapDesc.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + if(heapType == HeapDescriptorType::CBV_SRV_UAV) + { + RDCASSERTNOTEQUAL(category, DescriptorCategory::Sampler); + return ShaderDirectAccess(category, rm->GetOriginalID(heapId), byteOffset, byteSize); + } + } + } + RDCERR("Failed to find descriptor %u %u", (uint32_t)heapType, descriptorIndex); + return ShaderDirectAccess(); +} }; diff --git a/renderdoc/driver/d3d12/d3d12_dxil_debug.h b/renderdoc/driver/d3d12/d3d12_dxil_debug.h index a02ad8237..91564db11 100644 --- a/renderdoc/driver/d3d12/d3d12_dxil_debug.h +++ b/renderdoc/driver/d3d12/d3d12_dxil_debug.h @@ -61,6 +61,8 @@ public: const DXBC::ShaderType shaderType, const char *opString); ShaderVariable GetRenderTargetSampleInfo(const DXBC::ShaderType shaderType, const char *opString); ResourceReferenceInfo GetResourceReferenceInfo(const DXDebug::BindingSlot &slot); + ShaderDirectAccess GetShaderDirectAccess(DescriptorCategory category, + const DXDebug::BindingSlot &slot); private: WrappedID3D12Device *m_Device; diff --git a/renderdoc/driver/shaders/dxil/dxil_debug.h b/renderdoc/driver/shaders/dxil/dxil_debug.h index 959e2668b..6f556e768 100644 --- a/renderdoc/driver/shaders/dxil/dxil_debug.h +++ b/renderdoc/driver/shaders/dxil/dxil_debug.h @@ -46,6 +46,9 @@ typedef DXBC::InterpolationMode InterpolationMode; class Debugger; struct GlobalState; +// D3D12 descriptors are equal sized and treated as effectively one byte in size +const uint32_t D3D12_DESCRIPTOR_BYTESIZE = 1; + struct InstructionRange { uint32_t min; @@ -162,6 +165,8 @@ public: virtual ShaderVariable GetRenderTargetSampleInfo(const DXBC::ShaderType shaderType, const char *opString) = 0; virtual ResourceReferenceInfo GetResourceReferenceInfo(const DXDebug::BindingSlot &slot) = 0; + virtual ShaderDirectAccess GetShaderDirectAccess(DescriptorCategory category, + const DXDebug::BindingSlot &slot) = 0; }; struct MemoryTracking