[Mesa-dev] [PATCH 4/5] glsl/linker: Fail if gl_FragCoord layouts don't match.

Fabian Bieler fabianbieler at fastmail.fm
Wed May 8 15:51:16 PDT 2013


Fail linking if gl_FragCoord is used with different layout qualifiers in
seperate shader objects.

This fixes Piglit test shaders/link-mismatch-layout-01.
---
 src/glsl/linker.cpp | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 2b30d2b..4415b8d 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -646,6 +646,40 @@ cross_validate_globals(struct gl_shader_program *prog,
 			    mode_string(var), var->name);
                return false;
             }
+
+	    /* Validate layout qualifiers for gl_FragCoord.
+	     *
+	     * From the ARB_fragment_coord_conventions specs:
+	     *
+	     *    "If gl_FragCoord is redeclared in any fragment shader in a program,
+	     *    it must be redeclared in all the fragment shaders in that program
+	     *    that have a static use of gl_FragCoord. All redeclarations of
+	     *    gl_FragCoord in all fragment shaders in a single program must have
+	     *    the same set of qualifiers."
+	     */
+	    if (strcmp(var->name, "gl_FragCoord") == 0) {
+	       const bool layout_differs = var->pixel_center_integer != existing->pixel_center_integer ||
+					   var->origin_upper_left != existing->origin_upper_left;
+
+	       if (var->redeclared && layout_differs) {
+		  linker_error(prog,
+			       "All redeclarations of gl_FragCoord in all "
+			       "fragment shaders in a single program must have "
+			       "the same set of qualifiers.");
+		  return false;
+	       }
+
+	       if (var->used && layout_differs) {
+		  linker_error(prog,
+			       "If gl_FragCoord is redeclared with a layout "
+			       "qualifier in any fragment shader, it must be "
+			       "redeclared with the same layout qualifier in "
+			       "all fragment shaders that read from "
+			       "gl_FragCoord.");
+		  return false;
+	       }
+	    }
+
 	 } else
 	    variables.add_variable(var);
       }
-- 
1.8.1.2



More information about the mesa-dev mailing list