[Mesa-dev] [PATCH 08/10] i965: Make sampler counts available for the entire drawing operation.

Kenneth Graunke kenneth at whitecape.org
Wed Aug 14 18:55:14 PDT 2013


Previously, we computed sampler counts when generating the SAMPLER_STATE
table.  By computing it earlier, we should be able to shorten a bunch of
loops.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_context.h          |  2 +-
 src/mesa/drivers/dri/i965/brw_draw.c             |  7 +++++++
 src/mesa/drivers/dri/i965/brw_wm_sampler_state.c | 19 +++++++------------
 src/mesa/drivers/dri/i965/gen7_sampler_state.c   | 12 +++++-------
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 8184739..ff0a65c 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -817,7 +817,7 @@ struct brw_context
       /** Upload a SAMPLER_STATE table. */
       void (*upload_sampler_state_table)(struct brw_context *brw,
                                          struct gl_program *prog,
-                                         uint32_t *sampler_count,
+                                         uint32_t sampler_count,
                                          uint32_t *sst_offset,
                                          uint32_t *sdc_offset);
 
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index 6170d07..424d39f 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -371,6 +371,13 @@ static bool brw_try_draw_prims( struct gl_context *ctx,
    if (ctx->NewState)
       _mesa_update_state( ctx );
 
+   /* Find the highest sampler unit used by each shader program.  A bit-count
+    * won't work since ARB programs use the texture unit number as the sampler
+    * index.
+    */
+   brw->wm.sampler_count = _mesa_fls(ctx->FragmentProgram._Current->Base.SamplersUsed);
+   brw->vs.sampler_count = _mesa_fls(ctx->VertexProgram._Current->Base.SamplersUsed);
+
    /* We have to validate the textures *before* checking for fallbacks;
     * otherwise, the software fallback won't be able to rely on the
     * texture state, the firstLevel and lastLevel fields won't be
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 a03953f..f2117a4 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
@@ -369,7 +369,7 @@ static void brw_update_sampler_state(struct brw_context *brw,
 static void
 brw_upload_sampler_state_table(struct brw_context *brw,
                                struct gl_program *prog,
-                               uint32_t *sampler_count,
+                               uint32_t sampler_count,
                                uint32_t *sst_offset,
                                uint32_t *sdc_offset)
 {
@@ -378,20 +378,15 @@ brw_upload_sampler_state_table(struct brw_context *brw,
 
    GLbitfield SamplersUsed = prog->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.
-    */
-   *sampler_count = _mesa_fls(SamplersUsed);
-
-   if (*sampler_count == 0)
+   if (sampler_count == 0)
       return;
 
    samplers = brw_state_batch(brw, AUB_TRACE_SAMPLER_STATE,
-			      *sampler_count * sizeof(*samplers),
+			      sampler_count * sizeof(*samplers),
 			      32, sst_offset);
-   memset(samplers, 0, *sampler_count * sizeof(*samplers));
+   memset(samplers, 0, sampler_count * sizeof(*samplers));
 
-   for (unsigned s = 0; s < *sampler_count; s++) {
+   for (unsigned s = 0; s < sampler_count; s++) {
       if (SamplersUsed & (1 << s)) {
          const unsigned unit = prog->SamplerUnits[s];
          if (ctx->Texture.Unit[unit]._ReallyEnabled)
@@ -409,7 +404,7 @@ brw_upload_fs_samplers(struct brw_context *brw)
    /* BRW_NEW_FRAGMENT_PROGRAM */
    struct gl_program *fs = (struct gl_program *) brw->fragment_program;
    brw->vtbl.upload_sampler_state_table(brw, fs,
-                                        &brw->wm.sampler_count,
+                                        brw->wm.sampler_count,
                                         &brw->wm.sampler_offset,
                                         brw->wm.sdc_offset);
 }
@@ -430,7 +425,7 @@ brw_upload_vs_samplers(struct brw_context *brw)
    /* BRW_NEW_VERTEX_PROGRAM */
    struct gl_program *vs = (struct gl_program *) brw->vertex_program;
    brw->vtbl.upload_sampler_state_table(brw, vs,
-                                        &brw->vs.sampler_count,
+                                        brw->vs.sampler_count,
                                         &brw->vs.sampler_offset,
                                         brw->vs.sdc_offset);
 }
diff --git a/src/mesa/drivers/dri/i965/gen7_sampler_state.c b/src/mesa/drivers/dri/i965/gen7_sampler_state.c
index 5701f4d..193b5b1 100644
--- a/src/mesa/drivers/dri/i965/gen7_sampler_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_sampler_state.c
@@ -187,7 +187,7 @@ gen7_update_sampler_state(struct brw_context *brw, int unit, int ss_index,
 static void
 gen7_upload_sampler_state_table(struct brw_context *brw,
                                 struct gl_program *prog,
-                                uint32_t *sampler_count,
+                                uint32_t sampler_count,
                                 uint32_t *sst_offset,
                                 uint32_t *sdc_offset)
 {
@@ -196,17 +196,15 @@ gen7_upload_sampler_state_table(struct brw_context *brw,
 
    GLbitfield SamplersUsed = prog->SamplersUsed;
 
-   *sampler_count = _mesa_fls(SamplersUsed);
-
-   if (*sampler_count == 0)
+   if (sampler_count == 0)
       return;
 
    samplers = brw_state_batch(brw, AUB_TRACE_SAMPLER_STATE,
-			      *sampler_count * sizeof(*samplers),
+			      sampler_count * sizeof(*samplers),
 			      32, sst_offset);
-   memset(samplers, 0, *sampler_count * sizeof(*samplers));
+   memset(samplers, 0, sampler_count * sizeof(*samplers));
 
-   for (unsigned s = 0; s < *sampler_count; s++) {
+   for (unsigned s = 0; s < sampler_count; s++) {
       if (SamplersUsed & (1 << s)) {
          const unsigned unit = prog->SamplerUnits[s];
          if (ctx->Texture.Unit[unit]._ReallyEnabled)
-- 
1.8.3.4



More information about the mesa-dev mailing list