[Mesa-dev] [PATCH 44/47] i965/fs: Use untyped_surface_read for 16-bit load_ssbo

Alejandro PiƱeiro apinheiro at igalia.com
Thu Aug 24 13:54:59 UTC 2017


From: Jose Maria Casanova Crespo <jmcasanova at igalia.com>

SSBO loads were using byte_scattered read messages as they allow
reading 16-bit size components. byte_scattered messages can only
operate one component at a time so we needed to emit as many messages
as components.

But for vec2 and vec4 of 16-bit, being multiple of 32-bit we can use the
untyped_surface_read message to read pairs of 16-bit components using only
one message. Once each pair is read it is unshuffled to return the proper
16-bit components.

On 16-bit scalar and vec3 16-bit the not paired component is read using
only one byte_scattered_read message.
---
 src/intel/compiler/brw_fs_nir.cpp | 42 +++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp
index f8a53767445..55b2dfd0caf 100644
--- a/src/intel/compiler/brw_fs_nir.cpp
+++ b/src/intel/compiler/brw_fs_nir.cpp
@@ -2319,19 +2319,41 @@ do_untyped_vector_read(const fs_builder &bld,
          bld.ADD(read_offset, read_offset, brw_imm_ud(16));
       }
    } else if (type_sz(dest.type) == 2) {
-      for (unsigned i = 0; i < num_components; i++) {
+      assert(dest.stride == 2);
+
+      int component_pairs = num_components / 2;
+      /* Pairs of 16-bit components can be read with untyped read */
+      if (component_pairs > 0) {
+         fs_reg read_result = emit_untyped_read(bld, surf_index,
+                                                offset_reg,
+                                                1 /* dims */,
+                                                component_pairs,
+                                                BRW_PREDICATE_NONE);
+         read_result.stride = 2;
+         read_result.type = dest.type;
+
+         /* Each 32-bit read needs to be unshuffled as 2 16-bit components */
+         for (int i = 0; i < component_pairs * 2 ; i++)
+            bld.MOV(offset(dest, bld, i),
+                    byte_offset(offset(read_result, bld, i / 2), i % 2 * 2));
+      }
+      /* Last component of vec3 and scalar 16-bit read needs to be read
+       * using one byte_scattered_read message
+       */
+      if (num_components % 2) {
          fs_reg base_offset = bld.vgrf(BRW_REGISTER_TYPE_UD);
          bld.ADD(base_offset,
                  offset_reg,
-                 brw_imm_ud(i * type_sz(dest.type)));
-         fs_reg read_reg = emit_byte_scattered_read(bld, surf_index, base_offset,
-                                                    1 /* dims */,
-                                                    1,
-                                                    BRW_PREDICATE_NONE);
-         read_reg = retype(read_reg, BRW_REGISTER_TYPE_UD);
-         fs_reg retval = retype(offset(dest,bld,i), BRW_REGISTER_TYPE_UD);
-         retval.stride = 1;
-         bld.MOV(retval, read_reg);
+                 brw_imm_ud((num_components - 1) * type_sz(dest.type)));
+         fs_reg read_result = emit_byte_scattered_read(bld, surf_index,
+                                                       base_offset,
+                                                       1 /* dims */,
+                                                       1,
+                                                       BRW_PREDICATE_NONE);
+         read_result.type = dest.type;
+         read_result.stride = 2;
+         bld.MOV(offset(dest, bld, num_components - 1),
+                 read_result);
       }
    } else {
       unreachable("Unsupported type");
-- 
2.11.0



More information about the mesa-dev mailing list