glsl: Check that gl_ClipDistance[] is not sized too large.
authorPaul Berry <stereotype441@gmail.com>
Thu, 11 Aug 2011 22:23:33 +0000 (15:23 -0700)
committerPaul Berry <stereotype441@gmail.com>
Thu, 8 Sep 2011 16:37:45 +0000 (09:37 -0700)
Fixes piglit tests
clip-distance-explicit-too-large-with-access.{frag,vert} and
clip-distance-explicit-too-large.{frag,vert}.

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

index fbb2c1461405ed363dd8936a3705405059fe931c..a4eaf857058795173eb63570d975b3f31f6c11d8 100644 (file)
@@ -912,6 +912,21 @@ check_builtin_array_max_size(const char *name, unsigned size,
                        "be larger than gl_MaxTextureCoords (%u)\n",
                        state->Const.MaxTextureCoords);
       return true;
+   } else if (strcmp("gl_ClipDistance", name) == 0
+              && size > state->Const.MaxClipPlanes) {
+      /* From section 7.1 (Vertex Shader Special Variables) of the
+       * GLSL 1.30 spec:
+       *
+       *   "The gl_ClipDistance array is predeclared as unsized and
+       *   must be sized by the shader either redeclaring it with a
+       *   size or indexing it only with integral constant
+       *   expressions. ... The size can be at most
+       *   gl_MaxClipDistances."
+       */
+      _mesa_glsl_error(&loc, state, "`gl_ClipDistance' array size cannot "
+                       "be larger than gl_MaxClipDistances (%u)\n",
+                       state->Const.MaxClipPlanes);
+      return true;
    }
    return false;
 }