freedreno/a6xx: invalidate tex state cache entries on rebind
authorRob Clark <robdclark@chromium.org>
Fri, 24 Apr 2020 22:15:09 +0000 (15:15 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Apr 2020 00:08:57 +0000 (00:08 +0000)
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 <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4744>

src/gallium/drivers/freedreno/a6xx/fd6_texture.c
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/freedreno/freedreno_resource.c

index 5fa64e1da49b675f7b8ff2aa2cba091a3b8d85d5..a5396d939c89ce701dbeb447f569ba56ca4511fb 100644 (file)
@@ -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);
 }
 
index 57a172eede8f7732ede68314bd3a5cdf58b7976e..b920c01f7c65a1466e95c0ecbdfec8f03e9d8cc7 100644 (file)
@@ -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);
index 88967bf977741e2af76d35570fa4a04a513c2eeb..25793a71859ef1c92da6399d61006f22819da246 100644 (file)
@@ -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;