[Mesa-dev] [PATCH 1/3] glsl: Make it possible to ignore built-ins when matching signatures.

Kenneth Graunke kenneth at whitecape.org
Thu Jul 24 14:05:40 PDT 2014


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 at whitecape.org>
---
 src/glsl/ast_function.cpp                      | 15 ++++++++-------
 src/glsl/builtin_functions.cpp                 |  3 ++-
 src/glsl/ir.h                                  |  4 +++-
 src/glsl/ir_function.cpp                       | 10 +++++++---
 src/glsl/ir_reader.cpp                         |  3 ++-
 src/glsl/link_functions.cpp                    |  2 +-
 src/glsl/linker.cpp                            |  3 ++-
 src/glsl/lower_packed_varyings.cpp             |  2 +-
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp   |  2 +-
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp |  2 +-
 src/mesa/program/ir_to_mesa.cpp                |  2 +-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp     |  2 +-
 12 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 4981fe1..39c7bee 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -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. */
diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index e01742c..185fe98 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -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;
 
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index ea19924..260dd34 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -974,6 +974,7 @@ public:
     */
    ir_function_signature *matching_signature(_mesa_glsl_parse_state *state,
                                              const exec_list *actual_param,
+                                             bool allow_builtins,
 					     bool *match_is_exact);
 
    /**
@@ -981,7 +982,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
diff --git a/src/glsl/ir_function.cpp b/src/glsl/ir_function.cpp
index 7d6c2f4..98bec45 100644
--- a/src/glsl/ir_function.cpp
+++ b/src/glsl/ir_function.cpp
@@ -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)) {
diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp
index e3566e1..ae00e79 100644
--- a/src/glsl/ir_reader.cpp
+++ b/src/glsl/ir_reader.cpp
@@ -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());
diff --git a/src/glsl/link_functions.cpp b/src/glsl/link_functions.cpp
index 2ce9609..f86aec6 100644
--- a/src/glsl/link_functions.cpp
+++ b/src/glsl/link_functions.cpp
@@ -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))
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index d588bc6..0096fb0 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -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;
       }
diff --git a/src/glsl/lower_packed_varyings.cpp b/src/glsl/lower_packed_varyings.cpp
index c72b80a..7801483 100644
--- a/src/glsl/lower_packed_varyings.cpp
+++ b/src/glsl/lower_packed_varyings.cpp
@@ -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);
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 3b03eef..752e5a4 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -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);
 
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index e16e93c..23d1dae 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -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);
 
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 2a82e9d..b088160 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -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);
 
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 5c51e63..1d55c0c 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -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);
 
-- 
2.0.2



More information about the mesa-dev mailing list