i965: Fix out-of-order sampler unit usage in ARB fragment programs.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 12 Sep 2012 05:14:59 +0000 (22:14 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Fri, 14 Sep 2012 09:03:00 +0000 (02:03 -0700)
ARB fragment programs use texture unit numbers directly, unlike GLSL
which has an extra indirection.  If a fragment program only uses one
texture assigned to GL_TEXTURE1, SamplersUsed will only contain a single
bit, which would make us only upload a single surface/sampler state
entry.  However, it needs to be the second entry.

Using _mesa_fls() instead of _mesa_bitcount() solves this.  For ARB
programs, this makes num_samplers the ID of the highest texture unit
used.  Since GLSL uses consecutive integers assigned by the linker,
_mesa_fls() should give the same result as _mesa_bitcount()..

Fixes a regression since 85e8e9e000732908b259a7e2cbc1724a1be2d447,
which caused GPU hangs in ETQW (and probably others), as well as
breaking piglit test fp-fragment-position.

v2: Add a comment, as suggested by Matt.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54098
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54179
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Tested-by: meng <mengmeng.meng@intel.com>
(cherry picked from commit 28f4be9eb91b12a2c6b1db6660cca71a98c486ec)

src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c

index 610ef34..e51381b 100644 (file)
@@ -341,7 +341,10 @@ brw_upload_samplers(struct brw_context *brw)
 
    GLbitfield SamplersUsed = vs->SamplersUsed | fs->SamplersUsed;
 
-   brw->sampler.count = _mesa_bitcount(SamplersUsed);
+   /* ARB programs use the texture unit number as the sampler index, so we
+    * need to find the highest unit used.  A bit-count will not work.
+    */
+   brw->sampler.count = _mesa_fls(SamplersUsed);
 
    if (brw->sampler.count == 0)
       return;
index eefa427..582e239 100644 (file)
@@ -1250,7 +1250,7 @@ brw_update_texture_surfaces(struct brw_context *brw)
    struct gl_program *vs = (struct gl_program *) brw->vertex_program;
    struct gl_program *fs = (struct gl_program *) brw->fragment_program;
 
-   unsigned num_samplers = _mesa_bitcount(vs->SamplersUsed | fs->SamplersUsed);
+   unsigned num_samplers = _mesa_fls(vs->SamplersUsed | fs->SamplersUsed);
 
    for (unsigned s = 0; s < num_samplers; s++) {
       brw->vs.surf_offset[SURF_INDEX_VS_TEXTURE(s)] = 0;