[Mesa-dev] [PATCH 118/133] nir: Add a sampler index indirect to nir_tex_instr

Jason Ekstrand jason at jlekstrand.net
Mon Dec 15 22:13:01 PST 2014


---
 src/glsl/nir/nir.c          | 11 +++++++++++
 src/glsl/nir/nir.h          | 10 ++++++++++
 src/glsl/nir/nir_print.c    |  4 ++++
 src/glsl/nir/nir_validate.c |  3 +++
 4 files changed, 28 insertions(+)

diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 60c9cff..8bcc64a 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -461,6 +461,13 @@ nir_tex_instr_create(void *mem_ctx, unsigned num_srcs)
    instr->has_predicate = false;
    src_init(&instr->predicate);
 
+   instr->sampler_index = 0;
+   instr->has_sampler_indirect = false;
+   src_init(&instr->sampler_indirect);
+   instr->sampler_indirect_max = 0;
+
+   instr->sampler = NULL;
+
    return instr;
 }
 
@@ -1529,6 +1536,10 @@ visit_tex_src(nir_tex_instr *instr, nir_foreach_src_cb cb, void *state)
       if (!visit_src(&instr->predicate, cb, state))
          return false;
 
+   if (instr->has_sampler_indirect)
+      if (!visit_src(&instr->sampler_indirect, cb, state))
+         return false;
+
    if (instr->sampler != NULL)
       if (!visit_deref_src(instr->sampler, cb, state))
          return false;
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 32bf634..bc7a226 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -838,7 +838,17 @@ typedef struct {
    /* gather component selector */
    unsigned component : 2;
 
+   /** The sampler index
+    *
+    * If has_indirect is true, then the sampler index is given by
+    * sampler_index + sampler_indirect where sampler_indirect has a maximum
+    * possible value of sampler_indirect_max.
+    */
    unsigned sampler_index;
+   bool has_sampler_indirect;
+   nir_src sampler_indirect;
+   unsigned sampler_indirect_max;
+
    nir_deref_var *sampler; /* if this is NULL, use sampler_index instead */
 } nir_tex_instr;
 
diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
index 962e408..67df9a5 100644
--- a/src/glsl/nir/nir_print.c
+++ b/src/glsl/nir/nir_print.c
@@ -498,6 +498,10 @@ print_tex_instr(nir_tex_instr *instr, print_var_state *state, FILE *fp)
       print_deref(instr->sampler, state, fp);
    } else {
       fprintf(fp, "%u", instr->sampler_index);
+      if (instr->has_sampler_indirect) {
+         fprintf(fp, " + ");
+         print_src(&instr->sampler_indirect, fp);
+      }
    }
 
    fprintf(fp, " (sampler)");
diff --git a/src/glsl/nir/nir_validate.c b/src/glsl/nir/nir_validate.c
index e565b3c..ed6e482 100644
--- a/src/glsl/nir/nir_validate.c
+++ b/src/glsl/nir/nir_validate.c
@@ -399,6 +399,9 @@ validate_tex_instr(nir_tex_instr *instr, validate_state *state)
       validate_src(&instr->src[i], state);
    }
 
+   if (instr->has_sampler_indirect)
+      validate_src(&instr->sampler_indirect, state);
+
    if (instr->sampler != NULL)
       validate_deref_var(instr->sampler, state);
 }
-- 
2.2.0



More information about the mesa-dev mailing list