[Mesa-dev] [PATCH] glsl: Eliminate unused built-in variables after compilation

Kenneth Graunke kenneth at whitecape.org
Sat May 31 01:10:32 PDT 2014


On Thursday, May 29, 2014 02:37:34 PM Ian Romanick wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
> 
> After compilation (and before linking) we can eliminate quite a few
> built-in variables.  Basically, any uniform or constant (e.g.,
> gl_MaxVertexTextureImageUnits) that isn't used (with one exception) can
> be eliminated.  System values, vertex shader inputs (with one
> exception), and fragment shader outputs that are not used and not
> re-declared in the shader text can also be removed.
> 
> gl_ModelViewProjectMatrix and gl_Vertex are used by the built-in
> function ftransform.  There are some complications with eliminating
> these variables (see the comment in the patch), so they are not
> eliminated.
> 
> Reduces the peak ir_variable memory usage in a trimmed apitrace of dota2
> by 3.5MB on 64-bit.

Except that it doesn't.  Your patch removes these variables from the IR, which 
means that your memory counting trick stops accounting for them.  But they're 
allocated using the symbol table as the memory context, which lives as long as 
the gl_shader object.  So they're never actually *freed*.

Massif on an apitrace of Portal shows no difference in memory usage.

That said, perhaps this can be part of the solution...
 
> Before: IR MEM: variable usage / name / total: 5327760 894914 6222674
> After:  IR MEM: variable usage / name / total: 2156568 318192 2474760
> 
> Reduces the peak ir_variable memory usage in a trimmed apitrace of dota2
> by 2.8MB on 32-bit.
> 
> Before: IR MEM: variable usage / name / total: 4118280 644100 4762380
> After:  IR MEM: variable usage / name / total: 1473408 256871 1730279
> 
> v2: Don't remove any built-in with Transpose in the name.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140531/b8e5ccf9/attachment.sig>


More information about the mesa-dev mailing list