glsl: remove stale FIXME
[mesa.git] / src / compiler / glsl / ast_function.cpp
index 0665e0c3938223c5d89ce3cbe7c016b0daa53a16..d097410d4bd5d255cecef8282de837d83d960f8e 100644 (file)
@@ -25,7 +25,7 @@
 #include "ast.h"
 #include "compiler/glsl_types.h"
 #include "ir.h"
-#include "main/core.h" /* for MIN2 */
+#include "main/mtypes.h"
 #include "main/shaderobj.h"
 #include "builtin_functions.h"
 
@@ -37,6 +37,7 @@ process_parameters(exec_list *instructions, exec_list *actual_parameters,
                    exec_list *parameters,
                    struct _mesa_glsl_parse_state *state)
 {
+   void *mem_ctx = state;
    unsigned count = 0;
 
    foreach_list_typed(ast_node, ast, link, parameters) {
@@ -48,7 +49,16 @@ process_parameters(exec_list *instructions, exec_list *actual_parameters,
       ast->set_is_lhs(true);
       ir_rvalue *result = ast->hir(instructions, state);
 
-      ir_constant *const constant = result->constant_expression_value();
+      /* Error happened processing function parameter */
+      if (!result) {
+         actual_parameters->push_tail(ir_rvalue::error_value(mem_ctx));
+         count++;
+         continue;
+      }
+
+      ir_constant *const constant =
+         result->constant_expression_value(mem_ctx);
+
       if (constant != NULL)
          result = constant;
 
@@ -107,35 +117,35 @@ verify_image_parameter(YYLTYPE *loc, _mesa_glsl_parse_state *state,
     *  qualifiers. [...] It is legal to have additional qualifiers
     *  on a formal parameter, but not to have fewer."
     */
-   if (actual->data.image_coherent && !formal->data.image_coherent) {
+   if (actual->data.memory_coherent && !formal->data.memory_coherent) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`coherent' qualifier", formal->name);
       return false;
    }
 
-   if (actual->data.image_volatile && !formal->data.image_volatile) {
+   if (actual->data.memory_volatile && !formal->data.memory_volatile) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`volatile' qualifier", formal->name);
       return false;
    }
 
-   if (actual->data.image_restrict && !formal->data.image_restrict) {
+   if (actual->data.memory_restrict && !formal->data.memory_restrict) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`restrict' qualifier", formal->name);
       return false;
    }
 
-   if (actual->data.image_read_only && !formal->data.image_read_only) {
+   if (actual->data.memory_read_only && !formal->data.memory_read_only) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`readonly' qualifier", formal->name);
       return false;
    }
 
-   if (actual->data.image_write_only && !formal->data.image_write_only) {
+   if (actual->data.memory_write_only && !formal->data.memory_write_only) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`writeonly' qualifier", formal->name);
@@ -195,9 +205,6 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
       const ast_expression *const actual_ast =
          exec_node_data(ast_expression, actual_ast_node, link);
 
-      /* FIXME: 'loc' is incorrect (as of 2011-01-21). It is always
-       * FIXME: 0:0(0).
-       */
       YYLTYPE loc = actual_ast->get_location();
 
       /* Verify that 'const_in' parameters are ir_constants. */
@@ -224,17 +231,28 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
             val = ((ir_swizzle *)val)->val;
          }
 
-         while (val->ir_type == ir_type_dereference_array) {
-            val = ((ir_dereference_array *)val)->array;
+         for (;;) {
+            if (val->ir_type == ir_type_dereference_array) {
+               val = ((ir_dereference_array *)val)->array;
+            } else if (val->ir_type == ir_type_dereference_record &&
+                       !state->es_shader) {
+               val = ((ir_dereference_record *)val)->record;
+            } else
+               break;
          }
 
-         if (!val->as_dereference_variable() ||
-             val->variable_referenced()->data.mode != ir_var_shader_in) {
+         ir_variable *var = NULL;
+         if (const ir_dereference_variable *deref_var = val->as_dereference_variable())
+            var = deref_var->variable_referenced();
+
+         if (!var || var->data.mode != ir_var_shader_in) {
             _mesa_glsl_error(&loc, state,
                              "parameter `%s` must be a shader input",
                              formal->name);
             return false;
          }
+
+         var->data.must_be_shader_input = 1;
       }
 
       /* Verify that 'out' and 'inout' actual parameters are lvalues. */
@@ -281,7 +299,7 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
                              mode, formal->name,
                              actual->variable_referenced()->name);
             return false;
-         } else if (!actual->is_lvalue()) {
+         } else if (!actual->is_lvalue(state)) {
             _mesa_glsl_error(&loc, state,
                              "function parameter '%s %s' is not an lvalue",
                              mode, formal->name);
@@ -334,6 +352,47 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
    return true;
 }
 
+struct copy_index_deref_data {
+   void *mem_ctx;
+   exec_list *before_instructions;
+};
+
+static void
+copy_index_derefs_to_temps(ir_instruction *ir, void *data)
+{
+   struct copy_index_deref_data *d = (struct copy_index_deref_data *)data;
+
+   if (ir->ir_type == ir_type_dereference_array) {
+      ir_dereference_array *a = (ir_dereference_array *) ir;
+      ir = a->array->as_dereference();
+
+      ir_rvalue *idx = a->array_index;
+      ir_variable *var = idx->variable_referenced();
+
+      /* If the index is read only it cannot change so there is no need
+       * to copy it.
+       */
+      if (!var || var->data.read_only || var->data.memory_read_only)
+         return;
+
+      ir_variable *tmp = new(d->mem_ctx) ir_variable(idx->type, "idx_tmp",
+                                                      ir_var_temporary);
+      d->before_instructions->push_tail(tmp);
+
+      ir_dereference_variable *const deref_tmp_1 =
+         new(d->mem_ctx) ir_dereference_variable(tmp);
+      ir_assignment *const assignment =
+         new(d->mem_ctx) ir_assignment(deref_tmp_1,
+                                       idx->clone(d->mem_ctx, NULL));
+      d->before_instructions->push_tail(assignment);
+
+      /* Replace the array index with a dereference of the new temporary */
+      ir_dereference_variable *const deref_tmp_2 =
+         new(d->mem_ctx) ir_dereference_variable(tmp);
+      a->array_index = deref_tmp_2;
+   }
+}
+
 static void
 fix_parameter(void *mem_ctx, ir_rvalue *actual, const glsl_type *formal_type,
               exec_list *before_instructions, exec_list *after_instructions,
@@ -345,9 +404,21 @@ fix_parameter(void *mem_ctx, ir_rvalue *actual, const glsl_type *formal_type,
     * nothing needs to be done to fix the parameter.
     */
    if (formal_type == actual->type
-       && (expr == NULL || expr->operation != ir_binop_vector_extract))
+       && (expr == NULL || expr->operation != ir_binop_vector_extract)
+       && actual->as_dereference_variable())
       return;
 
+   /* An array index could also be an out variable so we need to make a copy
+    * of them before the function is called.
+    */
+   if (!actual->as_dereference_variable()) {
+      struct copy_index_deref_data data;
+      data.mem_ctx = mem_ctx;
+      data.before_instructions = before_instructions;
+
+      visit_tree(actual, copy_index_derefs_to_temps, &data);
+   }
+
    /* To convert an out parameter, we need to create a temporary variable to
     * hold the value before conversion, and then perform the conversion after
     * the function call returns.
@@ -388,7 +459,7 @@ fix_parameter(void *mem_ctx, ir_rvalue *actual, const glsl_type *formal_type,
       ir_dereference_variable *const deref_tmp_1 =
          new(mem_ctx) ir_dereference_variable(tmp);
       ir_assignment *const assignment =
-         new(mem_ctx) ir_assignment(deref_tmp_1, actual);
+         new(mem_ctx) ir_assignment(deref_tmp_1, actual->clone(mem_ctx, NULL));
       before_instructions->push_tail(assignment);
    }
 
@@ -431,8 +502,7 @@ generate_call(exec_list *instructions, ir_function_signature *sig,
               exec_list *actual_parameters,
               ir_variable *sub_var,
               ir_rvalue *array_idx,
-              struct _mesa_glsl_parse_state *state,
-              bool inline_immediately)
+              struct _mesa_glsl_parse_state *state)
 {
    void *ctx = state;
    exec_list post_call_conversions;
@@ -516,8 +586,10 @@ generate_call(exec_list *instructions, ir_function_signature *sig,
     * If the function call is a constant expression, don't generate any
     * instructions; just generate an ir_constant.
     */
-   if (state->is_version(120, 100)) {
-      ir_constant *value = sig->constant_expression_value(actual_parameters,
+   if (state->is_version(120, 100) ||
+       state->ctx->Const.AllowGLSLBuiltinConstantExpression) {
+      ir_constant *value = sig->constant_expression_value(ctx,
+                                                          actual_parameters,
                                                           NULL);
       if (value != NULL) {
          return value;
@@ -544,10 +616,6 @@ generate_call(exec_list *instructions, ir_function_signature *sig,
    ir_call *call = new(ctx) ir_call(sig, deref,
                                     actual_parameters, sub_var, array_idx);
    instructions->push_tail(call);
-   if (inline_immediately) {
-      call->generate_inline(call);
-      call->remove();
-   }
 
    /* Also emit any necessary out-parameter conversions. */
    instructions->append_list(&post_call_conversions);
@@ -595,9 +663,13 @@ match_function_by_name(const char *name,
    }
 
    /* Local shader has no exact candidates; check the built-ins. */
-   _mesa_glsl_initialize_builtin_functions();
    sig = _mesa_glsl_find_builtin_function(state, name, actual_parameters);
-   return sig;
+
+   /* if _mesa_glsl_find_builtin_function failed, fall back to the result
+    * of choose_best_inexact_overload() instead. This should only affect
+    * GLES.
+    */
+   return sig ? sig : local_sig;
 }
 
 static ir_function_signature *
@@ -661,14 +733,34 @@ generate_array_index(void *mem_ctx, exec_list *instructions,
       ir_variable *sub_var = NULL;
       *function_name = array->primary_expression.identifier;
 
-      match_subroutine_by_name(*function_name, actual_parameters,
-                               state, &sub_var);
+      if (!match_subroutine_by_name(*function_name, actual_parameters,
+                                    state, &sub_var)) {
+         _mesa_glsl_error(&loc, state, "Unknown subroutine `%s'",
+                          *function_name);
+         *function_name = NULL; /* indicate error condition to caller */
+         return NULL;
+      }
 
       ir_rvalue *outer_array_idx = idx->hir(instructions, state);
       return new(mem_ctx) ir_dereference_array(sub_var, outer_array_idx);
    }
 }
 
+static bool
+function_exists(_mesa_glsl_parse_state *state,
+                struct glsl_symbol_table *symbols, const char *name)
+{
+   ir_function *f = symbols->get_function(name);
+   if (f != NULL) {
+      foreach_in_list(ir_function_signature, sig, &f->signatures) {
+         if (sig->is_builtin() && !sig->is_builtin_available(state))
+            continue;
+         return true;
+      }
+   }
+   return false;
+}
+
 static void
 print_function_prototypes(_mesa_glsl_parse_state *state, YYLTYPE *loc,
                           ir_function *f)
@@ -699,9 +791,9 @@ no_matching_function_error(const char *name,
 {
    gl_shader *sh = _mesa_glsl_get_builtin_function_shader();
 
-   if (state->symbols->get_function(name) == NULL
+   if (!function_exists(state, state->symbols, name)
        && (!state->uses_builtin_functions
-           || sh->symbols->get_function(name) == NULL)) {
+           || !function_exists(state, sh->symbols, name))) {
       _mesa_glsl_error(loc, state, "no function with name '%s'", name);
    } else {
       char *str = prototype_string(NULL, name, actual_parameters);
@@ -738,8 +830,8 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
    if (src->type->is_error())
       return src;
 
-   assert(a <= GLSL_TYPE_BOOL);
-   assert(b <= GLSL_TYPE_BOOL);
+   assert(a <= GLSL_TYPE_IMAGE);
+   assert(b <= GLSL_TYPE_IMAGE);
 
    if (a == b)
       return src;
@@ -767,6 +859,12 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
       case GLSL_TYPE_INT64:
          result = new(ctx) ir_expression(ir_unop_i642u, src);
          break;
+      case GLSL_TYPE_SAMPLER:
+         result = new(ctx) ir_expression(ir_unop_unpack_sampler_2x32, src);
+         break;
+      case GLSL_TYPE_IMAGE:
+         result = new(ctx) ir_expression(ir_unop_unpack_image_2x32, src);
+         break;
       }
       break;
    case GLSL_TYPE_INT:
@@ -909,13 +1007,29 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
          break;
       }
       break;
+   case GLSL_TYPE_SAMPLER:
+      switch (b) {
+      case GLSL_TYPE_UINT:
+         result = new(ctx)
+            ir_expression(ir_unop_pack_sampler_2x32, desired_type, src);
+         break;
+      }
+      break;
+   case GLSL_TYPE_IMAGE:
+      switch (b) {
+      case GLSL_TYPE_UINT:
+         result = new(ctx)
+            ir_expression(ir_unop_pack_image_2x32, desired_type, src);
+         break;
+      }
+      break;
    }
 
    assert(result != NULL);
    assert(result->type == desired_type);
 
    /* Try constant folding; it may fold in the conversion we just added. */
-   ir_constant *const constant = result->constant_expression_value();
+   ir_constant *const constant = result->constant_expression_value(ctx);
    return (constant != NULL) ? (ir_rvalue *) constant : (ir_rvalue *) result;
 }
 
@@ -943,6 +1057,7 @@ static bool
 implicitly_convert_component(ir_rvalue * &from, const glsl_base_type to,
                              struct _mesa_glsl_parse_state *state)
 {
+   void *mem_ctx = state;
    ir_rvalue *result = from;
 
    if (to != from->type->base_type) {
@@ -961,7 +1076,7 @@ implicitly_convert_component(ir_rvalue * &from, const glsl_base_type to,
       }
    }
 
-   ir_rvalue *const constant = result->constant_expression_value();
+   ir_rvalue *const constant = result->constant_expression_value(mem_ctx);
 
    if (constant != NULL)
       result = constant;
@@ -1099,7 +1214,7 @@ process_vec_mat_constructor(exec_list *instructions,
       if (var->type->is_matrix()) {
          ir_rvalue *lhs =
             new(ctx) ir_dereference_array(var, new(ctx) ir_constant(i));
-         assignment = new(ctx) ir_assignment(lhs, rhs, NULL);
+         assignment = new(ctx) ir_assignment(lhs, rhs);
       } else {
          /* use writemask rather than index for vector */
          assert(var->type->is_vector());
@@ -1235,7 +1350,7 @@ process_array_constructor(exec_list *instructions,
       ir_rvalue *lhs = new(ctx) ir_dereference_array(var,
                                                      new(ctx) ir_constant(i));
 
-      ir_instruction *assignment = new(ctx) ir_assignment(lhs, rhs, NULL);
+      ir_instruction *assignment = new(ctx) ir_assignment(lhs, rhs);
       instructions->push_tail(assignment);
 
       i++;
@@ -1248,7 +1363,7 @@ process_array_constructor(exec_list *instructions,
 /**
  * Determine if a list consists of a single scalar r-value
  */
-bool
+static bool
 single_scalar_parameter(exec_list *parameters)
 {
    const ir_rvalue *const p = (ir_rvalue *) parameters->get_head_raw();
@@ -1269,7 +1384,7 @@ single_scalar_parameter(exec_list *parameters)
  * An \c ir_dereference_variable of the temprorary generated in the constructor
  * body.
  */
-ir_rvalue *
+static ir_rvalue *
 emit_inline_vector_constructor(const glsl_type *type,
                                exec_list *instructions,
                                exec_list *parameters,
@@ -1433,7 +1548,7 @@ emit_inline_vector_constructor(const glsl_type *type,
  * \c src_base + \c count must be less than or equal to the number of
  * components in the source vector.
  */
-ir_instruction *
+static ir_instruction *
 assign_to_matrix_column(ir_variable *var, unsigned column, unsigned row_base,
                         ir_rvalue *src, unsigned src_base, unsigned count,
                         void *mem_ctx)
@@ -1473,7 +1588,7 @@ assign_to_matrix_column(ir_variable *var, unsigned column, unsigned row_base,
  * An \c ir_dereference_variable of the temprorary generated in the constructor
  * body.
  */
-ir_rvalue *
+static ir_rvalue *
 emit_inline_matrix_constructor(const glsl_type *type,
                                exec_list *instructions,
                                exec_list *parameters,
@@ -1504,8 +1619,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
        * components with zero.
        */
       glsl_base_type param_base_type = first_param->type->base_type;
-      assert(param_base_type == GLSL_TYPE_FLOAT ||
-             param_base_type == GLSL_TYPE_DOUBLE);
+      assert(first_param->type->is_float() || first_param->type->is_double());
       ir_variable *rhs_var =
          new(ctx) ir_variable(glsl_type::get_instance(param_base_type, 4, 1),
                               "mat_ctor_vec",
@@ -1514,15 +1628,14 @@ emit_inline_matrix_constructor(const glsl_type *type,
 
       ir_constant_data zero;
       for (unsigned i = 0; i < 4; i++)
-         if (param_base_type == GLSL_TYPE_FLOAT)
+         if (first_param->type->is_float())
             zero.f[i] = 0.0;
          else
             zero.d[i] = 0.0;
 
       ir_instruction *inst =
          new(ctx) ir_assignment(new(ctx) ir_dereference_variable(rhs_var),
-                                new(ctx) ir_constant(rhs_var->type, &zero),
-                                NULL);
+                                new(ctx) ir_constant(rhs_var->type, &zero));
       instructions->push_tail(inst);
 
       ir_dereference *const rhs_ref =
@@ -1555,7 +1668,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
          ir_rvalue *const rhs = new(ctx) ir_swizzle(rhs_ref, rhs_swiz[i],
                                                     type->vector_elements);
 
-         inst = new(ctx) ir_assignment(col_ref, rhs, NULL);
+         inst = new(ctx) ir_assignment(col_ref, rhs);
          instructions->push_tail(inst);
       }
 
@@ -1568,7 +1681,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
          ir_rvalue *const rhs = new(ctx) ir_swizzle(rhs_ref, 1, 1, 1, 1,
                                                     type->vector_elements);
 
-         inst = new(ctx) ir_assignment(col_ref, rhs, NULL);
+         inst = new(ctx) ir_assignment(col_ref, rhs);
          instructions->push_tail(inst);
       }
    } else if (first_param->type->is_matrix()) {
@@ -1622,7 +1735,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
             ir_rvalue *const lhs =
                new(ctx) ir_dereference_array(var, new(ctx) ir_constant(col));
 
-            ir_instruction *inst = new(ctx) ir_assignment(lhs, rhs, NULL);
+            ir_instruction *inst = new(ctx) ir_assignment(lhs, rhs);
             instructions->push_tail(inst);
          }
       }
@@ -1640,7 +1753,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
       ir_dereference *const rhs_var_ref =
          new(ctx) ir_dereference_variable(rhs_var);
       ir_instruction *const inst =
-         new(ctx) ir_assignment(rhs_var_ref, first_param, NULL);
+         new(ctx) ir_assignment(rhs_var_ref, first_param);
       instructions->push_tail(inst);
 
       const unsigned last_row = MIN2(src_matrix->type->vector_elements,
@@ -1703,7 +1816,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
 
          ir_dereference *rhs_var_ref =
             new(ctx) ir_dereference_variable(rhs_var);
-         ir_instruction *inst = new(ctx) ir_assignment(rhs_var_ref, rhs, NULL);
+         ir_instruction *inst = new(ctx) ir_assignment(rhs_var_ref, rhs);
          instructions->push_tail(inst);
 
          do {
@@ -1743,7 +1856,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
 }
 
 
-ir_rvalue *
+static ir_rvalue *
 emit_inline_record_constructor(const glsl_type *type,
                                exec_list *instructions,
                                exec_list *parameters,
@@ -1767,8 +1880,7 @@ emit_inline_record_constructor(const glsl_type *type,
       ir_rvalue *const rhs = ((ir_instruction *) node)->as_rvalue();
       assert(rhs != NULL);
 
-      ir_instruction *const assign =
-         new(mem_ctx) ir_assignment(lhs, rhs, NULL);
+      ir_instruction *const assign = new(mem_ctx) ir_assignment(lhs, rhs);
 
       instructions->push_tail(assign);
       node = node->next;
@@ -1929,6 +2041,13 @@ ast_function_expression::handle_method(exec_list *instructions,
    return ir_rvalue::error_value(ctx);
 }
 
+static inline bool is_valid_constructor(const glsl_type *type,
+                                        struct _mesa_glsl_parse_state *state)
+{
+   return type->is_numeric() || type->is_boolean() ||
+          (state->has_bindless() && (type->is_sampler() || type->is_image()));
+}
+
 ir_rvalue *
 ast_function_expression::hir(exec_list *instructions,
                              struct _mesa_glsl_parse_state *state)
@@ -1961,9 +2080,21 @@ ast_function_expression::hir(exec_list *instructions,
 
 
       /* Constructors for opaque types are illegal.
+       *
+       * From section 4.1.7 of the ARB_bindless_texture spec:
+       *
+       * "Samplers are represented using 64-bit integer handles, and may be "
+       *  converted to and from 64-bit integers using constructors."
+       *
+       * From section 4.1.X of the ARB_bindless_texture spec:
+       *
+       * "Images are represented using 64-bit integer handles, and may be
+       *  converted to and from 64-bit integers using constructors."
        */
-      if (constructor_type->contains_opaque()) {
-         _mesa_glsl_error(& loc, state, "cannot construct opaque type `%s'",
+      if (constructor_type->contains_atomic() ||
+          (!state->has_bindless() && constructor_type->contains_opaque())) {
+         _mesa_glsl_error(& loc, state, "cannot construct %s type `%s'",
+                          state->has_bindless() ? "atomic" : "opaque",
                           constructor_type->name);
          return ir_rvalue::error_value(ctx);
       }
@@ -1976,8 +2107,8 @@ ast_function_expression::hir(exec_list *instructions,
       }
 
       if (constructor_type->is_array()) {
-         if (!state->check_version(120, 300, &loc,
-                                   "array constructors forbidden")) {
+         if (!state->check_version(state->allow_glsl_120_subset_in_110 ? 110 : 120,
+                                   300, &loc, "array constructors forbidden")) {
             return ir_rvalue::error_value(ctx);
          }
 
@@ -2000,13 +2131,13 @@ ast_function_expression::hir(exec_list *instructions,
        * must have the exact number of arguments with matching types in the
        * correct order.
        */
-      if (constructor_type->is_record()) {
+      if (constructor_type->is_struct()) {
          return process_record_constructor(instructions, constructor_type,
                                            &loc, &this->expressions,
                                            state);
       }
 
-      if (!constructor_type->is_numeric() && !constructor_type->is_boolean())
+      if (!is_valid_constructor(constructor_type, state))
          return ir_rvalue::error_value(ctx);
 
       /* Total number of components of the type being constructed. */
@@ -2036,7 +2167,7 @@ ast_function_expression::hir(exec_list *instructions,
             return ir_rvalue::error_value(ctx);
          }
 
-         if (!result->type->is_numeric() && !result->type->is_boolean()) {
+         if (!is_valid_constructor(result->type, state)) {
             _mesa_glsl_error(& loc, state, "cannot construct `%s' from a "
                              "non-numeric data type",
                              constructor_type->name);
@@ -2111,8 +2242,8 @@ ast_function_expression::hir(exec_list *instructions,
             instructions->push_tail(var);
             instructions->push_tail(
                new(ctx) ir_assignment(new(ctx) ir_dereference_variable(var),
-                                      matrix, NULL));
-            var->constant_value = matrix->constant_expression_value();
+                                      matrix));
+            var->constant_value = matrix->constant_expression_value(ctx);
 
             /* Replace the matrix with dereferences of its columns. */
             for (int i = 0; i < matrix->type->matrix_columns; i++) {
@@ -2128,17 +2259,58 @@ ast_function_expression::hir(exec_list *instructions,
 
       /* Type cast each parameter and, if possible, fold constants.*/
       foreach_in_list_safe(ir_rvalue, ir, &actual_parameters) {
-         const glsl_type *desired_type =
-            glsl_type::get_instance(constructor_type->base_type,
-                                    ir->type->vector_elements,
-                                    ir->type->matrix_columns);
+         const glsl_type *desired_type;
+
+         /* From section 5.4.1 of the ARB_bindless_texture spec:
+          *
+          * "In the following four constructors, the low 32 bits of the sampler
+          *  type correspond to the .x component of the uvec2 and the high 32
+          *  bits correspond to the .y component."
+          *
+          *  uvec2(any sampler type)     // Converts a sampler type to a
+          *                              //   pair of 32-bit unsigned integers
+          *  any sampler type(uvec2)     // Converts a pair of 32-bit unsigned integers to
+          *                              //   a sampler type
+          *  uvec2(any image type)       // Converts an image type to a
+          *                              //   pair of 32-bit unsigned integers
+          *  any image type(uvec2)       // Converts a pair of 32-bit unsigned integers to
+          *                              //   an image type
+          */
+         if (ir->type->is_sampler() || ir->type->is_image()) {
+            /* Convert a sampler/image type to a pair of 32-bit unsigned
+             * integers as defined by ARB_bindless_texture.
+             */
+            if (constructor_type != glsl_type::uvec2_type) {
+               _mesa_glsl_error(&loc, state, "sampler and image types can only "
+                                "be converted to a pair of 32-bit unsigned "
+                                "integers");
+            }
+            desired_type = glsl_type::uvec2_type;
+         } else if (constructor_type->is_sampler() ||
+                    constructor_type->is_image()) {
+            /* Convert a pair of 32-bit unsigned integers to a sampler or image
+             * type as defined by ARB_bindless_texture.
+             */
+            if (ir->type != glsl_type::uvec2_type) {
+               _mesa_glsl_error(&loc, state, "sampler and image types can only "
+                                "be converted from a pair of 32-bit unsigned "
+                                "integers");
+            }
+            desired_type = constructor_type;
+         } else {
+            desired_type =
+               glsl_type::get_instance(constructor_type->base_type,
+                                       ir->type->vector_elements,
+                                       ir->type->matrix_columns);
+         }
+
          ir_rvalue *result = convert_component(ir, desired_type);
 
          /* Attempt to convert the parameter to a constant valued expression.
           * After doing so, track whether or not all the parameters to the
           * constructor are trivially constant valued expressions.
           */
-         ir_rvalue *const constant = result->constant_expression_value();
+         ir_rvalue *const constant = result->constant_expression_value(ctx);
 
          if (constant != NULL)
             result = constant;
@@ -2228,27 +2400,55 @@ ast_function_expression::hir(exec_list *instructions,
                                         new(ctx) ir_dereference_variable(mvp),
                                         new(ctx) ir_dereference_variable(vtx));
       } else {
-         if (state->stage == MESA_SHADER_TESS_CTRL &&
-             sig->is_builtin() && strcmp(func_name, "barrier") == 0) {
+         bool is_begin_interlock = false;
+         bool is_end_interlock = false;
+         if (sig->is_builtin() &&
+             state->stage == MESA_SHADER_FRAGMENT &&
+             state->ARB_fragment_shader_interlock_enable) {
+            is_begin_interlock = strcmp(func_name, "beginInvocationInterlockARB") == 0;
+            is_end_interlock = strcmp(func_name, "endInvocationInterlockARB") == 0;
+         }
+
+         if (sig->is_builtin() &&
+             ((state->stage == MESA_SHADER_TESS_CTRL &&
+               strcmp(func_name, "barrier") == 0) ||
+              is_begin_interlock || is_end_interlock)) {
             if (state->current_function == NULL ||
                 strcmp(state->current_function->function_name(), "main") != 0) {
                _mesa_glsl_error(&loc, state,
-                                "barrier() may only be used in main()");
+                                "%s() may only be used in main()", func_name);
             }
 
             if (state->found_return) {
                _mesa_glsl_error(&loc, state,
-                                "barrier() may not be used after return");
+                                "%s() may not be used after return", func_name);
             }
 
             if (instructions != &state->current_function->body) {
                _mesa_glsl_error(&loc, state,
-                                "barrier() may not be used in control flow");
+                                "%s() may not be used in control flow", func_name);
             }
          }
 
+         /* There can be only one begin/end interlock pair in the function. */
+         if (is_begin_interlock) {
+            if (state->found_begin_interlock)
+               _mesa_glsl_error(&loc, state,
+                                "beginInvocationInterlockARB may not be used twice");
+            state->found_begin_interlock = true;
+         } else if (is_end_interlock) {
+            if (!state->found_begin_interlock)
+               _mesa_glsl_error(&loc, state,
+                                "endInvocationInterlockARB may not be used "
+                                "before beginInvocationInterlockARB");
+            if (state->found_end_interlock)
+               _mesa_glsl_error(&loc, state,
+                                "endInvocationInterlockARB may not be used twice");
+            state->found_end_interlock = true;
+         }
+
          value = generate_call(instructions, sig, &actual_parameters, sub_var,
-                               array_idx, state, sig->is_builtin());
+                               array_idx, state);
          if (!value) {
             ir_variable *const tmp = new(ctx) ir_variable(glsl_type::void_type,
                                                           "void_var",
@@ -2299,7 +2499,7 @@ ast_aggregate_initializer::hir(exec_list *instructions,
                                        &this->expressions, state);
    }
 
-   if (constructor_type->is_record()) {
+   if (constructor_type->is_struct()) {
       return process_record_constructor(instructions, constructor_type, &loc,
                                         &this->expressions, state);
    }