Mesa (main): freedreno/ir3: Move a6xx's get_ssbo_size shl to NIR.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 18 00:34:06 UTC 2021


Module: Mesa
Branch: main
Commit: 994793c50067172da9a2302f8ee0377bd2b73fc6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=994793c50067172da9a2302f8ee0377bd2b73fc6

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Mar 11 11:14:07 2021 -0800

freedreno/ir3: Move a6xx's get_ssbo_size shl to NIR.

Just cleaning up a TODO.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12258>

---

 src/freedreno/ir3/ir3_compiler_nir.c |  9 +--------
 src/freedreno/ir3/ir3_nir.c          | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c
index 23ca8a25cde..b634eb50e96 100644
--- a/src/freedreno/ir3/ir3_compiler_nir.c
+++ b/src/freedreno/ir3/ir3_compiler_nir.c
@@ -867,14 +867,7 @@ emit_intrinsic_ssbo_size(struct ir3_context *ctx, nir_intrinsic_instr *intr,
    ir3_handle_bindless_cat6(resinfo, intr->src[0]);
 
    if (ctx->compiler->gen >= 6) {
-      struct ir3_instruction *resinfo_dst;
-      ir3_split_dest(b, &resinfo_dst, resinfo, 0, 1);
-      /* Unfortunately resinfo returns the array length, i.e. in dwords,
-      * while NIR expects us to return the size in bytes.
-      *
-      * TODO: fix this in NIR.
-      */
-      *dst = ir3_SHL_B(b, resinfo_dst, 0, create_immed(b, 2), 0);
+      ir3_split_dest(b, dst, resinfo, 0, 1);
    } else {
       /* On a5xx, resinfo returns the low 16 bits of ssbo size in .x and the high 16 bits in .y */
       struct ir3_instruction *resinfo_dst[2];
diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c
index 56ecb6b4cf8..0b35ef90856 100644
--- a/src/freedreno/ir3/ir3_nir.c
+++ b/src/freedreno/ir3/ir3_nir.c
@@ -292,6 +292,33 @@ should_split_wrmask(const nir_instr *instr, const void *data)
    }
 }
 
+static bool
+ir3_nir_lower_ssbo_size_filter(const nir_instr *instr, const void *data)
+{
+   return instr->type == nir_instr_type_intrinsic &&
+          nir_instr_as_intrinsic(instr)->intrinsic ==
+             nir_intrinsic_get_ssbo_size;
+}
+
+static nir_ssa_def *
+ir3_nir_lower_ssbo_size_instr(nir_builder *b, nir_instr *instr, void *data)
+{
+   nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
+   return nir_ishl(b, &intr->dest.ssa, nir_imm_int(b, 2));
+}
+
+/**
+ * The resinfo opcode we have for getting the SSBO size on a6xx returns a number
+ * of dwords, while the NIR intrinsic coming in is a number of bytes.  Switch
+ * things so the NIR intrinsic in our backend means dwords.
+ */
+static bool
+ir3_nir_lower_ssbo_size(nir_shader *s)
+{
+   return nir_shader_lower_instructions(s, ir3_nir_lower_ssbo_size_filter,
+                                        ir3_nir_lower_ssbo_size_instr, NULL);
+}
+
 void
 ir3_nir_lower_io_to_temporaries(nir_shader *s)
 {
@@ -535,6 +562,9 @@ ir3_nir_post_finalize(struct ir3_compiler *compiler, nir_shader *s)
    NIR_PASS_V(s, nir_lower_image, &lower_image_opts);
    NIR_PASS_V(s, nir_lower_idiv, &idiv_options); /* idiv generated by cube lowering */
 
+   if (compiler->gen >= 6)
+      OPT_V(s, ir3_nir_lower_ssbo_size);
+
    ir3_optimize_loop(compiler, s);
 }
 



More information about the mesa-commit mailing list