[Mesa-dev] [PATCH 2/3] glsl: Conditionally allow redeclaration of builtins
John Brooks
john at fastquake.com
Fri May 12 13:39:48 UTC 2017
Conditional on allow_glsl_builtin_redeclaration driconf option.
Signed-off-by: John Brooks <john at fastquake.com>
---
src/compiler/glsl/ast_to_hir.cpp | 16 ++++++++++++++++
src/compiler/glsl/glsl_parser_extras.cpp | 2 ++
src/compiler/glsl/glsl_parser_extras.h | 1 +
3 files changed, 19 insertions(+)
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 0dc69ef..c743dfe 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -4276,6 +4276,22 @@ get_variable_being_redeclared(ir_variable *var, YYLTYPE loc,
*/
earlier->data.precision = var->data.precision;
+ } else if(earlier->data.how_declared == ir_var_declared_implicitly &&
+ state->allow_builtin_redeclaration) {
+ /* Allow verbatim redeclarations of built-in variables. Not explicitly
+ * valid, but some applications do it.
+ */
+ if(earlier->data.mode != var->data.mode &&
+ !(earlier->data.mode == ir_var_system_value &&
+ var->data.mode == ir_var_shader_in)) {
+ _mesa_glsl_error(&loc, state,
+ "redeclaration of `%s' with incorrect qualifiers",
+ var->name);
+ } else if (earlier->type != var->type) {
+ _mesa_glsl_error(&loc, state,
+ "redeclaration of `%s' has incorrect type",
+ var->name);
+ }
} else if (allow_all_redeclarations) {
if (earlier->data.mode != var->data.mode) {
_mesa_glsl_error(&loc, state,
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index d731e35..1405a7e 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -305,6 +305,8 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
sizeof(this->atomic_counter_offsets));
this->allow_extension_directive_midshader =
ctx->Const.AllowGLSLExtensionDirectiveMidShader;
+ this->allow_builtin_redeclaration =
+ ctx->Const.AllowGLSLBuiltinRedeclaration;
this->cs_input_local_size_variable_specified = false;
diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
index 3a84d65..3981994 100644
--- a/src/compiler/glsl/glsl_parser_extras.h
+++ b/src/compiler/glsl/glsl_parser_extras.h
@@ -842,6 +842,7 @@ struct _mesa_glsl_parse_state {
unsigned atomic_counter_offsets[MAX_COMBINED_ATOMIC_BUFFERS];
bool allow_extension_directive_midshader;
+ bool allow_builtin_redeclaration;
/**
* Known subroutine type declarations.
--
2.7.4
More information about the mesa-dev
mailing list