<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Nov 29, 2017 at 6:57 PM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">SSBO loads were using byte_scattered read messages as they allow<br>
reading 16-bit size components. byte_scattered messages can only<br>
operate one component at a time so we needed to emit as many messages<br>
as components.<br>
<br>
But for vec2 and vec4 of 16-bit, being multiple of 32-bit we can use the<br>
untyped_surface_read message to read pairs of 16-bit components using only<br>
one message. Once each pair is read it is unshuffled to return the proper<br>
16-bit components.<br>
<br>
On 16-bit scalar and vec3 16-bit the not paired component is read using<br>
only one byte_scattered_read message.<br></blockquote><div><br></div><div>My gut tells me that, for vec3's, we'd be better off with a single untyped read than one untyped read and one byte scattered read.  Also, are there alignment issues with untyped surface reads/writes that might cause us problems on vec3's?  I don't know what the alignment rules are for 16-bit vec3's in Vulkan.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
v2: Removed use of stride = 2 on sources (Jason Ekstrand)<br>
    Rework optimization using unshuffle 16 reads (Chema Casanova)<br>
---<br>
 src/intel/compiler/brw_fs_nir.<wbr>cpp | 43 ++++++++++++++++++++++++++++++<wbr>---------<br>
 1 file changed, 33 insertions(+), 10 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 fa7aa9c247..57e79853ef 100644<br>
--- a/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
+++ b/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
@@ -2354,16 +2354,39 @@ do_untyped_vector_read(const fs_builder &bld,<br>
          bld.ADD(read_offset, read_offset, brw_imm_ud(16));<br>
       }<br>
    } else if (type_sz(dest.type) == 2) {<br>
-      fs_reg read_offset = bld.vgrf(BRW_REGISTER_TYPE_UD)<wbr>;<br>
-      bld.MOV(read_offset, offset_reg);<br>
-      for (unsigned i = 0; i < num_components; i++) {<br>
-         fs_reg read_reg = emit_byte_scattered_read(bld, surf_index, read_offset,<br>
-                                                    1 /* dims */,<br>
-                                                    1,<br>
-                                                    16 /*bit_size */,<br>
-                                                    BRW_PREDICATE_NONE);<br>
-         bld.MOV(offset(dest,bld,i), subscript(read_reg, dest.type, 0));<br>
-         bld.ADD(read_offset, read_offset, brw_imm_ud(type_sz(dest.type))<wbr>);<br>
+      assert(dest.stride == 1);<br>
+<br>
+      int component_pairs = num_components / 2;<br>
+      /* Pairs of 16-bit components can be read with untyped read */<br>
+      if (component_pairs > 0) {<br>
+         fs_reg read_result = emit_untyped_read(bld, surf_index,<br>
+                                                offset_reg,<br>
+                                                1 /* dims */,<br>
+                                                component_pairs,<br>
+                                                BRW_PREDICATE_NONE);<br>
+         shuffle_32bit_load_result_to_<wbr>16bit_data(bld,<br>
+               retype(dest, BRW_REGISTER_TYPE_HF),<br>
+               retype(read_result, BRW_REGISTER_TYPE_F),<br></blockquote><div><br></div><div>I'd rather we use W and D rather than HF and F.  Rounding errors scare me.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+               component_pairs * 2);<br>
+      }<br>
+      /* Last component of vec3 and scalar 16-bit read needs to be read<br>
+       * using one byte_scattered_read message<br>
+       */<br>
+      if (num_components % 2) {<br>
+         fs_reg read_offset = bld.vgrf(BRW_REGISTER_TYPE_UD)<wbr>;<br>
+         bld.ADD(read_offset,<br>
+                 offset_reg,<br>
+                 brw_imm_ud((num_components - 1) * type_sz(dest.type)));<br>
+         fs_reg read_result = emit_byte_scattered_read(bld, surf_index,<br>
+                                                       read_offset,<br>
+                                                       1 /* dims */,<br>
+                                                       1,<br>
+                                                       16 /* bit_size */,<br>
+                                                       BRW_PREDICATE_NONE);<br>
+         read_result.type = dest.type;<br>
+         read_result.stride = 2;<br>
+<br>
+         bld.MOV(offset(dest, bld, num_components - 1), read_result);<br>
       }<br>
    } else {<br>
       unreachable("Unsupported type");<br>
<span class="gmail-HOEnZb"><font color="#888888">--<br>
2.14.3<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>