Mesa (master): nir/lower_double_ops: lower fract()

Samuel Iglesias Gonsálvez samuelig at kemper.freedesktop.org
Thu Apr 28 10:02:38 UTC 2016


Module: Mesa
Branch: master
Commit: bf91df7f7ff0c07e12d49a47df3b67ee149540f9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bf91df7f7ff0c07e12d49a47df3b67ee149540f9

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Tue Jan  5 09:14:51 2016 +0100

nir/lower_double_ops: lower fract()

At least i965 hardware does not have native support for fract() on doubles.

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

---

 src/compiler/nir/nir.h                  |  1 +
 src/compiler/nir/nir_lower_double_ops.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 252567c..ac96727 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2420,6 +2420,7 @@ typedef enum {
    nir_lower_dtrunc = (1 << 3),
    nir_lower_dfloor = (1 << 4),
    nir_lower_dceil = (1 << 5),
+   nir_lower_dfract = (1 << 6)
 } nir_lower_doubles_options;
 
 void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);
diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c
index 2d94f78..f1fa2c3 100644
--- a/src/compiler/nir/nir_lower_double_ops.c
+++ b/src/compiler/nir/nir_lower_double_ops.c
@@ -383,6 +383,12 @@ lower_ceil(nir_builder *b, nir_ssa_def *src)
                     nir_fadd(b, tr, nir_imm_double(b, 1.0)));
 }
 
+static nir_ssa_def *
+lower_fract(nir_builder *b, nir_ssa_def *src)
+{
+   return nir_fsub(b, src, nir_ffloor(b, src));
+}
+
 static void
 lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
 {
@@ -421,6 +427,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
          return;
       break;
 
+   case nir_op_ffract:
+      if (!(options & nir_lower_dfract))
+         return;
+      break;
+
    default:
       return;
    }
@@ -453,6 +464,9 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
    case nir_op_fceil:
       result = lower_ceil(&bld, src);
       break;
+   case nir_op_ffract:
+      result = lower_fract(&bld, src);
+      break;
    default:
       unreachable("unhandled opcode");
    }




More information about the mesa-commit mailing list