Module: Mesa
Branch: main
Commit: 3c668513b9e3c87f067b3e1b715715d70bcdcc82
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3c668513b9e3c87f067b3e1b715715d70bcdcc82

Author: Rob Clark <[email protected]>
Date:   Wed Feb 15 14:06:17 2023 -0800

freedreno/a6xx: Fix view_seqno in tex cache key

If the view's seqno increments, it needs to happen *before* the tex cache
key is constructed.  Normally this happens when the sampler views are
bound.  But if the texture backing a current sampler view is rebound we
need to handle this before the cache lookup.

Signed-off-by: Rob Clark <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21408>

---

 src/gallium/drivers/freedreno/a6xx/fd6_texture.c | 32 +++++++++++++++++-------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c 
b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c
index 2ea25dc1b88..013cfa4e75a 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c
@@ -608,11 +608,9 @@ build_texture_state(struct fd_context *ctx, enum 
pipe_shader_type type,
 
          if (tex->textures[i]) {
             view = fd6_pipe_sampler_view(tex->textures[i]);
-            if (unlikely(view->rsc_seqno !=
-                         fd_resource(view->base.texture)->seqno)) {
-               fd6_sampler_view_update(ctx,
-                                       
fd6_pipe_sampler_view(tex->textures[i]));
-            }
+            struct fd_resource *rsc = fd_resource(view->base.texture);
+            fd6_assert_valid_format(rsc, view->base.format);
+            assert(view->rsc_seqno == rsc->seqno);
          } else {
             static const struct fd6_pipe_sampler_view dummy_view = {};
             view = &dummy_view;
@@ -683,7 +681,7 @@ handle_invalidates(struct fd_context *ctx)
 {
    struct fd6_context *fd6_ctx = fd6_context(ctx);
 
-   fd_screen_assert_locked(ctx->screen);
+   fd_screen_lock(ctx->screen);
 
    hash_table_foreach (fd6_ctx->tex_cache, entry) {
       struct fd6_texture_state *state = entry->data;
@@ -692,6 +690,22 @@ handle_invalidates(struct fd_context *ctx)
          remove_tex_entry(fd6_ctx, entry);
    }
 
+   fd_screen_unlock(ctx->screen);
+
+   for (unsigned type = 0; type < ARRAY_SIZE(ctx->tex); type++) {
+      struct fd_texture_stateobj *tex = &ctx->tex[type];
+
+      for (unsigned i = 0; i < tex->num_textures; i++) {
+         struct fd6_pipe_sampler_view *so =
+               fd6_pipe_sampler_view(tex->textures[i]);
+
+         if (!so)
+            continue;
+
+         fd6_sampler_view_update(ctx, so);
+      }
+   }
+
    fd6_ctx->tex_cache_needs_invalidate = false;
 }
 
@@ -703,6 +717,9 @@ fd6_texture_state(struct fd_context *ctx, enum 
pipe_shader_type type)
    struct fd6_texture_state *state = NULL;
    struct fd6_texture_key key;
 
+   if (unlikely(fd6_ctx->tex_cache_needs_invalidate))
+      handle_invalidates(ctx);
+
    memset(&key, 0, sizeof(key));
 
    for (unsigned i = 0; i < tex->num_textures; i++) {
@@ -730,9 +747,6 @@ fd6_texture_state(struct fd_context *ctx, enum 
pipe_shader_type type)
    uint32_t hash = tex_key_hash(&key);
    fd_screen_lock(ctx->screen);
 
-   if (unlikely(fd6_ctx->tex_cache_needs_invalidate))
-      handle_invalidates(ctx);
-
    struct hash_entry *entry =
       _mesa_hash_table_search_pre_hashed(fd6_ctx->tex_cache, hash, &key);
 

Reply via email to