aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/opt_algebraic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl/opt_algebraic.cpp')
-rw-r--r--mesalib/src/glsl/opt_algebraic.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/mesalib/src/glsl/opt_algebraic.cpp b/mesalib/src/glsl/opt_algebraic.cpp
index d39761260..75948db16 100644
--- a/mesalib/src/glsl/opt_algebraic.cpp
+++ b/mesalib/src/glsl/opt_algebraic.cpp
@@ -84,6 +84,12 @@ is_vec_one(ir_constant *ir)
return (ir == NULL) ? false : ir->is_one();
}
+static inline bool
+is_vec_basis(ir_constant *ir)
+{
+ return (ir == NULL) ? false : ir->is_basis();
+}
+
static void
update_type(ir_expression *ir)
{
@@ -309,6 +315,31 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
}
break;
+ case ir_binop_dot:
+ if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) {
+ this->progress = true;
+ return ir_constant::zero(mem_ctx, ir->type);
+ }
+ if (is_vec_basis(op_const[0])) {
+ this->progress = true;
+ unsigned component = 0;
+ for (unsigned c = 0; c < op_const[0]->type->vector_elements; c++) {
+ if (op_const[0]->value.f[c] == 1.0)
+ component = c;
+ }
+ return new(mem_ctx) ir_swizzle(ir->operands[1], component, 0, 0, 0, 1);
+ }
+ if (is_vec_basis(op_const[1])) {
+ this->progress = true;
+ unsigned component = 0;
+ for (unsigned c = 0; c < op_const[1]->type->vector_elements; c++) {
+ if (op_const[1]->value.f[c] == 1.0)
+ component = c;
+ }
+ return new(mem_ctx) ir_swizzle(ir->operands[0], component, 0, 0, 0, 1);
+ }
+ break;
+
case ir_binop_logic_and:
/* FINISHME: Also simplify (a && a) to (a). */
if (is_vec_one(op_const[0])) {