summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2012-11-28 00:18:02 -0800
committerAndreas Boll <andreas.boll.dev@gmail.com>2013-02-13 18:46:39 +0100
commit765221c0d5fdb0357bf6fae3220c7d57d93f938d (patch)
tree139fba36d8296303ebed5e6deb98f4d24ef0c18a
parentc10c3eab4c9d8617bb12dc5958eb9cfe06cc2e4d (diff)
glsl: Track UBO block names in the symbol table.
The GLSL 1.40 spec says: "Uniform block names and variable names declared within uniform blocks are scoped at the program level." Track the block name in the symbol table and emit errors when conflicts exist. Fixes es3conform's uniform_buffer_object_block_name_conflict test, and fixes the piglit block-name-clashes-with-{variable,function,struct}.vert tests. NOTE: This is a candidate for the 9.0 branch. v2: Fix bad constructor initialization. Noticed by Topi Pohjolainen. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> (cherry picked from commit 4f29169913f99252c54e1922f6d164e2ef530a58)
-rw-r--r--src/glsl/ast_to_hir.cpp6
-rw-r--r--src/glsl/glsl_symbol_table.cpp14
-rw-r--r--src/glsl/glsl_symbol_table.h1
3 files changed, 18 insertions, 3 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 5157661b39..f9613c9999 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -4039,6 +4039,12 @@ ast_uniform_block::hir(exec_list *instructions,
struct gl_uniform_block *ubo = get_next_uniform_block(state);
ubo->Name = ralloc_strdup(state->uniform_blocks, this->block_name);
+ if (!state->symbols->add_uniform_block(ubo)) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(&loc, state, "Uniform block name `%s' already taken in "
+ "the current scope.\n", ubo->Name);
+ }
+
unsigned int num_variables = 0;
foreach_list_typed(ast_declarator_list, decl_list, link, &declarations) {
foreach_list_const(node, &decl_list->declarations) {
diff --git a/src/glsl/glsl_symbol_table.cpp b/src/glsl/glsl_symbol_table.cpp
index bcb65d3018..c27f57a49c 100644
--- a/src/glsl/glsl_symbol_table.cpp
+++ b/src/glsl/glsl_symbol_table.cpp
@@ -41,13 +41,15 @@ public:
ralloc_free(entry);
}
- symbol_table_entry(ir_variable *v) : v(v), f(0), t(0) {}
- symbol_table_entry(ir_function *f) : v(0), f(f), t(0) {}
- symbol_table_entry(const glsl_type *t) : v(0), f(0), t(t) {}
+ symbol_table_entry(ir_variable *v) : v(v), f(0), t(0), u(0) {}
+ symbol_table_entry(ir_function *f) : v(0), f(f), t(0), u(0) {}
+ symbol_table_entry(const glsl_type *t) : v(0), f(0), t(t), u(0) {}
+ symbol_table_entry(struct gl_uniform_block *u) : v(0), f(0), t(0), u(u) {}
ir_variable *v;
ir_function *f;
const glsl_type *t;
+ struct gl_uniform_block *u;
};
glsl_symbol_table::glsl_symbol_table()
@@ -132,6 +134,12 @@ bool glsl_symbol_table::add_function(ir_function *f)
return _mesa_symbol_table_add_symbol(table, -1, f->name, entry) == 0;
}
+bool glsl_symbol_table::add_uniform_block(struct gl_uniform_block *u)
+{
+ symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(u);
+ return _mesa_symbol_table_add_symbol(table, -1, u->Name, entry) == 0;
+}
+
void glsl_symbol_table::add_global_function(ir_function *f)
{
symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(f);
diff --git a/src/glsl/glsl_symbol_table.h b/src/glsl/glsl_symbol_table.h
index 637bc033b9..6565e81fea 100644
--- a/src/glsl/glsl_symbol_table.h
+++ b/src/glsl/glsl_symbol_table.h
@@ -98,6 +98,7 @@ public:
bool add_variable(ir_variable *v);
bool add_type(const char *name, const glsl_type *t);
bool add_function(ir_function *f);
+ bool add_uniform_block(struct gl_uniform_block *u);
/*@}*/
/**