Mesa (glsl2): ir_constant_expression: Add support for array == and !=.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Jul 22 00:21:29 UTC 2010


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

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Jul 20 03:08:32 2010 -0700

ir_constant_expression: Add support for array == and !=.

Piglit parser tests const-array-03.frag and const-array-04.frag now
generate the correct code.

---

 src/glsl/ir.cpp                     |   11 ++++++++---
 src/glsl/ir_constant_expression.cpp |   17 ++++++++++++++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index d3f7302..5054ec7 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -430,9 +430,14 @@ ir_constant::has_value(const ir_constant *c) const
    if (this->type != c->type)
       return false;
 
-   /* FINISHME: This will probably also handle constant arrays as soon as those
-    * FINISHME: are supported.
-    */
+   if (this->type->is_array()) {
+      for (unsigned i = 0; i < this->type->length; i++) {
+	 if (this->array_elements[i]->has_value(c->array_elements[i]))
+	    return false;
+      }
+      return true;
+   }
+
    if (this->type->base_type == GLSL_TYPE_STRUCT) {
       const exec_node *a_node = this->components.head;
       const exec_node *b_node = c->components.head;
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index d72a57c..5bef17c 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -73,6 +73,22 @@ ir_expression::constant_expression_value()
       components = op[1]->type->components();
    }
 
+   void *ctx = talloc_parent(this);
+
+   /* Handle array operations here, rather than below. */
+   if (op[0]->type->is_array()) {
+      assert(op[1] != NULL && op[1]->type->is_array());
+      switch (this->operation) {
+      case ir_binop_equal:
+	 return new(ctx) ir_constant(op[0]->has_value(op[1]));
+      case ir_binop_nequal:
+	 return new(ctx) ir_constant(!op[0]->has_value(op[1]));
+      default:
+	 break;
+      }
+      return NULL;
+   }
+
    switch (this->operation) {
    case ir_unop_logic_not:
       assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
@@ -616,7 +632,6 @@ ir_expression::constant_expression_value()
       return NULL;
    }
 
-   void *ctx = talloc_parent(this);
    return new(ctx) ir_constant(this->type, &data);
 }
 




More information about the mesa-commit mailing list