[Mesa-dev] [PATCH 45/50] glsl: Add a lowering pass for 64-bit float frac()

Dave Airlie airlied at gmail.com
Tue Mar 13 04:25:10 UTC 2018


From: Elie Tournier <tournier.elie at gmail.com>

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

diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp
index 3064eef..94b262d 100644
--- a/src/compiler/glsl/lower_instructions.cpp
+++ b/src/compiler/glsl/lower_instructions.cpp
@@ -181,6 +181,7 @@ private:
    void dmax_to_less(ir_expression *ir);
    void dfloor_to_dtrunc(ir_expression *ir);
    void dceil_to_dtrunc(ir_expression *ir);
+   void dfrac_to_dtrunc(ir_expression *ir);
 
    ir_expression *_carry(operand a, operand b);
 };
@@ -1761,6 +1762,24 @@ lower_instructions_visitor::dceil_to_dtrunc(ir_expression *ir)
    this->progress = true;
 }
 
+void
+lower_instructions_visitor::dfrac_to_dtrunc(ir_expression *ir)
+{
+   ir_expression *const floor_expr =
+      new(ir) ir_expression(ir_unop_floor,
+                            ir->operands[0]->type, ir->operands[0]);
+   dfloor_to_dtrunc(floor_expr);
+   ir_expression *const neg_expr =
+      new(ir) ir_expression(ir_unop_neg,
+                            ir->operands[0]->type, floor_expr);
+
+   ir->operation = ir_binop_add;
+   ir->init_num_operands();
+   ir->operands[1] = neg_expr;
+
+   this->progress = true;
+}
+
 ir_visitor_status
 lower_instructions_visitor::visit_leave(ir_expression *ir)
 {
@@ -1926,6 +1945,12 @@ lower_instructions_visitor::visit_leave(ir_expression *ir)
          dmax_to_less(ir);
       break;
 
+   case ir_unop_fract:
+      if (lowering(DOPS_TO_DTRUNC) &&
+          ir->type->is_double())
+         dfrac_to_dtrunc(ir);
+      break;
+
    default:
       return visit_continue;
    }
-- 
2.9.5



More information about the mesa-dev mailing list