aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/ast_function.cpp
diff options
context:
space:
mode:
authorErik Faye-Lund <[email protected]>2019-06-13 12:03:27 +0200
committerErik Faye-Lund <[email protected]>2019-07-25 17:20:10 +0200
commitc5f14322965cc006038e293902412e76ad268767 (patch)
treeeb654f38e1edbeb699c288f971bb4ddfc951b2b4 /src/compiler/glsl/ast_function.cpp
parent7e1fe81f565fb72c63705b516d3e3b4c06184fc5 (diff)
glsl: report no function instead of empty candidate list
When generating the error message for a missing function error where all available overloads were missing due to a too low GLSL version, we used to report something like this: ---8<--- 0:224(14): error: no matching function for call to `textureCubeLod(samplerCube, vec3, float)'; candidates are: 0:224(14): error: type mismatch ---8<--- This is a pretty confusing error message, and can throw people off when debugging. So let's instead check if any overload is available before we decide what to print. This allow us to report something like this instead: ---8<--- 0:224(14): error: no function with name 'textureCubeLod' 0:224(14): error: type mismatch ---8<--- This is arguably easier to understand for programmers, and doesn't send you on a wild goose chase to figure out what argument is wrong just because you stopped reading the message prematurely. I'm of course referring to a friend, not me. For sure. I would never do that. Signed-off-by: Erik Faye-Lund <[email protected]> Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/compiler/glsl/ast_function.cpp')
-rw-r--r--src/compiler/glsl/ast_function.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp
index 80cbb582b0e..0ed47660e22 100644
--- a/src/compiler/glsl/ast_function.cpp
+++ b/src/compiler/glsl/ast_function.cpp
@@ -748,6 +748,21 @@ generate_array_index(void *mem_ctx, exec_list *instructions,
}
}
+static bool
+function_exists(_mesa_glsl_parse_state *state,
+ struct glsl_symbol_table *symbols, const char *name)
+{
+ ir_function *f = symbols->get_function(name);
+ if (f != NULL) {
+ foreach_in_list(ir_function_signature, sig, &f->signatures) {
+ if (sig->is_builtin() && !sig->is_builtin_available(state))
+ continue;
+ return true;
+ }
+ }
+ return false;
+}
+
static void
print_function_prototypes(_mesa_glsl_parse_state *state, YYLTYPE *loc,
ir_function *f)
@@ -778,9 +793,9 @@ no_matching_function_error(const char *name,
{
gl_shader *sh = _mesa_glsl_get_builtin_function_shader();
- if (state->symbols->get_function(name) == NULL
+ if (!function_exists(state, state->symbols, name)
&& (!state->uses_builtin_functions
- || sh->symbols->get_function(name) == NULL)) {
+ || !function_exists(state, sh->symbols, name))) {
_mesa_glsl_error(loc, state, "no function with name '%s'", name);
} else {
char *str = prototype_string(NULL, name, actual_parameters);