glsl: Error out on invalid uses of the early_fragment_tests layout qualifier.
authorFrancisco Jerez <currojerez@riseup.net>
Thu, 4 Dec 2014 08:54:13 +0000 (10:54 +0200)
committerFrancisco Jerez <currojerez@riseup.net>
Mon, 4 May 2015 14:44:16 +0000 (17:44 +0300)
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/glsl/ast_to_hir.cpp
src/glsl/ast_type.cpp
src/glsl/glsl_parser.yy

index fa05c6565bcae43c2ee6e93e6b0588a9802ba861..7051d93149e4815ebe41a6b494cde762e2ea3f4a 100644 (file)
@@ -2802,6 +2802,20 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
    }
 
    apply_image_qualifier_to_variable(qual, var, state, loc);
+
+   /* From section 4.4.1.3 of the GLSL 4.50 specification (Fragment Shader
+    * Inputs):
+    *
+    *  "Fragment shaders also allow the following layout qualifier on in only
+    *   (not with variable declarations)
+    *     layout-qualifier-id
+    *        early_fragment_tests
+    *   [...]"
+    */
+   if (qual->flags.q.early_fragment_tests) {
+      _mesa_glsl_error(loc, state, "early_fragment_tests layout qualifier only "
+                       "valid in fragment shader input layout declaration.");
+   }
 }
 
 /**
index b596cd59ecf8ce7d614f63fc823fd19ea412dd5d..34c2b735a9ffd331e85db7600fb34d405dfd27d4 100644 (file)
@@ -293,11 +293,7 @@ ast_type_qualifier::merge_in_qualifier(YYLTYPE *loc,
       valid_in_mask.flags.q.invocations = 1;
       break;
    case MESA_SHADER_FRAGMENT:
-      if (q.flags.q.early_fragment_tests) {
-         state->early_fragment_tests = true;
-      } else {
-         _mesa_glsl_error(loc, state, "invalid input layout qualifier");
-      }
+      valid_in_mask.flags.q.early_fragment_tests = 1;
       break;
    case MESA_SHADER_COMPUTE:
       create_cs_ast |=
@@ -345,6 +341,10 @@ ast_type_qualifier::merge_in_qualifier(YYLTYPE *loc,
       this->invocations = q.invocations;
    }
 
+   if (q.flags.q.early_fragment_tests) {
+      state->early_fragment_tests = true;
+   }
+
    if (create_gs_ast) {
       node = new(mem_ctx) ast_gs_input_layout(*loc, q.prim_type);
    } else if (create_cs_ast) {
index c305889e10561e9c608aac1de8598d2f82da4c64..a3ba3f6d0ff95a15a6656595e2f0496b9eefa75b 100644 (file)
@@ -1366,6 +1366,21 @@ layout_qualifier_id:
 
          if (!$$.flags.i &&
              match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
+            /* From section 4.4.1.3 of the GLSL 4.50 specification
+             * (Fragment Shader Inputs):
+             *
+             *  "Fragment shaders also allow the following layout
+             *   qualifier on in only (not with variable declarations)
+             *     layout-qualifier-id
+             *        early_fragment_tests
+             *   [...]"
+             */
+            if (state->stage != MESA_SHADER_FRAGMENT) {
+               _mesa_glsl_error(& @1, state,
+                                "early_fragment_tests layout qualifier only "
+                                "valid in fragment shaders");
+            }
+
             $$.flags.q.early_fragment_tests = 1;
          }
       }