glsl: Reassociate multiplication of mat*mat*vec.
authorMatt Turner <mattst88@gmail.com>
Sat, 28 Mar 2015 00:13:51 +0000 (17:13 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 31 Mar 2015 21:01:15 +0000 (14:01 -0700)
commit2c38f891ad82881cd3cc6e4323bfca7bdb13d13a
treebd04bc7cc008aea3ea525f5f1bfe03a45dd80d14
parentcf2dc1624fe711ad0aa89322a1142eae46bbfc30
glsl: Reassociate multiplication of mat*mat*vec.

The typical case of mat4*mat4*vec4 is 80 scalar multiplications, but
mat4*(mat4*vec4) is only 32.

On HSW (with vec4 vertex shaders):
instructions in affected programs:     4420 -> 3194 (-27.74%)

On BDW (with scalar vertex shaders):
instructions in affected programs:     12756 -> 6726 (-47.27%)

Implementing a general matrix chain ordering is harder (or at least
tedious) because of having to walk the GLSL IR to create a list of
multiplicands. I'm guessing that this patch handles 90+% of cases, but
of course to tell definitively you'd have to implement the general
thing.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
src/glsl/opt_algebraic.cpp