diff options
author | Kenneth Graunke <kenneth@whitecape.org> | 2010-08-23 14:52:06 -0700 |
---|---|---|
committer | Ian Romanick <ian.d.romanick@intel.com> | 2010-08-26 09:19:48 -0700 |
commit | a044285e25615f2d97636fe3ba47d580c3537bc4 (patch) | |
tree | 54364a47e124422994d0a47ee1bd9d569f9a491d | |
parent | b6f15869b324ae64a00d0fe46fa3c8c62c1edb6c (diff) |
glsl: Move built-ins to live beyond the global scope.
Per the GLSL 1.20 specification (presumably a clarification of 1.10).
Also, when creating user functions, make a new ir_function that shadows the
built-in ir_function, rather than adding new signatures. User functions
are supposed to hide built-ins, not overload them.
Fixes piglit tests redeclaration-{04, 12, 14}.vert.
-rw-r--r-- | src/glsl/ast_to_hir.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 9b723162f6..548b3d8e5a 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -64,6 +64,21 @@ _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) state->current_function = NULL; + /* Section 4.2 of the GLSL 1.20 specification states: + * "The built-in functions are scoped in a scope outside the global scope + * users declare global variables in. That is, a shader's global scope, + * available for user-defined functions and global variables, is nested + * inside the scope containing the built-in functions." + * + * Since built-in functions like ftransform() access built-in variables, + * it follows that those must be in the outer scope as well. + * + * We push scope here to create this nesting effect...but don't pop. + * This way, a shader's globals are still in the symbol table for use + * by the linker. + */ + state->symbols->push_scope(); + foreach_list_typed (ast_node, ast, link, & state->translation_unit) ast->hir(instructions, state); } @@ -1890,11 +1905,12 @@ ast_declarator_list::hir(exec_list *instructions, /* Check if this declaration is actually a re-declaration, either to * resize an array or add qualifiers to an existing variable. * - * This is allowed for variables in the current scope. + * This is allowed for variables in the current scope, or when at + * global scope (for built-ins in the implicit outer scope). */ ir_variable *earlier = state->symbols->get_variable(decl->identifier); - if (earlier != NULL - && state->symbols->name_declared_this_scope(decl->identifier)) { + if (earlier != NULL && (state->current_function == NULL || + state->symbols->name_declared_this_scope(decl->identifier))) { /* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec, * @@ -2178,7 +2194,7 @@ ast_function::hir(exec_list *instructions, * that the previously seen signature does not have an associated definition. */ f = state->symbols->get_function(name, false); - if (f != NULL) { + if (f != NULL && !f->is_builtin) { sig = f->exact_matching_signature(&hir_parameters); if (sig != NULL) { const char *badvar = sig->qualifiers_match(&hir_parameters); |