nir/builder: Use nir_after_instr to advance the cursor
[mesa.git] / src / glsl / ir_function.cpp
index deec1dfe86000a3ab2216a618c107bfdcb401a8e..93034bedb5a5ecd7728aeca882b6a3112b7abc16 100644 (file)
@@ -24,6 +24,7 @@
 #include "glsl_types.h"
 #include "ir.h"
 #include "glsl_parser_extras.h"
+#include "main/errors.h"
 
 typedef enum {
    PARAMETER_LIST_NO_MATCH,
@@ -71,6 +72,7 @@ parameter_lists_match(_mesa_glsl_parse_state *state,
       switch ((enum ir_variable_mode)(param->data.mode)) {
       case ir_var_auto:
       case ir_var_uniform:
+      case ir_var_shader_storage:
       case ir_var_temporary:
         /* These are all error conditions.  It is invalid for a parameter to
          * a function to be declared as auto (not in, out, or inout) or
@@ -147,9 +149,11 @@ get_parameter_match_type(const ir_variable *param,
    if (from_type == to_type)
       return PARAMETER_EXACT_MATCH;
 
-   /* XXX: When ARB_gpu_shader_fp64 support is added, check for float->double,
-    * and int/uint->double conversions
-    */
+   if (to_type->base_type == GLSL_TYPE_DOUBLE) {
+      if (from_type->base_type == GLSL_TYPE_FLOAT)
+         return PARAMETER_FLOAT_TO_DOUBLE;
+      return PARAMETER_INT_TO_DOUBLE;
+   }
 
    if (to_type->base_type == GLSL_TYPE_FLOAT)
       return PARAMETER_INT_TO_FLOAT;
@@ -281,18 +285,22 @@ choose_best_inexact_overload(_mesa_glsl_parse_state *state,
 
 ir_function_signature *
 ir_function::matching_signature(_mesa_glsl_parse_state *state,
-                                const exec_list *actual_parameters)
+                                const exec_list *actual_parameters,
+                                bool allow_builtins)
 {
    bool is_exact;
-   return matching_signature(state, actual_parameters, &is_exact);
+   return matching_signature(state, actual_parameters, allow_builtins,
+                             &is_exact);
 }
 
 ir_function_signature *
 ir_function::matching_signature(_mesa_glsl_parse_state *state,
                                 const exec_list *actual_parameters,
+                                bool allow_builtins,
                                 bool *is_exact)
 {
    ir_function_signature **inexact_matches = NULL;
+   ir_function_signature **inexact_matches_temp;
    ir_function_signature *match = NULL;
    int num_inexact_matches = 0;
 
@@ -306,11 +314,10 @@ ir_function::matching_signature(_mesa_glsl_parse_state *state,
     *  multiple ways to apply these conversions to the actual arguments of a
     *  call such that the call can be made to match multiple signatures."
     */
-   foreach_list(n, &this->signatures) {
-      ir_function_signature *const sig = (ir_function_signature *) n;
-
+   foreach_in_list(ir_function_signature, sig, &this->signatures) {
       /* Skip over any built-ins that aren't available in this shader. */
-      if (sig->is_builtin() && !sig->is_builtin_available(state))
+      if (sig->is_builtin() && (!allow_builtins ||
+                                !sig->is_builtin_available(state)))
          continue;
 
       switch (parameter_lists_match(state, & sig->parameters, actual_parameters)) {
@@ -319,11 +326,16 @@ ir_function::matching_signature(_mesa_glsl_parse_state *state,
          free(inexact_matches);
          return sig;
       case PARAMETER_LIST_INEXACT_MATCH:
-         inexact_matches = (ir_function_signature **)
+         inexact_matches_temp = (ir_function_signature **)
                realloc(inexact_matches,
                        sizeof(*inexact_matches) *
                        (num_inexact_matches + 1));
-         assert(inexact_matches);
+         if (inexact_matches_temp == NULL) {
+            _mesa_error_no_memory(__func__);
+            free(inexact_matches);
+            return NULL;
+         }
+         inexact_matches = inexact_matches_temp;
          inexact_matches[num_inexact_matches++] = sig;
          continue;
       case PARAMETER_LIST_NO_MATCH:
@@ -380,9 +392,7 @@ ir_function_signature *
 ir_function::exact_matching_signature(_mesa_glsl_parse_state *state,
                                       const exec_list *actual_parameters)
 {
-   foreach_list(n, &this->signatures) {
-      ir_function_signature *const sig = (ir_function_signature *) n;
-
+   foreach_in_list(ir_function_signature, sig, &this->signatures) {
       /* Skip over any built-ins that aren't available in this shader. */
       if (sig->is_builtin() && !sig->is_builtin_available(state))
          continue;