[Mesa-dev] [PATCH 07/10] i965/vec4: Support arbitrarily large sampler state indices on Haswell+.

Kenneth Graunke kenneth at whitecape.org
Sat Jan 18 20:20:09 PST 2014


Like the scalar backend, we add an offset to the "Sampler State Pointer"
field to select a group of 16 samplers, then use the "Sampler Index"
field to select within that group.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_vec4_generator.cpp | 19 ++++++++++++++++++-
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp   | 10 ++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
index d40c8d4..99f83a4 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
@@ -387,6 +387,23 @@ vec4_generator::generate_tex(vec4_instruction *inst,
             brw_MOV(p, get_element_ud(header, 2),
                     brw_imm_ud(inst->texture_offset));
          }
+
+         if (inst->sampler >= 16) {
+            /* The "Sampler Index" field can only store values between 0 and 15.
+             * However, we can add an offset to the "Sampler State Pointer"
+             * field, effectively selecting a different set of 16 samplers.
+             *
+             * The "Sampler State Pointer" needs to be aligned to a 32-byte
+             * offset, and each sampler state is only 16-bytes, so we can't
+             * exclusively use the offset - we have to use both.
+             */
+            assert(brw->is_haswell); /* field only exists on Haswell */
+            brw_ADD(p,
+                    get_element_ud(header, 3),
+                    get_element_ud(brw_vec8_grf(0, 0), 3),
+                    brw_imm_ud(16 * (inst->sampler / 16) *
+                               sizeof(gen7_sampler_state)));
+         }
          brw_pop_insn_state(p);
       }
    }
@@ -415,7 +432,7 @@ vec4_generator::generate_tex(vec4_instruction *inst,
 	      inst->base_mrf,
 	      src,
               surface_index,
-	      inst->sampler,
+	      inst->sampler % 16,
 	      msg_type,
 	      1, /* response length */
 	      inst->mlen,
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index 2b6f3e9..f7e45e7 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -2370,9 +2370,15 @@ vec4_visitor::visit(ir_texture *ir)
    if (ir->op == ir_tg4)
       inst->texture_offset |= gather_channel(ir, sampler)<<16;
 
-   /* Texel offsets go in the message header; Gen4 also requires headers. */
+   /* The message header is necessary for:
+    * - Gen4 (always)
+    * - Texel offsets
+    * - Gather channel selection
+    * - Sampler indices too large to fit in a 4-bit value.
+    */
    inst->header_present =
-      brw->gen < 5 || inst->texture_offset != 0 || ir->op == ir_tg4;
+      brw->gen < 5 || inst->texture_offset != 0 || ir->op == ir_tg4 ||
+      sampler >= 16;
    inst->base_mrf = 2;
    inst->mlen = inst->header_present + 1; /* always at least one */
    inst->sampler = sampler;
-- 
1.8.5.2



More information about the mesa-dev mailing list