[Mesa-dev] [PATCH] i965: Fix out-of-order sampler unit usage in ARB fragment programs.

Kenneth Graunke kenneth at whitecape.org
Tue Sep 11 18:28:04 PDT 2012


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 ffs() 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, ffs() should give the same result.

Fixes a regression since 85e8e9e000732908b259a7e2cbc1724a1be2d447,
which broke piglit test fp-fragment-position.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54098
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_wm_sampler_state.c | 2 +-
 src/mesa/drivers/dri/i965/brw_wm_surface_state.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
index 610ef34..795c9ae 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
@@ -341,7 +341,7 @@ brw_upload_samplers(struct brw_context *brw)
 
    GLbitfield SamplersUsed = vs->SamplersUsed | fs->SamplersUsed;
 
-   brw->sampler.count = _mesa_bitcount(SamplersUsed);
+   brw->sampler.count = ffs(SamplersUsed);
 
    if (brw->sampler.count == 0)
       return;
diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index eefa427..6a69349 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -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 = ffs(vs->SamplersUsed | fs->SamplersUsed);
 
    for (unsigned s = 0; s < num_samplers; s++) {
       brw->vs.surf_offset[SURF_INDEX_VS_TEXTURE(s)] = 0;
-- 
1.7.11.4



More information about the mesa-dev mailing list