summaryrefslogtreecommitdiff
path: root/src/glsl/ir_validate.cpp
diff options
context:
space:
mode:
authorLuca Barbieri <luca@luca-barbieri.com>2010-09-08 01:31:39 +0200
committerIan Romanick <ian.d.romanick@intel.com>2010-09-13 17:53:04 -0700
commit4dfb89904c0a3d2166e9a3fc0253a254680e91bc (patch)
treecbdcd0ef976c8cb33d604a29caf10bec1571af3b /src/glsl/ir_validate.cpp
parent2cdbced10d98214616bcc5f960b21185c433d23b (diff)
glsl: introduce ir_binop_all_equal and ir_binop_any_equal, allow vector cmps
Currently GLSL IR forbids any vector comparisons, and defines "ir_binop_equal" and "ir_binop_nequal" to compare all elements and give a single bool. This is highly unintuitive and prevents generation of optimal Mesa IR. Hence, first rename "ir_binop_equal" to "ir_binop_all_equal" and "ir_binop_nequal" to "ir_binop_any_nequal". Second, readd "ir_binop_equal" and "ir_binop_nequal" with the same semantics as less, lequal, etc. Third, allow all comparisons to acts on vectors. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Diffstat (limited to 'src/glsl/ir_validate.cpp')
-rw-r--r--src/glsl/ir_validate.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
index 445169f520..1c50957d13 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -293,24 +293,30 @@ ir_validate::visit_leave(ir_expression *ir)
assert(ir->operands[0]->type == ir->type);
}
break;
+
case ir_binop_less:
case ir_binop_greater:
case ir_binop_lequal:
case ir_binop_gequal:
- /* GLSL < > <= >= operators take scalar floats/ints, but in the
- * IR we may want to do them for vectors instead to support the
- * lessEqual() and friends builtins.
+ case ir_binop_equal:
+ case ir_binop_nequal:
+ /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
+ * ==, and != operators. The IR operators perform a component-wise
+ * comparison on scalar or vector types and return a boolean scalar or
+ * vector type of the same size.
*/
- assert(ir->type == glsl_type::bool_type);
+ assert(ir->type->base_type == GLSL_TYPE_BOOL);
assert(ir->operands[0]->type == ir->operands[1]->type);
+ assert(ir->operands[0]->type->is_vector()
+ || ir->operands[0]->type->is_scalar());
+ assert(ir->operands[0]->type->vector_elements
+ == ir->type->vector_elements);
break;
- case ir_binop_equal:
- case ir_binop_nequal:
- /* GLSL == and != operate on vectors and return a bool, and the
- * IR matches that. We may want to switch up the IR to work on
- * vectors and return a bvec and make the operators break down
- * to ANDing/ORing the results of the vector comparison.
+ case ir_binop_all_equal:
+ case ir_binop_any_nequal:
+ /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
+ * return a scalar boolean. The IR matches that.
*/
assert(ir->type == glsl_type::bool_type);
assert(ir->operands[0]->type == ir->operands[1]->type);