[Mesa-dev] [PATCH 07/10] glsl: Update ir_variable::max_ifc_array_access properly.

Paul Berry stereotype441 at gmail.com
Fri Sep 27 12:05:33 PDT 2013


This patch adds an implementation of
ir_dereference_record::update_max_array_access(), which ensures that
ir_variable::max_ifc_array_access is properly updated to reflect the
shader's use of arrays appearing within interface blocks.
---
 src/glsl/ir.cpp | 36 ++++++++++++++++++++++++++++++++++++
 src/glsl/ir.h   |  2 ++
 2 files changed, 38 insertions(+)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 96d4c05..134b100 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1367,6 +1367,42 @@ ir_dereference_record::ir_dereference_record(ir_variable *var,
    this->type = this->record->type->field_type(field);
 }
 
+
+void
+ir_dereference_record::update_max_array_access(unsigned idx, YYLTYPE *loc,
+                                               struct _mesa_glsl_parse_state *state)
+{
+   /* There are two possibilities we need to consider:
+    *
+    * - Accessing an element of an array that is a member of a named interface
+    *   block (e.g. ifc.foo[i])
+    *
+    * - Accessing an element of an array that is a member of a named interface
+    *   block array (e.g. ifc[j].foo[i]).
+    */
+   ir_dereference_variable *deref_var = this->record->as_dereference_variable();
+   if (deref_var == NULL) {
+      if (ir_dereference_array *deref_array =
+          this->record->as_dereference_array()) {
+         deref_var = deref_array->array->as_dereference_variable();
+      }
+   }
+
+   if (deref_var != NULL) {
+      unsigned field_index = this->record->type->field_index(this->field);
+      assert(field_index < deref_var->var->get_interface_type()->length);
+      if (idx > deref_var->var->max_ifc_array_access[field_index]) {
+         deref_var->var->max_ifc_array_access[field_index] = idx;
+
+         /* Check whether this access will, as a side effect, implicitly cause
+          * the size of a built-in array to be too large.
+          */
+         check_builtin_array_max_size(this->field, idx+1, *loc, state);
+      }
+   }
+}
+
+
 bool
 ir_dereference::is_lvalue() const
 {
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 63b7f5d..4f63562 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1952,6 +1952,8 @@ public:
    }
 
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+   virtual void update_max_array_access(unsigned idx, YYLTYPE *loc,
+                                        struct _mesa_glsl_parse_state *state);
 
    ir_rvalue *record;
    const char *field;
-- 
1.8.4



More information about the mesa-dev mailing list