zink: simplify some dumb code in invalidate_buffer (v2)

the ref has to be preserved so that rebind doesn't destroy it prematurely

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12118>
This commit is contained in:
Mike Blumenkrantz 2021-07-28 19:16:04 -04:00 committed by Marge Bot
parent 2668489cf9
commit 461662bf3c

View file

@ -1022,25 +1022,19 @@ invalidate_buffer(struct zink_context *ctx, struct zink_resource *res)
return false;
struct zink_resource_object *old_obj = res->obj;
bool has_usage = zink_resource_has_usage(res);
struct zink_resource_object *new_obj = resource_object_create(screen, &res->base.b, NULL, NULL, NULL, 0);
if (!new_obj) {
debug_printf("new backing resource alloc failed!");
return false;
}
bool needs_unref = true;
if (has_usage) {
zink_batch_reference_resource_move(&ctx->batch, res);
needs_unref = false;
}
/* this ref must be transferred before rebind or else BOOM */
zink_batch_reference_resource_move(&ctx->batch, res);
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);
if (needs_unref)
zink_resource_object_reference(screen, &old_obj, NULL);
return true;
}