zink: always unref old images when adding new binds
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 23 Jan 2023 21:34:31 +0000 (16:34 -0500)
committerMarge Bot <emma+marge@anholt.net>
Tue, 31 Jan 2023 16:31:46 +0000 (16:31 +0000)
at some point this was correct, but refactoring has since occurred,
and this ends up leaking storage image objects

cc: mesa-stable

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

src/gallium/drivers/zink/zink_resource.c

index 9721ef1..b99c7c4 100644 (file)
@@ -1314,11 +1314,6 @@ add_resource_bind(struct zink_context *ctx, struct zink_resource *res, unsigned
    res->layout = VK_IMAGE_LAYOUT_UNDEFINED;
    res->obj->access = 0;
    res->obj->access_stage = 0;
-   bool needs_unref = true;
-   if (zink_resource_has_usage(res)) {
-      zink_batch_reference_resource_move(&ctx->batch, res);
-      needs_unref = false;
-   }
    res->obj = new_obj;
    for (unsigned i = 0; i <= res->base.b.last_level; i++) {
       struct pipe_box box = {0, 0, 0,
@@ -1327,8 +1322,7 @@ add_resource_bind(struct zink_context *ctx, struct zink_resource *res, unsigned
       box.depth = util_num_layers(&res->base.b, i);
       ctx->base.resource_copy_region(&ctx->base, &res->base.b, i, 0, 0, 0, &staging.base.b, i, &box);
    }
-   if (needs_unref)
-      zink_resource_object_reference(screen, &old_obj, NULL);
+   zink_resource_object_reference(screen, &old_obj, NULL);
    return true;
 }