[Mesa-dev] [PATCH 05/10] glsl: Don't allow gl_FragData[i], with i>0 in GLES shaders

Eduardo Lima Mitev elima at igalia.com
Mon Dec 1 05:04:45 PST 2014


The OpenGL ES Shading Language specification describes the
values that may be output by a fragment shader. These are
gl_FragColor and gl_FragData[0]. Multiple render targets
are not supported in GLES.

Fixes dEQP test:
  * dEQP-GLES3.functional.shaders.fragdata.invalid_assign_to_1
---
 src/glsl/ast_array_index.cpp | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/glsl/ast_array_index.cpp b/src/glsl/ast_array_index.cpp
index ff0c757..b507d34 100644
--- a/src/glsl/ast_array_index.cpp
+++ b/src/glsl/ast_array_index.cpp
@@ -46,7 +46,9 @@ ast_array_specifier::print(void) const
  *
  * This function also checks whether the array is a built-in array whose
  * maximum size is too small to accommodate the given index, and if so uses
- * loc and state to report the error.
+ * loc and state to report the error. It also checks that the built-in array
+ * gl_FragData is not accessed with indexes greater than zero in OpenGL ES,
+ * where multiple render targets are not allowed.
  */
 static void
 update_max_array_access(ir_rvalue *ir, int idx, YYLTYPE *loc,
@@ -54,6 +56,23 @@ update_max_array_access(ir_rvalue *ir, int idx, YYLTYPE *loc,
 {
    if (ir_dereference_variable *deref_var = ir->as_dereference_variable()) {
       ir_variable *var = deref_var->var;
+
+      /* Page 89 in the section 3.8 (Fragment Shaders) of the the
+       * OpenGL ES 2.0.25 spec says:
+       *     "The OpenGL ES Shading Language specification describes the
+       *     values that may be output by a fragment shader. These are
+       *     gl_FragColor and gl_FragData[0].
+       *              ...
+       *     gl_FragData is supported for compatibility with the desktop
+       *     OpenGL Shading Language, but only a single fragment color
+       *     output is allowed in the OpenGL ES Shading Language."
+       */
+      if (state->es_shader && idx > 0 &&
+          strcmp(var->name, "gl_FragData") == 0) {
+         _mesa_glsl_error(loc, state,
+                          "multiple render targets are not supported");
+      }
+
       if (idx > (int)var->data.max_array_access) {
          var->data.max_array_access = idx;
 
-- 
2.1.3



More information about the mesa-dev mailing list