zink: stop leaking resource surface cache hash tables

these are owned by the resource, so stick them on a resource context
instead of the screen context

Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13248>
This commit is contained in:
Mike Blumenkrantz 2021-10-07 11:31:49 -04:00 committed by Marge Bot
parent f00ad70bfb
commit 2750853894
1 changed files with 10 additions and 7 deletions

View File

@ -108,15 +108,18 @@ zink_resource_destroy(struct pipe_screen *pscreen,
if (pres->target == PIPE_BUFFER) {
util_range_destroy(&res->valid_buffer_range);
util_idalloc_mt_free(&screen->buffer_ids, res->base.buffer_id_unique);
assert(!_mesa_hash_table_num_entries(&res->bufferview_cache));
simple_mtx_destroy(&res->bufferview_mtx);
} else
} else {
assert(!_mesa_hash_table_num_entries(&res->surface_cache));
simple_mtx_destroy(&res->surface_mtx);
}
/* no need to do anything for the caches, these objects own the resource lifetimes */
zink_resource_object_reference(screen, &res->obj, NULL);
zink_resource_object_reference(screen, &res->scanout_obj, NULL);
threaded_resource_deinit(pres);
FREE(res);
ralloc_free(res);
}
static VkImageAspectFlags
@ -730,14 +733,14 @@ resource_create(struct pipe_screen *pscreen,
const uint64_t *modifiers, int modifiers_count)
{
struct zink_screen *screen = zink_screen(pscreen);
struct zink_resource *res = CALLOC_STRUCT(zink_resource);
struct zink_resource *res = rzalloc(NULL, struct zink_resource);
if (modifiers_count > 0) {
/* for rebinds */
res->modifiers_count = modifiers_count;
res->modifiers = mem_dup(modifiers, modifiers_count * sizeof(uint64_t));
if (!res->modifiers) {
FREE(res);
ralloc_free(res);
return NULL;
}
/* TODO: remove this when multi-plane modifiers are supported */
@ -767,7 +770,7 @@ resource_create(struct pipe_screen *pscreen,
res->obj = resource_object_create(screen, &templ2, whandle, &optimal_tiling, NULL, 0);
if (!res->obj) {
free(res->modifiers);
FREE(res);
ralloc_free(res);
return NULL;
}
@ -811,10 +814,10 @@ resource_create(struct pipe_screen *pscreen,
}
if (res->obj->is_buffer) {
res->base.buffer_id_unique = util_idalloc_mt_alloc(&screen->buffer_ids);
_mesa_hash_table_init(&res->bufferview_cache, screen, NULL, equals_bvci);
_mesa_hash_table_init(&res->bufferview_cache, res, NULL, equals_bvci);
simple_mtx_init(&res->bufferview_mtx, mtx_plain);
} else {
_mesa_hash_table_init(&res->surface_cache, screen, NULL, equals_ivci);
_mesa_hash_table_init(&res->surface_cache, res, NULL, equals_ivci);
simple_mtx_init(&res->surface_mtx, mtx_plain);
}
return &res->base.b;