Module: Mesa
Branch: master
Commit: 4b244dc64f439da11bba7224db836b376e2ca75a
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4b244dc64f439da11bba7224db836b376e2ca75a

Author: Iago Toral Quiroga <ito...@igalia.com>
Date:   Thu Apr  8 09:02:16 2021 +0200

broadcom/compiler: add a definition for the unifa skip distance

We will be using this distance to setup another optimization in a
follow-up patch.

Reviewed-by: Alejandro PiƱeiro <apinhe...@igalia.com>

x# Please enter the commit message for your changes. Lines starting

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

---

 src/broadcom/compiler/nir_to_vir.c   | 13 +++++++++++--
 src/broadcom/compiler/v3d_compiler.h |  7 +++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/broadcom/compiler/nir_to_vir.c 
b/src/broadcom/compiler/nir_to_vir.c
index 2fbc81c4535..fbfb57489da 100644
--- a/src/broadcom/compiler/nir_to_vir.c
+++ b/src/broadcom/compiler/nir_to_vir.c
@@ -2644,6 +2644,12 @@ emit_ldunifa(struct v3d_compile *c, struct qreg *result)
 static void
 ntq_emit_load_ubo_unifa(struct v3d_compile *c, nir_intrinsic_instr *instr)
 {
+        /* Every ldunifa auto-increments the unifa address by 4 bytes, so our
+         * last unifa offset is 4 bytes ahead of the offset of the last load.
+         */
+        static const int32_t max_unifa_skip_dist =
+                MAX_UNIFA_SKIP_DISTANCE - 4;
+
         bool dynamic_src = !nir_src_is_const(instr->src[1]);
         uint32_t const_offset =
                 dynamic_src ? 0 : nir_src_as_uint(instr->src[1]);
@@ -2656,7 +2662,10 @@ ntq_emit_load_ubo_unifa(struct v3d_compile *c, 
nir_intrinsic_instr *instr)
                 index++;
 
         /* We can only keep track of the last unifa address we used with
-         * constant offset loads.
+         * constant offset loads. If the new load targets the same UBO and
+         * is close enough to the previous load, we can skip the unifa register
+         * write by emitting dummy ldunifa instructions to update the unifa
+         * address.
          */
         bool skip_unifa = false;
         uint32_t ldunifa_skips = 0;
@@ -2665,7 +2674,7 @@ ntq_emit_load_ubo_unifa(struct v3d_compile *c, 
nir_intrinsic_instr *instr)
         } else if (c->cur_block == c->last_unifa_block &&
                    c->last_unifa_index == index &&
                    c->last_unifa_offset <= const_offset &&
-                   c->last_unifa_offset + 12 >= const_offset) {
+                   c->last_unifa_offset + max_unifa_skip_dist >= const_offset) 
{
                 skip_unifa = true;
                 ldunifa_skips = (const_offset - c->last_unifa_offset) / 4;
         } else {
diff --git a/src/broadcom/compiler/v3d_compiler.h 
b/src/broadcom/compiler/v3d_compiler.h
index a741c1785ec..40447e5b44e 100644
--- a/src/broadcom/compiler/v3d_compiler.h
+++ b/src/broadcom/compiler/v3d_compiler.h
@@ -61,6 +61,13 @@
  */
 #define MAX_TMU_QUEUE_SIZE 8
 
+/**
+ * Maximum offset distance in bytes between two consecutive constant UBO loads
+ * for the same UBO where we would favor updating the unifa address by emitting
+ * dummy ldunifa instructions to avoid writing the unifa register.
+ */
+#define MAX_UNIFA_SKIP_DISTANCE 16
+
 struct nir_builder;
 
 struct v3d_fs_inputs {

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to