Mesa (main): zink: only force all buffer rebinds if rebinds exist on other contexts

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 24 14:36:55 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Thu Jun  3 15:28:44 2021 -0400

zink: only force all buffer rebinds if rebinds exist on other contexts

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12425>

---

 src/gallium/drivers/zink/zink_context.c | 26 ++++++++++++++------------
 src/gallium/drivers/zink/zink_context.h |  2 +-
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 27bb8b09e04..d3813cb8bb2 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -3222,7 +3222,7 @@ rebind_ibo(struct zink_context *ctx, enum pipe_shader_type shader, unsigned slot
    return res;
 }
 
-static void
+static unsigned
 rebind_buffer(struct zink_context *ctx, struct zink_resource *res)
 {
    const unsigned total_rebinds = res->bind_count[0] + res->bind_count[1];
@@ -3244,7 +3244,7 @@ rebind_buffer(struct zink_context *ctx, struct zink_resource *res)
    if (res->vbo_bind_mask) {
       u_foreach_bit(slot, res->vbo_bind_mask) {
          if (ctx->vertex_buffers[slot].buffer.resource != &res->base.b) //wrong context
-            return;
+            return 0;
          set_vertex_buffer_clamped(ctx, slot);
          num_rebinds++;
       }
@@ -3255,7 +3255,7 @@ rebind_buffer(struct zink_context *ctx, struct zink_resource *res)
            num_rebinds < total_rebinds && shader < PIPE_SHADER_TYPES; shader++) {
          u_foreach_bit(slot, res->ubo_bind_mask[shader]) {
             if (&res->base.b != ctx->ubos[shader][slot].buffer) //wrong context
-               return;
+               return 0;
 
             rebind_ubo(ctx, shader, slot);
             num_rebinds++;
@@ -3266,7 +3266,7 @@ rebind_buffer(struct zink_context *ctx, struct zink_resource *res)
       u_foreach_bit(slot, res->ssbo_bind_mask[shader]) {
          struct pipe_shader_buffer *ssbo = &ctx->ssbos[shader][slot];
          if (&res->base.b != ssbo->buffer) //wrong context
-            return;
+            return 0;
 
          rebind_ssbo(ctx, shader, slot);
          has_write |= (ctx->writable_ssbos[shader] & BITFIELD64_BIT(slot)) != 0;
@@ -3275,7 +3275,7 @@ rebind_buffer(struct zink_context *ctx, struct zink_resource *res)
       u_foreach_bit(slot, res->sampler_binds[shader]) {
          struct zink_sampler_view *sampler_view = zink_sampler_view(ctx->sampler_views[shader][slot]);
          if (&res->base.b != sampler_view->base.texture) //wrong context
-            return;
+            return 0;
 
          rebind_tbo(ctx, shader, slot);
          num_rebinds++;
@@ -3291,10 +3291,12 @@ rebind_buffer(struct zink_context *ctx, struct zink_resource *res)
             const struct zink_image_view *image_view = &ctx->image_views[shader][slot];
             has_write |= (image_view->base.access & PIPE_IMAGE_ACCESS_WRITE) != 0;
             num_image_rebinds_remaining[shader == PIPE_SHADER_COMPUTE]--;
+            num_rebinds++;
          }
       }
    }
    zink_batch_resource_usage_set(&ctx->batch, res, has_write);
+   return num_rebinds;
 }
 
 static bool
@@ -3346,17 +3348,17 @@ rebind_image(struct zink_context *ctx, struct zink_resource *res)
     }
 }
 
-void
+bool
 zink_resource_rebind(struct zink_context *ctx, struct zink_resource *res)
 {
    /* force counter buffer reset */
    res->bind_history &= ~ZINK_RESOURCE_USAGE_STREAMOUT;
    if (!res->bind_count[0] && !res->bind_count[1])
-      return;
+      return true;
    if (res->base.b.target == PIPE_BUFFER)
-      rebind_buffer(ctx, res);
-   else
-      rebind_image(ctx, res);
+      return rebind_buffer(ctx, res) == res->bind_count[0] + res->bind_count[1];
+   rebind_image(ctx, res);
+   return false;
 }
 
 void
@@ -3411,8 +3413,8 @@ zink_context_replace_buffer_storage(struct pipe_context *pctx, struct pipe_resou
    d->access = s->access;
    d->access_stage = s->access_stage;
    d->unordered_barrier = s->unordered_barrier;
-   zink_resource_rebind(ctx, d);
-   ctx->buffer_rebind_counter = p_atomic_inc_return(&zink_screen(ctx->base.screen)->buffer_rebind_counter);
+   if (!zink_resource_rebind(ctx, d))
+      ctx->buffer_rebind_counter = p_atomic_inc_return(&zink_screen(ctx->base.screen)->buffer_rebind_counter);
 }
 
 static bool
diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index 1dc83cdcaad..0a29e2f1126 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -452,7 +452,7 @@ zink_rect_from_box(const struct pipe_box *box)
    return (struct u_rect){box->x, box->x + box->width, box->y, box->y + box->height};
 }
 
-void
+bool
 zink_resource_rebind(struct zink_context *ctx, struct zink_resource *res);
 
 void



More information about the mesa-commit mailing list