[Mesa-dev] [PATCH 43/47] glsl: Add a lowering pass for 64-bit float max()

Elie Tournier tournier.elie at gmail.com
Wed Aug 23 11:08:13 UTC 2017


Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
---
 src/compiler/glsl/lower_instructions.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp
index 76dde68c23..c6c3a627d3 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 min_to_less(ir_expression *ir);
+   void max_to_less(ir_expression *ir);
 
    ir_expression *_carry(operand a, operand b);
 };
@@ -1645,6 +1646,20 @@ lower_instructions_visitor::min_to_less(ir_expression *ir)
    this->progress = true;
 }
 
+void
+lower_instructions_visitor::max_to_less(ir_expression *ir)
+{
+   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();
+   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)
 {
@@ -1794,6 +1809,12 @@ lower_instructions_visitor::visit_leave(ir_expression *ir)
          min_to_less(ir);
       break;
 
+   case ir_binop_max:
+      if (lowering(MIN_MAX_TO_LESS) &&
+          ir->type->is_double() && ir->type->is_scalar())
+         max_to_less(ir);
+      break;
+
    default:
       return visit_continue;
    }
-- 
2.14.1



More information about the mesa-dev mailing list