asahi: unbind samplers and fix sampler_count if state is NULL
authorIago López Galeiras <iaguis@gmail.com>
Tue, 13 Dec 2022 17:51:25 +0000 (18:51 +0100)
committerMarge Bot <emma+marge@anholt.net>
Wed, 14 Dec 2022 00:13:44 +0000 (00:13 +0000)
When states is NULL, unbind samplers (to avoid dangling pointers) and
set sampler_count to the highest non-null samplers[] entry instead of
setting it to 0.

This is ported from a similar fix in panfrost:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20285

Signed-off-by: Iago López Galeiras <iaguis@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20306>

src/gallium/drivers/asahi/agx_state.c
src/gallium/drivers/asahi/agx_state.h

index 40e3554..7a693bf 100644 (file)
@@ -426,11 +426,18 @@ agx_bind_sampler_states(struct pipe_context *pctx,
 {
    struct agx_context *ctx = agx_context(pctx);
 
-   ctx->stage[shader].sampler_count = states ? count : 0;
    ctx->stage[shader].dirty = ~0;
 
-   memcpy(&ctx->stage[shader].samplers[start], states,
-          sizeof(struct agx_sampler_state *) * count);
+   for (unsigned i = 0; i < count; i++) {
+      unsigned p = start + i;
+      ctx->stage[shader].samplers[p] = states ? states[i] : NULL;
+      if (ctx->stage[shader].samplers[p])
+         ctx->stage[shader].valid_samplers |= BITFIELD_BIT(p);
+      else
+         ctx->stage[shader].valid_samplers &= ~BITFIELD_BIT(p);
+   }
+
+   ctx->stage[shader].sampler_count = util_last_bit(ctx->stage[shader].valid_samplers);
 }
 
 /* Channels agree for RGBA but are weird for force 0/1 */
index 7866895..4fc59a8 100644 (file)
@@ -87,6 +87,7 @@ struct agx_stage {
    struct agx_sampler_view *textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
 
    unsigned sampler_count, texture_count;
+   uint32_t valid_samplers;
 };
 
 struct agx_batch {