Mesa (master): glsl: Add a new matching_signature() variant that returns exact/inexact.

Kenneth Graunke kwg at kemper.freedesktop.org
Tue Nov 15 01:19:26 UTC 2011


Module: Mesa
Branch: master
Commit: 861d0a5e12b1baa31211cb8aff983b8fb9b97482
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=861d0a5e12b1baa31211cb8aff983b8fb9b97482

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Fri Nov 11 00:48:14 2011 -0800

glsl: Add a new matching_signature() variant that returns exact/inexact.

When matching function signatures across multiple linked shaders, we
often want to see if the current shader has _any_ match, but also know
whether or not it was exact.  (If not, we may want to keep looking.)

This could be done via the existing mechanisms:

   sig = f->exact_matching_signature(params);
   if (sig != NULL) {
      exact = true;
   } else {
      sig = f->matching_signature(params);
      exact = false;
   }

However, this requires walking the list of function signatures twice,
which also means walking each signature's formal parameter lists twice.
This could be rather expensive.

Since matching_signature already internally knows whether a match was
exact or not, we can just return it to get that information for free.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Paul Berry <stereotype441 at gmail.com>

---

 src/glsl/ir.h            |    7 +++++++
 src/glsl/ir_function.cpp |   11 +++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 5878c05..1faae3c 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -566,6 +566,13 @@ public:
 
    /**
     * Find a signature that matches a set of actual parameters, taking implicit
+    * conversions into account.  Also flags whether the match was exact.
+    */
+   ir_function_signature *matching_signature(const exec_list *actual_param,
+					     bool *match_is_exact);
+
+   /**
+    * Find a signature that matches a set of actual parameters, taking implicit
     * conversions into account.
     */
    ir_function_signature *matching_signature(const exec_list *actual_param);
diff --git a/src/glsl/ir_function.cpp b/src/glsl/ir_function.cpp
index 51d32b4..b34a500 100644
--- a/src/glsl/ir_function.cpp
+++ b/src/glsl/ir_function.cpp
@@ -118,6 +118,14 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
 ir_function_signature *
 ir_function::matching_signature(const exec_list *actual_parameters)
 {
+   bool is_exact;
+   return matching_signature(actual_parameters, &is_exact);
+}
+
+ir_function_signature *
+ir_function::matching_signature(const exec_list *actual_parameters,
+			        bool *is_exact)
+{
    ir_function_signature *match = NULL;
    bool multiple_inexact_matches = false;
 
@@ -137,6 +145,7 @@ ir_function::matching_signature(const exec_list *actual_parameters)
 
       switch (parameter_lists_match(& sig->parameters, actual_parameters)) {
       case PARAMETER_LIST_EXACT_MATCH:
+	 *is_exact = true;
 	 return sig;
       case PARAMETER_LIST_INEXACT_MATCH:
 	 if (match == NULL)
@@ -159,6 +168,8 @@ ir_function::matching_signature(const exec_list *actual_parameters)
     * FINISHME: a "no matching signature" error; it should report that the
     * FINISHME: call is ambiguous.  But reporting errors from here is hard.
     */
+   *is_exact = false;
+
    if (multiple_inexact_matches)
       return NULL;
 




More information about the mesa-commit mailing list