summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnuj Phogat <anuj.phogat@gmail.com>2014-02-20 18:32:25 -0800
committerCarl Worth <cworth@cworth.org>2014-05-05 11:23:19 -0700
commit81f98ffb61a60525d991ba8b9b702b141b2192de (patch)
tree330994007bd458f3db2413742d6d132ac1189481
parent072a79b18893a09a2ffc44cc9ce7898a26af14f9 (diff)
glsl: Compile error if fs uses gl_FragCoord before first redeclaration
Section 4.3.8.1, page 39 of GLSL 1.50 spec says: "Within any shader, the first redeclarations of gl_FragCoord must appear before any use of gl_FragCoord." GLSL compiler should generate an error in following case: vec4 p = gl_FragCoord; layout(origin_upper_left) in vec4 gl_FragCoord; void main() { } Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com> Cc: <mesa-stable@lists.freedesktop.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> (cherry picked from commit a751adf07117ec4b3659fe60d0a833ebfcd4f840)
-rw-r--r--src/glsl/ast_to_hir.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index c04b6aeb16d..c5996faaf75 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2387,6 +2387,23 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
if (var->name != NULL && strcmp(var->name, "gl_FragCoord") == 0) {
+ /* Section 4.3.8.1, page 39 of GLSL 1.50 spec says:
+ *
+ * "Within any shader, the first redeclarations of gl_FragCoord
+ * must appear before any use of gl_FragCoord."
+ *
+ * Generate a compiler error if above condition is not met by the
+ * fragment shader.
+ */
+ ir_variable *earlier = state->symbols->get_variable("gl_FragCoord");
+ if (earlier != NULL &&
+ earlier->data.used &&
+ !state->fs_redeclares_gl_fragcoord) {
+ _mesa_glsl_error(loc, state,
+ "gl_FragCoord used before its first redeclaration "
+ "in fragment shader");
+ }
+
/* Make sure all gl_FragCoord redeclarations specify the same layout
* qualifiers.
*/