From d51fc12af9dd0189be7b3eae0c96a6336eeaca18 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 12 Dec 2022 19:32:32 +0300 Subject: [PATCH] panfrost: fix sampler_count and unbind samplers in bind_sampler_states 1. Old approach did not support unbind (set to NULL) samplers because it only copied memory if sampler is not empty. New approach checks if sampler is empty - it will set NULL. 2. Old approach just set sampler_count to 0 if sampler is empty. That's wrong and we need to find highest non-null samplers[] entry. It was done in new approach. 3. Gallium dosc says: ``` NOTE: at this time, start is always zero ... This may change in the future. ``` It's better to take into consideration start parameter in new approach. Part-of: --- src/gallium/drivers/panfrost/pan_context.c | 15 ++++++++++----- src/gallium/drivers/panfrost/pan_context.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 80a39a3a220..5cac001abfe 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -323,14 +323,19 @@ panfrost_bind_sampler_states( unsigned start_slot, unsigned num_sampler, void **sampler) { - assert(start_slot == 0); - struct panfrost_context *ctx = pan_context(pctx); ctx->dirty_shader[shader] |= PAN_DIRTY_STAGE_SAMPLER; - ctx->sampler_count[shader] = sampler ? num_sampler : 0; - if (sampler) - memcpy(ctx->samplers[shader], sampler, num_sampler * sizeof (void *)); + for (unsigned i = 0; i < num_sampler; i++) { + unsigned p = start_slot + i; + ctx->samplers[shader][p] = sampler ? sampler[i] : NULL; + if (ctx->samplers[shader][p]) + ctx->valid_samplers[shader] |= BITFIELD_BIT(p); + else + ctx->valid_samplers[shader] &= ~BITFIELD_BIT(p); + } + + ctx->sampler_count[shader] = util_last_bit(ctx->valid_samplers[shader]); } static void diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 37c0f6fc099..2bcaf3533e7 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -196,6 +196,7 @@ struct panfrost_context { struct panfrost_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; unsigned sampler_count[PIPE_SHADER_TYPES]; + uint32_t valid_samplers[PIPE_SHADER_TYPES]; struct panfrost_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS]; unsigned sampler_view_count[PIPE_SHADER_TYPES];