From 6d005ba3fc12c1ff06808da71140794231c1ca16 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 30 Oct 2020 08:18:31 -0400 Subject: [PATCH] zink: more consolidation for null sampler/image view hashing by using the new helper functions, this is even more consistent Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_context.c | 68 +++++++++++++++++++++------------ src/gallium/drivers/zink/zink_context.h | 20 ++-------- src/gallium/drivers/zink/zink_draw.c | 16 ++------ 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index daabcf0..b425f8b 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -109,23 +109,49 @@ calc_descriptor_hash_sampler_state(struct zink_sampler_state *sampler_state) sampler_state->hash = XXH32(hash_data, data_size, 0); } +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; +} + +uint32_t +zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer) +{ + return get_sampler_view_hash(sampler_view) ? get_sampler_view_hash(sampler_view) : + (is_buffer ? zink_screen(ctx->base.screen)->null_descriptor_hashes.buffer_view : + zink_screen(ctx->base.screen)->null_descriptor_hashes.image_view); +} + +uint32_t +zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer) +{ + return get_image_view_hash(image_view) ? get_image_view_hash(image_view) : + (is_buffer ? zink_screen(ctx->base.screen)->null_descriptor_hashes.buffer_view : + zink_screen(ctx->base.screen)->null_descriptor_hashes.image_view); +} + static uint32_t calc_descriptor_state_hash_sampler(struct zink_context *ctx, struct zink_shader *zs, enum pipe_shader_type shader, int i, int idx, uint32_t hash) { - struct zink_screen *screen = zink_screen(ctx->base.screen); - for (unsigned k = 0; k < zs->bindings[ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW][i].size; k++) { struct zink_sampler_view *sampler_view = zink_sampler_view(ctx->sampler_views[shader][idx + k]); - if (!sampler_view) { - uint32_t val = zs->bindings[ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW][i].type == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER ? - screen->null_descriptor_hashes.buffer_view : - screen->null_descriptor_hashes.image_view; - hash = XXH32(&val, sizeof(uint32_t), hash); - continue; - } - 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) + bool is_buffer = zink_shader_descriptor_is_buffer(zs, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW, i); + uint32_t val = zink_get_sampler_view_hash(ctx, sampler_view, is_buffer); + hash = XXH32(&val, sizeof(uint32_t), hash); + if (is_buffer) continue; struct zink_sampler_state *sampler_state = ctx->sampler_states[shader][idx + k]; @@ -140,16 +166,9 @@ static uint32_t calc_descriptor_state_hash_image(struct zink_context *ctx, struct zink_shader *zs, enum pipe_shader_type shader, int i, int idx, uint32_t hash) { for (unsigned k = 0; k < zs->bindings[ZINK_DESCRIPTOR_TYPE_IMAGE][i].size; k++) { - if (!get_resource_for_descriptor(ctx, ZINK_DESCRIPTOR_TYPE_IMAGE, shader, idx + k)) { - struct zink_screen *screen = zink_screen(ctx->base.screen); - uint32_t val = zs->bindings[ZINK_DESCRIPTOR_TYPE_IMAGE][i].type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER ? - screen->null_descriptor_hashes.buffer_view : - screen->null_descriptor_hashes.image_view; - hash = XXH32(&val, sizeof(uint32_t), hash); - break; - } - uint32_t iv_hash = get_image_view_hash(&ctx->image_views[shader][idx + k]); - hash = XXH32(&iv_hash, sizeof(uint32_t), hash); + uint32_t val = zink_get_image_view_hash(ctx, &ctx->image_views[shader][idx + k], + zink_shader_descriptor_is_buffer(zs, ZINK_DESCRIPTOR_TYPE_IMAGE, i)); + hash = XXH32(&val, sizeof(uint32_t), hash); } return hash; } @@ -1001,8 +1020,9 @@ zink_set_sampler_views(struct pipe_context *pctx, res->bind_history |= BITFIELD_BIT(ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW); res->bind_stages |= 1 << shader_type; } - uint32_t hash_a = get_sampler_view_hash(a); - uint32_t hash_b = get_sampler_view_hash(b); + bool is_buffer = zink_program_descriptor_is_buffer(ctx, shader_type, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW, start_slot + i); + uint32_t hash_a = zink_get_sampler_view_hash(ctx, a, is_buffer); + uint32_t hash_b = zink_get_sampler_view_hash(ctx, b, is_buffer); update |= !!a != !!b || hash_a != hash_b; pipe_sampler_view_reference(&ctx->sampler_views[shader_type][start_slot + i], pview); } diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h index 5f30030..c5da1d1 100644 --- a/src/gallium/drivers/zink/zink_context.h +++ b/src/gallium/drivers/zink/zink_context.h @@ -366,21 +366,9 @@ zink_buffer_view_reference(struct zink_screen *screen, 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; -} +uint32_t +zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer); +uint32_t +zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer); -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 6796f66..e4728d7 100644 --- a/src/gallium/drivers/zink/zink_draw.c +++ b/src/gallium/drivers/zink/zink_draw.c @@ -40,12 +40,8 @@ desc_set_sampler_add(struct zink_context *ctx, struct zink_descriptor_set *zds, * whenever a resource is destroyed */ #ifndef NDEBUG - uint32_t null_hash = is_buffer ? zink_screen(ctx->base.screen)->null_descriptor_hashes.buffer_view : - zink_screen(ctx->base.screen)->null_descriptor_hashes.image_view; - uint32_t cur_hash = get_sampler_view_hash(zds->sampler_views[i]) ? get_sampler_view_hash(zds->sampler_views[i]) : - null_hash; - uint32_t new_hash = get_sampler_view_hash(sv) ? get_sampler_view_hash(sv) : - null_hash; + uint32_t cur_hash = zink_get_sampler_view_hash(ctx, zds->sampler_views[i], is_buffer); + uint32_t new_hash = zink_get_sampler_view_hash(ctx, sv, is_buffer); #endif assert(!cache_hit || cur_hash == new_hash); assert(!cache_hit || zds->sampler_states[i] == state); @@ -65,12 +61,8 @@ desc_set_image_add(struct zink_context *ctx, struct zink_descriptor_set *zds, st * whenever a resource is destroyed */ #ifndef NDEBUG - uint32_t null_hash = is_buffer ? zink_screen(ctx->base.screen)->null_descriptor_hashes.buffer_view : - zink_screen(ctx->base.screen)->null_descriptor_hashes.image_view; - uint32_t cur_hash = get_image_view_hash(zds->image_views[i]) ? get_image_view_hash(zds->image_views[i]) : - null_hash; - uint32_t new_hash = get_image_view_hash(image_view) ? get_image_view_hash(image_view) : - null_hash; + uint32_t cur_hash = zink_get_image_view_hash(ctx, zds->image_views[i], is_buffer); + uint32_t new_hash = zink_get_image_view_hash(ctx, image_view, is_buffer); #endif assert(!cache_hit || cur_hash == new_hash); if (!cache_hit) -- 2.7.4