[Mesa-dev] [PATCH 09/23] i965: Make brw_upload_sampler_state_table handle Gen7+ as well.

Kenneth Graunke kenneth at whitecape.org
Tue Jul 29 16:29:14 PDT 2014


This copies a few changes from gen7_upload_sampler_state_table; the next
patch will delete that function.

Gen7+ has per-stage sampler state pointer update packets, so we emit
them as soon as we emit a new table for a stage.  On Gen6 and earlier,
we have a single packet, so we delay until we've changed everything
that's going to be changed.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_sampler_state.c  | 39 +++++++++++++++++++++++---
 src/mesa/drivers/dri/i965/brw_state.h          |  3 ++
 src/mesa/drivers/dri/i965/gen7_sampler_state.c |  2 +-
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_sampler_state.c b/src/mesa/drivers/dri/i965/brw_sampler_state.c
index a14b5b3..dc351bd 100644
--- a/src/mesa/drivers/dri/i965/brw_sampler_state.c
+++ b/src/mesa/drivers/dri/i965/brw_sampler_state.c
@@ -39,6 +39,7 @@
 #include "brw_context.h"
 #include "brw_state.h"
 #include "brw_defines.h"
+#include "intel_batchbuffer.h"
 #include "intel_mipmap_tree.h"
 
 #include "main/macros.h"
@@ -402,9 +403,16 @@ brw_upload_sampler_state_table(struct brw_context *brw,
       if (SamplersUsed & (1 << s)) {
          const unsigned unit = prog->SamplerUnits[s];
          if (ctx->Texture.Unit[unit]._Current) {
-            brw_update_sampler_state(brw, unit,
-                                     (struct brw_sampler_state *) sampler_state,
-                                     batch_offset_for_sampler_state);
+            if (brw->gen >= 7) {
+               gen7_update_sampler_state(brw, unit,
+                                         (struct gen7_sampler_state *)
+                                         sampler_state);
+            } else {
+               brw_update_sampler_state(brw, unit,
+                                        (struct brw_sampler_state *)
+                                        sampler_state,
+                                        batch_offset_for_sampler_state);
+            }
          }
       }
 
@@ -412,7 +420,30 @@ brw_upload_sampler_state_table(struct brw_context *brw,
       batch_offset_for_sampler_state += size_in_bytes;
    }
 
-   brw->state.dirty.cache |= CACHE_NEW_SAMPLER;
+   if (brw->gen >= 7) {
+      /* Emit a 3DSTATE_SAMPLER_STATE_POINTERS_XS packet. */
+      static const uint16_t packet_headers[] = {
+         [MESA_SHADER_VERTEX] = _3DSTATE_SAMPLER_STATE_POINTERS_VS,
+         [MESA_SHADER_GEOMETRY] = _3DSTATE_SAMPLER_STATE_POINTERS_GS,
+         [MESA_SHADER_FRAGMENT] = _3DSTATE_SAMPLER_STATE_POINTERS_PS,
+      };
+
+      /* Ivybridge requires a workaround flush before VS packets. */
+      if (brw->gen == 7 && !brw->is_haswell && !brw->is_baytrail &&
+          stage_state->stage == MESA_SHADER_VERTEX) {
+         gen7_emit_vs_workaround_flush(brw);
+      }
+
+      BEGIN_BATCH(2);
+      OUT_BATCH(packet_headers[stage_state->stage] << 16 | (2 - 2));
+      OUT_BATCH(stage_state->sampler_offset);
+      ADVANCE_BATCH();
+   } else {
+      /* Flag that the sampler state table pointer has changed; later atoms
+       * will handle it.
+       */
+      brw->state.dirty.cache |= CACHE_NEW_SAMPLER;
+   }
 }
 
 static void
diff --git a/src/mesa/drivers/dri/i965/brw_state.h b/src/mesa/drivers/dri/i965/brw_state.h
index 77de785..64652cb 100644
--- a/src/mesa/drivers/dri/i965/brw_state.h
+++ b/src/mesa/drivers/dri/i965/brw_state.h
@@ -252,6 +252,9 @@ void upload_default_color(struct brw_context *brw,
 void gen4_init_vtable_sampler_functions(struct brw_context *brw);
 
 /* gen7_sampler_state.c */
+void gen7_update_sampler_state(struct brw_context *brw,
+                               int unit,
+                               struct gen7_sampler_state *sampler_state);
 void gen7_init_vtable_sampler_functions(struct brw_context *brw);
 
 /* gen6_sf_state.c */
diff --git a/src/mesa/drivers/dri/i965/gen7_sampler_state.c b/src/mesa/drivers/dri/i965/gen7_sampler_state.c
index b6d45cc..66af26a 100644
--- a/src/mesa/drivers/dri/i965/gen7_sampler_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_sampler_state.c
@@ -33,7 +33,7 @@
 /**
  * Sets the sampler state for a single unit.
  */
-static void
+void
 gen7_update_sampler_state(struct brw_context *brw, int unit,
 			  struct gen7_sampler_state *sampler)
 {
-- 
2.0.2



More information about the mesa-dev mailing list