zink: move resource unrefs to flush thread

unrefs here (almost always) mean destruction, which means eating the cost
of the atomics for the unrefs and then also the destructors

instead, handle this at the end of the next submit from this batch, since the
submit thread is never as busy as the driver thread

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12759>
This commit is contained in:
Mike Blumenkrantz
2021-08-31 16:42:17 -04:00
committed by Marge Bot
parent 03489cf519
commit 46b6ecd4ab
2 changed files with 16 additions and 1 deletions
+14 -1
View File
@@ -37,7 +37,7 @@ zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
set_foreach_remove(bs->resources, entry) {
struct zink_resource_object *obj = (struct zink_resource_object *)entry->key;
zink_resource_object_usage_unset(obj, bs);
zink_resource_object_reference(screen, &obj, NULL);
util_dynarray_append(&bs->unref_resources, struct zink_resource_object*, obj);
}
set_foreach_remove(bs->active_queries, entry) {
@@ -97,11 +97,21 @@ zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
bs->usage.usage = 0;
}
static void
unref_resources(struct zink_screen *screen, struct zink_batch_state *bs)
{
while (util_dynarray_contains(&bs->unref_resources, struct zink_resource_object*)) {
struct zink_resource_object *obj = util_dynarray_pop(&bs->unref_resources, struct zink_resource_object*);
zink_resource_object_reference(screen, &obj, NULL);
}
}
void
zink_clear_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
{
bs->fence.completed = true;
zink_reset_batch_state(ctx, bs);
unref_resources(zink_screen(ctx->base.screen), bs);
}
void
@@ -141,6 +151,7 @@ zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs
util_dynarray_fini(&bs->zombie_samplers);
util_dynarray_fini(&bs->dead_framebuffers);
util_dynarray_fini(&bs->unref_resources);
_mesa_set_destroy(bs->surfaces, NULL);
_mesa_set_destroy(bs->bufferviews, NULL);
_mesa_set_destroy(bs->programs, NULL);
@@ -189,6 +200,7 @@ create_batch_state(struct zink_context *ctx)
util_dynarray_init(&bs->zombie_samplers, NULL);
util_dynarray_init(&bs->dead_framebuffers, NULL);
util_dynarray_init(&bs->persistent_resources, NULL);
util_dynarray_init(&bs->unref_resources, NULL);
cnd_init(&bs->usage.flush);
mtx_init(&bs->usage.mtx, mtx_plain);
@@ -392,6 +404,7 @@ end:
cnd_broadcast(&bs->usage.flush);
p_atomic_set(&bs->fence.submitted, true);
unref_resources(screen, bs);
}
+2
View File
@@ -81,6 +81,8 @@ struct zink_batch_state {
struct set *surfaces;
struct set *bufferviews;
struct util_dynarray unref_resources;
struct util_dynarray persistent_resources;
struct util_dynarray zombie_samplers;
struct util_dynarray dead_framebuffers;