Mesa (master): glsl: allow invariant on fragment shader outputs.

Andres Gomez tanty at kemper.freedesktop.org
Tue Dec 20 10:11:05 UTC 2016


Module: Mesa
Branch: master
Commit: ab8ea1b3d481ff39fbfc2b75a63b24838aaf7476
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ab8ea1b3d481ff39fbfc2b75a63b24838aaf7476

Author: Dave Airlie <airlied at redhat.com>
Date:   Mon May 23 14:18:03 2016 +1000

glsl: allow invariant on fragment shader outputs.

>From page 27 (page 33 of the PDF) of the GLSL 1.20 spec:

    " Only variables output from a vertex shader can be candidates for
      invariance."

But this later changes to:

>From page 37 (page 43 of the PDF) of the GLSL 1.30 spec:

    " Only variables output from a shader can be candidates for
      invariance."

We can also find:

>From page 37 (page 43 of the PDF) of the GLSL 1.30 spec:

    " Initially, by default, all output variables are allowed to be
      variant. To force all output variables to be invariant, use the
      pragma

        #pragma STDGL invariant(all)

      before all declarations in a shader. If this pragma is used after
      the declaration of any variables or functions, then the set of
      outputs that behave as invariant is undefined. It is an error to
      use this pragma in a fragment shader."

But this needs to be corrected and it is being addressed at:
https://cvs.khronos.org/bugzilla/show_bug.cgi?id=16140

Fixes GL45-CTS.shading_language_420pack.qualifier_order.

Signed-off-by: Dave Airlie <airlied at redhat.com>
Reviewed-by: Andres Gomez <agomez at igalia.com>

---

 src/compiler/glsl/ast_to_hir.cpp | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 1e14d27..9c63386 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -2634,6 +2634,28 @@ is_varying_var(ir_variable *var, gl_shader_stage target)
    }
 }
 
+static bool
+is_allowed_invariant(ir_variable *var, struct _mesa_glsl_parse_state *state)
+{
+   if (is_varying_var(var, state->stage))
+      return true;
+
+   /* From Section 4.6.1 ("The Invariant Qualifier") GLSL 1.20 spec:
+    * "Only variables output from a vertex shader can be candidates
+    * for invariance".
+    */
+   if (!state->is_version(130, 0))
+      return false;
+
+   /*
+    * Later specs remove this language - so allowed invariant
+    * on fragment shader outputs as well.
+    */
+   if (state->stage == MESA_SHADER_FRAGMENT &&
+       var->data.mode == ir_var_shader_out)
+      return true;
+   return false;
+}
 
 /**
  * Matrix layout qualifiers are only allowed on certain types
@@ -4495,7 +4517,7 @@ ast_declarator_list::hir(exec_list *instructions,
             _mesa_glsl_error(& loc, state,
                              "undeclared variable `%s' cannot be marked "
                              "invariant", decl->identifier);
-         } else if (!is_varying_var(earlier, state->stage)) {
+         } else if (!is_allowed_invariant(earlier, state)) {
             _mesa_glsl_error(&loc, state,
                              "`%s' cannot be marked invariant; interfaces between "
                              "shader stages only.", decl->identifier);
@@ -4791,7 +4813,7 @@ ast_declarator_list::hir(exec_list *instructions,
       }
 
       if (this->type->qualifier.flags.q.invariant) {
-         if (!is_varying_var(var, state->stage)) {
+         if (!is_allowed_invariant(var, state)) {
             _mesa_glsl_error(&loc, state,
                              "`%s' cannot be marked invariant; interfaces between "
                              "shader stages only", var->name);




More information about the mesa-commit mailing list