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 <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
@@ -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. */
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+3
-1
@@ -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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -677,7 +677,8 @@ ir_reader::read_call(s_expression *expr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ir_function_signature *callee = f->matching_signature(state, ¶meters);
|
||||
ir_function_signature *callee =
|
||||
f->matching_signature(state, ¶meters, true);
|
||||
if (callee == NULL) {
|
||||
ir_read_error(expr, "couldn't find matching signature for function "
|
||||
"%s", name->value());
|
||||
|
||||
@@ -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))
|
||||
|
||||
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2511,7 +2511,7 @@ fs_visitor::visit(ir_function *ir)
|
||||
const ir_function_signature *sig;
|
||||
exec_list empty;
|
||||
|
||||
sig = ir->matching_signature(NULL, &empty);
|
||||
sig = ir->matching_signature(NULL, &empty, false);
|
||||
|
||||
assert(sig);
|
||||
|
||||
|
||||
@@ -1068,7 +1068,7 @@ vec4_visitor::visit(ir_function *ir)
|
||||
const ir_function_signature *sig;
|
||||
exec_list empty;
|
||||
|
||||
sig = ir->matching_signature(NULL, &empty);
|
||||
sig = ir->matching_signature(NULL, &empty, false);
|
||||
|
||||
assert(sig);
|
||||
|
||||
|
||||
@@ -793,7 +793,7 @@ ir_to_mesa_visitor::visit(ir_function *ir)
|
||||
const ir_function_signature *sig;
|
||||
exec_list empty;
|
||||
|
||||
sig = ir->matching_signature(NULL, &empty);
|
||||
sig = ir->matching_signature(NULL, &empty, false);
|
||||
|
||||
assert(sig);
|
||||
|
||||
|
||||
@@ -1192,7 +1192,7 @@ glsl_to_tgsi_visitor::visit(ir_function *ir)
|
||||
const ir_function_signature *sig;
|
||||
exec_list empty;
|
||||
|
||||
sig = ir->matching_signature(NULL, &empty);
|
||||
sig = ir->matching_signature(NULL, &empty, false);
|
||||
|
||||
assert(sig);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user