i965/fs: Don't clobber sampler message MRFs with subexpressions.
authorKenneth Graunke <kenneth@whitecape.org>
Sun, 5 Aug 2012 03:55:21 +0000 (20:55 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 6 Aug 2012 18:16:11 +0000 (11:16 -0700)
commitc0f60106df724188d6ffe7c9f21eeff22186ab25
treee09b5490d9a20723464f6fdafd75147a6016de07
parent27bf9c1997b77f85c2099436e9ad5dfc0f1608c7
i965/fs: Don't clobber sampler message MRFs with subexpressions.

Consider a texture call such as:

   textureLod(s, coordinate, log2(...))

First, we begin setting up the sampler message by loading the texture
coordinates into MRFs, starting with m2.  Then, we realize we need the
LOD, and go to compute it with:

   ir->lod_info.lod->accept(this);

On Gen4-5, this will generate a SEND instruction to compute log2(),
loading the operand into m2, and clobbering our texcoord.

Similar issues exist on Gen6+.  For example, nested texture calls:

  textureLod(s1, c1, texture(s2, c2).x)

Any texturing call where evaluating the subexpression trees for LOD or
shadow comparitor would generate SEND instructions could potentially
break.  In some cases (like register spilling), we get lucky and avoid
the issue by using non-overlapping MRF regions.  But we shouldn't count
on that.

Fixes four Piglit test regressions on Gen4-5:
- glsl-fs-shadow2DGradARB-{01,04,07,cumulative}

NOTE: This is a candidate for stable release branches.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52129
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp