From fcc6ab508760430e31c19f6db6fe1acdf247ee48 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Wed, 3 Jul 2024 14:24:05 +0100 Subject: [PATCH] Added helper D3D12ShaderDebug::GetSampleInfo() Used by DXBC and DXIL Shader Debuggers --- renderdoc/driver/d3d12/d3d12_shaderdebug.cpp | 77 ++++++++++++-------- renderdoc/driver/d3d12/d3d12_shaderdebug.h | 4 + 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp b/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp index bb071ebc2..70e240fdb 100644 --- a/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp +++ b/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp @@ -843,6 +843,44 @@ ShaderVariable D3D12ShaderDebug::GetResourceInfo(WrappedID3D12Device *device, return result; } +ShaderVariable D3D12ShaderDebug::GetSampleInfo(WrappedID3D12Device *device, + D3D12_DESCRIPTOR_RANGE_TYPE descType, + const DXBCDXILDebug::BindingSlot &slot, + const DXBC::ShaderType shaderType, + const char *opString) +{ + ShaderVariable result("", 0U, 0U, 0U, 0U); + + D3D12Descriptor descriptor = FindDescriptor(device, descType, slot, shaderType); + + if(descriptor.GetType() == D3D12DescriptorType::SRV && descType == D3D12_DESCRIPTOR_RANGE_TYPE_SRV) + { + D3D12ResourceManager *rm = device->GetResourceManager(); + + ResourceId srvId = descriptor.GetResResourceId(); + ID3D12Resource *pResource = rm->GetCurrentAs(srvId); + D3D12_RESOURCE_DESC resDesc = pResource->GetDesc(); + D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = descriptor.GetSRV(); + if(srvDesc.ViewDimension == D3D12_SRV_DIMENSION_UNKNOWN) + srvDesc = MakeSRVDesc(resDesc); + + if(srvDesc.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DMS || + srvDesc.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY) + { + result.value.u32v[0] = resDesc.SampleDesc.Count; + result.value.u32v[1] = 0; + result.value.u32v[2] = 0; + result.value.u32v[3] = 0; + } + else + { + RDCERR("Invalid resource dimension for GetSampleInfo"); + } + } + + return result; +} + class D3D12DebugAPIWrapper : public DXBCDebug::DebugAPIWrapper { public: @@ -1295,14 +1333,14 @@ ShaderVariable D3D12DebugAPIWrapper::GetSampleInfo(DXBCBytecode::OperandType typ const DXBCDebug::BindingSlot &slot, const char *opString) { - ShaderVariable result("", 0U, 0U, 0U, 0U); - - D3D12ResourceManager *rm = m_pDevice->GetResourceManager(); - + DXBC::ShaderType shaderType = GetShaderType(); if(type == DXBCBytecode::TYPE_RASTERIZER) { - if(GetShaderType() != DXBC::ShaderType::Compute) + ShaderVariable result("", 0U, 0U, 0U, 0U); + if(shaderType != DXBC::ShaderType::Compute) { + D3D12ResourceManager *rm = m_pDevice->GetResourceManager(); + const D3D12RenderState &rs = m_pDevice->GetQueue()->GetCommandData()->m_RenderState; // try depth first - both should match sample count though to be valid @@ -1320,33 +1358,8 @@ ShaderVariable D3D12DebugAPIWrapper::GetSampleInfo(DXBCBytecode::OperandType typ return result; } - D3D12Descriptor descriptor = FindDescriptor(type, slot); - - if(descriptor.GetType() == D3D12DescriptorType::SRV && - type != DXBCBytecode::TYPE_UNORDERED_ACCESS_VIEW) - { - ResourceId srvId = descriptor.GetResResourceId(); - ID3D12Resource *pResource = rm->GetCurrentAs(srvId); - D3D12_RESOURCE_DESC resDesc = pResource->GetDesc(); - D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = descriptor.GetSRV(); - if(srvDesc.ViewDimension == D3D12_SRV_DIMENSION_UNKNOWN) - srvDesc = MakeSRVDesc(resDesc); - - if(srvDesc.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DMS || - srvDesc.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY) - { - result.value.u32v[0] = resDesc.SampleDesc.Count; - result.value.u32v[1] = 0; - result.value.u32v[2] = 0; - result.value.u32v[3] = 0; - } - else - { - RDCERR("Invalid resource dimension for GetSampleInfo"); - } - } - - return result; + D3D12_DESCRIPTOR_RANGE_TYPE descType = ConvertOperandTypeToDescriptorType(type); + return D3D12ShaderDebug::GetSampleInfo(m_pDevice, descType, slot, shaderType, opString); } ShaderVariable D3D12DebugAPIWrapper::GetBufferInfo(DXBCBytecode::OperandType type, diff --git a/renderdoc/driver/d3d12/d3d12_shaderdebug.h b/renderdoc/driver/d3d12/d3d12_shaderdebug.h index 375634e81..49d65a3d5 100644 --- a/renderdoc/driver/d3d12/d3d12_shaderdebug.h +++ b/renderdoc/driver/d3d12/d3d12_shaderdebug.h @@ -58,4 +58,8 @@ D3D12Descriptor FindDescriptor(WrappedID3D12Device *device, D3D12_DESCRIPTOR_RAN ShaderVariable GetResourceInfo(WrappedID3D12Device *device, D3D12_DESCRIPTOR_RANGE_TYPE descType, const DXBCDXILDebug::BindingSlot &slot, uint32_t mipLevel, const DXBC::ShaderType shaderType, int &dim, bool isDXIL); + +ShaderVariable GetSampleInfo(WrappedID3D12Device *device, D3D12_DESCRIPTOR_RANGE_TYPE descType, + const DXBCDXILDebug::BindingSlot &slot, + const DXBC::ShaderType shaderType, const char *opString); };