<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Oct 12, 2017 at 11:38 AM, Jose Maria Casanova Crespo <span dir="ltr"><<a href="mailto:jmcasanova@igalia.com" target="_blank">jmcasanova@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: Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>><br>
<br>
We need to rely on byte scattered writes as untyped writes are 32-bit<br>
size. We could try to keep using 32-bit messages when we have two or<br>
four 16-bit elements, but for simplicity sake, we use the same message<br>
for any component number. We revisit this in this serie.<br>
<br>
v2: Removed use of stride = 2 on 16-bit sources (Jason Ekstrand)<br>
<br>
Signed-off-by: Jose Maria Casanova Crespo <<a href="mailto:jmcasanova@igalia.com">jmcasanova@igalia.com</a>><br>
Signed-off-by: Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a><br>
---<br>
 src/intel/compiler/brw_fs_nir.<wbr>cpp | 35 +++++++++++++++++++++++++++++-<wbr>-----<br>
 1 file changed, 29 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/src/intel/compiler/brw_fs_<wbr>nir.cpp b/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
index e108b5517b..13c16fc912 100644<br>
--- a/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
+++ b/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
@@ -28,6 +28,7 @@<br>
<br>
 using namespace brw;<br>
 using namespace brw::surface_access;<br>
+using namespace brw::scattered_access;<br>
<br>
 void<br>
 fs_visitor::emit_nir_code()<br>
@@ -4085,8 +4086,15 @@ fs_visitor::nir_emit_<wbr>intrinsic(const fs_builder &bld, nir_intrinsic_instr *instr<br>
           * length of the write to what we can do and let the next iteration<br>
           * handle the rest<br>
           */<br>
-         if (type_size > 4)<br>
+         if (type_size > 4) {<br></blockquote></div><div class="gmail_quote"><br></div><div class="gmail_quote">Maybe move the above comment to here.<br></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
             length = MIN2(2, length);<br>
+         } else if (type_size == 2) {<br>
+            /* For 16-bit types we are using byte scattered writes, that can<br>
+             * only write one component per call. So we limit the length, and<br>
+             * let the write happening in several iterations.<br>
+             */<br>
+            length = 1;<br>
+         }<br>
<br>
          fs_reg offset_reg;<br>
          nir_const_value *const_offset = nir_src_as_const_value(instr-><wbr>src[2]);<br>
@@ -4100,11 +4108,26 @@ fs_visitor::nir_emit_<wbr>intrinsic(const fs_builder &bld, nir_intrinsic_instr *instr<br>
                     brw_imm_ud(type_size * first_component));<br>
          }<br>
<br>
-<br>
-         emit_untyped_write(bld, surf_index, offset_reg,<br>
-                            offset(val_reg, bld, first_component * type_slots),<br>
-                            1 /* dims */, length * type_slots,<br>
-                            BRW_PREDICATE_NONE);<br>
+         if (type_size == 2) {<br>
+            /* Untyped Surface messages have a fixed 32-bit size, so we need<br>
+             * to rely on byte scattered in order to write 16-bit elements.<br>
+             * The byte_scattered_write message needs that every written 16-bit<br>
+             * type to be aligned 32-bits (stride=2).<br>
+             */<br>
+            fs_reg tmp = bld.vgrf(BRW_REGISTER_TYPE_F);<br>
+            val_reg.type = BRW_REGISTER_TYPE_HF;<br>
+            bld.MOV (subscript(tmp, BRW_REGISTER_TYPE_HF, 0),<br>
+                     offset(val_reg, bld, first_component));<br></blockquote><div><br></div><div>We should probably use W types here so we don't get any float conversion problems.</div><div><br></div><div>With that fixed and the previous patch squashed in,<br></div><div><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+            emit_byte_scattered_write(bld, surf_index, offset_reg,<br>
+                                      tmp,<br>
+                                      1 /* dims */, length * type_slots,<br>
+                                      BRW_PREDICATE_NONE);<br>
+         } else {<br>
+            emit_untyped_write(bld, surf_index, offset_reg,<br>
+                               offset(val_reg, bld, first_component * type_slots),<br>
+                               1 /* dims */, length * type_slots,<br>
+                               BRW_PREDICATE_NONE);<br>
+         }<br>
<br>
          /* Clear the bits in the writemask that we just wrote, then try<br>
           * again to see if more channels are left.<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.13.6<br>
<br>
______________________________<wbr>_________________<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/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>