<div dir="ltr">On 27 September 2013 12:05, Paul Berry <span dir="ltr"><<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This patch adds an implementation of<br>
ir_dereference_record::update_max_array_access(), which ensures that<br>
ir_variable::max_ifc_array_access is properly updated to reflect the<br>
shader's use of arrays appearing within interface blocks.<br>
---<br>
 src/glsl/ir.cpp | 36 ++++++++++++++++++++++++++++++++++++<br>
 src/glsl/ir.h   |  2 ++<br>
 2 files changed, 38 insertions(+)<br>
<br>
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp<br>
index 96d4c05..134b100 100644<br>
--- a/src/glsl/ir.cpp<br>
+++ b/src/glsl/ir.cpp<br>
@@ -1367,6 +1367,42 @@ ir_dereference_record::ir_dereference_record(ir_variable *var,<br>
    this->type = this->record->type->field_type(field);<br>
 }<br>
<br>
+<br>
+void<br>
+ir_dereference_record::update_max_array_access(unsigned idx, YYLTYPE *loc,<br>
+                                               struct _mesa_glsl_parse_state *state)<br>
+{<br>
+   /* There are two possibilities we need to consider:<br>
+    *<br>
+    * - Accessing an element of an array that is a member of a named interface<br>
+    *   block (e.g. ifc.foo[i])<br>
+    *<br>
+    * - Accessing an element of an array that is a member of a named interface<br>
+    *   block array (e.g. ifc[j].foo[i]).<br>
+    */<br>
+   ir_dereference_variable *deref_var = this->record->as_dereference_variable();<br>
+   if (deref_var == NULL) {<br>
+      if (ir_dereference_array *deref_array =<br>
+          this->record->as_dereference_array()) {<br>
+         deref_var = deref_array->array->as_dereference_variable();<br>
+      }<br>
+   }<br>
+<br>
+   if (deref_var != NULL) {<br></blockquote><div><br>Oops, I just noticed that this will crash if it encounters GLSL of the 
form foo.bar[i] or foo[i].bar[j] where foo is an ordinary struct (or 
array of structs) rather than an interface block.  This is easy to fix--just bail out if deref_var->var->get_interface_type() returns NULL.<br><br>I'll fix this as soon as Jordan and I have resolved our discussion on "[PATCH 00/10] glsl: Support unsized arrays in interface blocks."<br>
 <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+      unsigned field_index = this->record->type->field_index(this->field);<br>
+      assert(field_index < deref_var->var->get_interface_type()->length);</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">


+      if (idx > deref_var->var->max_ifc_array_access[field_index]) {<br>
+         deref_var->var->max_ifc_array_access[field_index] = idx;<br>
+<br>
+         /* Check whether this access will, as a side effect, implicitly cause<br>
+          * the size of a built-in array to be too large.<br>
+          */<br>
+         check_builtin_array_max_size(this->field, idx+1, *loc, state);<br>
+      }<br>
+   }<br>
+}<br>
+<br>
+<br>
 bool<br>
 ir_dereference::is_lvalue() const<br>
 {<br>
diff --git a/src/glsl/ir.h b/src/glsl/ir.h<br>
index 63b7f5d..4f63562 100644<br>
--- a/src/glsl/ir.h<br>
+++ b/src/glsl/ir.h<br>
@@ -1952,6 +1952,8 @@ public:<br>
    }<br>
<br>
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);<br>
+   virtual void update_max_array_access(unsigned idx, YYLTYPE *loc,<br>
+                                        struct _mesa_glsl_parse_state *state);<br>
<br>
    ir_rvalue *record;<br>
    const char *field;<br>
<span><font color="#888888">--<br>
1.8.4<br>
<br>
</font></span></blockquote></div><br></div></div>