Mesa (main): zink: defer deletion of no-attachment framebuffers

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 24 19:38:42 UTC 2021


Module: Mesa
Branch: main
Commit: 1af66186941232fcb4c0a76bb1bb214c84f17e37
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1af66186941232fcb4c0a76bb1bb214c84f17e37

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Tue Aug 24 11:28:22 2021 -0400

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 at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12429>

---

 src/gallium/drivers/zink/zink_batch.c   | 6 ++++++
 src/gallium/drivers/zink/zink_batch.h   | 1 +
 src/gallium/drivers/zink/zink_context.c | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c
index 17aecc73eed..c4074b09175 100644
--- a/src/gallium/drivers/zink/zink_batch.c
+++ b/src/gallium/drivers/zink/zink_batch.c
@@ -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);
diff --git a/src/gallium/drivers/zink/zink_batch.h b/src/gallium/drivers/zink/zink_batch.h
index fb929bb7f0c..178ff6db9ce 100644
--- a/src/gallium/drivers/zink/zink_batch.h
+++ b/src/gallium/drivers/zink/zink_batch.h
@@ -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 */
 
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index d3813cb8bb2..3b6b4e8927b 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -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



More information about the mesa-commit mailing list