glsl: Conditionally allow redeclaration of built-in variables
authorJohn Brooks <john@fastquake.com>
Mon, 15 May 2017 05:47:38 +0000 (01:47 -0400)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Sat, 20 May 2017 15:30:05 +0000 (17:30 +0200)
Conditional on allow_glsl_builtin_variable_redeclaration driconf option.

v2 (Samuel Pitoiset):
    - Rename allow_glsl_builtin_redeclaration ->
      allow_glsl_builtin_variable_redeclaration
    - style: put spaces after 'if'

Signed-off-by: John Brooks <john@fastquake.com>
Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/compiler/glsl/ast_to_hir.cpp
src/compiler/glsl/glsl_parser_extras.cpp
src/compiler/glsl/glsl_parser_extras.h

index 0dc69ef4b11ca3d617c04e997528465f711798af..2dec8bbc32b7722079ab3e42e6d47f09e1676c50 100644 (file)
@@ -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_variable_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,
index d731e35e212f746e1e601903d7f0692df812dcb5..0f892b03a13fa629e54d0ee092dad0660bed73f8 100644 (file)
@@ -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_variable_redeclaration =
+      ctx->Const.AllowGLSLBuiltinVariableRedeclaration;
 
    this->cs_input_local_size_variable_specified = false;
 
index 3a84d655b14c16dbddd917e6763d1cd03b965193..be6c8dce6b48420962bdef4d06c37580a7f14016 100644 (file)
@@ -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_variable_redeclaration;
 
    /**
     * Known subroutine type declarations.