PDA

View Full Version : 0.0 x sth



wizzo
10-21-2004, 06:29 AM
while trying to get rid of the specular in m phong shader, I multiplied it by 0.0 (why didnt i commented it, who knows ?)

and the frame rate went up. does anyone know why ?

is this a compiler optimisation ? 0.0 x expression isnt evaluated and return 0.0 ? sounds possible even if not really usefull

wizzo

Sumpfratte
10-22-2004, 01:15 AM
well i think this is similar to the || or && logical optimization in c++ or java.

if you have f.e. the expression (A && B) and you know that A is false, you also know that the whole expression can't be true and so you have not to calculate B.

wizzo
10-22-2004, 02:12 AM
well, yeah, i suspected something like that, but when i multiplied my expression by a float set at 0.0, the framerate went back down imediately;

it would means that you cant count on that as an *optimisation*; otherwise you could just do something like :

boolean_expression * FunctionThatDoesSomethingComplex();

and you could get rid of a lot of work.

I dont know yet, i hadnt time to try it out, i will do that asap

wizzo

rgpc
10-22-2004, 02:29 AM
So it's faster when you use the constant 0.0 but slower when you use a variable with the value 0.0 in it? That kind of makes sense because the variable may have changed value and the compiler hasn't looked at what has happened to the value of the variable whereas it knows the constant will always be 0.0.

wizzo
10-22-2004, 02:38 AM
i thinks thats whats happening, even if uniform variables ARE constant, so its value shouldnt change, but as its after the compiler stage, it doesnt change anything

wizzo

Jan
10-22-2004, 07:56 AM
Is that really such a mysterium??

When compiling your shader, the compiler tries to optimize as much as possible. Later, when the shader gets used, such an optimization doesn´t take place anymore, and it is certainly impossible, because that would mean, the driver would have to recompile the shader, with known values, everytime you change your uniforms, etc.

So, later there actually takes a multiplication place, even with 0.0.

Jan.

wizzo
10-23-2004, 06:00 AM
nono, it isnt mysterium =)

thanks for your replies

wizzo