[Mesa-dev] [PATCH 12/19] nir: add support for sampler AoA with const index

Timothy Arceri t_arceri at yahoo.com.au
Sat Jun 20 05:33:09 PDT 2015


---
 src/glsl/nir/nir_lower_samplers.cpp | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/glsl/nir/nir_lower_samplers.cpp b/src/glsl/nir/nir_lower_samplers.cpp
index c450198..a79b093 100644
--- a/src/glsl/nir/nir_lower_samplers.cpp
+++ b/src/glsl/nir/nir_lower_samplers.cpp
@@ -60,9 +60,23 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
    if (instr->sampler == NULL)
       return;
 
+   /* Get number of array dimensions */
+   unsigned num_dimensions = 1;
+   for (nir_deref *deref = &instr->sampler->deref;
+        deref->child; deref = deref->child) {
+      if (deref->child->deref_type == nir_deref_type_array) {
+         nir_deref_array *deref_array = nir_deref_as_array(deref->child);
+         if (deref_array->deref.child &&
+            !deref->child->type->without_array()->is_record()) {
+            num_dimensions++;
+         }
+      }
+   }
+
    /* Get the name and the offset */
    instr->sampler_index = 0;
    char *name = ralloc_strdup(mem_ctx, instr->sampler->var->name);
+   unsigned curr_dim = num_dimensions;
 
    for (nir_deref *deref = &instr->sampler->deref;
         deref->child; deref = deref->child) {
@@ -78,8 +92,10 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
                deref_array->deref_array_type == nir_deref_array_type_direct ?
                   deref_array->base_offset : 0);
          } else {
-            assert(deref->child->type->base_type == GLSL_TYPE_SAMPLER);
-            instr->sampler_index = deref_array->base_offset;
+            /* calculate offset allowing for for arrays of arrays */
+            instr->sampler_index +=
+               pow(glsl_get_length(deref->type), --curr_dim) *
+                  deref_array->base_offset;
          }
 
          /* XXX: We're assuming here that the indirect is the last array
-- 
2.1.0



More information about the mesa-dev mailing list