From 5f2171625b17d66fd568e3813c9dff11fe0f307e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= Date: Tue, 13 Dec 2022 18:51:25 +0100 Subject: [PATCH] asahi: unbind samplers and fix sampler_count if state is NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Part-of: --- src/gallium/drivers/asahi/agx_state.c | 13 ++++++++++--- src/gallium/drivers/asahi/agx_state.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 40e35540554..7a693bf1c29 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -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 */ diff --git a/src/gallium/drivers/asahi/agx_state.h b/src/gallium/drivers/asahi/agx_state.h index 78668951b76..4fc59a8213d 100644 --- a/src/gallium/drivers/asahi/agx_state.h +++ b/src/gallium/drivers/asahi/agx_state.h @@ -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 {