[Mesa-dev] [PATCH 2/5] Add a variable context to constant_expression_value().
Olivier Galibert
galibert at pobox.com
Fri Apr 27 01:28:01 PDT 2012
Signed-off-by: Olivier Galibert <galibert at pobox.com>
---
src/glsl/ir.h | 24 +++++++++++++----------
src/glsl/ir_constant_expression.cpp | 36 +++++++++++++++++++++--------------
2 files changed, 36 insertions(+), 24 deletions(-)
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index ddfaf36..6e67085 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -146,7 +146,7 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
virtual ir_rvalue * as_rvalue()
{
@@ -763,7 +763,7 @@ public:
virtual ir_assignment *clone(void *mem_ctx, struct hash_table *ht) const;
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
virtual void accept(ir_visitor *v)
{
@@ -999,10 +999,14 @@ public:
/**
* Attempt to constant-fold the expression
*
+ * The "variable_context" hash table links variable names (strings)
+ * to ir_constant * and represent the variables values. \c NULL
+ * represents an empty context.
+ *
* If the expression cannot be constant folded, this method will return
* \c NULL.
*/
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
/**
* Determine the number of operands used by an expression
@@ -1065,7 +1069,7 @@ public:
virtual ir_call *clone(void *mem_ctx, struct hash_table *ht) const;
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
virtual ir_call *as_call()
{
@@ -1297,7 +1301,7 @@ public:
virtual ir_texture *clone(void *mem_ctx, struct hash_table *) const;
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
virtual void accept(ir_visitor *v)
{
@@ -1389,7 +1393,7 @@ public:
virtual ir_swizzle *clone(void *mem_ctx, struct hash_table *) const;
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
virtual ir_swizzle *as_swizzle()
{
@@ -1456,7 +1460,7 @@ public:
virtual ir_dereference_variable *clone(void *mem_ctx,
struct hash_table *) const;
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
virtual ir_dereference_variable *as_dereference_variable()
{
@@ -1505,7 +1509,7 @@ public:
virtual ir_dereference_array *clone(void *mem_ctx,
struct hash_table *) const;
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
virtual ir_dereference_array *as_dereference_array()
{
@@ -1544,7 +1548,7 @@ public:
virtual ir_dereference_record *clone(void *mem_ctx,
struct hash_table *) const;
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
/**
* Get the variable that is ultimately referenced by an r-value
@@ -1609,7 +1613,7 @@ public:
virtual ir_constant *clone(void *mem_ctx, struct hash_table *) const;
- virtual ir_constant *constant_expression_value();
+ virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
virtual ir_constant *as_constant()
{
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index 4e1714a..ee1cc1a 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -38,6 +38,7 @@
#include "ir.h"
#include "ir_visitor.h"
#include "glsl_types.h"
+#include "program/hash_table.h"
/* Using C99 rounding functions for roundToEven() implementation is
* difficult, because round(), rint, and nearbyint() are affected by
@@ -71,14 +72,14 @@ dot(ir_constant *op0, ir_constant *op1)
}
ir_constant *
-ir_rvalue::constant_expression_value()
+ir_rvalue::constant_expression_value(struct hash_table *variable_context)
{
assert(this->type->is_error());
return NULL;
}
ir_constant *
-ir_expression::constant_expression_value()
+ir_expression::constant_expression_value(struct hash_table *variable_context)
{
if (this->type->is_error())
return NULL;
@@ -89,7 +90,7 @@ ir_expression::constant_expression_value()
memset(&data, 0, sizeof(data));
for (unsigned operand = 0; operand < this->get_num_operands(); operand++) {
- op[operand] = this->operands[operand]->constant_expression_value();
+ op[operand] = this->operands[operand]->constant_expression_value(variable_context);
if (!op[operand])
return NULL;
}
@@ -886,7 +887,7 @@ ir_expression::constant_expression_value()
ir_constant *
-ir_texture::constant_expression_value()
+ir_texture::constant_expression_value(struct hash_table *variable_context)
{
/* texture lookups aren't constant expressions */
return NULL;
@@ -894,9 +895,9 @@ ir_texture::constant_expression_value()
ir_constant *
-ir_swizzle::constant_expression_value()
+ir_swizzle::constant_expression_value(struct hash_table *variable_context)
{
- ir_constant *v = this->val->constant_expression_value();
+ ir_constant *v = this->val->constant_expression_value(variable_context);
if (v != NULL) {
ir_constant_data data = { { 0 } };
@@ -923,12 +924,19 @@ ir_swizzle::constant_expression_value()
ir_constant *
-ir_dereference_variable::constant_expression_value()
+ir_dereference_variable::constant_expression_value(struct hash_table *variable_context)
{
/* This may occur during compile and var->type is glsl_type::error_type */
if (!var)
return NULL;
+ /* Give priority to the context hashtable, if it exists */
+ if (variable_context) {
+ ir_constant *value = (ir_constant *)hash_table_find(variable_context, var->name);
+ if(value)
+ return value;
+ }
+
/* The constant_value of a uniform variable is its initializer,
* not the lifetime constant value of the uniform.
*/
@@ -943,10 +951,10 @@ ir_dereference_variable::constant_expression_value()
ir_constant *
-ir_dereference_array::constant_expression_value()
+ir_dereference_array::constant_expression_value(struct hash_table *variable_context)
{
- ir_constant *array = this->array->constant_expression_value();
- ir_constant *idx = this->array_index->constant_expression_value();
+ ir_constant *array = this->array->constant_expression_value(variable_context);
+ ir_constant *idx = this->array_index->constant_expression_value(variable_context);
if ((array != NULL) && (idx != NULL)) {
void *ctx = ralloc_parent(this);
@@ -998,7 +1006,7 @@ ir_dereference_array::constant_expression_value()
ir_constant *
-ir_dereference_record::constant_expression_value()
+ir_dereference_record::constant_expression_value(struct hash_table *variable_context)
{
ir_constant *v = this->record->constant_expression_value();
@@ -1007,7 +1015,7 @@ ir_dereference_record::constant_expression_value()
ir_constant *
-ir_assignment::constant_expression_value()
+ir_assignment::constant_expression_value(struct hash_table *variable_context)
{
/* FINISHME: Handle CEs involving assignment (return RHS) */
return NULL;
@@ -1015,14 +1023,14 @@ ir_assignment::constant_expression_value()
ir_constant *
-ir_constant::constant_expression_value()
+ir_constant::constant_expression_value(struct hash_table *variable_context)
{
return this;
}
ir_constant *
-ir_call::constant_expression_value()
+ir_call::constant_expression_value(struct hash_table *variable_context)
{
return this->callee->constant_expression_value(&this->actual_parameters);
}
--
1.7.10.280.gaa39
More information about the mesa-dev
mailing list