mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 06:40:11 +01:00
zink: move surface and bufferview caches onto resources
this makes the locking smaller in scope and also make the lookups faster due to having smaller populations in the hash tables Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12843>
This commit is contained in:
parent
e28df76c3a
commit
01f00eb90d
6 changed files with 65 additions and 64 deletions
|
|
@ -621,8 +621,8 @@ get_buffer_view(struct zink_context *ctx, struct zink_resource *res, enum pipe_f
|
|||
bvci.range = !offset && range == res->base.b.width0 ? VK_WHOLE_SIZE : range;
|
||||
|
||||
uint32_t hash = hash_bufferview(&bvci);
|
||||
simple_mtx_lock(&screen->bufferview_mtx);
|
||||
struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&screen->bufferview_cache, hash, &bvci);
|
||||
simple_mtx_lock(&res->bufferview_mtx);
|
||||
struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&res->bufferview_cache, hash, &bvci);
|
||||
if (he) {
|
||||
buffer_view = he->data;
|
||||
p_atomic_inc(&buffer_view->reference.count);
|
||||
|
|
@ -641,10 +641,10 @@ get_buffer_view(struct zink_context *ctx, struct zink_resource *res, enum pipe_f
|
|||
buffer_view->bvci = bvci;
|
||||
buffer_view->buffer_view = view;
|
||||
buffer_view->hash = hash;
|
||||
_mesa_hash_table_insert_pre_hashed(&screen->bufferview_cache, hash, &buffer_view->bvci, buffer_view);
|
||||
_mesa_hash_table_insert_pre_hashed(&res->bufferview_cache, hash, &buffer_view->bvci, buffer_view);
|
||||
}
|
||||
out:
|
||||
simple_mtx_unlock(&screen->bufferview_mtx);
|
||||
simple_mtx_unlock(&res->bufferview_mtx);
|
||||
return buffer_view;
|
||||
}
|
||||
|
||||
|
|
@ -747,11 +747,12 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres,
|
|||
void
|
||||
zink_destroy_buffer_view(struct zink_screen *screen, struct zink_buffer_view *buffer_view)
|
||||
{
|
||||
simple_mtx_lock(&screen->bufferview_mtx);
|
||||
struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&screen->bufferview_cache, buffer_view->hash, &buffer_view->bvci);
|
||||
struct zink_resource *res = zink_resource(buffer_view->pres);
|
||||
simple_mtx_lock(&res->bufferview_mtx);
|
||||
struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&res->bufferview_cache, buffer_view->hash, &buffer_view->bvci);
|
||||
assert(he);
|
||||
_mesa_hash_table_remove(&screen->bufferview_cache, he);
|
||||
simple_mtx_unlock(&screen->bufferview_mtx);
|
||||
_mesa_hash_table_remove(&res->bufferview_cache, he);
|
||||
simple_mtx_unlock(&res->bufferview_mtx);
|
||||
pipe_resource_reference(&buffer_view->pres, NULL);
|
||||
VKSCR(DestroyBufferView)(screen->dev, buffer_view->buffer_view, NULL);
|
||||
zink_descriptor_set_refs_clear(&buffer_view->desc_set_refs, buffer_view);
|
||||
|
|
|
|||
|
|
@ -58,6 +58,19 @@
|
|||
#define DRM_FORMAT_MOD_LINEAR 0
|
||||
#endif
|
||||
|
||||
|
||||
static bool
|
||||
equals_ivci(const void *a, const void *b)
|
||||
{
|
||||
return memcmp(a, b, sizeof(VkImageViewCreateInfo)) == 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
equals_bvci(const void *a, const void *b)
|
||||
{
|
||||
return memcmp(a, b, sizeof(VkBufferViewCreateInfo)) == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
zink_transfer_flush_region(struct pipe_context *pctx,
|
||||
struct pipe_transfer *ptrans,
|
||||
|
|
@ -95,7 +108,10 @@ 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);
|
||||
}
|
||||
simple_mtx_destroy(&res->bufferview_mtx);
|
||||
} else
|
||||
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);
|
||||
|
|
@ -772,9 +788,14 @@ resource_create(struct pipe_screen *pscreen,
|
|||
64, NULL,
|
||||
&res->dt_stride);
|
||||
}
|
||||
if (res->obj->is_buffer)
|
||||
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);
|
||||
simple_mtx_init(&res->bufferview_mtx, mtx_plain);
|
||||
} else {
|
||||
_mesa_hash_table_init(&res->surface_cache, screen, NULL, equals_ivci);
|
||||
simple_mtx_init(&res->surface_mtx, mtx_plain);
|
||||
}
|
||||
return &res->base.b;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ struct zink_batch;
|
|||
struct zink_context;
|
||||
struct zink_bo;
|
||||
|
||||
#include "util/hash_table.h"
|
||||
#include "util/simple_mtx.h"
|
||||
#include "util/u_transfer.h"
|
||||
#include "util/u_range.h"
|
||||
|
|
@ -122,6 +123,17 @@ struct zink_resource {
|
|||
uint32_t all_binds;
|
||||
};
|
||||
|
||||
union {
|
||||
struct {
|
||||
struct hash_table bufferview_cache;
|
||||
simple_mtx_t bufferview_mtx;
|
||||
};
|
||||
struct {
|
||||
struct hash_table surface_cache;
|
||||
simple_mtx_t surface_mtx;
|
||||
};
|
||||
};
|
||||
|
||||
bool dmabuf_acquire;
|
||||
struct sw_displaytarget *dt;
|
||||
unsigned dt_stride;
|
||||
|
|
|
|||
|
|
@ -106,18 +106,6 @@ zink_get_name(struct pipe_screen *pscreen)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static bool
|
||||
equals_ivci(const void *a, const void *b)
|
||||
{
|
||||
return memcmp(a, b, sizeof(VkImageViewCreateInfo)) == 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
equals_bvci(const void *a, const void *b)
|
||||
{
|
||||
return memcmp(a, b, sizeof(VkBufferViewCreateInfo)) == 0;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
hash_framebuffer_state(const void *key)
|
||||
{
|
||||
|
|
@ -1065,17 +1053,6 @@ zink_destroy_screen(struct pipe_screen *pscreen)
|
|||
VKSCR(DestroyDebugUtilsMessengerEXT)(screen->instance, screen->debugUtilsCallbackHandle, NULL);
|
||||
}
|
||||
|
||||
hash_table_foreach(&screen->surface_cache, entry) {
|
||||
struct pipe_surface *psurf = (struct pipe_surface*)entry->data;
|
||||
/* context is already destroyed, so this has to be destroyed directly */
|
||||
zink_destroy_surface(screen, psurf);
|
||||
}
|
||||
|
||||
hash_table_foreach(&screen->bufferview_cache, entry) {
|
||||
struct zink_buffer_view *bv = (struct zink_buffer_view*)entry->data;
|
||||
zink_buffer_view_reference(screen, &bv, NULL);
|
||||
}
|
||||
|
||||
if (!screen->info.have_KHR_imageless_framebuffer) {
|
||||
hash_table_foreach(&screen->framebuffer_cache, entry) {
|
||||
struct zink_framebuffer* fb = (struct zink_framebuffer*)entry->data;
|
||||
|
|
@ -1084,9 +1061,6 @@ zink_destroy_screen(struct pipe_screen *pscreen)
|
|||
simple_mtx_destroy(&screen->framebuffer_mtx);
|
||||
}
|
||||
|
||||
simple_mtx_destroy(&screen->surface_mtx);
|
||||
simple_mtx_destroy(&screen->bufferview_mtx);
|
||||
|
||||
u_transfer_helper_destroy(pscreen->transfer_helper);
|
||||
#ifdef ENABLE_SHADER_CACHE
|
||||
if (screen->disk_cache) {
|
||||
|
|
@ -1968,15 +1942,10 @@ zink_internal_create_screen(const struct pipe_screen_config *config)
|
|||
screen->resizable_bar = true;
|
||||
}
|
||||
|
||||
simple_mtx_init(&screen->surface_mtx, mtx_plain);
|
||||
simple_mtx_init(&screen->bufferview_mtx, mtx_plain);
|
||||
|
||||
if (!screen->info.have_KHR_imageless_framebuffer) {
|
||||
simple_mtx_init(&screen->framebuffer_mtx, mtx_plain);
|
||||
_mesa_hash_table_init(&screen->framebuffer_cache, screen, hash_framebuffer_state, equals_framebuffer_state);
|
||||
}
|
||||
_mesa_hash_table_init(&screen->surface_cache, screen, NULL, equals_ivci);
|
||||
_mesa_hash_table_init(&screen->bufferview_cache, screen, NULL, equals_bvci);
|
||||
|
||||
zink_screen_init_descriptor_funcs(screen, false);
|
||||
util_idalloc_mt_init_tc(&screen->buffer_ids);
|
||||
|
|
|
|||
|
|
@ -89,10 +89,6 @@ struct zink_screen {
|
|||
|
||||
struct hash_table framebuffer_cache;
|
||||
simple_mtx_t framebuffer_mtx;
|
||||
struct hash_table surface_cache;
|
||||
simple_mtx_t surface_mtx;
|
||||
struct hash_table bufferview_cache;
|
||||
simple_mtx_t bufferview_mtx;
|
||||
|
||||
struct slab_parent_pool transfer_pool;
|
||||
struct disk_cache *disk_cache;
|
||||
|
|
|
|||
|
|
@ -160,21 +160,21 @@ zink_get_surface(struct zink_context *ctx,
|
|||
const struct pipe_surface *templ,
|
||||
VkImageViewCreateInfo *ivci)
|
||||
{
|
||||
struct zink_screen *screen = zink_screen(ctx->base.screen);
|
||||
struct zink_surface *surface = NULL;
|
||||
struct zink_resource *res = zink_resource(pres);
|
||||
uint32_t hash = hash_ivci(ivci);
|
||||
|
||||
simple_mtx_lock(&screen->surface_mtx);
|
||||
struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(&screen->surface_cache, hash, ivci);
|
||||
simple_mtx_lock(&res->surface_mtx);
|
||||
struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(&res->surface_cache, hash, ivci);
|
||||
|
||||
if (!entry) {
|
||||
/* create a new surface */
|
||||
surface = create_surface(&ctx->base, pres, templ, ivci);
|
||||
surface->hash = hash;
|
||||
surface->ivci = *ivci;
|
||||
entry = _mesa_hash_table_insert_pre_hashed(&screen->surface_cache, hash, &surface->ivci, surface);
|
||||
entry = _mesa_hash_table_insert_pre_hashed(&res->surface_cache, hash, &surface->ivci, surface);
|
||||
if (!entry) {
|
||||
simple_mtx_unlock(&screen->surface_mtx);
|
||||
simple_mtx_unlock(&res->surface_mtx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ zink_get_surface(struct zink_context *ctx,
|
|||
surface = entry->data;
|
||||
p_atomic_inc(&surface->base.reference.count);
|
||||
}
|
||||
simple_mtx_unlock(&screen->surface_mtx);
|
||||
simple_mtx_unlock(&res->surface_mtx);
|
||||
|
||||
return &surface->base;
|
||||
}
|
||||
|
|
@ -233,12 +233,13 @@ void
|
|||
zink_destroy_surface(struct zink_screen *screen, struct pipe_surface *psurface)
|
||||
{
|
||||
struct zink_surface *surface = zink_surface(psurface);
|
||||
simple_mtx_lock(&screen->surface_mtx);
|
||||
struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&screen->surface_cache, surface->hash, &surface->ivci);
|
||||
struct zink_resource *res = zink_resource(psurface->texture);
|
||||
simple_mtx_lock(&res->surface_mtx);
|
||||
struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&res->surface_cache, surface->hash, &surface->ivci);
|
||||
assert(he);
|
||||
assert(he->data == surface);
|
||||
_mesa_hash_table_remove(&screen->surface_cache, he);
|
||||
simple_mtx_unlock(&screen->surface_mtx);
|
||||
_mesa_hash_table_remove(&res->surface_cache, he);
|
||||
simple_mtx_unlock(&res->surface_mtx);
|
||||
if (!screen->info.have_KHR_imageless_framebuffer)
|
||||
surface_clear_fb_refs(screen, psurface);
|
||||
zink_descriptor_set_refs_clear(&surface->desc_set_refs, surface);
|
||||
|
|
@ -261,6 +262,7 @@ bool
|
|||
zink_rebind_surface(struct zink_context *ctx, struct pipe_surface **psurface)
|
||||
{
|
||||
struct zink_surface *surface = zink_surface(*psurface);
|
||||
struct zink_resource *res = zink_resource((*psurface)->texture);
|
||||
struct zink_screen *screen = zink_screen(ctx->base.screen);
|
||||
if (surface->simage_view)
|
||||
return false;
|
||||
|
|
@ -268,8 +270,8 @@ zink_rebind_surface(struct zink_context *ctx, struct pipe_surface **psurface)
|
|||
zink_resource((*psurface)->texture), (*psurface), surface->base.texture->target);
|
||||
uint32_t hash = hash_ivci(&ivci);
|
||||
|
||||
simple_mtx_lock(&screen->surface_mtx);
|
||||
struct hash_entry *new_entry = _mesa_hash_table_search_pre_hashed(&screen->surface_cache, hash, &ivci);
|
||||
simple_mtx_lock(&res->surface_mtx);
|
||||
struct hash_entry *new_entry = _mesa_hash_table_search_pre_hashed(&res->surface_cache, hash, &ivci);
|
||||
if (zink_batch_usage_exists(surface->batch_uses))
|
||||
zink_batch_reference_surface(&ctx->batch, surface);
|
||||
surface_clear_fb_refs(screen, *psurface);
|
||||
|
|
@ -277,29 +279,29 @@ zink_rebind_surface(struct zink_context *ctx, struct pipe_surface **psurface)
|
|||
if (new_entry) {
|
||||
/* reuse existing surface; old one will be cleaned up naturally */
|
||||
struct zink_surface *new_surface = new_entry->data;
|
||||
simple_mtx_unlock(&screen->surface_mtx);
|
||||
simple_mtx_unlock(&res->surface_mtx);
|
||||
zink_batch_usage_set(&new_surface->batch_uses, ctx->batch.state);
|
||||
zink_surface_reference(screen, (struct zink_surface**)psurface, new_surface);
|
||||
return true;
|
||||
}
|
||||
struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(&screen->surface_cache, surface->hash, &surface->ivci);
|
||||
struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(&res->surface_cache, surface->hash, &surface->ivci);
|
||||
assert(entry);
|
||||
_mesa_hash_table_remove(&screen->surface_cache, entry);
|
||||
_mesa_hash_table_remove(&res->surface_cache, entry);
|
||||
VkImageView image_view;
|
||||
if (VKSCR(CreateImageView)(screen->dev, &ivci, NULL, &image_view) != VK_SUCCESS) {
|
||||
debug_printf("zink: failed to create new imageview");
|
||||
simple_mtx_unlock(&screen->surface_mtx);
|
||||
simple_mtx_unlock(&res->surface_mtx);
|
||||
return false;
|
||||
}
|
||||
surface->hash = hash;
|
||||
surface->ivci = ivci;
|
||||
entry = _mesa_hash_table_insert_pre_hashed(&screen->surface_cache, surface->hash, &surface->ivci, surface);
|
||||
entry = _mesa_hash_table_insert_pre_hashed(&res->surface_cache, surface->hash, &surface->ivci, surface);
|
||||
assert(entry);
|
||||
surface->simage_view = surface->image_view;
|
||||
surface->image_view = image_view;
|
||||
surface->obj = zink_resource(surface->base.texture)->obj;
|
||||
zink_batch_usage_set(&surface->batch_uses, ctx->batch.state);
|
||||
simple_mtx_unlock(&screen->surface_mtx);
|
||||
simple_mtx_unlock(&res->surface_mtx);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue