radeon / r200: Pass the API into _mesa_initialize_context
[mesa.git] / src / glsl / ast_array_index.cpp
index 75f3755d9bfff15811c54b2c85b8ef0c472dfc7f..f3b060ea6577782520674c7e26e5656787ca55df 100644 (file)
 #include "glsl_types.h"
 #include "ir.h"
 
+void
+ast_array_specifier::print(void) const
+{
+   if (this->is_unsized_array) {
+      printf("[ ] ");
+   }
+
+   foreach_list_typed (ast_node, array_dimension, link, &this->array_dimensions) {
+      printf("[ ");
+      array_dimension->print();
+      printf("] ");
+   }
+}
 
 /**
  * If \c ir is a reference to an array for which we are tracking the max array
@@ -41,14 +54,51 @@ update_max_array_access(ir_rvalue *ir, unsigned idx, YYLTYPE *loc,
 {
    if (ir_dereference_variable *deref_var = ir->as_dereference_variable()) {
       ir_variable *var = deref_var->var;
-      if (idx > var->max_array_access) {
-         var->max_array_access = idx;
+      if (idx > var->data.max_array_access) {
+         var->data.max_array_access = 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(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) {
+         if (deref_var->var->is_interface_instance()) {
+            const glsl_type *interface_type =
+               deref_var->var->get_interface_type();
+            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);
+            }
+         }
+      }
    }
 }
 
@@ -106,7 +156,7 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
            bound = array->type->vector_elements;
         }
       } else {
-        /* glsl_type::array_size() returns 0 for non-array types.  This means
+        /* glsl_type::array_size() returns -1 for non-array types.  This means
          * that we don't need to verify that the type is an array before
          * doing the bounds checking.
          */
@@ -128,10 +178,10 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
       if (array->type->is_array())
          update_max_array_access(array, idx, &loc, state);
    } else if (const_index == NULL && array->type->is_array()) {
-      if (array->type->array_size() == 0) {
+      if (array->type->is_unsized_array()) {
         _mesa_glsl_error(&loc, state, "unsized array index must be constant");
       } else if (array->type->fields.array->is_interface()
-                 && array->variable_referenced()->mode == ir_var_uniform) {
+                 && array->variable_referenced()->data.mode == ir_var_uniform) {
         /* Page 46 in section 4.3.7 of the OpenGL ES 3.00 spec says:
          *
          *     "All indexes used to index a uniform block array must be
@@ -147,7 +197,7 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
          */
         ir_variable *v = array->whole_variable_referenced();
         if (v != NULL)
-           v->max_array_access = array->type->array_size() - 1;
+           v->data.max_array_access = array->type->array_size() - 1;
       }
 
       /* From page 23 (29 of the PDF) of the GLSL 1.30 spec: