aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/ir_constant_expression.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl/ir_constant_expression.cpp')
-rwxr-xr-xmesalib/src/glsl/ir_constant_expression.cpp205
1 files changed, 104 insertions, 101 deletions
diff --git a/mesalib/src/glsl/ir_constant_expression.cpp b/mesalib/src/glsl/ir_constant_expression.cpp
index 48cf47f53..f5cb12343 100755
--- a/mesalib/src/glsl/ir_constant_expression.cpp
+++ b/mesalib/src/glsl/ir_constant_expression.cpp
@@ -379,8 +379,104 @@ unpack_half_1x16(uint16_t u)
return _mesa_half_to_float(u);
}
+/**
+ * Get the constant that is ultimately referenced by an r-value, in a constant
+ * expression evaluation context.
+ *
+ * The offset is used when the reference is to a specific column of a matrix.
+ */
+static bool
+constant_referenced(const ir_dereference *deref,
+ struct hash_table *variable_context,
+ ir_constant *&store, int &offset)
+{
+ store = NULL;
+ offset = 0;
+
+ if (variable_context == NULL)
+ return false;
+
+ switch (deref->ir_type) {
+ case ir_type_dereference_array: {
+ const ir_dereference_array *const da =
+ (const ir_dereference_array *) deref;
+
+ ir_constant *const index_c =
+ da->array_index->constant_expression_value(variable_context);
+
+ if (!index_c || !index_c->type->is_scalar() || !index_c->type->is_integer())
+ break;
+
+ const int index = index_c->type->base_type == GLSL_TYPE_INT ?
+ index_c->get_int_component(0) :
+ index_c->get_uint_component(0);
+
+ ir_constant *substore;
+ int suboffset;
+
+ const ir_dereference *const deref = da->array->as_dereference();
+ if (!deref)
+ break;
+
+ if (!constant_referenced(deref, variable_context, substore, suboffset))
+ break;
+
+ const glsl_type *const vt = da->array->type;
+ if (vt->is_array()) {
+ store = substore->get_array_element(index);
+ offset = 0;
+ } else if (vt->is_matrix()) {
+ store = substore;
+ offset = index * vt->vector_elements;
+ } else if (vt->is_vector()) {
+ store = substore;
+ offset = suboffset + index;
+ }
+
+ break;
+ }
+
+ case ir_type_dereference_record: {
+ const ir_dereference_record *const dr =
+ (const ir_dereference_record *) deref;
+
+ const ir_dereference *const deref = dr->record->as_dereference();
+ if (!deref)
+ break;
+
+ ir_constant *substore;
+ int suboffset;
+
+ if (!constant_referenced(deref, variable_context, substore, suboffset))
+ break;
+
+ /* Since we're dropping it on the floor...
+ */
+ assert(suboffset == 0);
+
+ store = substore->get_record_field(dr->field);
+ break;
+ }
+
+ case ir_type_dereference_variable: {
+ const ir_dereference_variable *const dv =
+ (const ir_dereference_variable *) deref;
+
+ store = (ir_constant *) hash_table_find(variable_context, dv->var);
+ break;
+ }
+
+ default:
+ assert(!"Should not get here.");
+ break;
+ }
+
+ return store != NULL;
+}
+
+
ir_constant *
-ir_rvalue::constant_expression_value(struct hash_table *variable_context)
+ir_rvalue::constant_expression_value(struct hash_table *)
{
assert(this->type->is_error());
return NULL;
@@ -1527,7 +1623,7 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
ir_constant *
-ir_texture::constant_expression_value(struct hash_table *variable_context)
+ir_texture::constant_expression_value(struct hash_table *)
{
/* texture lookups aren't constant expressions */
return NULL;
@@ -1563,19 +1659,6 @@ ir_swizzle::constant_expression_value(struct hash_table *variable_context)
}
-void
-ir_dereference_variable::constant_referenced(struct hash_table *variable_context,
- ir_constant *&store, int &offset) const
-{
- if (variable_context) {
- store = (ir_constant *)hash_table_find(variable_context, var);
- offset = 0;
- } else {
- store = NULL;
- offset = 0;
- }
-}
-
ir_constant *
ir_dereference_variable::constant_expression_value(struct hash_table *variable_context)
{
@@ -1603,60 +1686,6 @@ ir_dereference_variable::constant_expression_value(struct hash_table *variable_c
}
-void
-ir_dereference_array::constant_referenced(struct hash_table *variable_context,
- ir_constant *&store, int &offset) const
-{
- ir_constant *index_c = array_index->constant_expression_value(variable_context);
-
- if (!index_c || !index_c->type->is_scalar() || !index_c->type->is_integer()) {
- store = 0;
- offset = 0;
- return;
- }
-
- int index = index_c->type->base_type == GLSL_TYPE_INT ?
- index_c->get_int_component(0) :
- index_c->get_uint_component(0);
-
- ir_constant *substore;
- int suboffset;
- const ir_dereference *deref = array->as_dereference();
- if (!deref) {
- store = 0;
- offset = 0;
- return;
- }
-
- deref->constant_referenced(variable_context, substore, suboffset);
-
- if (!substore) {
- store = 0;
- offset = 0;
- return;
- }
-
- const glsl_type *vt = array->type;
- if (vt->is_array()) {
- store = substore->get_array_element(index);
- offset = 0;
- return;
- }
- if (vt->is_matrix()) {
- store = substore;
- offset = index * vt->vector_elements;
- return;
- }
- if (vt->is_vector()) {
- store = substore;
- offset = suboffset + index;
- return;
- }
-
- store = 0;
- offset = 0;
-}
-
ir_constant *
ir_dereference_array::constant_expression_value(struct hash_table *variable_context)
{
@@ -1712,33 +1741,8 @@ ir_dereference_array::constant_expression_value(struct hash_table *variable_cont
}
-void
-ir_dereference_record::constant_referenced(struct hash_table *variable_context,
- ir_constant *&store, int &offset) const
-{
- ir_constant *substore;
- int suboffset;
- const ir_dereference *deref = record->as_dereference();
- if (!deref) {
- store = 0;
- offset = 0;
- return;
- }
-
- deref->constant_referenced(variable_context, substore, suboffset);
-
- if (!substore) {
- store = 0;
- offset = 0;
- return;
- }
-
- store = substore->get_record_field(field);
- offset = 0;
-}
-
ir_constant *
-ir_dereference_record::constant_expression_value(struct hash_table *variable_context)
+ir_dereference_record::constant_expression_value(struct hash_table *)
{
ir_constant *v = this->record->constant_expression_value();
@@ -1747,7 +1751,7 @@ ir_dereference_record::constant_expression_value(struct hash_table *variable_con
ir_constant *
-ir_assignment::constant_expression_value(struct hash_table *variable_context)
+ir_assignment::constant_expression_value(struct hash_table *)
{
/* FINISHME: Handle CEs involving assignment (return RHS) */
return NULL;
@@ -1755,7 +1759,7 @@ ir_assignment::constant_expression_value(struct hash_table *variable_context)
ir_constant *
-ir_constant::constant_expression_value(struct hash_table *variable_context)
+ir_constant::constant_expression_value(struct hash_table *)
{
return this;
}
@@ -1796,9 +1800,8 @@ bool ir_function_signature::constant_expression_evaluate_expression_list(const s
ir_constant *store = NULL;
int offset = 0;
- asg->lhs->constant_referenced(variable_context, store, offset);
- if (!store)
+ if (!constant_referenced(asg->lhs, variable_context, store, offset))
return false;
ir_constant *value = asg->rhs->constant_expression_value(variable_context);
@@ -1829,9 +1832,9 @@ bool ir_function_signature::constant_expression_evaluate_expression_list(const s
ir_constant *store = NULL;
int offset = 0;
- call->return_deref->constant_referenced(variable_context, store, offset);
- if (!store)
+ if (!constant_referenced(call->return_deref, variable_context,
+ store, offset))
return false;
ir_constant *value = call->constant_expression_value(variable_context);