[Mesa-dev] [PATCH 2/4] mesa/glsl: new compiler option UnrollSamplerArrayDynamicIndexing

Tapani Pälli tapani.palli at intel.com
Tue Jun 9 05:00:58 PDT 2015


Patch provides new compiler option for backend to force unroll loops
that have non-constant expression indexing on sampler arrays.

This makes sure that we can never end up with a shader that uses loop
induction variable as sampler array index but does not unroll because
of having too much instructions. This would not work without dynamic
indexing support.

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
 src/glsl/loop_unroll.cpp | 10 ++++++++++
 src/mesa/main/mtypes.h   |  6 ++++++
 2 files changed, 16 insertions(+)

diff --git a/src/glsl/loop_unroll.cpp b/src/glsl/loop_unroll.cpp
index 635e1dd..b9de51d 100644
--- a/src/glsl/loop_unroll.cpp
+++ b/src/glsl/loop_unroll.cpp
@@ -100,6 +100,16 @@ public:
 
    virtual ir_visitor_status visit_enter(ir_dereference_array *ir)
    {
+      /* Force unroll in case of dynamic indexing with sampler arrays. */
+      if (options->UnrollSamplerArrayDynamicIndexing) {
+         if ((ir->array->type->is_array() &&
+              ir->array->type->contains_sampler()) &&
+             !ir->array_index->constant_expression_value()) {
+            unsupported_variable_indexing = true;
+            return visit_continue;
+         }
+      }
+
       /* Check for arrays variably-indexed by a loop induction variable.
        * Unrolling the loop may convert that access into constant-indexing.
        *
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 1598e2c..61d1dfb 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2896,6 +2896,12 @@ struct gl_shader_compiler_options
     */
    GLboolean OptimizeForAOS;
 
+   /**
+    * Unroll any loops with dynamic indexing to sampler array. This can be used
+    * to force loop unroll from the backend for GLSL <= 1.20 and GLSL ES 1.00.
+    */
+   GLboolean UnrollSamplerArrayDynamicIndexing;
+
    const struct nir_shader_compiler_options *NirOptions;
 };
 
-- 
2.1.0



More information about the mesa-dev mailing list