glsl: Update ir_variable::max_ifc_array_access properly.
authorPaul Berry <stereotype441@gmail.com>
Thu, 19 Sep 2013 16:36:41 +0000 (09:36 -0700)
committerPaul Berry <stereotype441@gmail.com>
Wed, 9 Oct 2013 23:49:38 +0000 (16:49 -0700)
This patch modifies update_max_array_access() so that it updates
ir_variable::max_ifc_array_access to reflect the shader's use of
arrays appearing within interface blocks.

v2: Use an ordinary function in ast_array_index.cpp rather than a
virtual function in ir_rvalue.  Avoid dereferencing NULL when handling
accesses to ordinary structs.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
src/glsl/ast_array_index.cpp

index 75f3755d9bfff15811c54b2c85b8ef0c472dfc7f..da96cc10ea991c8b3ff0aec700cf1b80e18ad35f 100644 (file)
@@ -49,6 +49,43 @@ update_max_array_access(ir_rvalue *ir, unsigned idx, YYLTYPE *loc,
           */
          check_builtin_array_max_size(var->name, idx+1, *loc, state);
       }
+   } else if (ir_dereference_record *deref_record =
+              ir->as_dereference_record()) {
+      /* 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 =
+         deref_record->record->as_dereference_variable();
+      if (deref_var == NULL) {
+         if (ir_dereference_array *deref_array =
+             deref_record->record->as_dereference_array()) {
+            deref_var = deref_array->array->as_dereference_variable();
+         }
+      }
+
+      if (deref_var != NULL) {
+         const glsl_type *interface_type =
+            deref_var->var->get_interface_type();
+         if (interface_type != NULL) {
+            unsigned field_index =
+               deref_record->record->type->field_index(deref_record->field);
+            assert(field_index < 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(deref_record->field, idx+1, *loc,
+                                            state);
+            }
+         }
+      }
    }
 }