<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 31, 2016 at 3:00 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"><span class="">From: Connor Abbott <<a href="mailto:connor.w.abbott@intel.com">connor.w.abbott@intel.com</a>><br>
<br>
v2: Undo unintended change to the signature of<br>
    nir_normalize_cubemap_coords (Iago).<br>
<br>
v3: Move to compiler/nir (Iago)<br>
<br>
</span>v4: Remove Authors from copyright header (Michael Schellenberger)<br>
<span class=""><br>
Signed-off-by: Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>><br>
---<br>
 src/compiler/Makefile.sources               |   1 +<br>
 src/compiler/glsl/Makefile.sources          |   1 +<br>
 src/compiler/nir/Makefile.sources           |   1 +<br>
 src/compiler/nir/nir.h                      |   2 +<br>
</span> src/compiler/nir/nir_lower_double_packing.c | 106 ++++++++++++++++++++++++++++<br>
 5 files changed, 111 insertions(+)<br>
<span class=""> create mode 100644 src/compiler/nir/nir_lower_double_packing.c<br>
<br>
diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources<br>
</span>index 0aee200..adb7caa 100644<br>
--- a/src/compiler/Makefile.sources<br>
+++ b/src/compiler/Makefile.sources<br>
@@ -186,6 +186,7 @@ NIR_FILES = \<br>
<span class="">        nir/nir_lower_alu_to_scalar.c \<br>
        nir/nir_lower_atomics.c \<br>
        nir/nir_lower_clip.c \<br>
+       nir/nir_lower_double_packing.c \<br>
        nir/nir_lower_global_vars_to_local.c \<br>
        nir/nir_lower_gs_intrinsics.c \<br>
        nir/nir_lower_load_const_to_scalar.c \<br>
diff --git a/src/compiler/glsl/Makefile.sources b/src/compiler/glsl/Makefile.sources<br>
</span>index 538196a..fadfab8 100644<br>
<span class="">--- a/src/compiler/glsl/Makefile.sources<br>
+++ b/src/compiler/glsl/Makefile.sources<br>
@@ -38,6 +38,7 @@ NIR_FILES = \<br>
        nir/nir_lower_alu_to_scalar.c \<br>
        nir/nir_lower_atomics.c \<br>
        nir/nir_lower_clip.c \<br>
+       nir/nir_lower_double_packing.c \<br>
        nir/nir_lower_global_vars_to_local.c \<br>
        nir/nir_lower_gs_intrinsics.c \<br>
        nir/nir_lower_load_const_to_scalar.c \<br>
diff --git a/src/compiler/nir/Makefile.sources b/src/compiler/nir/Makefile.sources<br>
</span>index 3474302..488040d 100644<br>
--- a/src/compiler/nir/Makefile.sources<br>
+++ b/src/compiler/nir/Makefile.sources<br>
@@ -29,6 +29,7 @@ NIR_FILES = \<br>
<span class="">        nir_lower_alu_to_scalar.c \<br>
        nir_lower_atomics.c \<br>
        nir_lower_clip.c \<br>
+       nir_lower_double_packing.c \<br>
        nir_lower_global_vars_to_local.c \<br>
        nir_lower_gs_intrinsics.c \<br>
        nir_lower_load_const_to_scalar.c \<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
</span>index ac709d5..4c9c16a 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -2278,6 +2278,8 @@ void nir_lower_to_source_mods(nir_shader *shader);<br>
<span class=""><br>
 bool nir_lower_gs_intrinsics(nir_shader *shader);<br>
<br>
+void nir_lower_double_pack(nir_shader *shader);<br>
+<br>
 bool nir_normalize_cubemap_coords(nir_shader *shader);<br>
<br>
 void nir_live_ssa_defs_impl(nir_function_impl *impl);<br>
diff --git a/src/compiler/nir/nir_lower_double_packing.c b/src/compiler/nir/nir_lower_double_packing.c<br>
new file mode 100644<br>
</span>index 0000000..7d8a4de<br>
--- /dev/null<br>
+++ b/src/compiler/nir/nir_lower_double_packing.c<br>
@@ -0,0 +1,106 @@<br>
<span class="im HOEnZb">+/*<br>
+ * Copyright © 2015 Intel Corporation<br>
</span><span class="im HOEnZb">+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ *<br>
</span><div class="HOEnZb"><div class="h5">+ */<br>
+<br>
+#include "nir.h"<br>
+#include "nir_builder.h"<br>
+<br>
+/*<br>
+ * lowers:<br>
+ *<br>
+ * packDouble2x32(foo) -> packDouble2x32Split(foo.x, foo.y)<br>
+ * unpackDouble2x32(foo) -> vec2(unpackDouble2x32_x(foo), unpackDouble2x32_y(foo))<br>
+ */<br>
+<br>
+static nir_ssa_def *<br>
+component(nir_builder *b, nir_ssa_def *src, unsigned component)<br>
+{<br>
+   return nir_swizzle(b, src, (unsigned[]) {component}, 1, true);<br>
+}<br></div></div></blockquote><div><br></div><div>This already exists in nir_builder.  It's called nir_channel<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">
+<br>
+static nir_ssa_def *<br>
+lower_pack_double(nir_builder *b, nir_ssa_def *src)<br>
+{<br>
+   return nir_pack_double_2x32_split(b, component(b, src, 0),<br>
+                                        component(b, src, 1));<br>
+}<br>
+<br>
+static nir_ssa_def *<br>
+lower_unpack_double(nir_builder *b, nir_ssa_def *src)<br>
+{<br>
+   return nir_vec2(b, nir_unpack_double_2x32_split_x(b, src),<br>
+                      nir_unpack_double_2x32_split_y(b, src));<br>
+}<br>
+<br>
+static void<br>
+lower_double_pack_instr(nir_alu_instr *instr)<br>
+{<br>
+   if (instr->op != nir_op_pack_double_2x32 &&<br>
+       instr->op != nir_op_unpack_double_2x32)<br>
+      return;<br>
+<br>
+   nir_builder b;<br>
+   nir_builder_init(&b, nir_cf_node_get_function(&instr->instr.block->cf_node));<br>
+   b.cursor = nir_before_instr(&instr->instr);<br>
+<br>
+   nir_ssa_def *src = nir_fmov_alu(&b, instr->src[0],<br>
+                                   nir_op_infos[instr->op].input_sizes[0]);<br></div></div></blockquote><div><br></div><div>nir_ssa_for_src in nir_builder does this.<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">
+   nir_ssa_def *dest =<br>
+      instr->op == nir_op_pack_double_2x32 ?<br>
+      lower_pack_double(&b, src) :<br>
+      lower_unpack_double(&b, src);<br>
+<br>
+   nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, nir_src_for_ssa(dest));<br>
+   nir_instr_remove(&instr->instr);<br>
+}<br>
+<br>
+static bool<br>
+lower_double_pack_block(nir_block *block, void *ctx)<br>
+{<br>
+   (void) ctx;<br>
+<br>
+   nir_foreach_instr_safe(block, instr) {<br>
+      if (instr->type != nir_instr_type_alu)<br>
+         continue;<br>
+<br>
+      lower_double_pack_instr(nir_instr_as_alu(instr));<br></div></div></blockquote><div><br></div><div>Personally, I'd just inline this.  The helper isn't really doing anything.<br><br></div><div>If you did, you could init the builder at the top or, for that matter, init it in lower_pack_impl and pass it in.  Does't much matter in the end.<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">
+   }<br>
+<br>
+   return true;<br>
+}<br>
+<br>
+static void<br>
+lower_double_pack_impl(nir_function_impl *impl)<br>
+{<br>
+   nir_foreach_block(impl, lower_double_pack_block, NULL);<br>
+}<br>
+<br>
+void<br>
+nir_lower_double_pack(nir_shader *shader)<br>
+{<br>
+   nir_foreach_function(shader, function) {<br>
+      if (function->impl)<br>
+         lower_double_pack_impl(function->impl);<br>
+   }<br>
+}<br>
+<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
2.5.0<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">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>
</div></div></blockquote></div><br></div></div>