<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 19, 2016 at 3:48 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>><br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 12, 2016 at 1:05 AM, Samuel Iglesias Gonsálvez <span dir="ltr"><<a href="mailto:siglesias@igalia.com" target="_blank">siglesias@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Iago Toral Quiroga <<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>><br>
<br>
At least i965 hardware does not have native support for ceil on doubles.<br>
---<br>
 src/compiler/nir/nir.h                  |  1 +<br>
 src/compiler/nir/nir_lower_double_ops.c | 27 +++++++++++++++++++++++++++<br>
 2 files changed, 28 insertions(+)<br>
<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index b7231a7..7c9e498 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -2288,6 +2288,7 @@ typedef enum {<br>
    nir_lower_drsq = (1 << 2),<br>
    nir_lower_dtrunc = (1 << 3),<br>
    nir_lower_dfloor = (1 << 4),<br>
+   nir_lower_dceil = (1 << 5),<br>
 } nir_lower_doubles_options;<br>
<br>
 void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);<br>
diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c<br>
index e1ec6da..66e2be4 100644<br>
--- a/src/compiler/nir/nir_lower_double_ops.c<br>
+++ b/src/compiler/nir/nir_lower_double_ops.c<br>
@@ -398,6 +398,25 @@ lower_floor(nir_builder *b, nir_ssa_def *src)<br>
                               src));<br>
 }<br>
<br>
+static nir_ssa_def *<br>
+lower_ceil(nir_builder *b, nir_ssa_def *src)<br>
+{<br>
+   /* if x < 0,                    ceil(x) = trunc(x)<br>
+    * else if (x - trunc(x) == 0), ceil(x) = x<br>
+    * else,                        ceil(x) = trunc(x) + 1<br>
+    */<br>
+   nir_ssa_def *tr = nir_ftrunc(b, src);<br>
+   return nir_bcsel(b,<br>
+                    nir_flt(b, src, nir_imm_double(b, 0.0)),<br>
+                    tr,<br>
+                    nir_bcsel(b,<br>
+                              nir_fne(b,<br>
+                                      nir_fsub(b, src, tr),<br>
+                                      nir_imm_double(b, 0.0)),<br>
+                              nir_fadd(b, tr, nir_imm_double(b, 1.0)),<br>
+                              src));<br></blockquote></div></div></div></div></blockquote><div><br></div><div>The comments I made on floor() apply here as well<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
 static void<br>
 lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)<br>
 {<br>
@@ -431,6 +450,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)<br>
          return;<br>
       break;<br>
<br>
+   case nir_op_fceil:<br>
+      if (!(options & nir_lower_dceil))<br>
+         return;<br>
+      break;<br>
+<br>
    default:<br>
       return;<br>
    }<br>
@@ -460,6 +484,9 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)<br>
    case nir_op_ffloor:<br>
       result = lower_floor(&bld, src);<br>
       break;<br>
+   case nir_op_fceil:<br>
+      result = lower_ceil(&bld, src);<br>
+      break;<br>
    default:<br>
       unreachable("unhandled opcode");<br>
    }<br>
<span><font color="#888888">--<br>
2.5.0<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>