[Mesa-dev] glsl2: optimizing unused struct assignments

Eric Anholt eric at anholt.net
Thu Aug 5 13:48:26 PDT 2010


On Thu, 5 Aug 2010 13:33:50 +0200, Aras Pranckevicius <aras at unity3d.com> wrote:
> > I believe the plan is to eventually break structures and arrays that are
> > not variably indexed into individual variables.  Your structure above
> > would be broken into s_used and s_unused.  The existing dead code paths
> > would take care of s_unused.  We'll need to do this break-up anyway to
> > do proper register assignment.
> 
> Ok, nice. If someone else is going to do that I don't have to worry
> about it. Any idea on when that work is planned to be done?
> 
> For the GLSL optimizer I'm working on this currently seems to be the
> largest possible optimization left. On a certain mobile platform that
> starts with 'i' a fragment shader like this:

Pushed a change that cleans up the shader you pasted.  Mostly.  There's
still some junk in it that we could do better at.  Results below.

By the way, it would be useful to get some examples of your shaders as
shader_runner tests in piglit.  That makes them easy to analyze for
optimization opportunities, and they serve as regression tests to make
sure we don't break your shaders.  Would you be up for making some of
those?

GLSL IR for linked fragment program 3:
(
(declare (out ) (array vec4 8) gl_FragData at 0x847b3a8)
(declare (uniform ) vec4 _Color at 0x83bcfe0)
(declare (uniform ) sampler2D _Detail at 0x83bd098)
(declare (uniform ) sampler2D _MainTex at 0x83c35e8)
(declare (in ) vec4 xlv_TEXCOORD0 at 0x83c36a0)
(declare (in ) vec4 xlv_TEXCOORD1 at 0x83c3760)
(function main
  (signature void
    (parameters
    )
    (
      (declare () vec4 c at 0x83df7c8)
      (assign (constant bool (1)) (xyzw) (var_ref c at 0x83df7c8)  (expression vec4 * (var_ref _Color at 0x83bcfe0) (tex (var_ref _MainTex at 0x83c35e8)  (swiz xy (var_ref xlv_TEXCOORD0 at 0x83c36a0) ) (0 0 0) 1 () )) ) 
      (declare (temporary ) vec4 assignment_tmp at 0x83ee630)
      (assign (constant bool (1)) (xyzw) (var_ref assignment_tmp at 0x83ee630)  (expression vec4 * (expression vec4 * (var_ref c at 0x83df7c8) (tex (var_ref _Detail at 0x83bd098)  (swiz xy (var_ref xlv_TEXCOORD1 at 0x83c3760) ) (0 0 0) 1 () )) (constant float (2.000000)) ) ) 
      (assign (constant bool (1)) (xyzw) (var_ref c at 0x83df7c8)  (var_ref assignment_tmp at 0x83ee630) ) 
      (assign (constant bool (1)) (xyzw) (array_ref (var_ref gl_FragData at 0x847b3a8) (constant int (0)) )  (swiz xyzw (var_ref assignment_tmp at 0x83ee630) )) 
    ))

)

Mesa IR for linked fragment program 3:
  0: (tex (var_ref _MainTex at 0x83c35e8)  (swiz xy (var_ref xlv_TEXCOORD0 at 0x83c36a0) ) (0 0 0) 1 () )
     MOV TEMP[1], INPUT[14].xyyy;

This gets copy-propagated to the next instruction in Mesa IR and is just
a result of laziness in ir_to_mesa.cpp.  (Same goes for extra move of
assignment rhs to lhs).

  1: TEX TEMP[2], TEMP[1], texture[0], 2D;
  2: (expression vec4 * (var_ref _Color at 0x83bcfe0) (tex (var_ref _MainTex at 0x83c35e8)  (swiz xy (var_ref xlv_TEXCOORD0 at 0x83c36a0) ) (0 0 0) 1 () )) 
     MUL TEMP[3], UNIFORM[0], TEMP[2];
  3: (assign (constant bool (1)) (xyzw) (var_ref c at 0x83df7c8)  (expression vec4 * (var_ref _Color at 0x83bcfe0) (tex (var_ref _MainTex at 0x83c35e8)  (swiz xy (var_ref xlv_TEXCOORD0 at 0x83c36a0) ) (0 0 0) 1 () )) ) 
     MOV TEMP[4], TEMP[3];
  4: (tex (var_ref _Detail at 0x83bd098)  (swiz xy (var_ref xlv_TEXCOORD1 at 0x83c3760) ) (0 0 0) 1 () )
     MOV TEMP[5], INPUT[15].xyyy;
  5: TEX TEMP[6], TEMP[5], texture[1], 2D;
  6: (expression vec4 * (var_ref c at 0x83df7c8) (tex (var_ref _Detail at 0x83bd098)  (swiz xy (var_ref xlv_TEXCOORD1 at 0x83c3760) ) (0 0 0) 1 () )) 
     MUL TEMP[7], TEMP[4], TEMP[6];
  7: (expression vec4 * (expression vec4 * (var_ref c at 0x83df7c8) (tex (var_ref _Detail at 0x83bd098)  (swiz xy (var_ref xlv_TEXCOORD1 at 0x83c3760) ) (0 0 0) 1 () )) (constant float (2.000000)) ) 
     MUL TEMP[8], TEMP[7], CONST[3].xxxx;
  8: (assign (constant bool (1)) (xyzw) (var_ref assignment_tmp at 0x83ee630)  (expression vec4 * (expression vec4 * (var_ref c at 0x83df7c8) (tex (var_ref _Detail at 0x83bd098)  (swiz xy (var_ref xlv_TEXCOORD1 at 0x83c3760) ) (0 0 0) 1 () )) (constant float (2.000000)) ) ) 
     MOV TEMP[9], TEMP[8];
  9: (assign (constant bool (1)) (xyzw) (var_ref c at 0x83df7c8)  (var_ref assignment_tmp at 0x83ee630) ) 
     MOV TEMP[4], TEMP[9];

This move to "c" is junk, which gets dead-coded by Mesa IR but we ought
to be able to kill it before then.  (If we do GVN on functions, that
would cover this, and we ought to do that).

 10: (assign (constant bool (1)) (xyzw) (array_ref (var_ref gl_FragData at 0x847b3a8) (constant int (0)) )  (swiz xyzw (var_ref assignment_tmp at 0x83ee630) )) 
     MOV OUTPUT[2], TEMP[9];
 11: END
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20100805/6cdbd5cc/attachment.pgp>


More information about the mesa-dev mailing list