aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/ir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl/ir.cpp')
-rw-r--r--mesalib/src/glsl/ir.cpp105
1 files changed, 24 insertions, 81 deletions
diff --git a/mesalib/src/glsl/ir.cpp b/mesalib/src/glsl/ir.cpp
index 8af58b847..77638ef26 100644
--- a/mesalib/src/glsl/ir.cpp
+++ b/mesalib/src/glsl/ir.cpp
@@ -1122,27 +1122,31 @@ ir_constant::has_value(const ir_constant *c) const
}
bool
-ir_constant::is_zero() const
+ir_constant::is_value(float f, int i) const
{
if (!this->type->is_scalar() && !this->type->is_vector())
return false;
+ /* Only accept boolean values for 0/1. */
+ if (int(bool(i)) != i && this->type->is_boolean())
+ return false;
+
for (unsigned c = 0; c < this->type->vector_elements; c++) {
switch (this->type->base_type) {
case GLSL_TYPE_FLOAT:
- if (this->value.f[c] != 0.0)
+ if (this->value.f[c] != f)
return false;
break;
case GLSL_TYPE_INT:
- if (this->value.i[c] != 0)
+ if (this->value.i[c] != i)
return false;
break;
case GLSL_TYPE_UINT:
- if (this->value.u[c] != 0)
+ if (this->value.u[c] != unsigned(i))
return false;
break;
case GLSL_TYPE_BOOL:
- if (this->value.b[c] != false)
+ if (this->value.b[c] != bool(i))
return false;
break;
default:
@@ -1159,76 +1163,21 @@ ir_constant::is_zero() const
}
bool
-ir_constant::is_one() const
+ir_constant::is_zero() const
{
- if (!this->type->is_scalar() && !this->type->is_vector())
- return false;
-
- for (unsigned c = 0; c < this->type->vector_elements; c++) {
- switch (this->type->base_type) {
- case GLSL_TYPE_FLOAT:
- if (this->value.f[c] != 1.0)
- return false;
- break;
- case GLSL_TYPE_INT:
- if (this->value.i[c] != 1)
- return false;
- break;
- case GLSL_TYPE_UINT:
- if (this->value.u[c] != 1)
- return false;
- break;
- case GLSL_TYPE_BOOL:
- if (this->value.b[c] != true)
- return false;
- break;
- default:
- /* The only other base types are structures, arrays, and samplers.
- * Samplers cannot be constants, and the others should have been
- * filtered out above.
- */
- assert(!"Should not get here.");
- return false;
- }
- }
+ return is_value(0.0, 0);
+}
- return true;
+bool
+ir_constant::is_one() const
+{
+ return is_value(1.0, 1);
}
bool
ir_constant::is_negative_one() const
{
- if (!this->type->is_scalar() && !this->type->is_vector())
- return false;
-
- if (this->type->is_boolean())
- return false;
-
- for (unsigned c = 0; c < this->type->vector_elements; c++) {
- switch (this->type->base_type) {
- case GLSL_TYPE_FLOAT:
- if (this->value.f[c] != -1.0)
- return false;
- break;
- case GLSL_TYPE_INT:
- if (this->value.i[c] != -1)
- return false;
- break;
- case GLSL_TYPE_UINT:
- if (int(this->value.u[c]) != -1)
- return false;
- break;
- default:
- /* The only other base types are structures, arrays, samplers, and
- * booleans. Samplers cannot be constants, and the others should
- * have been filtered out above.
- */
- assert(!"Should not get here.");
- return false;
- }
- }
-
- return true;
+ return is_value(-1.0, -1);
}
bool
@@ -1700,13 +1649,10 @@ modes_match(unsigned a, unsigned b)
const char *
ir_function_signature::qualifiers_match(exec_list *params)
{
- exec_list_iterator iter_a = parameters.iterator();
- exec_list_iterator iter_b = params->iterator();
-
/* check that the qualifiers match. */
- while (iter_a.has_next()) {
- ir_variable *a = (ir_variable *)iter_a.get();
- ir_variable *b = (ir_variable *)iter_b.get();
+ foreach_two_lists(a_node, &this->parameters, b_node, params) {
+ ir_variable *a = (ir_variable *) a_node;
+ ir_variable *b = (ir_variable *) b_node;
if (a->data.read_only != b->data.read_only ||
!modes_match(a->data.mode, b->data.mode) ||
@@ -1717,9 +1663,6 @@ ir_function_signature::qualifiers_match(exec_list *params)
/* parameter a's qualifiers don't match */
return a->name;
}
-
- iter_a.next();
- iter_b.next();
}
return NULL;
}
@@ -1768,8 +1711,8 @@ ir_rvalue::error_value(void *mem_ctx)
void
visit_exec_list(exec_list *list, ir_visitor *visitor)
{
- foreach_iter(exec_list_iterator, iter, *list) {
- ((ir_instruction *)iter.get())->accept(visitor);
+ foreach_list_safe(n, list) {
+ ((ir_instruction *) n)->accept(visitor);
}
}
@@ -1790,8 +1733,8 @@ steal_memory(ir_instruction *ir, void *new_ctx)
*/
if (constant != NULL) {
if (constant->type->is_record()) {
- foreach_iter(exec_list_iterator, iter, constant->components) {
- ir_constant *field = (ir_constant *)iter.get();
+ foreach_list(n, &constant->components) {
+ ir_constant *field = (ir_constant *) n;
steal_memory(field, ir);
}
} else if (constant->type->is_array()) {