summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2010-07-20 01:06:33 -0700
committerKenneth Graunke <[email protected]>2010-07-21 16:38:33 -0700
commit74e1802f5dd8921750851abc6128e4073602d405 (patch)
tree40e3e5f055b164a0af9993de18b7bc432775bbc1 /src/glsl
parent13a19745d46d383fa7fc148ce129150ebde151b7 (diff)
glsl2: Extend ir_constant to store constant arrays, and generate them.
Since GLSL permits arrays of structures, we need to store each element as an ir_constant*, not just ir_constant_data. Fixes parser tests const-array-01.frag, const-array-03.frag, const-array-04.frag, const-array-05.frag, though 03 and 04 generate the wrong code.
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/ast_function.cpp5
-rw-r--r--src/glsl/ir.cpp23
-rw-r--r--src/glsl/ir.h6
-rw-r--r--src/glsl/ir_clone.cpp11
4 files changed, 40 insertions, 5 deletions
diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 1982c83a430..855f27f1756 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -358,9 +358,8 @@ process_array_constructor(exec_list *instructions,
ir->replace_with(result);
}
- if (all_parameters_are_constant) {
- /* FINISHME: Add support for generating constant arrays. */
- }
+ if (all_parameters_are_constant)
+ return new(ctx) ir_constant(constructor_type, &actual_parameters);
ir_variable *var = new(ctx) ir_variable(constructor_type, "array_ctor",
ir_var_temporary);
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index a2732962f03..d3f7302b54f 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -253,9 +253,20 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
this->ir_type = ir_type_constant;
this->type = type;
- /* FINISHME: Support array types. */
assert(type->is_scalar() || type->is_vector() || type->is_matrix()
- || type->is_record());
+ || type->is_record() || type->is_array());
+
+ if (type->is_array()) {
+ this->array_elements = talloc_array(this, ir_constant *, type->length);
+ unsigned i = 0;
+ foreach_list(node, value_list) {
+ ir_constant *value = (ir_constant *) node;
+ assert(value->as_constant() != NULL);
+
+ this->array_elements[i++] = value;
+ }
+ return;
+ }
/* If the constant is a record, the types of each of the entries in
* value_list must be a 1-for-1 match with the structure components. Each
@@ -378,6 +389,14 @@ ir_constant::get_uint_component(unsigned i) const
return 0;
}
+ir_constant *
+ir_constant::get_array_element(unsigned i) const
+{
+ assert(this->type->is_array());
+ assert(i < this->type->length);
+
+ return array_elements[i];
+}
ir_constant *
ir_constant::get_record_field(const char *name)
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 3a643fc5807..c73bf4ce8b2 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1268,6 +1268,8 @@ public:
unsigned get_uint_component(unsigned i) const;
/*@}*/
+ ir_constant *get_array_element(unsigned i) const;
+
ir_constant *get_record_field(const char *name);
/**
@@ -1284,6 +1286,10 @@ public:
*/
union ir_constant_data value;
+ /* Array elements */
+ ir_constant **array_elements;
+
+ /* Structure fields */
exec_list components;
private:
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index f7e8794728c..a3e4a3ae311 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -337,6 +337,17 @@ ir_constant::clone(struct hash_table *ht) const
return c;
}
+ case GLSL_TYPE_ARRAY: {
+ ir_constant *c = new(ctx) ir_constant;
+
+ c->type = this->type;
+ c->array_elements = talloc_array(c, ir_constant *, this->type->length);
+ for (unsigned i = 0; i < this->type->length; i++) {
+ c->array_elements[i] = this->array_elements[i]->clone(NULL);
+ }
+ return c;
+ }
+
default:
assert(!"Should not get here."); break;
return NULL;