I'm having trouble with my pixel shader unnecessarily compiling extra assembly instructions.
An example of what I'm trying to do: I'd like one technique that uses a texture and one that doesn't, and have a "useTexture" boolean parameter. I would have on pixel shader function that's specified in two different techniques with different parameters. Inside the pixel shader is an if statement that's something like:
if (useTexture)
color *= tex2D(sampler, texCoord);
and the technique declaration looks like:
PixelShader = compile ps_2_0 Foo(true/false);
Now maybe I don't understand shader compilation very well, but it seems that it should be able to predict away the if statement. If useTexture is a constant it works fine, but if it's a uniform parameter it becomes needlessly longer. It's defined in the technique so it won't ever change right?
I tested this in NVShaderPerf. I couldn't figure out how to make fxc.exe let me specify the parameters I was passing into the function. I know uniform sounds like "constant for a draw call" rather than "constant forever", but there should be a way to do this easily right? I want to specify how a pixel shader function works in a technique, and I want it to be fast.
edit:
Ok, I guess it is optimized out like I thought it should be. I was worried that I was compiling conditionals in since I wasn't looking at the right assembly. I should have passed /T:fx_#_# instead of /T:ps_#_#. I sure feel silly now! Sorry for the waste of a thread.
[Edited by - stanlo on April 24, 2007 6:02:29 PM]