<div dir="ltr">On 4 September 2013 15:22, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">For the upcoming built-in function rewrite, we'll need to be able to<br>
answer "Is this built-in function signature available?".<br>
<br>
This is actually a somewhat complex question, since it depends on the<br>
language version, GLSL vs. GLSL ES, enabled extensions, and the current<br>
shader stage.<br>
<br>
Storing such a set of constraints in a structure would be painful, so<br>
instead we store a function pointer.  When creating a signature, we<br>
simply point to a predicate that inspects _mesa_glsl_parse_state and<br>
answers whether the signature is available in the current shader.<br>
<br>
Unfortunately, IR reader doesn't actually know when built-in functions<br>
are available, so this patch makes it lie and say that they're always<br>
present.  This allows us to hook up the new functionality; it just won't<br>
be useful until real data is populated.  In the meantime, the existing<br>
profile mechanism ensures built-ins are available in the right places.<br>
<br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
---<br>
 src/glsl/ir.cpp        |  8 +++++---<br>
 src/glsl/ir.h          | 14 +++++++++++++-<br>
 src/glsl/ir_clone.cpp  |  1 +<br>
 src/glsl/ir_reader.cpp | 13 +++++++++++--<br>
 4 files changed, 30 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp<br>
index c6d96d8..ea018eb 100644<br>
--- a/src/glsl/ir.cpp<br>
+++ b/src/glsl/ir.cpp<br>
@@ -1579,11 +1579,13 @@ ir_variable::determine_interpolation_mode(bool flat_shade)<br>
 }<br>
<br>
<br>
-ir_function_signature::ir_function_signature(const glsl_type *return_type)<br>
-   : return_type(return_type), is_defined(false), _function(NULL)<br>
+ir_function_signature::ir_function_signature(const glsl_type *return_type,<br>
+                                             builtin_available_predicate b)<br>
+   : return_type(return_type), is_defined(false), builtin_info(b),<br>
+     _function(NULL)<br>
 {<br>
    this->ir_type = ir_type_function_signature;<br>
-   this->is_builtin = false;<br>
+   this->is_builtin = builtin_info != NULL;<br>
    this->origin = NULL;<br>
 }<br>
<br>
diff --git a/src/glsl/ir.h b/src/glsl/ir.h<br>
index b45e6cb..d785259 100644<br>
--- a/src/glsl/ir.h<br>
+++ b/src/glsl/ir.h<br>
@@ -591,6 +591,11 @@ public:<br>
    const glsl_type *interface_type;<br>
 };<br>
<br>
+/**<br>
+ * A function that returns whether a built-in function is available in the<br>
+ * current shading language (based on version, ES or desktop, and extensions).<br>
+ */<br>
+typedef bool (*builtin_available_predicate)(const _mesa_glsl_parse_state *);<br>
<br>
 /*@{*/<br>
 /**<br>
@@ -602,7 +607,8 @@ class ir_function_signature : public ir_instruction {<br>
     * an ir_function.<br>
     */<br>
 public:<br>
-   ir_function_signature(const glsl_type *return_type);<br>
+   ir_function_signature(const glsl_type *return_type,<br>
+                         builtin_available_predicate builtin_info = NULL);<br>
<br>
    virtual ir_function_signature *clone(void *mem_ctx,<br>
                                        struct hash_table *ht) const;<br>
@@ -684,6 +690,12 @@ public:<br>
    struct exec_list body;<br>
<br>
 private:<br>
+   /**<br>
+    * A function pointer to a predicate that answers whether a built-in<br>
+    * function is available in the current shader.  NULL if not a built-in.<br>
+    */<br>
+   builtin_available_predicate builtin_info;<br>
+<br></blockquote><div><br></div><div>I'd prefer to see this called something like "builtin_avail" instead of "builtin_info" since that describes precisely what info it's storing about the function.  Calling it "builtin_info" makes it sound like it stores a variety of information about built-in functions.<br>
<br></div><div>It's a nit-pick, though, so either way, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>> <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

    /** Function of which this signature is one overload. */<br>
    class ir_function *_function;<br>
<br>
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp<br>
index 9d4178d..967ad70 100644<br>
--- a/src/glsl/ir_clone.cpp<br>
+++ b/src/glsl/ir_clone.cpp<br>
@@ -328,6 +328,7 @@ ir_function_signature::clone_prototype(void *mem_ctx, struct hash_table *ht) con<br>
<br>
    copy->is_defined = false;<br>
    copy->is_builtin = this->is_builtin;<br>
+   copy->builtin_info = this->builtin_info;<br>
    copy->origin = this;<br>
<br>
    /* Clone the parameter list, but NOT the body.<br>
diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp<br>
index f263fe8..8261d9f 100644<br>
--- a/src/glsl/ir_reader.cpp<br>
+++ b/src/glsl/ir_reader.cpp<br>
@@ -211,6 +211,12 @@ ir_reader::read_function(s_expression *expr, bool skip_body)<br>
    return added ? f : NULL;<br>
 }<br>
<br>
+static bool<br>
+always_available(const _mesa_glsl_parse_state *)<br>
+{<br>
+   return true;<br>
+}<br>
+<br>
 void<br>
 ir_reader::read_function_sig(ir_function *f, s_expression *expr, bool skip_body)<br>
 {<br>
@@ -251,8 +257,11 @@ ir_reader::read_function_sig(ir_function *f, s_expression *expr, bool skip_body)<br>
    ir_function_signature *sig = f->exact_matching_signature(&hir_parameters);<br>
    if (sig == NULL && skip_body) {<br>
       /* If scanning for prototypes, generate a new signature. */<br>
-      sig = new(mem_ctx) ir_function_signature(return_type);<br>
-      sig->is_builtin = true;<br>
+      /* ir_reader doesn't know what languages support a given built-in, so<br>
+       * just say that they're always available.  For now, other mechanisms<br>
+       * guarantee the right built-ins are available.<br>
+       */<br>
+      sig = new(mem_ctx) ir_function_signature(return_type, always_available);<br>
       f->add_signature(sig);<br>
    } else if (sig != NULL) {<br>
       const char *badvar = sig->qualifiers_match(&hir_parameters);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.4<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>