From: Elie Tournier <tournier.e...@gmail.com>

[airlied: update to handle max(dvec, double) case]
Signed-off-by: Elie Tournier <elie.tourn...@collabora.com>
---
 src/compiler/glsl/lower_instructions.cpp | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/compiler/glsl/lower_instructions.cpp 
b/src/compiler/glsl/lower_instructions.cpp
index 8c3d623..144bc41 100644
--- a/src/compiler/glsl/lower_instructions.cpp
+++ b/src/compiler/glsl/lower_instructions.cpp
@@ -177,6 +177,7 @@ private:
    void imul_high_to_mul(ir_expression *ir);
    void sqrt_to_abs_sqrt(ir_expression *ir);
    void dmin_to_less(ir_expression *ir);
+   void dmax_to_less(ir_expression *ir);
 
    ir_expression *_carry(operand a, operand b);
 };
@@ -1693,6 +1694,26 @@ lower_instructions_visitor::dmin_to_less(ir_expression 
*ir)
    this->progress = true;
 }
 
+void
+lower_instructions_visitor::dmax_to_less(ir_expression *ir)
+{
+   const unsigned vec_elem = ir->type->vector_elements;
+   ir_rvalue *x_clone = ir->operands[0]->clone(ir, NULL);
+   ir_rvalue *y_clone = ir->operands[1]->clone(ir, NULL);
+   ir->operation = ir_triop_csel;
+   ir->init_num_operands();
+   if (ir->operands[1]->type->vector_elements == 1 && vec_elem > 1) {
+          ir->operands[0] = less(ir->operands[0], swizzle(ir->operands[1], 
SWIZZLE_XXXX, vec_elem));
+          ir->operands[1] = swizzle(y_clone, SWIZZLE_XXXX, vec_elem);
+   } else {
+          ir->operands[0] = less(ir->operands[0], ir->operands[1]);
+          ir->operands[1] = y_clone;
+   }
+   ir->operands[2] = x_clone;
+
+   this->progress = true;
+}
+
 ir_visitor_status
 lower_instructions_visitor::visit_leave(ir_expression *ir)
 {
@@ -1842,6 +1863,12 @@ lower_instructions_visitor::visit_leave(ir_expression 
*ir)
          dmin_to_less(ir);
       break;
 
+   case ir_binop_max:
+      if (lowering(DMIN_DMAX_TO_LESS) &&
+          ir->type->is_double())
+         dmax_to_less(ir);
+      break;
+
    default:
       return visit_continue;
    }
-- 
2.9.5

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to