Mesa (glsl2): glsl2: Add support for the .length() method on arrays.

Ian Romanick idr at kemper.freedesktop.org
Wed Jul 21 00:21:54 UTC 2010


Module: Mesa
Branch: glsl2
Commit: 094cf8c199930d958d9e1139467eb8579d082df6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=094cf8c199930d958d9e1139467eb8579d082df6

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Sat Jul 17 22:50:26 2010 -0700

glsl2: Add support for the .length() method on arrays.

Fixes piglit test glsl-array-length, and provides proper error messages
for negative piglit tests array-length-110.frag, array-length-unsized.frag,
and array-length-args.frag.

---

 src/glsl/hir_field_selection.cpp |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/glsl/hir_field_selection.cpp b/src/glsl/hir_field_selection.cpp
index 5500e09..db1e069 100644
--- a/src/glsl/hir_field_selection.cpp
+++ b/src/glsl/hir_field_selection.cpp
@@ -71,6 +71,28 @@ _mesa_ast_field_selection_to_hir(const ast_expression *expr,
 			  "structure",
 			  expr->primary_expression.identifier);
       }
+   } else if (expr->subexpressions[1] != NULL) {
+      /* Handle "method calls" in GLSL 1.20 - namely, array.length() */
+      if (state->language_version < 120)
+	 _mesa_glsl_error(&loc, state, "Methods not supported in GLSL 1.10.");
+
+      ast_expression *call = expr->subexpressions[1];
+      assert(call->oper == ast_function_call);
+
+      const char *method;
+      method = call->subexpressions[0]->primary_expression.identifier;
+
+      if (op->type->is_array() && strcmp(method, "length") == 0) {
+	 if (!call->expressions.is_empty())
+	    _mesa_glsl_error(&loc, state, "length method takes no arguments.");
+
+	 if (op->type->array_size() == 0)
+	    _mesa_glsl_error(&loc, state, "length called on unsized array.");
+
+	 result = new(ctx) ir_constant(op->type->array_size());
+      } else {
+	 _mesa_glsl_error(&loc, state, "Unknown method: `%s'.", method);
+      }
    } else {
       _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
 		       "non-structure / non-vector.",




More information about the mesa-commit mailing list