summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2014-07-24 14:05:40 -0700
committerKenneth Graunke <[email protected]>2014-08-04 15:47:06 -0700
commit21129d4de300f1a934d02e30347c465520afef9e (patch)
tree499101703099b43852ce4119507131f9fd95550b /src/glsl
parentf82f2fb3dc770902f1657ab1c22e6004faa3afab (diff)
glsl: Make it possible to ignore built-ins when matching signatures.
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 <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/ast_function.cpp15
-rw-r--r--src/glsl/builtin_functions.cpp3
-rw-r--r--src/glsl/ir.h4
-rw-r--r--src/glsl/ir_function.cpp10
-rw-r--r--src/glsl/ir_reader.cpp3
-rw-r--r--src/glsl/link_functions.cpp2
-rw-r--r--src/glsl/linker.cpp3
-rw-r--r--src/glsl/lower_packed_varyings.cpp2
8 files changed, 26 insertions, 16 deletions
diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 4981fe17458..39c7beeb22a 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 e01742c4d05..185fe98b33d 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 49f74face65..31c354556e4 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -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
diff --git a/src/glsl/ir_function.cpp b/src/glsl/ir_function.cpp
index 7d6c2f45133..98bec45ceec 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 e3566e1d696..ae00e793496 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 2ce9609b55d..f86aec689b1 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 d588bc63ec4..0096fb023dc 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 c72b80a32fd..78014831566 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);