[Mesa-dev] RFC: r300 compiler loop emulation

Tom Stellard tstellar at gmail.com
Mon Jun 7 22:33:03 PDT 2010


On Mon, Jun 07, 2010 at 08:38:15AM -0600, Brian Paul wrote:
> Tom Stellard wrote:
> > Hi,
> > 
> > I have just published a branch with loop emulation for the r300
> > compiler here: http://cgit.freedesktop.org/~tstellar/mesa/ 
> > 
> > This adds support for unrolling of loops that have a constant number of
> > iterations (e.g. for(i=0; i<10; i++) or for(i=10; i>0; i--)
> > It only handles cases where the counter is either added to or subtracted
> > from, like the examples above, but I think this covers a majority
> > of loops.
> > 
> > Loops that have an unknown number of iterations are unrolled as many
> > times as possible without going over the instruction limit for the
> > shader program.
> > 
> > Right now, this is only enabled for fragment shaders, but I am working on
> > enabling it for vertex shaders.
> > 
> > Any comments/suggestions would be appreciated.  Thanks.
> 
> Is there any advantage to doing this in the r300 compiler instead of 
> the GLSL compiler?  The GLSL compiler already does loop unrolling in 
> some cases.  If we do it in the GLSL compiler, all the drivers can 
> benefit.
>

The r300 compiler needs to have very aggressive loop unrolling for the
r300 cards that don't have loop instructions.  I am not sure if the
kind of loop unrolling it is doing would be appropriate for the GLSL
compiler in all cases.  Although, I think you are right, just like other
optimizations any loop unrolling that the GLSL complier can do would be
a plus.

-Tom




More information about the mesa-dev mailing list