zink: only force all buffer rebinds if rebinds exist on other contexts
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 3 Jun 2021 19:28:44 +0000 (15:28 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 24 Aug 2021 14:17:51 +0000 (14:17 +0000)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12425>

src/gallium/drivers/zink/zink_context.c
src/gallium/drivers/zink/zink_context.h

index 27bb8b09e04b291f6054560daf861dfca33d97b9..d3813cb8bb25e7750e3bc2e059e3e4be904c05dc 100644 (file)
@@ -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
index 1dc83cdcaad9fc7b391dc62f0a4c0ef011858baf..0a29e2f112699b1193b193511a562cb4f3be8628 100644 (file)
@@ -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