glsl: check if any of the named builtins are available first
authorIlia Mirkin <imirkin@alum.mit.edu>
Mon, 3 Jul 2017 21:08:12 +0000 (17:08 -0400)
committerIlia Mirkin <imirkin@alum.mit.edu>
Thu, 6 Jul 2017 00:05:53 +0000 (20:05 -0400)
_mesa_glsl_has_builtin_function is used to determine whether any variant
of a builtin are available, for the purpose of enforcing the GLSL ES
3.00+ rule that overloads or overrides of builtins are disallowed.

However the builtin_builder contains information on all builtins,
irrespective of parse state, or versions, or extension enablement. As a
result we would say that a builtin existed even if it was not actually
available.

To resolve this, first check if at least one signature is available for
a builtin before returning true.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101666
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/glsl/ast_to_hir.cpp
src/compiler/glsl/builtin_functions.cpp
src/compiler/glsl/builtin_functions.h

index b1e490eefd9a00d7ac9a0fb25806b322ea344e73..c338ad79ca3d8f9d055db25742aef81321ea68bc 100644 (file)
@@ -5916,7 +5916,7 @@ ast_function::hir(exec_list *instructions,
       /* Local shader has no exact candidates; check the built-ins. */
       _mesa_glsl_initialize_builtin_functions();
       if (state->language_version >= 300 &&
-          _mesa_glsl_has_builtin_function(name)) {
+          _mesa_glsl_has_builtin_function(state, name)) {
          YYLTYPE loc = this->get_location();
          _mesa_glsl_error(& loc, state,
                           "A shader cannot redefine or overload built-in "
index cc1432197b9582a1415ca87cb1262fe5fe00df16..84833bdd7d5d637043a205df6f23659111574056 100644 (file)
@@ -6227,14 +6227,23 @@ _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
 }
 
 bool
-_mesa_glsl_has_builtin_function(const char *name)
+_mesa_glsl_has_builtin_function(_mesa_glsl_parse_state *state, const char *name)
 {
    ir_function *f;
+   bool ret = false;
    mtx_lock(&builtins_lock);
    f = builtins.shader->symbols->get_function(name);
+   if (f != NULL) {
+      foreach_in_list(ir_function_signature, sig, &f->signatures) {
+         if (sig->is_builtin_available(state)) {
+            ret = true;
+            break;
+         }
+      }
+   }
    mtx_unlock(&builtins_lock);
 
-   return f != NULL;
+   return ret;
 }
 
 gl_shader *
index 14a52b9402710d7722788914265abef8aaa2b4ef..2053c82b745a1dcfccfed887e4f4d85fe379648c 100644 (file)
@@ -32,7 +32,8 @@ _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
                                  const char *name, exec_list *actual_parameters);
 
 extern bool
-_mesa_glsl_has_builtin_function(const char *name);
+_mesa_glsl_has_builtin_function(_mesa_glsl_parse_state *state,
+                                const char *name);
 
 extern gl_shader *
 _mesa_glsl_get_builtin_function_shader(void);