View Full Version : 0.0 x sth
10-21-2004, 05: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
10-22-2004, 12: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.
10-22-2004, 01: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
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.
10-22-2004, 01: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
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.
10-23-2004, 05:00 AM
nono, it isnt mysterium =)
thanks for your replies
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.