[Mesa-dev] [PATCH] glsl: Optimize mul(a, -1) into neg(a).
mattst88 at gmail.com
Wed Oct 16 22:57:18 CEST 2013
On Wed, Oct 16, 2013 at 11:14 AM, Ian Romanick <idr at freedesktop.org> wrote:
> On 10/15/2013 11:55 PM, Matt Turner wrote:
>> Two extra instructions in some heroesofnewerth shaders, but a win for
>> everything else.
>> total instructions in shared programs: 1531352 -> 1530815 (-0.04%)
>> instructions in affected programs: 121898 -> 121361 (-0.44%)
> Just curious... what causes these expressions in the affected shaders?
> Did the app developer write it, do did another one of our passes
> generate it?
I've just looked at a single shader (amnesia/20.frag) that was
improved, so others may be different but it does
float fRimLight = dot(gvNormal, vec3(0.0, 0.0, -1.0));
opt_algebraic optimizes dot products with 0.0 or where arguments
contain a single 1.0 and some number of 0.0, so that code was
float fRimLight = gvNormal * -1.0;
... and the IR we generate for this (combined with some other bits are)
(assign (x) (var_ref channel_expressions at 2)
(expression float + (constant float (1.000000))
(expression float neg (expression
float abs (expression float neg (var_ref gvNormal_z))))))
i.e., 1.0 - abs(-gvNormal.z). abs(-val). Nice.
More information about the mesa-dev