From 1b29d0d69c790e53e29d3946ff77de4a96609ecd Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 6 Feb 2020 17:02:39 +0000 Subject: [PATCH] Respect interpolation modes on PS inputs when gathering debug data --- renderdoc/driver/d3d11/d3d11_shaderdebug.cpp | 6 ++--- renderdoc/driver/d3d12/d3d12_shaderdebug.cpp | 6 ++--- renderdoc/driver/shaders/dxbc/dxbc_debug.cpp | 25 ++++++++++++++++++- renderdoc/driver/shaders/dxbc/dxbc_debug.h | 2 +- .../driver/shaders/dxbc/dxbc_disassemble.cpp | 15 ++++++----- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp b/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp index 8a51f5be8..ebe9a67ac 100644 --- a/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp +++ b/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp @@ -2150,9 +2150,9 @@ ShaderDebugTrace *D3D11Replay::DebugPixel(uint32_t eventId, uint32_t x, uint32_t rdcstr extractHlsl; int structureStride = 0; - DXBCDebug::GatherPSInputDataForInitialValues(*dxbc->GetReflection(), *prevdxbc->GetReflection(), - initialValues, floatInputs, inputVarNames, - extractHlsl, structureStride); + DXBCDebug::GatherPSInputDataForInitialValues(dxbc, *prevdxbc->GetReflection(), initialValues, + floatInputs, inputVarNames, extractHlsl, + structureStride); uint32_t overdrawLevels = 100; // maximum number of overdraw levels diff --git a/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp b/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp index b75c6cbc9..81fb82b97 100644 --- a/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp +++ b/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp @@ -1214,9 +1214,9 @@ ShaderDebugTrace *D3D12Replay::DebugPixel(uint32_t eventId, uint32_t x, uint32_t rdcstr extractHlsl; int structureStride = 0; - DXBCDebug::GatherPSInputDataForInitialValues(*dxbc->GetReflection(), *prevDxbc->GetReflection(), - initialValues, floatInputs, inputVarNames, - extractHlsl, structureStride); + DXBCDebug::GatherPSInputDataForInitialValues(dxbc, *prevDxbc->GetReflection(), initialValues, + floatInputs, inputVarNames, extractHlsl, + structureStride); uint32_t overdrawLevels = 100; // maximum number of overdraw levels diff --git a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp index 2170093b9..1fa41ba99 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp @@ -4431,12 +4431,15 @@ void LookupSRVFormatFromShaderReflection(const DXBC::Reflection &reflection, } } -void GatherPSInputDataForInitialValues(const DXBC::Reflection &psDxbc, +void GatherPSInputDataForInitialValues(const DXBC::DXBCContainer *dxbc, const DXBC::Reflection &prevStageDxbc, rdcarray &initialValues, rdcarray &floatInputs, rdcarray &inputVarNames, rdcstr &psInputDefinition, int &structureStride) { + const DXBC::Reflection &psDxbc = *dxbc->GetReflection(); + const DXBCBytecode::Program *program = dxbc->GetDXBCByteCode(); + // When debugging a pixel shader, we need to get the initial values of each pixel shader // input for the pixel that we are debugging, from whichever the previous shader stage was // configured in the pipeline. This function returns the input element definitions, other @@ -4568,8 +4571,28 @@ void GatherPSInputDataForInitialValues(const DXBC::Reflection &psDxbc, } } + DXBCBytecode::InterpolationMode interpolation = DXBCBytecode::INTERPOLATION_UNDEFINED; + + if(program) + { + for(size_t d = 0; d < program->GetNumDeclarations(); d++) + { + const DXBCBytecode::Declaration &decl = program->GetDeclaration(d); + + if(decl.declaration == DXBCBytecode::OPCODE_DCL_INPUT_PS && + decl.operand.indices[0].absolute && decl.operand.indices[0].index == sig.regIndex) + { + interpolation = decl.interpolation; + break; + } + } + } + if(nointerp) psInputDefinition += "nointerpolation "; + else if(interpolation != DXBCBytecode::INTERPOLATION_UNDEFINED && + interpolation != DXBCBytecode::INTERPOLATION_CONSTANT) + psInputDefinition += ToStr(interpolation) + " "; psInputDefinition += "float"; } diff --git a/renderdoc/driver/shaders/dxbc/dxbc_debug.h b/renderdoc/driver/shaders/dxbc/dxbc_debug.h index 521ec56f1..d10442b13 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_debug.h +++ b/renderdoc/driver/shaders/dxbc/dxbc_debug.h @@ -207,7 +207,7 @@ void FillViewFmt(DXGI_FORMAT format, GlobalState::ViewFmt &viewFmt); void LookupSRVFormatFromShaderReflection(const DXBC::Reflection &reflection, const BindingSlot &slot, GlobalState::ViewFmt &viewFmt); -void GatherPSInputDataForInitialValues(const DXBC::Reflection &psDxbc, +void GatherPSInputDataForInitialValues(const DXBC::DXBCContainer *dxbc, const DXBC::Reflection &prevStageDxbc, rdcarray &initialValues, rdcarray &floatInputs, rdcarray &inputVarNames, diff --git a/renderdoc/driver/shaders/dxbc/dxbc_disassemble.cpp b/renderdoc/driver/shaders/dxbc/dxbc_disassemble.cpp index 57e1e9b69..9f1b9910f 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_disassemble.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_disassemble.cpp @@ -2803,14 +2803,17 @@ rdcstr DoStringise(const DXBCBytecode::InterpolationMode &el) BEGIN_ENUM_STRINGISE(DXBCBytecode::InterpolationMode) { STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_UNDEFINED, "undefined"); - STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_CONSTANT, "constant"); + // differs slightly from fxc but it's very convenient to use the hlsl terms, which are used in + // all other cases + STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_CONSTANT, "nointerpolation"); STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR, "linear"); - STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_CENTROID, "linearCentroid"); - STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_NOPERSPECTIVE, "linearNopersp"); + STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_CENTROID, "linear centroid"); + STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_NOPERSPECTIVE, "linear noperspective"); STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID, - "linearNoperspCentroid"); - STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_SAMPLE, "linearSample"); - STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE, "linaerNoperspSample"); + "linear noperspective centroid"); + STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_SAMPLE, "linear sample"); + STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE, + "linear noperspective sample"); } END_ENUM_STRINGISE(); }