panfrost: fix sampler_count and unbind samplers in bind_sampler_states
authorAleksey Komarov <q4arus@ya.ru>
Mon, 12 Dec 2022 16:32:32 +0000 (19:32 +0300)
committerMarge Bot <emma+marge@anholt.net>
Tue, 13 Dec 2022 18:28:21 +0000 (18:28 +0000)
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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20285>

src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h

index 80a39a3..5cac001 100644 (file)
@@ -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
index 37c0f6f..2bcaf35 100644 (file)
@@ -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];