Module: Mesa Branch: master Commit: dc80529e1fe35936698d5eda864877ac3bd6ecca URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=dc80529e1fe35936698d5eda864877ac3bd6ecca
Author: Mike Blumenkrantz <[email protected]> Date: Thu Nov 5 10:28:32 2020 -0500 zink: simplify bufferview and imageview descriptor state hashing now that we have the hash for the internal objects available at all times, we can directly reuse this instead of computing it each time, giving us more accurate hashes as well as saving us cpu cycles Reviewed-by: Dave Airlie <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9543> --- src/gallium/drivers/zink/zink_context.c | 45 +++++---------------------------- src/gallium/drivers/zink/zink_context.h | 18 ++++++++++++- src/gallium/drivers/zink/zink_draw.c | 4 +-- 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index aeaecd43944..5e6bca53849 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -82,30 +82,6 @@ calc_descriptor_state_hash_ssbo(struct zink_context *ctx, struct zink_shader *zs return hash; } -static void -calc_descriptor_hash_sampler_view(struct zink_context *ctx, struct zink_sampler_view *sampler_view) -{ - void *hash_data; - size_t data_size; - - if (!sampler_view) { - sampler_view->hash = zink_screen(ctx->base.screen)->null_descriptor_hashes.sampler_view; - return; - } - - uint32_t hash = _mesa_hash_pointer(sampler_view->base.texture); - if (sampler_view->base.target == PIPE_BUFFER) { - hash_data = &sampler_view->base.u.buf; - data_size = sizeof(sampler_view->base.u.buf); - sampler_view->hash = XXH32(hash_data, data_size, hash); - return; - } - - hash_data = &sampler_view->image_view; - data_size = sizeof(VkImageView); - sampler_view->hash = XXH32(hash_data, data_size, hash); -} - static void calc_descriptor_hash_sampler_state(struct zink_sampler_state *sampler_state) { @@ -125,7 +101,8 @@ calc_descriptor_state_hash_sampler(struct zink_context *ctx, struct zink_shader hash = XXH32(&screen->null_descriptor_hashes.sampler_view, sizeof(uint32_t), hash); continue; } - hash = XXH32(&sampler_view->hash, sizeof(uint32_t), hash); + uint32_t sv_hash = get_sampler_view_hash(sampler_view); + hash = XXH32(&sv_hash, sizeof(uint32_t), hash); if (sampler_view->base.target == PIPE_BUFFER) continue; @@ -151,17 +128,8 @@ calc_descriptor_state_hash_image(struct zink_context *ctx, struct zink_shader *z hash = XXH32(hash_data, data_size, hash); break; } - struct zink_resource *res = zink_resource(ctx->image_views[shader][idx + k].base.resource); - if (res->base.target == PIPE_BUFFER) { - hash = XXH32(&ctx->image_views[shader][idx + k].base.resource, sizeof(void*), hash); - hash_data = &ctx->image_views[shader][idx + k].base.u.buf; - data_size = sizeof(ctx->image_views[shader][idx + k].base.u.buf); - hash = XXH32(hash_data, data_size, hash); - } else { - hash_data = &ctx->image_views[shader][idx + k].surface->image_view; - data_size = sizeof(VkImageView); - hash = XXH32(hash_data, data_size, hash); - } + uint32_t iv_hash = get_image_view_hash(&ctx->image_views[shader][idx + k]); + hash = XXH32(&iv_hash, sizeof(uint32_t), hash); } return hash; } @@ -654,7 +622,6 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres, return NULL; } util_dynarray_init(&sampler_view->desc_set_refs.refs, NULL); - calc_descriptor_hash_sampler_view(zink_context(pctx), sampler_view); return &sampler_view->base; } @@ -965,7 +932,9 @@ zink_set_sampler_views(struct pipe_context *pctx, struct pipe_sampler_view *pview = views ? views[i] : NULL; struct zink_sampler_view *a = zink_sampler_view(ctx->sampler_views[shader_type][start_slot + i]); struct zink_sampler_view *b = zink_sampler_view(pview); - update |= !!a != !!b || (a && a->hash != b->hash); + uint32_t hash_a = get_sampler_view_hash(a); + uint32_t hash_b = get_sampler_view_hash(b); + update |= !!a != !!b || hash_a != hash_b; pipe_sampler_view_reference(&ctx->sampler_views[shader_type][start_slot + i], pview); } for (; i < num_views + unbind_num_trailing_slots; ++i) { diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h index 80c6ba21f77..6f92b6fa045 100644 --- a/src/gallium/drivers/zink/zink_context.h +++ b/src/gallium/drivers/zink/zink_context.h @@ -87,7 +87,6 @@ struct zink_sampler_view { struct zink_surface *image_view; struct zink_buffer_view *buffer_view; }; - uint32_t hash; uint32_t batch_uses; }; @@ -363,4 +362,21 @@ zink_buffer_view_reference(struct zink_context *ctx, void zink_context_update_descriptor_states(struct zink_context *ctx, bool is_compute); +static inline uint32_t +get_sampler_view_hash(const struct zink_sampler_view *sampler_view) +{ + if (!sampler_view) + return 0; + return sampler_view->base.target == PIPE_BUFFER ? + sampler_view->buffer_view->hash : sampler_view->image_view->hash; +} + +static inline uint32_t +get_image_view_hash(const struct zink_image_view *image_view) +{ + if (!image_view || !image_view->base.resource) + return 0; + return image_view->base.resource->target == PIPE_BUFFER ? + image_view->buffer_view->hash : image_view->surface->hash; +} #endif diff --git a/src/gallium/drivers/zink/zink_draw.c b/src/gallium/drivers/zink/zink_draw.c index d8413d1295f..e9216e094a3 100644 --- a/src/gallium/drivers/zink/zink_draw.c +++ b/src/gallium/drivers/zink/zink_draw.c @@ -38,7 +38,7 @@ desc_set_sampler_add(struct zink_descriptor_set *zds, struct zink_sampler_view * * hash table on every resource with the associated descriptor sets that then needs to be iterated through * whenever a resource is destroyed */ - assert(!cache_hit || zds->sampler_views[i] == sv); + assert(!cache_hit || get_sampler_view_hash(zds->sampler_views[i]) == get_sampler_view_hash(sv)); assert(!cache_hit || zds->sampler_states[i] == state); if (!cache_hit) { zink_sampler_view_desc_set_add(sv, zds, i); @@ -54,7 +54,7 @@ desc_set_image_add(struct zink_descriptor_set *zds, struct zink_image_view *imag * hash table on every resource with the associated descriptor sets that then needs to be iterated through * whenever a resource is destroyed */ - assert(!cache_hit || zds->image_views[i] == image_view); + assert(!cache_hit || get_image_view_hash(zds->image_views[i]) == get_image_view_hash(image_view)); if (!cache_hit) zink_image_view_desc_set_add(image_view, zds, i); } _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
