From: Rob Clark Date: Fri, 24 Apr 2020 22:15:09 +0000 (-0700) Subject: freedreno/a6xx: invalidate tex state cache entries on rebind X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6de01faac5a20208422fb75d22f2bd88c53f53d8;p=mesa.git freedreno/a6xx: invalidate tex state cache entries on rebind When a resource's backing bo changes, its seqno will be incremented. Which would result in a new tex state cache key, and nothing to clean up the old tex state until the sampler view/state is destroyed. But in some games, that may never happen, or at least not happen before we run out of memory. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2830 Signed-off-by: Rob Clark Part-of: --- diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c index 5fa64e1da49..a5396d939c8 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c @@ -441,10 +441,31 @@ fd6_texture_state_destroy(struct fd6_texture_state *state) free(state); } +static void +fd6_rebind_resource(struct fd_context *ctx, struct fd_resource *rsc) +{ + if (!(rsc->dirty & FD_DIRTY_TEX)) + return; + + struct fd6_context *fd6_ctx = fd6_context(ctx); + + 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) { + fd6_texture_state_destroy(entry->data); + _mesa_hash_table_remove(fd6_ctx->tex_cache, entry); + } + } + } +} + void fd6_texture_init(struct pipe_context *pctx) { - struct fd6_context *fd6_ctx = fd6_context(fd_context(pctx)); + struct fd_context *ctx = fd_context(pctx); + struct fd6_context *fd6_ctx = fd6_context(ctx); pctx->create_sampler_state = fd6_sampler_state_create; pctx->delete_sampler_state = fd6_sampler_state_delete; @@ -454,6 +475,8 @@ fd6_texture_init(struct pipe_context *pctx) pctx->sampler_view_destroy = fd6_sampler_view_destroy; pctx->set_sampler_views = fd_set_sampler_views; + ctx->rebind_resource = fd6_rebind_resource; + fd6_ctx->tex_cache = _mesa_hash_table_create(NULL, key_hash, key_equals); } diff --git a/src/gallium/drivers/freedreno/freedreno_context.h b/src/gallium/drivers/freedreno/freedreno_context.h index 57a172eede8..b920c01f7c6 100644 --- a/src/gallium/drivers/freedreno/freedreno_context.h +++ b/src/gallium/drivers/freedreno/freedreno_context.h @@ -324,6 +324,9 @@ struct fd_context { struct pipe_debug_callback debug; + /* Called on rebind_resource() for any per-gen cleanup required: */ + void (*rebind_resource)(struct fd_context *ctx, struct fd_resource *rsc); + /* GMEM/tile handling fxns: */ void (*emit_tile_init)(struct fd_batch *batch); void (*emit_tile_prep)(struct fd_batch *batch, const struct fd_tile *tile); diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index 88967bf9777..25793a71859 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -69,6 +69,9 @@ rebind_resource_in_ctx(struct fd_context *ctx, struct fd_resource *rsc) { struct pipe_resource *prsc = &rsc->base; + if (ctx->rebind_resource) + ctx->rebind_resource(ctx, rsc); + /* VBOs */ if (rsc->dirty & FD_DIRTY_VTXBUF) { struct fd_vertexbuf_stateobj *vb = &ctx->vtx.vertexbuf;