glsl: Make it possible to ignore built-ins when matching signatures.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 24 Jul 2014 21:05:40 +0000 (14:05 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 4 Aug 2014 22:47:06 +0000 (15:47 -0700)
Historically, we've implemented the rules for overriding built-in
functions by creating multiple ir_functions and relying on the symbol
table to hide the one containing built-in functions.  That works, but
has a few drawbacks, so the next patch will change it.

Instead, we'll have a single ir_function for a particular name, which
will contain both built-in and user-defined signatures.  Passing an
extra parameter to matching_signature makes it easy to ignore built-ins
when they're supposed to be hidden.

I didn't add the parameter to exact_matching_signature since it wasn't
necessary.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
12 files changed:
src/glsl/ast_function.cpp
src/glsl/builtin_functions.cpp
src/glsl/ir.h
src/glsl/ir_function.cpp
src/glsl/ir_reader.cpp
src/glsl/link_functions.cpp
src/glsl/linker.cpp
src/glsl/lower_packed_varyings.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 4981fe1745852d39366d3a23f450e672624dfe2e..39c7beeb22aa74a1ea45a30f707f2713c7f44314 100644 (file)
@@ -450,20 +450,21 @@ match_function_by_name(const char *name,
       goto done; /* no match */
 
    if (f != NULL) {
+      /* In desktop GL, the presence of a user-defined signature hides any
+       * built-in signatures, so we must ignore them.  In contrast, in ES2
+       * user-defined signatures add new overloads, so we must consider them.
+       */
+      bool allow_builtins = state->es_shader || !f->has_user_signature();
+
       /* Look for a match in the local shader.  If exact, we're done. */
       bool is_exact = false;
       sig = local_sig = f->matching_signature(state, actual_parameters,
-                                              &is_exact);
+                                              allow_builtins, &is_exact);
       if (is_exact)
         goto done;
 
-      if (!state->es_shader && f->has_user_signature()) {
-        /* In desktop GL, the presence of a user-defined signature hides any
-         * built-in signatures, so we must ignore them.  In contrast, in ES2
-         * user-defined signatures add new overloads, so we must proceed.
-         */
+      if (!allow_builtins)
         goto done;
-      }
    }
 
    /* Local shader has no exact candidates; check the built-ins. */
index e01742c4d05ee24eace91aaeaf0691ed3e9aa8a2..185fe98b33d7207852af872b07fd60c162f8fa58 100644 (file)
@@ -706,7 +706,8 @@ builtin_builder::find(_mesa_glsl_parse_state *state,
    if (f == NULL)
       return NULL;
 
-   ir_function_signature *sig = f->matching_signature(state, actual_parameters);
+   ir_function_signature *sig =
+      f->matching_signature(state, actual_parameters, true);
    if (sig == NULL)
       return NULL;
 
index 49f74face65631af7627292098b52a3915281b40..31c354556e44a3dbadc55af181d5db3d161acef2 100644 (file)
@@ -979,6 +979,7 @@ public:
     */
    ir_function_signature *matching_signature(_mesa_glsl_parse_state *state,
                                              const exec_list *actual_param,
+                                             bool allow_builtins,
                                             bool *match_is_exact);
 
    /**
@@ -986,7 +987,8 @@ public:
     * conversions into account.
     */
    ir_function_signature *matching_signature(_mesa_glsl_parse_state *state,
-                                             const exec_list *actual_param);
+                                             const exec_list *actual_param,
+                                             bool allow_builtins);
 
    /**
     * Find a signature that exactly matches a set of actual parameters without
index 7d6c2f45133c249b93c320f90f5bcfb38da49e7b..98bec45ceec9e208181beea3843c4dd12cd59910 100644 (file)
@@ -281,15 +281,18 @@ 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;
@@ -308,7 +311,8 @@ ir_function::matching_signature(_mesa_glsl_parse_state *state,
     */
    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)) {
index e3566e1d6966e6729f6c66e2bf5cb8f2bdbbe026..ae00e793496c5cbc1c90fcaedfdcdad0e632e246 100644 (file)
@@ -677,7 +677,8 @@ ir_reader::read_call(s_expression *expr)
       return NULL;
    }
 
-   ir_function_signature *callee = f->matching_signature(state, &parameters);
+   ir_function_signature *callee =
+      f->matching_signature(state, &parameters, true);
    if (callee == NULL) {
       ir_read_error(expr, "couldn't find matching signature for function "
                     "%s", name->value());
index 2ce9609b55d8b08637b75ec2c5273532e3ae9c42..f86aec689b1138886d91aa521892ce587fcc2010 100644 (file)
@@ -307,7 +307,7 @@ find_matching_signature(const char *name, const exec_list *actual_parameters,
         continue;
 
       ir_function_signature *sig =
-         f->matching_signature(NULL, actual_parameters);
+         f->matching_signature(NULL, actual_parameters, use_builtin);
 
       if ((sig == NULL) ||
           (!sig->is_defined && !sig->is_intrinsic))
index d588bc63ec42f49efec0901f7652ebec06b35b1e..0096fb023dce0efe1e041de2b85281a00d02eb4b 100644 (file)
@@ -1129,7 +1129,8 @@ get_main_function_signature(gl_shader *sh)
        * We don't have to check for multiple definitions of main (in multiple
        * shaders) because that would have already been caught above.
        */
-      ir_function_signature *sig = f->matching_signature(NULL, &void_parameters);
+      ir_function_signature *sig =
+         f->matching_signature(NULL, &void_parameters, false);
       if ((sig != NULL) && sig->is_defined) {
         return sig;
       }
index c72b80a32fda353a18aab7c596055c0e56005db8..78014831566c5d7ae47d91e04b91f0109cb749d5 100644 (file)
@@ -655,7 +655,7 @@ lower_packed_varyings(void *mem_ctx, unsigned locations_used,
    ir_function *main_func = shader->symbols->get_function("main");
    exec_list void_parameters;
    ir_function_signature *main_func_sig
-      = main_func->matching_signature(NULL, &void_parameters);
+      = main_func->matching_signature(NULL, &void_parameters, false);
    exec_list new_instructions;
    lower_packed_varyings_visitor visitor(mem_ctx, locations_used, mode,
                                          gs_input_vertices, &new_instructions);
index 3b03eef77cdad355bc9afcbfe04e9127a4168cbb..752e5a413ecc78e4587e1444b631c55000fe9a33 100644 (file)
@@ -2511,7 +2511,7 @@ fs_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(NULL, &empty);
+      sig = ir->matching_signature(NULL, &empty, false);
 
       assert(sig);
 
index e16e93cc27ab917dd55355d10e01532751f8f756..23d1daec3153bd44f0862f0855a4a7c22183985f 100644 (file)
@@ -1068,7 +1068,7 @@ vec4_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(NULL, &empty);
+      sig = ir->matching_signature(NULL, &empty, false);
 
       assert(sig);
 
index 2a82e9d9ddc81a925a74d40fa0a2a315b700bef3..b088160d3c3f85d08a2486470f9ef36df6ff3438 100644 (file)
@@ -793,7 +793,7 @@ ir_to_mesa_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(NULL, &empty);
+      sig = ir->matching_signature(NULL, &empty, false);
 
       assert(sig);
 
index 293bc5c1b7dd4097b1f4ca4a11402e9e9a5d0073..a165d6a5c1fc9e7054893806df70b3145d69d23c 100644 (file)
@@ -1192,7 +1192,7 @@ glsl_to_tgsi_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(NULL, &empty);
+      sig = ir->matching_signature(NULL, &empty, false);
 
       assert(sig);