zink: move resource object ref to batch in invalidate hook
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 12 May 2021 11:16:54 +0000 (07:16 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 7 Jul 2021 00:22:09 +0000 (00:22 +0000)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11692>

src/gallium/drivers/zink/zink_resource.c

index 0691277..a8245af 100644 (file)
@@ -750,13 +750,20 @@ invalidate_buffer(struct zink_context *ctx, struct zink_resource *res)
       debug_printf("new backing resource alloc failed!");
       return false;
    }
+   bool needs_unref = true;
+   if (zink_batch_usage_exists(old_obj->reads) ||
+       zink_batch_usage_exists(old_obj->writes)) {
+      zink_batch_reference_resource_move(&ctx->batch, res);
+      needs_unref = false;
+   }
    res->obj = new_obj;
    res->access_stage = 0;
    res->access = 0;
    res->unordered_barrier = false;
    zink_resource_rebind(ctx, res);
    zink_descriptor_set_refs_clear(&old_obj->desc_set_refs, old_obj);
-   zink_resource_object_reference(screen, &old_obj, NULL);
+   if (needs_unref)
+      zink_resource_object_reference(screen, &old_obj, NULL);
    return true;
 }