[Mesa-dev] [PATCH 2/2] glsl: update default precision qualifiers when they are set in the shader
Samuel Iglesias Gonsálvez
siglesias at igalia.com
Thu Oct 20 10:39:59 UTC 2016
For that, we use gls_symbol_table::set_default_precision_qualifier() that
can update an existing definition or add a new one if it doesn't exist.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97804
Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
---
src/compiler/glsl/ast_to_hir.cpp | 2 +-
src/compiler/glsl/glsl_symbol_table.cpp | 15 +++++++++++++++
src/compiler/glsl/glsl_symbol_table.h | 2 ++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 6e2f253..cc50ff8 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -6559,7 +6559,7 @@ ast_type_specifier::hir(exec_list *instructions,
* is a slight abuse of the symbol table, but it has the semantics
* that we want.
*/
- state->symbols->add_default_precision_qualifier(this->type_name,
+ state->symbols->set_default_precision_qualifier(this->type_name,
this->default_precision);
}
diff --git a/src/compiler/glsl/glsl_symbol_table.cpp b/src/compiler/glsl/glsl_symbol_table.cpp
index 6d7baad..11e5c00 100644
--- a/src/compiler/glsl/glsl_symbol_table.cpp
+++ b/src/compiler/glsl/glsl_symbol_table.cpp
@@ -258,6 +258,21 @@ int glsl_symbol_table::get_default_precision_qualifier(const char *type_name)
return entry->a->default_precision;
}
+bool glsl_symbol_table::set_default_precision_qualifier(const char *type_name,
+ int precision)
+{
+ char *name = ralloc_asprintf(mem_ctx, "#default_precision_%s", type_name);
+ symbol_table_entry *entry = get_entry(name);
+ if (!entry)
+ return add_default_precision_qualifier(type_name, precision);
+
+ ast_type_specifier *default_specifier = new(mem_ctx) ast_type_specifier(name);
+ default_specifier->default_precision = precision;
+
+ entry = new(mem_ctx) symbol_table_entry(default_specifier);
+ return _mesa_symbol_table_replace_symbol(table, -1, name, entry) == 0;
+}
+
symbol_table_entry *glsl_symbol_table::get_entry(const char *name)
{
return (symbol_table_entry *)
diff --git a/src/compiler/glsl/glsl_symbol_table.h b/src/compiler/glsl/glsl_symbol_table.h
index 2f94d4c..69a6912 100644
--- a/src/compiler/glsl/glsl_symbol_table.h
+++ b/src/compiler/glsl/glsl_symbol_table.h
@@ -90,6 +90,8 @@ struct glsl_symbol_table {
const glsl_type *get_interface(const char *name,
enum ir_variable_mode mode);
int get_default_precision_qualifier(const char *type_name);
+ bool set_default_precision_qualifier(const char *type_name, int precision);
+
/*@}*/
/**
--
2.7.4
More information about the mesa-dev
mailing list