From 3919c19468e71fd9590b53e6160db79afb55bfc8 Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Thu, 21 Mar 2013 09:57:20 -0700 Subject: [PATCH] glsl_symbol_table: add interface block namespaces For interface blocks, there are three separate namespaces for uniform, input and output blocks. Signed-off-by: Jordan Justen Reviewed-by: Kenneth Graunke --- src/glsl/glsl_symbol_table.cpp | 84 ++++++++++++++++++++++++++++++++-- src/glsl/glsl_symbol_table.h | 4 ++ 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/glsl/glsl_symbol_table.cpp b/src/glsl/glsl_symbol_table.cpp index 8d34547c6ff..50bf11302b3 100644 --- a/src/glsl/glsl_symbol_table.cpp +++ b/src/glsl/glsl_symbol_table.cpp @@ -41,13 +41,67 @@ 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) {} + bool add_interface(const glsl_type *i, enum ir_variable_mode mode) + { + const glsl_type **dest; + + switch (mode) { + case ir_var_uniform: + dest = &ibu; + break; + case ir_var_shader_in: + dest = &ibi; + break; + case ir_var_shader_out: + dest = &ibo; + break; + default: + assert(!"Unsupported interface variable mode!"); + return false; + } + + if (*dest != NULL) { + return false; + } else { + *dest = i; + return true; + } + } + + const glsl_type *get_interface(enum ir_variable_mode mode) + { + switch (mode) { + case ir_var_uniform: + return ibu; + case ir_var_shader_in: + return ibi; + case ir_var_shader_out: + return ibo; + default: + assert(!"Unsupported interface variable mode!"); + return NULL; + } + } + + symbol_table_entry(ir_variable *v) : + v(v), f(0), t(0), ibu(0), ibi(0), ibo(0) {} + symbol_table_entry(ir_function *f) : + v(0), f(f), t(0), ibu(0), ibi(0), ibo(0) {} + symbol_table_entry(const glsl_type *t) : + v(0), f(0), t(t), ibu(0), ibi(0), ibo(0) {} + symbol_table_entry(const glsl_type *t, enum ir_variable_mode mode) : + v(0), f(0), t(0), ibu(0), ibi(0), ibo(0) + { + assert(t->is_interface()); + add_interface(t, mode); + } ir_variable *v; ir_function *f; const glsl_type *t; + const glsl_type *ibu; + const glsl_type *ibi; + const glsl_type *ibo; }; glsl_symbol_table::glsl_symbol_table() @@ -118,6 +172,23 @@ bool glsl_symbol_table::add_type(const char *name, const glsl_type *t) return _mesa_symbol_table_add_symbol(table, -1, name, entry) == 0; } +bool glsl_symbol_table::add_interface(const char *name, const glsl_type *i, + enum ir_variable_mode mode) +{ + assert(i->is_interface()); + symbol_table_entry *entry = get_entry(name); + if (entry == NULL) { + symbol_table_entry *entry = + new(mem_ctx) symbol_table_entry(i, mode); + bool add_interface_symbol_result = + _mesa_symbol_table_add_symbol(table, -1, name, entry) == 0; + assert(add_interface_symbol_result); + return add_interface_symbol_result; + } else { + return entry->add_interface(i, mode); + } +} + bool glsl_symbol_table::add_function(ir_function *f) { if (this->separate_function_namespace && name_declared_this_scope(f->name)) { @@ -152,6 +223,13 @@ const glsl_type *glsl_symbol_table::get_type(const char *name) return entry != NULL ? entry->t : NULL; } +const glsl_type *glsl_symbol_table::get_interface(const char *name, + enum ir_variable_mode mode) +{ + symbol_table_entry *entry = get_entry(name); + return entry != NULL ? entry->get_interface(mode) : NULL; +} + ir_function *glsl_symbol_table::get_function(const char *name) { symbol_table_entry *entry = get_entry(name); diff --git a/src/glsl/glsl_symbol_table.h b/src/glsl/glsl_symbol_table.h index 9f5602787f0..2753bdf3156 100644 --- a/src/glsl/glsl_symbol_table.h +++ b/src/glsl/glsl_symbol_table.h @@ -99,6 +99,8 @@ 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_interface(const char *name, const glsl_type *i, + enum ir_variable_mode mode); /*@}*/ /** @@ -113,6 +115,8 @@ public: ir_variable *get_variable(const char *name); const glsl_type *get_type(const char *name); ir_function *get_function(const char *name); + const glsl_type *get_interface(const char *name, + enum ir_variable_mode mode); /*@}*/ private: -- 2.30.2