From 514b5ced978bcaae4e2a3220d0c10bc665d4b5ff Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sun, 4 Oct 2020 11:04:22 -0400 Subject: [PATCH] zink: add program pointer to desc set struct we generally want to avoid this, but it lets us skip a lot of hash lookups, which is a performance hit Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/gallium/drivers/zink/zink_batch.c | 39 +++++++++++-------------- src/gallium/drivers/zink/zink_batch.h | 5 ++-- src/gallium/drivers/zink/zink_context.c | 7 +++-- src/gallium/drivers/zink/zink_program.c | 3 +- src/gallium/drivers/zink/zink_program.h | 3 ++ 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c index 822f1109b48..7984efbf526 100644 --- a/src/gallium/drivers/zink/zink_batch.c +++ b/src/gallium/drivers/zink/zink_batch.c @@ -50,18 +50,17 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch) util_dynarray_clear(&batch->zombie_samplers); util_dynarray_clear(&batch->persistent_resources); - hash_table_foreach(batch->programs, entry) { - struct zink_program *pg = (struct zink_program*)entry->key; - struct set *desc_sets = (struct set*)entry->data; - set_foreach(desc_sets, sentry) { - struct zink_descriptor_set *zds = (void*)sentry->key; - /* reset descriptor pools when no batch is using this program to avoid - * having some inactive program hogging a billion descriptors - */ - pipe_reference(&zds->reference, NULL); - zink_program_recycle_desc_set(pg, zds); - } - _mesa_set_destroy(desc_sets, NULL); + set_foreach(batch->desc_sets, entry) { + struct zink_descriptor_set *zds = (void*)entry->key; + /* reset descriptor pools when no batch is using this program to avoid + * having some inactive program hogging a billion descriptors + */ + pipe_reference(&zds->reference, NULL); + zink_program_recycle_desc_set(zds->pg, zds); + _mesa_set_remove(batch->desc_sets, entry); + } + + set_foreach(batch->programs, entry) { if (batch->batch_id == ZINK_COMPUTE_BATCH_ID) { struct zink_compute_program *comp = (struct zink_compute_program*)entry->key; zink_compute_program_reference(screen, &comp, NULL); @@ -70,7 +69,7 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch) zink_gfx_program_reference(screen, &prog, NULL); } } - _mesa_hash_table_clear(batch->programs, NULL); + _mesa_set_clear(batch->programs, NULL); set_foreach(batch->fbs, entry) { struct zink_framebuffer *fb = (void*)entry->key; @@ -226,23 +225,19 @@ void zink_batch_reference_program(struct zink_batch *batch, struct zink_program *pg) { - struct hash_entry *entry = _mesa_hash_table_search(batch->programs, pg); - if (!entry) { - entry = _mesa_hash_table_insert(batch->programs, pg, _mesa_pointer_set_create(batch->programs)); + if (!_mesa_set_search(batch->programs, pg)) { + _mesa_set_add(batch->programs, pg); pipe_reference(NULL, &pg->reference); } batch->has_work = true; } bool -zink_batch_add_desc_set(struct zink_batch *batch, struct zink_program *pg, struct zink_descriptor_set *zds) +zink_batch_add_desc_set(struct zink_batch *batch, struct zink_descriptor_set *zds) { - struct hash_entry *entry = _mesa_hash_table_search(batch->programs, pg); - assert(entry); - struct set *desc_sets = (void*)entry->data; - if (!_mesa_set_search(desc_sets, zds)) { + if (!_mesa_set_search(batch->desc_sets, zds)) { pipe_reference(NULL, &zds->reference); - _mesa_set_add(desc_sets, zds); + _mesa_set_add(batch->desc_sets, zds); return true; } return false; diff --git a/src/gallium/drivers/zink/zink_batch.h b/src/gallium/drivers/zink/zink_batch.h index 989a50473a3..d5b902d7a2d 100644 --- a/src/gallium/drivers/zink/zink_batch.h +++ b/src/gallium/drivers/zink/zink_batch.h @@ -50,11 +50,12 @@ struct zink_batch { struct zink_fence *fence; struct set *fbs; - struct hash_table *programs; + struct set *programs; struct set *resources; struct set *sampler_views; struct set *surfaces; + struct set *desc_sets; struct util_dynarray persistent_resources; struct util_dynarray zombie_samplers; @@ -97,5 +98,5 @@ zink_batch_reference_surface(struct zink_batch *batch, struct zink_surface *surface); bool -zink_batch_add_desc_set(struct zink_batch *batch, struct zink_program *pg, struct zink_descriptor_set *zds); +zink_batch_add_desc_set(struct zink_batch *batch, struct zink_descriptor_set *zds); #endif diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 99346c59de3..c945619ed35 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -262,7 +262,7 @@ destroy_batch(struct zink_context* ctx, struct zink_batch* batch) _mesa_set_destroy(batch->sampler_views, NULL); util_dynarray_fini(&batch->zombie_samplers); _mesa_set_destroy(batch->surfaces, NULL); - _mesa_hash_table_destroy(batch->programs, NULL); + _mesa_set_destroy(batch->programs, NULL); _mesa_set_destroy(batch->active_queries, NULL); } @@ -2004,10 +2004,11 @@ init_batch(struct zink_context *ctx, struct zink_batch *batch, unsigned idx) batch->fbs = _mesa_pointer_set_create(NULL); batch->resources = _mesa_pointer_set_create(NULL); batch->sampler_views = _mesa_pointer_set_create(NULL); - batch->programs = _mesa_pointer_hash_table_create(NULL); batch->surfaces = _mesa_pointer_set_create(NULL); + batch->programs = _mesa_pointer_set_create(NULL); + batch->desc_sets = _mesa_pointer_set_create(ctx); - if (!batch->resources || !batch->sampler_views || + if (!batch->resources || !batch->sampler_views || !batch->desc_sets || !batch->programs || !batch->surfaces) return false; diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c index 377440113fc..66adc6caf32 100644 --- a/src/gallium/drivers/zink/zink_program.c +++ b/src/gallium/drivers/zink/zink_program.c @@ -882,6 +882,7 @@ allocate_desc_set(struct zink_screen *screen, struct zink_program *pg, enum zink for (unsigned i = 0; i < bucket_size; i ++) { struct zink_descriptor_set *zds = &alloc[i]; pipe_reference_init(&zds->reference, 1); + zds->pg = pg; zds->hash = 0; zds->invalid = true; zds->type = type; @@ -1015,7 +1016,7 @@ out: } quick_out: zds->invalid = false; - if (zink_batch_add_desc_set(batch, pg, zds)) + if (zink_batch_add_desc_set(batch, zds)) batch->descs_used += pg->num_descriptors[type]; pg->last_set[type] = zds; return zds; diff --git a/src/gallium/drivers/zink/zink_program.h b/src/gallium/drivers/zink/zink_program.h index 3961f184379..eec2f8a8bff 100644 --- a/src/gallium/drivers/zink/zink_program.h +++ b/src/gallium/drivers/zink/zink_program.h @@ -42,6 +42,8 @@ struct hash_table; struct set; struct util_dynarray; +struct zink_program; + struct zink_push_constant { unsigned draw_mode_is_indexed; unsigned draw_id; @@ -70,6 +72,7 @@ struct zink_descriptor_state_key { }; struct zink_descriptor_set { + struct zink_program *pg; enum zink_descriptor_type type; struct pipe_reference reference; //incremented for batch usage VkDescriptorSet desc_set;