From 2d1789e667c4180777829f96856daf91326721b9 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 6 Jul 2010 17:11:03 -0700 Subject: ir_to_mesa: Add support for conditional moves. Nothing generates conditional moves yet. --- src/mesa/shader/ir_to_mesa.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp index e1b0397dde..021e270f18 100644 --- a/src/mesa/shader/ir_to_mesa.cpp +++ b/src/mesa/shader/ir_to_mesa.cpp @@ -286,6 +286,20 @@ ir_to_mesa_dst_reg_from_src(ir_to_mesa_src_reg reg) return dst_reg; } +inline ir_to_mesa_src_reg +ir_to_mesa_src_reg_from_dst(ir_to_mesa_dst_reg reg) +{ + ir_to_mesa_src_reg src_reg; + + src_reg.file = reg.file; + src_reg.index = reg.index; + src_reg.swizzle = SWIZZLE_XYZW; + src_reg.negate = 0; + src_reg.reladdr = 0; + + return src_reg; +} + /** * Emits Mesa scalar opcodes to produce unique answers across channels. * @@ -1192,14 +1206,22 @@ ir_to_mesa_visitor::visit(ir_assignment *ir) assert(r.file != PROGRAM_UNDEFINED); if (ir->condition) { - ir_constant *condition_constant; + ir_to_mesa_src_reg condition; - condition_constant = ir->condition->constant_expression_value(); + ir->condition->accept(this); + condition = this->result; - assert(condition_constant && condition_constant->value.b[0]); + /* We use the OPCODE_CMP (a < 0 ? b : c) for conditional moves, + * and the condition we produced is 0.0 or 1.0. By flipping the + * sign, we can choose which value OPCODE_CMP produces without + * an extra computing the condition. + */ + condition.negate = ~condition.negate; + ir_to_mesa_emit_op3(ir, OPCODE_CMP, l, + condition, r, ir_to_mesa_src_reg_from_dst(l)); + } else { + ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); } - - ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); } -- cgit v1.2.3