zink: defer deletion of no-attachment framebuffers

the ref on these is owned by the context, so defer deletion to avoid
premature destruction if the fb might be in use

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12429>
This commit is contained in:
Mike Blumenkrantz 2021-08-24 11:28:22 -04:00 committed by Marge Bot
parent 3622562e44
commit 1af6618694
3 changed files with 10 additions and 0 deletions

View file

@ -56,6 +56,10 @@ zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
zink_buffer_view_reference(screen, &buffer_view, NULL);
}
util_dynarray_foreach(&bs->dead_framebuffers, struct zink_framebuffer*, fb) {
zink_framebuffer_reference(screen, fb, NULL);
}
util_dynarray_clear(&bs->dead_framebuffers);
util_dynarray_foreach(&bs->zombie_samplers, VkSampler, samp) {
vkDestroySampler(screen->dev, *samp, NULL);
}
@ -143,6 +147,7 @@ zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs
_mesa_set_destroy(bs->fbs, NULL);
util_dynarray_fini(&bs->zombie_samplers);
util_dynarray_fini(&bs->dead_framebuffers);
_mesa_set_destroy(bs->surfaces, NULL);
_mesa_set_destroy(bs->bufferviews, NULL);
_mesa_set_destroy(bs->programs, NULL);
@ -191,6 +196,7 @@ create_batch_state(struct zink_context *ctx)
SET_CREATE_OR_FAIL(bs->programs);
SET_CREATE_OR_FAIL(bs->active_queries);
util_dynarray_init(&bs->zombie_samplers, NULL);
util_dynarray_init(&bs->dead_framebuffers, NULL);
util_dynarray_init(&bs->persistent_resources, NULL);
cnd_init(&bs->usage.flush);

View file

@ -86,6 +86,7 @@ struct zink_batch_state {
struct util_dynarray persistent_resources;
struct util_dynarray zombie_samplers;
struct util_dynarray dead_framebuffers;
struct set *active_queries; /* zink_query objects which were active at some point in this batch */

View file

@ -2039,6 +2039,9 @@ zink_set_framebuffer_state(struct pipe_context *pctx,
/* if this has no attachments then its lifetime has ended */
_mesa_hash_table_remove(&screen->framebuffer_cache, he);
he = NULL;
/* ensure an unflushed fb doesn't get destroyed by deferring it */
util_dynarray_append(&ctx->batch.state->dead_framebuffers, struct zink_framebuffer*, ctx->framebuffer);
ctx->framebuffer = NULL;
}
/* a framebuffer loses 1 ref every time we unset it;
* we do NOT add refs here, as the ref has already been added in