Mesa (master): glsl: Compile error if fs uses gl_FragCoord before first redeclaration
Anuj Phogat
aphogat at kemper.freedesktop.org
Thu May 1 18:25:12 UTC 2014
Module: Mesa
Branch: master
Commit: a751adf07117ec4b3659fe60d0a833ebfcd4f840
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a751adf07117ec4b3659fe60d0a833ebfcd4f840
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date: Thu Feb 20 18:32:25 2014 -0800
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 at gmail.com>
Cc: <mesa-stable at lists.freedesktop.org>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/glsl/ast_to_hir.cpp | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 35220dd..f257a24 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2535,6 +2535,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.
*/
More information about the mesa-commit
mailing list