From 3877803a16441ea3fef7bec67c416911be113db1 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 7 Nov 2024 15:07:14 +0000 Subject: [PATCH] Compute and return usedInputs from GatherPSInputDataForInitialValues Ignored for DXBC. For DXIL this is used instead of searching the generated HLSL shader source --- renderdoc/driver/d3d11/d3d11_shaderdebug.cpp | 3 ++- renderdoc/driver/d3d12/d3d12_shaderdebug.cpp | 17 +++++++++-------- renderdoc/driver/shaders/dxbc/dx_debug.cpp | 11 ++++++++--- renderdoc/driver/shaders/dxbc/dx_debug.h | 5 ++++- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp b/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp index cefeb37bf..65a50c862 100644 --- a/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp +++ b/renderdoc/driver/d3d11/d3d11_shaderdebug.cpp @@ -1884,9 +1884,10 @@ ShaderDebugTrace *D3D11Replay::DebugPixel(uint32_t eventId, uint32_t x, uint32_t const rdcarray &inputSig = dxbc->GetReflection()->InputSig; DXBCDebug::GetInterpolationModeForInputParams(inputSig, dxbc->GetDXBCByteCode(), interpModes); + std::map usedInputs; // not used for D3D11 DXDebug::GatherPSInputDataForInitialValues(inputSig, prevdxbc->GetReflection()->OutputSig, interpModes, initialValues, floatInputs, inputVarNames, - extractHlsl, structureStride); + extractHlsl, structureStride, usedInputs); 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 856bb40b1..2a4a4bb9f 100644 --- a/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp +++ b/renderdoc/driver/d3d12/d3d12_shaderdebug.cpp @@ -2298,9 +2298,10 @@ ShaderDebugTrace *D3D12Replay::DebugPixel(uint32_t eventId, uint32_t x, uint32_t else DXILDebug::GetInterpolationModeForInputParams(inputSig, dxbc->GetDXILByteCode(), interpModes); + std::map usedInputs; // only used for DXIL DXDebug::GatherPSInputDataForInitialValues(inputSig, prevDxbc->GetReflection()->OutputSig, interpModes, initialValues, floatInputs, inputVarNames, - extractHlsl, structureStride); + extractHlsl, structureStride, usedInputs); uint32_t overdrawLevels = 100; // maximum number of overdraw levels @@ -2467,17 +2468,17 @@ struct PSInitialData // The semantics that RenderDoc requires in the shader bool inputHas_SV_Position = false; bool inputHas_SV_PrimitiveID = false; - bool inputHas_SV_SampleIndex = false; - bool inputHas_SV_Coverage = false; - bool inputHas_SV_IsFrontFace = false; // SV_Coverage, SV_IsFrontFace, SV_SampleIndex : are not in the input structure, see // GatherPSInputDataForInitialValues + bool inputHas_SV_Coverage = false; + bool inputHas_SV_IsFrontFace = false; + bool inputHas_SV_SampleIndex = false; // DXC compiler errors if a semantic input is declared in multiple places if(dxbc->GetDXILByteCode()) { - inputHas_SV_Position = extractHlsl.contains(": SV_Position"); - inputHas_SV_PrimitiveID = extractHlsl.contains(": SV_PrimitiveID"); + inputHas_SV_Position = usedInputs.count(ShaderBuiltin::Position) > 0; + inputHas_SV_PrimitiveID = usedInputs.count(ShaderBuiltin::PrimitiveIndex) > 0; } extractHlsl += "void ExtractInputsPS(PSInput IN"; @@ -2496,9 +2497,9 @@ struct PSInitialData // Only used for DXIL shaders: copy any SV inputs we need from the input structure if(inputHas_SV_Position) - extractHlsl += " float4 debug_pixelPos = IN.input_SV_Position;\n"; + extractHlsl += " float4 debug_pixelPos = IN." + usedInputs[ShaderBuiltin::Position] + ";\n"; if(usePrimitiveID && inputHas_SV_PrimitiveID) - extractHlsl += " uint prim = IN.input_SV_PrimitiveID;\n"; + extractHlsl += " uint prim = IN." + usedInputs[ShaderBuiltin::PrimitiveIndex] + ";\n"; extractHlsl += " uint idx = " + ToStr(overdrawLevels) + ";\n"; extractHlsl += StringFormat::Fmt( diff --git a/renderdoc/driver/shaders/dxbc/dx_debug.cpp b/renderdoc/driver/shaders/dxbc/dx_debug.cpp index 48e71360f..7b53e44b3 100644 --- a/renderdoc/driver/shaders/dxbc/dx_debug.cpp +++ b/renderdoc/driver/shaders/dxbc/dx_debug.cpp @@ -33,7 +33,8 @@ void GatherPSInputDataForInitialValues(const rdcarray &stageInputS const rdcarray &interpModes, rdcarray &initialValues, rdcarray &floatInputs, rdcarray &inputVarNames, - rdcstr &psInputDefinition, int &structureStride) + rdcstr &psInputDefinition, int &structureStride, + std::map &usedInputs) { // 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 @@ -54,6 +55,7 @@ void GatherPSInputDataForInitialValues(const rdcarray &stageInputS if(stageInputSig.empty()) { psInputDefinition += "float4 input_dummy : SV_Position;\n"; + usedInputs[ShaderBuiltin::Position] = "input_dummy"; initialValues.push_back(PSInputElement(-1, 0, 4, ShaderBuiltin::Undefined, true)); @@ -276,12 +278,15 @@ void GatherPSInputDataForInitialValues(const rdcarray &stageInputS } } - psInputDefinition += ToStr((uint32_t)numCols) + " input_" + name; + rdcstr inputName = "input_" + name; + psInputDefinition += ToStr((uint32_t)numCols) + " " + inputName; if(arrayLength > 0) psInputDefinition += "[" + ToStr(arrayLength) + "]"; psInputDefinition += " : " + name; + if(sig.systemValue != ShaderBuiltin::Undefined) + usedInputs[sig.systemValue] = inputName; - inputVarNames[i] = "input_" + name; + inputVarNames[i] = inputName; if(arrayLength > 0) inputVarNames[i] += StringFormat::Fmt("[%d]", RDCMAX(0, arrayIndex)); diff --git a/renderdoc/driver/shaders/dxbc/dx_debug.h b/renderdoc/driver/shaders/dxbc/dx_debug.h index 90725fe9f..6a3ae2a9e 100644 --- a/renderdoc/driver/shaders/dxbc/dx_debug.h +++ b/renderdoc/driver/shaders/dxbc/dx_debug.h @@ -24,6 +24,8 @@ #pragma once +#include + namespace DXBC { enum ResourceRetType; @@ -67,7 +69,8 @@ void GatherPSInputDataForInitialValues(const rdcarray &stageInputS const rdcarray &interpModes, rdcarray &initialValues, rdcarray &floatInputs, rdcarray &inputVarNames, - rdcstr &psInputDefinition, int &structureStride); + rdcstr &psInputDefinition, int &structureStride, + std::map &usedInputs); enum class GatherChannel : uint8_t {