[Mesa-dev] [PATCH 0/3] [RFC] mesa/st: glsl_to_tgsi: improved temp-reg lifetime estimation

Gert Wollny gw.fossdev at gmail.com
Mon Jun 12 12:34:21 UTC 2017


Am Montag, den 12.06.2017, 12:28 +0200 schrieb Nicolai Hähnle:
> On 10.06.2017 01:15, Gert Wollny wrote:
> > 
> Plenty of style issues aside, can you explain where and why you get 
> tighter lifetimes?

In the original code if a temporary is used within a loop it gets the
whole life time of the loop assigned. 

With this patch I track in more detail where a temporary is accesses
and base the lifetime on this: For instance, if a variable is first
unconditionally written and later read for the last time in the same
scope (loop, if, or switch branch), then the lifetime can be restricted
to that first-written - last-read range.

The code gets more complex because it tries to resolve this also for
nested scopes, and one also has to take care about whether a variable
is written only conditionally within a loop, or conditionally read
before it is written (in the source code sense, but not in the program
flow sense).

Shaders that profit from this better lifetime estimation are the ones
that have many short living values within long loops, think 

for () {
  float4 t[1] = f(in2); 
  float4 t[2] = g(in1); 
  float4 t[3] = op(t[1], t[2]); 
   ...
  sum += t[200];
}
 
Here the old code would keep all of the t[i] alive for the whole loop,
and in fact with the GpuTest Piano benchmark I have seen a shader with
>2000 temporaries where many were used in a loop but only required for
two or three lines so that my code could merge them to less then 100
temporaries, and this made it possible for the tgsi to bytecode layer
in r600g to actually translate the shader.

Best, 
Gert 

PS: Regarding style, I am fully aware that I have to iterate over this
code a few more times. I tried to adhere to the way the existing code
represents itself to me, but I'm happy to listen to any advise I can
get. 

In any case, I though it might be best to send this patch out now for
discussion. Now, with the unit tests in place I will rework it and
focus also more on style questions. One thing that comes up immediately
up is that I will try to reduce the use of dynamically allocated
memory, since 60% of the run time of my code is with memory allocation
and de-allocation. 




More information about the mesa-dev mailing list