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 <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9348>
This commit is contained in:
Mike Blumenkrantz 2020-10-04 11:04:22 -04:00 committed by Marge Bot
parent b4105e8ac0
commit 514b5ced97
5 changed files with 29 additions and 28 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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;