i965: Make brw_upload_sampler_state_table handle Gen7+ as well.
authorKenneth Graunke <kenneth@whitecape.org>
Sat, 26 Jul 2014 18:36:33 +0000 (11:36 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Sat, 2 Aug 2014 12:14:42 +0000 (05:14 -0700)
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.

v2: Split 3DSTATE_SAMPLER_STATE_POINTERS_XS packet emission into a
    helper function (suggested by Topi Pohjolainen).

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
src/mesa/drivers/dri/i965/brw_sampler_state.c
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/gen7_sampler_state.c

index a14b5b38255a40dea4f4acffe00fd9afdf20cc70..7ccf14640f8a8b3928559a7272aed84eff54b159 100644 (file)
 #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"
 #include "main/samplerobj.h"
 
+/**
+ * Emit a 3DSTATE_SAMPLER_STATE_POINTERS_{VS,HS,GS,DS,PS} packet.
+ */
+static void
+gen7_emit_sampler_state_pointers_xs(struct brw_context *brw,
+                                    struct brw_stage_state *stage_state)
+{
+   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();
+}
+
 uint32_t
 translate_wrap_mode(struct brw_context *brw, GLenum wrap, bool using_nearest)
 {
@@ -402,9 +428,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 +445,15 @@ 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. */
+      gen7_emit_sampler_state_pointers_xs(brw, stage_state);
+   } else {
+      /* Flag that the sampler state table pointer has changed; later atoms
+       * will handle it.
+       */
+      brw->state.dirty.cache |= CACHE_NEW_SAMPLER;
+   }
 }
 
 static void
index 77de78518416eb070851fb03a224c4f9f1638f72..64652cbbeb6e9310bd812c6ac14a07c4ad9326f7 100644 (file)
@@ -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 */
index b6d45cc0d3f10c535746a72ce8237dfa3ad26566..66af26a63e44999dde6f847de9418a46812d09e3 100644 (file)
@@ -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)
 {