Allow unused registers to be output to reflection
When compiling, the compiler will detect unused registers and kick them. This is great to be able to check what is actually used by the shader, but unfortunately that also prevents us from having stable shader reflection. If the shader artist connects a variable that is now compiled out, it would break their workflow. And if another variable is now not compiled out they'll have to connect it again. It would be great if O0 or a flag to avoid stripping this is available. Because right now we rely on manually tokenizing and parsing the entire file.
Is this for the spir-v code generation or DXIL?
DXIL
@Nielsbishere - can you help me understand your scenario a bit more please with maybe a minimal code example?
Usually this isn't an issue in HLSL shaders because you use explicit bindings to fix the register values: eg.:
Texture2D aTexture : register(t30)
@damyanp The reason for this is because (our) shader artists don't like having to type these registers manually. These shaders are exposed in our visual scripting language as a node and the node links need to be stable (which is not possible if the registers are stripped, as they would change if you don't use every register or start using a register). As a temporary fix, our shader pre-processor will insert this manually. However, personally I'd like to kick our shader preprocessor. So the more stuff we can get standardized in DXC, the better. Because that means we can eventually let go of this preprocessor, which will standardize our workflow and make life a lot easier.
I think this would make the most sense as a rewriter mode. One that could pre-assign registers to resources and emit a resource binding table define for use with the -binding-table-define option (hidden option, see dxc --help-hidden).
That could be developed in a custom branch of DXC, and/or submitted as a contribution to this project if you'd like. See: CONTRIBUTING.md.
I'll keep that in mind. Maybe I can roll some features in it that are required such as certain missing reflection information too