glsl: Extend ir_constant::zero to handle more types.
authorOlivier Galibert <galibert@pobox.com>
Wed, 2 May 2012 21:11:37 +0000 (23:11 +0200)
committerKenneth Graunke <kenneth@whitecape.org>
Tue, 8 May 2012 19:55:38 +0000 (12:55 -0700)
Signed-off-by: Olivier Galibert <galibert@pobox.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net> [v1]
src/glsl/ir.cpp

index 1ba87515ea7024061b3a6905f7f95a7286bd8a20..d0a6d09ebe082ae8bbe5fdc2103c62994b11fdf4 100644 (file)
@@ -716,12 +716,27 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
 ir_constant *
 ir_constant::zero(void *mem_ctx, const glsl_type *type)
 {
-   assert(type->is_numeric() || type->is_boolean());
+   assert(type->is_scalar() || type->is_vector() || type->is_matrix()
+         || type->is_record() || type->is_array());
 
    ir_constant *c = new(mem_ctx) ir_constant;
    c->type = type;
    memset(&c->value, 0, sizeof(c->value));
 
+   if (type->is_array()) {
+      c->array_elements = ralloc_array(c, ir_constant *, type->length);
+
+      for (unsigned i = 0; i < type->length; i++)
+        c->array_elements[i] = ir_constant::zero(c, type->element_type());
+   }
+
+   if (type->is_record()) {
+      for (unsigned i = 0; i < type->length; i++) {
+        ir_constant *comp = ir_constant::zero(mem_ctx, type->fields.structure[i].type);
+        c->components.push_tail(comp);
+      }
+   }
+
    return c;
 }