I load a pixel shader with 'SetPixelShader' in DX9. This shader contains
several conditionals... eg....
if_le v0.x, c_TestConstant.z
else
endif
Since the constant is defined when the shader is loaded, is this 'compiled out'
or does the compare still occur at each pixel ( and therefore still take cycles...) ???
The reason I need to do this is that I want to roll a set of shaders into a
single uber-shader.
Thanks..
Pixel shader constants, shader 3.0
Started by Spudman, Apr 05 2006 11:01 AM
5 replies to this topic
#1
Posted 05 April 2006 - 11:01 AM
#2
Posted 05 April 2006 - 01:13 PM
The driver may create multiple shader in this case and set them accordingly to the constant states, but there will be a point where the driver decides that its more expensive to do the caching of the shaders than actually execute the branch on hardware.
But I wouldn't worry about that all that much, a static branch is pretty cheap on all GPUs that support it :)
But I wouldn't worry about that all that much, a static branch is pretty cheap on all GPUs that support it :)
#3
Posted 05 April 2006 - 02:46 PM
Axel said:
But I wouldn't worry about that all that much, a static branch is pretty cheap on all GPUs that support it
The problem is that Spudman's example is NOT a static branch.
(static branches are evaluated at compile time)
Dynamic branches are pretty bad for performance on nVidia hardware, specially if you have lots of branches (like we did). ATi (ps3.0) hardware, on the other hand, seems to handle dynamic branching fairly well. Still, dynamic branching is by no means free - so avoid it whenever you can.
#4
Posted 05 April 2006 - 09:14 PM
Ooopss... bad example this, it isn't a static branch, what I really meant was
to give a static branch, in this case can I assume that the compiler will
try to produce the variants at compile time ? - I have the situation of 16
pixel shaders, all slightly different, which are switched between quite rapidly and I want to group them all in one shader, and switch between them on a
shader constant.
to give a static branch, in this case can I assume that the compiler will
try to produce the variants at compile time ? - I have the situation of 16
pixel shaders, all slightly different, which are switched between quite rapidly and I want to group them all in one shader, and switch between them on a
shader constant.
#5
Posted 05 April 2006 - 09:59 PM
jofferman said:
The problem is that Spudman's example is NOT a static branch.
jofferman said:
(static branches are evaluated at compile time)
jofferman said:
Dynamic branches are pretty bad for performance on nVidia hardware, specially if you have lots of branches (like we did). ATi (ps3.0) hardware, on the other hand, seems to handle dynamic branching fairly well. Still, dynamic branching is by no means free - so avoid it whenever you can.
jofferman said:
I have the situation of 16 pixel shaders, all slightly different, which are switched between quite rapidly and I want to group them all in one shader, and switch between them on a shader constant.
#6
Posted 06 April 2006 - 08:54 AM
Quote
Thats not true. The hardware must also have instructions for static branches, because you can end up with pretty much permutations if you have 10 branches or something like that in your shader
No, the hardware doesn't have instructions for static branching. However, fxc will evaluate static branches during shader compilation. If you want fxc to generate a shader for each of permutation of your static branches, you'll have to create a technique for each of those permutations - which can be very tedious.
We have an inhouse tool that automatically generates all permutations of every shader we use, since there are so many permutations. Our latest game (Tomb Raider: Legend) has, in total, some 20,000 shader permutations!
Jim.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












