[Mesa-dev] [PATCH] glsl: Only allow `invariant` on shader in/out between stages.

Chris Forbes chrisf at ijw.co.nz
Sun Apr 20 21:06:46 PDT 2014


Previously this was special-cased for VS and FS; it never got updated
when geometry shaders came along. Generalize using is_varying_var() so
this won't be broken again with tessellation.

Note that there are two copies of the logic for `invariant`: It can be
present as part of a new declaration, and also as a redeclaration of an
existing variable or block member.

Fixes the four new piglits:
   specc/glsl-1.50/compiler/invariant-qualifier-*.geom

Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
---
 src/glsl/ast_to_hir.cpp | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 35d58e9..e4f3f77 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3065,16 +3065,10 @@ ast_declarator_list::hir(exec_list *instructions,
             _mesa_glsl_error(& loc, state,
                              "undeclared variable `%s' cannot be marked "
                              "invariant", decl->identifier);
-         } else if ((state->stage == MESA_SHADER_VERTEX)
-                    && (earlier->data.mode != ir_var_shader_out)) {
-            _mesa_glsl_error(& loc, state,
-                             "`%s' cannot be marked invariant, vertex shader "
-                             "outputs only", decl->identifier);
-         } else if ((state->stage == MESA_SHADER_FRAGMENT)
-                    && (earlier->data.mode != ir_var_shader_in)) {
-            _mesa_glsl_error(& loc, state,
-                             "`%s' cannot be marked invariant, fragment shader "
-                             "inputs only", decl->identifier);
+         } else if (!is_varying_var(earlier, state->stage)) {
+            _mesa_glsl_error(&loc, state,
+                             "`%s' cannot be marked invariant; interfaces between "
+                             "shader stages only.", decl->identifier);
          } else if (earlier->data.used) {
             _mesa_glsl_error(& loc, state,
                             "variable `%s' may not be redeclared "
@@ -3250,19 +3244,13 @@ ast_declarator_list::hir(exec_list *instructions,
 				       & loc, false);
 
       if (this->type->qualifier.flags.q.invariant) {
-         if ((state->stage == MESA_SHADER_VERTEX) &&
-             var->data.mode != ir_var_shader_out) {
-            _mesa_glsl_error(& loc, state,
-                             "`%s' cannot be marked invariant, vertex shader "
-                             "outputs only", var->name);
-         } else if ((state->stage == MESA_SHADER_FRAGMENT) &&
-                    var->data.mode != ir_var_shader_in) {
-            /* FINISHME: Note that this doesn't work for invariant on
-             * a function signature inval
-             */
-            _mesa_glsl_error(& loc, state,
-                             "`%s' cannot be marked invariant, fragment shader "
-                             "inputs only", var->name);
+         /* FINISHME: Note that this doesn't work for invariant on
+          * a function signature inval
+          */
+         if (!is_varying_var(var, state->stage)) {
+            _mesa_glsl_error(&loc, state,
+                             "`%s' cannot be marked invariant; interfaces between "
+                             "shader stages only", var->name);
          }
       }
 
-- 
1.9.2



More information about the mesa-dev mailing list