glsl: Make sure gl_ClipDistance and gl_ClipVertex are not both written.
authorPaul Berry <stereotype441@gmail.com>
Fri, 12 Aug 2011 01:10:22 +0000 (18:10 -0700)
committerPaul Berry <stereotype441@gmail.com>
Thu, 8 Sep 2011 16:38:03 +0000 (09:38 -0700)
From section 7.1 (Vertex Shader Special Variables) of the GLSL 1.30
spec:

  "It is an error for a shader to statically write both
  gl_ClipVertex and gl_ClipDistance."

Fixes piglit test mixing-clip-distance-and-clip-vertex-disallowed.c.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/linker.cpp

index ba81c59ff2ca021c440113ef10a7c424bd2098cc..195f58f29c6bb191aaa4d1e73a9080343a6071c7 100644 (file)
@@ -262,6 +262,25 @@ validate_vertex_shader_executable(struct gl_shader_program *prog,
       return false;
    }
 
+   if (prog->Version >= 130) {
+      /* From section 7.1 (Vertex Shader Special Variables) of the
+       * GLSL 1.30 spec:
+       *
+       *   "It is an error for a shader to statically write both
+       *   gl_ClipVertex and gl_ClipDistance."
+       */
+      find_assignment_visitor clip_vertex("gl_ClipVertex");
+      find_assignment_visitor clip_distance("gl_ClipDistance");
+
+      clip_vertex.run(shader->ir);
+      clip_distance.run(shader->ir);
+      if (clip_vertex.variable_found() && clip_distance.variable_found()) {
+         linker_error(prog, "vertex shader writes to both `gl_ClipVertex' "
+                      "and `gl_ClipDistance'\n");
+         return false;
+      }
+   }
+
    return true;
 }