From a3c73987ab92f7a43cd4e8918bde8b4bd04ca9fd Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sat, 11 Feb 2023 12:28:52 -0800 Subject: [PATCH] freedreno/a6xx: Move rsc seqno out of tex cache key Since we invalidate tex cache entries if an associated pipe_resource is rebound, we don't rely on the rsc_seqno being part of the tex cache key. Signed-off-by: Rob Clark Part-of: --- src/gallium/drivers/freedreno/a6xx/fd6_texture.c | 37 +++++++++++++++--------- src/gallium/drivers/freedreno/a6xx/fd6_texture.h | 20 +++++-------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c index 7cc4c42..a30d5d4 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c @@ -317,8 +317,8 @@ fd6_sampler_state_delete(struct pipe_context *pctx, void *hwcso) hash_table_foreach (fd6_ctx->tex_cache, entry) { struct fd6_texture_state *state = entry->data; - for (unsigned i = 0; i < ARRAY_SIZE(state->key.samp); i++) { - if (samp->seqno == state->key.samp[i].seqno) { + for (unsigned i = 0; i < ARRAY_SIZE(state->key.samp_seqno); i++) { + if (samp->seqno == state->key.samp_seqno[i]) { remove_tex_entry(fd6_ctx, entry); break; } @@ -479,8 +479,8 @@ fd6_sampler_view_destroy(struct pipe_context *pctx, hash_table_foreach (fd6_ctx->tex_cache, entry) { struct fd6_texture_state *state = entry->data; - for (unsigned i = 0; i < ARRAY_SIZE(state->key.view); i++) { - if (view->seqno == state->key.view[i].seqno) { + for (unsigned i = 0; i < ARRAY_SIZE(state->key.view_seqno); i++) { + if (view->seqno == state->key.view_seqno[i]) { remove_tex_entry(fd6_ctx, entry); break; } @@ -705,13 +705,7 @@ fd6_texture_state(struct fd_context *ctx, enum pipe_shader_type type, struct fd6_pipe_sampler_view *view = fd6_pipe_sampler_view(tex->textures[i]); - /* NOTE that if the backing rsc was uncompressed between the - * time that the CSO was originally created and now, the rsc - * seqno would have changed, so we don't have to worry about - * getting a bogus cache hit. - */ - key.view[i].rsc_seqno = fd_resource(view->base.texture)->seqno; - key.view[i].seqno = view->seqno; + key.view_seqno[i] = view->seqno; } for (unsigned i = 0; i < tex->num_samplers; i++) { @@ -721,7 +715,7 @@ fd6_texture_state(struct fd_context *ctx, enum pipe_shader_type type, struct fd6_sampler_stateobj *sampler = fd6_sampler_stateobj(tex->samplers[i]); - key.samp[i].seqno = sampler->seqno; + key.samp_seqno[i] = sampler->seqno; } key.type = type; @@ -737,11 +731,24 @@ fd6_texture_state(struct fd_context *ctx, enum pipe_shader_type type, if (entry) { state = entry->data; + for (unsigned i = 0; i < tex->num_textures; i++) { + uint16_t seqno = tex->textures[i] ? + fd_resource(tex->textures[i]->texture)->seqno : 0; + + assert(state->view_rsc_seqno[i] == seqno); + } goto out_unlock; } state = CALLOC_STRUCT(fd6_texture_state); + for (unsigned i = 0; i < tex->num_textures; i++) { + if (!tex->textures[i]) + continue; + + state->view_rsc_seqno[i] = fd_resource(tex->textures[i]->texture)->seqno; + } + state->key = key; state->stateobj = fd_ringbuffer_new_object(ctx->pipe, 32 * 4); @@ -778,8 +785,10 @@ fd6_rebind_resource(struct fd_context *ctx, struct fd_resource *rsc) assert_dt hash_table_foreach (fd6_ctx->tex_cache, entry) { struct fd6_texture_state *state = entry->data; - for (unsigned i = 0; i < ARRAY_SIZE(state->key.view); i++) { - if (rsc->seqno == state->key.view[i].rsc_seqno) { + STATIC_ASSERT(ARRAY_SIZE(state->view_rsc_seqno) == ARRAY_SIZE(state->key.view_seqno)); + + for (unsigned i = 0; i < ARRAY_SIZE(state->view_rsc_seqno); i++) { + if (rsc->seqno == state->view_rsc_seqno[i]) { struct fd6_texture_state *tex = entry->data; tex->invalidate = true; fd6_ctx->tex_cache_needs_invalidate = true; diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_texture.h b/src/gallium/drivers/freedreno/a6xx/fd6_texture.h index 89c2adb..f970d6a 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_texture.h +++ b/src/gallium/drivers/freedreno/a6xx/fd6_texture.h @@ -112,24 +112,20 @@ void fd6_texture_fini(struct pipe_context *pctx); */ struct fd6_texture_key { - struct { - /* We need to track the seqno of the rsc as well as of the - * sampler view, because resource shadowing/etc can result - * that the underlying bo changes (which means the previous - * state was no longer valid. - */ - uint16_t rsc_seqno; - uint16_t seqno; - } view[16]; - struct { - uint16_t seqno; - } samp[16]; + uint16_t view_seqno[16]; + uint16_t samp_seqno[16]; uint8_t type; }; struct fd6_texture_state { struct fd6_texture_key key; struct fd_ringbuffer *stateobj; + /** + * Track the rsc seqno's associated with the texture views so + * we know what to invalidate when a rsc is rebound when the + * underlying bo changes. (For example, demotion from UBWC.) + */ + uint16_t view_rsc_seqno[16]; bool invalidate; }; -- 2.7.4