Mesa (main): panfrost: Only upload UBOs when needed

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Jul 3 13:36:08 UTC 2021


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

Author: Icecream95 <ixn at disroot.org>
Date:   Thu May 20 09:10:40 2021 +1200

panfrost: Only upload UBOs when needed

If all of the used values from a UBO are pushed, it doesn't need to be
uploaded.

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

---

 src/gallium/drivers/panfrost/pan_cmdstream.c | 6 ++----
 src/panfrost/bifrost/bifrost_compile.c       | 2 ++
 src/panfrost/midgard/midgard_compile.c       | 2 ++
 src/panfrost/util/pan_ir.h                   | 2 ++
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c
index e5af9959985..a03715052bd 100644
--- a/src/gallium/drivers/panfrost/pan_cmdstream.c
+++ b/src/gallium/drivers/panfrost/pan_cmdstream.c
@@ -1221,12 +1221,10 @@ panfrost_emit_const_buf(struct panfrost_batch *batch,
 
         /* The rest are honest-to-goodness UBOs */
 
-        for (unsigned ubo = 0; ubo < ubo_count; ++ubo) {
+        u_foreach_bit(ubo, ss->info.ubo_mask & buf->enabled_mask) {
                 size_t usz = buf->cb[ubo].buffer_size;
-                bool enabled = buf->enabled_mask & (1 << ubo);
-                bool empty = usz == 0;
 
-                if (!enabled || empty) {
+                if (usz == 0) {
                         ubo_ptr[ubo] = 0;
                         continue;
                 }
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c
index 4a53f9da7c0..b3b7192eb4f 100644
--- a/src/panfrost/bifrost/bifrost_compile.c
+++ b/src/panfrost/bifrost/bifrost_compile.c
@@ -3467,6 +3467,8 @@ bifrost_compile_shader_nir(nir_shader *nir,
         info->bifrost.wait_6 = (first_deps & (1 << 6));
         info->bifrost.wait_7 = (first_deps & (1 << 7));
 
+        info->ubo_mask = ctx->ubo_mask & BITSET_MASK(ctx->nir->info.num_ubos);
+
         if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal) {
                 disassemble_bifrost(stdout, binary->data, binary->size,
                                     bifrost_debug & BIFROST_DBG_VERBOSE);
diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index a8d254802fa..e9729eca55b 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -3230,6 +3230,8 @@ midgard_compile_shader_nir(nir_shader *nir,
         /* Report the very first tag executed */
         info->midgard.first_tag = midgard_get_first_tag_from_block(ctx, 0);
 
+        info->ubo_mask = ctx->ubo_mask & BITSET_MASK(ctx->nir->info.num_ubos);
+
         if ((midgard_debug & MIDGARD_DBG_SHADERS) &&
             ((midgard_debug & MIDGARD_DBG_INTERNAL) || !nir->info.internal)) {
                 disassemble_midgard(stdout, binary->data,
diff --git a/src/panfrost/util/pan_ir.h b/src/panfrost/util/pan_ir.h
index 910bacad5bf..1ff240b3070 100644
--- a/src/panfrost/util/pan_ir.h
+++ b/src/panfrost/util/pan_ir.h
@@ -216,6 +216,8 @@ struct pan_shader_info {
          * Uniforms (Bifrost) */
         struct panfrost_ubo_push push;
 
+        uint32_t ubo_mask;
+
         union {
                 struct bifrost_shader_info bifrost;
                 struct midgard_shader_info midgard;



More information about the mesa-commit mailing list