glsl: Store a predicate for whether a built-in signature is available.

For the upcoming built-in function rewrite, we'll need to be able to
answer "Is this built-in function signature available?".

This is actually a somewhat complex question, since it depends on the
language version, GLSL vs. GLSL ES, enabled extensions, and the current
shader stage.

Storing such a set of constraints in a structure would be painful, so
instead we store a function pointer.  When creating a signature, we
simply point to a predicate that inspects _mesa_glsl_parse_state and
answers whether the signature is available in the current shader.

Unfortunately, IR reader doesn't actually know when built-in functions
are available, so this patch makes it lie and say that they're always
present.  This allows us to hook up the new functionality; it just won't
be useful until real data is populated.  In the meantime, the existing
profile mechanism ensures built-ins are available in the right places.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
This commit is contained in:
Kenneth Graunke
2013-08-30 16:00:43 -07:00
parent 6c3db2167c
commit ca321d07fd
4 changed files with 30 additions and 6 deletions
+11 -2
View File
@@ -211,6 +211,12 @@ ir_reader::read_function(s_expression *expr, bool skip_body)
return added ? f : NULL;
}
static bool
always_available(const _mesa_glsl_parse_state *)
{
return true;
}
void
ir_reader::read_function_sig(ir_function *f, s_expression *expr, bool skip_body)
{
@@ -251,8 +257,11 @@ ir_reader::read_function_sig(ir_function *f, s_expression *expr, bool skip_body)
ir_function_signature *sig = f->exact_matching_signature(&hir_parameters);
if (sig == NULL && skip_body) {
/* If scanning for prototypes, generate a new signature. */
sig = new(mem_ctx) ir_function_signature(return_type);
sig->is_builtin = true;
/* ir_reader doesn't know what languages support a given built-in, so
* just say that they're always available. For now, other mechanisms
* guarantee the right built-ins are available.
*/
sig = new(mem_ctx) ir_function_signature(return_type, always_available);
f->add_signature(sig);
} else if (sig != NULL) {
const char *badvar = sig->qualifiers_match(&hir_parameters);