From eab5314af870be07aa00d8f3daded3ee8981df80 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 3 Feb 2023 13:16:40 +0000 Subject: [PATCH] Allow SV_PrimitiveID in PS inputs mixed with non-SV inputs * Sometimes fxc gives an error about this - error X4576: Non system-generated input signature parameter () cannot appear after a system generated value. * There doesn't seem to be a documented way to know how/when this is important, but unfortunately in some cases SV values can take up registers and affect register packing so we can't always omit them. Here for primitive ID as long as it was previously declared mid-inputs, we allow it to be declared there as normal to preserve interface matching. --- renderdoc/driver/shaders/dxbc/dxbc_debug.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp index 22dd78221..3cafa97d8 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp @@ -4952,8 +4952,7 @@ void GatherPSInputDataForInitialValues(const DXBC::DXBCContainer *dxbc, bool included = true; // handled specially to account for SV_ ordering - if(sig.systemValue == ShaderBuiltin::PrimitiveIndex || - sig.systemValue == ShaderBuiltin::MSAACoverage || + if(sig.systemValue == ShaderBuiltin::MSAACoverage || sig.systemValue == ShaderBuiltin::IsFrontFace || sig.systemValue == ShaderBuiltin::MSAASampleIndex) { @@ -4961,6 +4960,15 @@ void GatherPSInputDataForInitialValues(const DXBC::DXBCContainer *dxbc, included = false; } + // it seems sometimes primitive ID can be included within inputs and isn't subject to the SV_ + // ordering restrictions - possibly to allow for geometry shaders to output the primitive ID as + // an interpolant. Only comment it out if it's the last input. + if(i + 1 == numInputs && sig.systemValue == ShaderBuiltin::PrimitiveIndex) + { + psInputDefinition += "//"; + included = false; + } + int arrayIndex = -1; for(size_t a = 0; a < arrays.size(); a++)