zink: fix shadow mask change logic when binding sampler views
authorSoroushIMG <soroush.kashani@imgtec.com>
Sat, 25 Feb 2023 22:19:49 +0000 (22:19 +0000)
committerMarge Bot <emma+marge@anholt.net>
Tue, 14 Mar 2023 17:03:29 +0000 (17:03 +0000)
First make sure shadow mask change sets dirty state.
Second move shadow mask bit removal to unbind_samplerview which
is cleaner and correctly clears the shadow bit when binding buffer texture.

Fixes: 5193f4f712b ("zink: add a fs shader key member to indicate depth texturing mode")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21571>

src/gallium/drivers/zink/zink_context.c

index dbb00d2..cf77cec 100644 (file)
@@ -1931,6 +1931,10 @@ unbind_samplerview(struct zink_context *ctx, gl_shader_stage stage, unsigned slo
       if (!res->sampler_bind_count[stage == MESA_SHADER_COMPUTE])
          check_for_layout_update(ctx, res, stage == MESA_SHADER_COMPUTE);
    }
+   if (stage == MESA_SHADER_FRAGMENT) {
+      assert(slot < 32);
+      ctx->di.shadow.mask &= ~BITFIELD_BIT(slot);
+   }
 }
 
 static void
@@ -1946,6 +1950,7 @@ zink_set_sampler_views(struct pipe_context *pctx,
    unsigned i;
 
    const uint32_t mask = BITFIELD_RANGE(start_slot, num_views);
+   uint32_t shadow_mask = ctx->di.shadow.mask;
    ctx->di.cubes[shader_type] &= ~mask;
 
    bool update = false;
@@ -2015,7 +2020,7 @@ zink_set_sampler_views(struct pipe_context *pctx,
                shadow_update |= memcmp(&ctx->di.shadow.swizzle[start_slot + i],
                                        &b->swizzle, sizeof(struct zink_fs_shadow_swizzle));
                memcpy(&ctx->di.shadow.swizzle[start_slot + i], &b->swizzle, sizeof(struct zink_fs_shadow_swizzle));
-            } else if (ctx->di.shadow.mask) {
+            } else if (shader_type == MESA_SHADER_FRAGMENT) {
                assert(start_slot + i < 32); //bitfield size
                ctx->di.shadow.mask &= ~BITFIELD_BIT(start_slot + i);
             }
@@ -2025,10 +2030,6 @@ zink_set_sampler_views(struct pipe_context *pctx,
       } else if (a) {
          unbind_samplerview(ctx, shader_type, start_slot + i);
          update = true;
-         if (ctx->di.shadow.mask) {
-            assert(start_slot + i < 32); //bitfield size
-            ctx->di.shadow.mask &= ~BITFIELD_BIT(start_slot + i);
-         }
       }
       if (take_ownership) {
          pipe_sampler_view_reference(&ctx->sampler_views[shader_type][start_slot + i], NULL);
@@ -2045,10 +2046,6 @@ zink_set_sampler_views(struct pipe_context *pctx,
          &ctx->sampler_views[shader_type][start_slot + i],
          NULL);
       update_descriptor_state_sampler(ctx, shader_type, start_slot + i, NULL);
-      if (ctx->di.shadow.mask) {
-         assert(start_slot + i < 32); //bitfield size
-         ctx->di.shadow.mask &= ~BITFIELD_BIT(start_slot + i);
-      }
    }
    ctx->di.num_sampler_views[shader_type] = start_slot + num_views;
    if (update) {
@@ -2056,6 +2053,7 @@ zink_set_sampler_views(struct pipe_context *pctx,
       zink_context_invalidate_descriptor_state(ctx, shader_type, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW, start_slot, num_views);
       if (!screen->info.have_EXT_non_seamless_cube_map)
          update_nonseamless_shader_key(ctx, shader_type);
+         shadow_update |= shadow_mask != ctx->di.shadow.mask;
       zink_set_fs_shadow_needs_shader_swizzle_key(ctx, shadow_update);
    }
 }