[Mesa-dev] [PATCH 1/2] glsl: Fix redeclaration rules for gl_FragCoord.

Chris Forbes chrisf at ijw.co.nz
Sat Apr 12 22:30:06 PDT 2014


The ARB_fragment_coord_conventions spec, section 4.3.x (Input Layout
Qualifiers) says:

  "All redeclarations of gl_FragCoord in all fragment shaders in a
  single program must have the same set of qualifiers. Within any
  shader, the first redeclarations of gl_FragCoord must appear before
  any use of gl_FragCoord."

Fixes piglit's tests:
   arb_fragment_coord_conventions/compiler/redeclaration-after-use
   arb_fragment_coord_conventions/compiler/redeclaration-around-use
   glsl-1.50/compiler/fragment_coord_conventions/layout-qualifiers-conflicting-case-1
   glsl-1.50/compiler/fragment_coord_conventions/layout-qualifiers-conflicting-case-2

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

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 9b9d511..d1eb3e2 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2715,9 +2715,29 @@ get_variable_being_redeclared(ir_variable *var, YYLTYPE loc,
       /* Allow redeclaration of gl_FragCoord for ARB_fcc layout
        * qualifiers.
        */
+
+      if (earlier->data.how_declared != ir_var_declared_implicitly
+          && (earlier->data.origin_upper_left != var->data.origin_upper_left
+             || earlier->data.pixel_center_integer != var->data.pixel_center_integer)) {
+         _mesa_glsl_error(&loc, state,
+                          "Inconsistent redeclarations of gl_FragCoord");
+      }
+
       earlier->data.origin_upper_left = var->data.origin_upper_left;
       earlier->data.pixel_center_integer = var->data.pixel_center_integer;
 
+      if (earlier->data.used &&
+          earlier->data.how_declared == ir_var_declared_implicitly) {
+         /* ARB_fragment_coord_conventions spec Section 4.3.x.1
+          * (Input Layout Qualifier) says:
+          *
+          * "Within any shader, the first redeclarations of gl_FragCoord
+          * must appear before any use of gl_FragCoord."
+          */
+         _mesa_glsl_error(&loc, state,
+                          "First redeclaration of gl_FragCoord must appear before any use");
+      }
+
       /* According to section 4.3.7 of the GLSL 1.30 spec,
        * the following built-in varaibles can be redeclared with an
        * interpolation qualifier:
-- 
1.9.2



More information about the mesa-dev mailing list