[Mesa-dev] [RFC 5/6] nir: Replace tex_instr.array_size with max_sampler_index

Jason Ekstrand jason at jlekstrand.net
Sat Feb 6 05:10:54 UTC 2016


---
 src/compiler/nir/nir.c                     | 2 +-
 src/compiler/nir/nir.h                     | 4 ++--
 src/compiler/nir/nir_clone.c               | 2 +-
 src/compiler/nir/nir_instr_set.c           | 4 ++--
 src/compiler/nir/nir_lower_samplers.c      | 4 ++--
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp   | 2 +-
 src/mesa/drivers/dri/i965/brw_vec4_nir.cpp | 3 +--
 7 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 2247a98..805c72d 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -487,7 +487,7 @@ nir_tex_instr_create(nir_shader *shader, unsigned num_srcs)
       src_init(&instr->src[i].src);
 
    instr->sampler_index = 0;
-   instr->sampler_array_size = 0;
+   instr->max_sampler_index = 0;
    instr->sampler = NULL;
 
    return instr;
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 3b85bf5..b077f5a 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -980,8 +980,8 @@ typedef struct {
     */
    unsigned sampler_index;
 
-   /** The size of the sampler array or 0 if it's not an array */
-   unsigned sampler_array_size;
+   /** The maximum total sampler index including base and indirect*/
+   unsigned max_sampler_index;
 
    nir_deref_var *sampler; /* if this is NULL, use sampler_index instead */
 } nir_tex_instr;
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c
index 5eff743..fc2e2d1 100644
--- a/src/compiler/nir/nir_clone.c
+++ b/src/compiler/nir/nir_clone.c
@@ -358,7 +358,7 @@ clone_tex(clone_state *state, const nir_tex_instr *tex)
    memcpy(ntex->const_offset, tex->const_offset, sizeof(ntex->const_offset));
    ntex->component = tex->component;
    ntex->sampler_index = tex->sampler_index;
-   ntex->sampler_array_size = tex->sampler_array_size;
+   ntex->max_sampler_index = tex->max_sampler_index;
    if (tex->sampler)
       ntex->sampler = clone_deref_var(state, tex->sampler, &ntex->instr);
 
diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c
index d3f939f..32c7318 100644
--- a/src/compiler/nir/nir_instr_set.c
+++ b/src/compiler/nir/nir_instr_set.c
@@ -156,7 +156,7 @@ hash_tex(uint32_t hash, const nir_tex_instr *instr)
    unsigned component = instr->component;
    hash = HASH(hash, component);
    hash = HASH(hash, instr->sampler_index);
-   hash = HASH(hash, instr->sampler_array_size);
+   hash = HASH(hash, instr->max_sampler_index);
 
    assert(!instr->sampler);
 
@@ -306,7 +306,7 @@ nir_instrs_equal(const nir_instr *instr1, const nir_instr *instr2)
                  sizeof(tex1->const_offset)) != 0 ||
           tex1->component != tex2->component ||
          tex1->sampler_index != tex2->sampler_index ||
-         tex1->sampler_array_size != tex2->sampler_array_size) {
+         tex1->max_sampler_index != tex2->max_sampler_index) {
          return false;
       }
 
diff --git a/src/compiler/nir/nir_lower_samplers.c b/src/compiler/nir/nir_lower_samplers.c
index 96e8291..c889df0 100644
--- a/src/compiler/nir/nir_lower_samplers.c
+++ b/src/compiler/nir/nir_lower_samplers.c
@@ -125,8 +125,6 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
       nir_instr_rewrite_src(&instr->instr,
                             &instr->src[instr->num_srcs - 1].src,
                             nir_src_for_ssa(indirect));
-
-      instr->sampler_array_size = array_elements;
    }
 
    if (location > shader_program->NumUniformStorage - 1 ||
@@ -138,6 +136,8 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
    instr->sampler_index +=
       shader_program->UniformStorage[location].opaque[stage].index;
 
+   instr->max_sampler_index = instr->sampler_index + array_elements - 1;
+
    instr->sampler = NULL;
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
index 0efb2fa..159561a 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
@@ -3009,7 +3009,7 @@ fs_visitor::nir_emit_texture(const fs_builder &bld, nir_tex_instr *instr)
 
       case nir_tex_src_sampler_offset: {
          /* Figure out the highest possible sampler index and mark it as used */
-         uint32_t max_used = sampler + instr->sampler_array_size - 1;
+         uint32_t max_used = instr->max_sampler_index;
          if (instr->op == nir_texop_tg4 && devinfo->gen < 8) {
             max_used += stage_prog_data->binding_table.gather_texture_start;
          } else {
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
index d3ac7ab..747263e 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
@@ -1720,8 +1720,7 @@ vec4_visitor::nir_emit_texture(nir_tex_instr *instr)
           * the last element of the array. Mark it here, because the generator
           * doesn't have enough information to determine the bound.
           */
-         uint32_t array_size = instr->sampler_array_size;
-         uint32_t max_used = sampler + array_size - 1;
+         uint32_t max_used = instr->max_sampler_index;
          if (instr->op == nir_texop_tg4) {
             max_used += prog_data->base.binding_table.gather_texture_start;
          } else {
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list