From 77b3a3f00fa6a3ba98c13c629144052c1b8bdaab Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 7 Oct 2021 17:45:26 -0400 Subject: [PATCH] zink: stop leaking buffers on replacement I tried to be pointlessly clever here to avoid an atomic op, but the move() here ended up leaking a ref in some cases (descriptor bind + multiple replacements in same cmdbuf) more importantly, it's a stupid idea now that zink_resource_object structs are entirely owned by the driver, meaning their refcounts are never altered in threads, and thus the atomic ops are just regular ops Reviewed-by: Adam Jackson Part-of: --- src/gallium/drivers/zink/zink_context.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 3fc510b06da..88fb40d208e 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -3958,13 +3958,11 @@ zink_context_replace_buffer_storage(struct pipe_context *pctx, struct pipe_resou assert(d->obj); assert(s->obj); util_idalloc_mt_free(&screen->buffer_ids, delete_buffer_id); - zink_resource_object_reference(screen, NULL, s->obj); - if (zink_resource_has_unflushed_usage(d) || - (zink_resource_has_usage(d) && zink_resource_has_binds(d))) - zink_batch_reference_resource_move(&ctx->batch, d); - else - zink_resource_object_reference(screen, &d->obj, NULL); - d->obj = s->obj; + /* add a ref just like check_resource_for_batch_ref() would've */ + if (zink_resource_has_binds(d) && zink_resource_has_usage(d)) + zink_batch_reference_resource(&ctx->batch, d); + /* don't be too creative */ + zink_resource_object_reference(screen, &d->obj, s->obj); /* force counter buffer reset */ d->so_valid = false; if (num_rebinds && rebind_buffer(ctx, d, rebind_mask, num_rebinds) < num_rebinds)