I am trying to find a way to organize my evergrowing number of shader techniques/functions (I am coding in sm_3.0). One way is to do this:
float4 PS_Crossroads(PS_INPUT input, uniform bool left_right) : COLOR0
{
if (left_right)
GoLeft();
else
GoRight();
...
}
technique LEFT
{
pass Pass1
{
VertexShader = compile vs_3_0 VertSh();
PixelShader = compile ps_3_0 PS_Crossroads(true);
}
}
technique RIGHT
{
pass Pass1
{
VertexShader = compile vs_3_0 VertSh();
PixelShader = compile ps_3_0 PS_Crossroads(false);
}
}
My question is will this cause a branch at runtime or will the compiler be smart enough to split it into two separate techniques?
Thanks.
P.S. Ok I won't post this as answer, because we already have an answer by someone much more experienced than me, but from my humble tests (on different PCs) and my humble Google research, this approach (using uniform constants) is efficient and indeed forces the compiler to create different shader versions for each branch, removing flow controll completely from the finall compiled shader. I tested the compiled shader codes with Nvidia NSight.