OK #DX12 #expert #shaders #howto solve this .. you have an HLSL shader where you declare let's say FOR EXAMPLE
cbuffer Constants : register(b0)
{
float4 Banana;
float4x4 World;
float4 Pappine;
}
But then MAYBE later on you have an #ifdef /something that makes the shader NOT use "Banana" .. now the optimizator "would remove Banana from the cbuffer block" so now you'll have 16 bytes less in the structure but "how do you know when you load the shader" that is happened ? You see the shit.
How can you tell the shader compiler NOT to remove "unused vars" from the "uniforms" OR know that "var does not exist any more" ? Can you someway "query a compiled shader object" to know what vars actually are present in the uniforms block or not ? IN THEORY I SUPPOSE IT SHOULD be possible, because the .CSO I suppose it's still SPIRV or something but is there any DX12 function for that ?
@gilesgoat what if you do 'unusedVariable = unusedVariable;'?
Maybe it'll trick the compiler into thinking it is in use so it is included, but then strip that line out of the compiled code as a NOP?
It works to suppress unused variable warnings, so maybe here too?
@sinbad Yes and no, the HLSL shaders are pre-compiled objects ( CSO = compiled shader obj ) done I think via the FXC / DXC compiler that from what I checked does not have that option. I don't know if I could 'externally compile' using a different shader compiler and someway "import into DX12" the compiled shaders.
@gilesgoat hmm ok that PR was supposed to add the option -fspv-preserve-interface to DXC so I thought it might do it