i965: Make sampler counts available for the entire drawing operation.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 9 Jul 2013 22:09:05 +0000 (15:09 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 19 Aug 2013 20:17:00 +0000 (13:17 -0700)
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@whitecape.org>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_draw.c
src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
src/mesa/drivers/dri/i965/gen7_sampler_state.c

index fbe00b12fb809b052620e641215eabe391ef7bac..d7de0bf79b2bb1c7bad68252697313ab4f871398 100644 (file)
@@ -818,7 +818,7 @@ struct brw_context
       /** Upload a SAMPLER_STATE table. */
       void (*upload_sampler_state_table)(struct brw_context *brw,
                                          struct gl_program *prog,
       /** 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);
 
                                          uint32_t *sst_offset,
                                          uint32_t *sdc_offset);
 
index 6170d0728e197581782010c63b31e0ed8ca01e18..424d39fb8c2cd77d811a98a69ba4a7816ca3454a 100644 (file)
@@ -371,6 +371,13 @@ static bool brw_try_draw_prims( struct gl_context *ctx,
    if (ctx->NewState)
       _mesa_update_state( 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
    /* 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
index a03953f17cdf5ea36548c56ff201d8f0b73cd729..f2117a48e1a3ec71bca4be56ca5b6203d74ce744 100644 (file)
@@ -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,
 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)
 {
                                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;
 
 
    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,
       return;
 
    samplers = brw_state_batch(brw, AUB_TRACE_SAMPLER_STATE,
-                             *sampler_count * sizeof(*samplers),
+                             sampler_count * sizeof(*samplers),
                              32, sst_offset);
                              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)
       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_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);
 }
                                         &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_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);
 }
                                         &brw->vs.sampler_offset,
                                         brw->vs.sdc_offset);
 }
index 5701f4d8f04508392c2df4dd5382ad0abc716e43..193b5b12752d9a7731befd574696746b5b6516fa 100644 (file)
@@ -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,
 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)
 {
                                 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;
 
 
    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,
       return;
 
    samplers = brw_state_batch(brw, AUB_TRACE_SAMPLER_STATE,
-                             *sampler_count * sizeof(*samplers),
+                             sampler_count * sizeof(*samplers),
                              32, sst_offset);
                              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)
       if (SamplersUsed & (1 << s)) {
          const unsigned unit = prog->SamplerUnits[s];
          if (ctx->Texture.Unit[unit]._ReallyEnabled)