panfrost: implement gallium->set_shader_images
authorItalo Nicola <italonicola@collabora.com>
Fri, 11 Dec 2020 16:47:35 +0000 (16:47 +0000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 27 Jan 2021 12:39:41 +0000 (12:39 +0000)
Implements gallium images endpoint.
If an AFBC resource is bound to an image, we convert it to tiled, since
images need pixel-level granularity and AFBC doesn't allow for that.

Signed-off-by: Italo Nicola <italonicola@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8066>

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

index 95ee7e5..3382c35 100644 (file)
@@ -637,6 +637,47 @@ panfrost_bind_rasterizer_state(
         ctx->rasterizer = hwcso;
 }
 
+static void
+panfrost_set_shader_images(
+        struct pipe_context *pctx,
+        enum pipe_shader_type shader,
+        unsigned start_slot, unsigned count,
+        const struct pipe_image_view *iviews)
+{
+        struct panfrost_context *ctx = pan_context(pctx);
+
+        /* Unbind start_slot...start_slot+count */
+        if (!iviews) {
+                for (int i = start_slot; i < start_slot + count; i++) {
+                        pipe_resource_reference(&ctx->images[shader][i].resource, NULL);
+                }
+
+                ctx->image_mask[shader] &= ~(((1ull << count) - 1) << start_slot);
+                return;
+        }
+
+        /* Bind start_slot...start_slot+count */
+        for (int i = 0; i < count; i++) {
+                const struct pipe_image_view *image = &iviews[i];
+                SET_BIT(ctx->image_mask[shader], 1 << (start_slot + i), image->resource);
+
+                if (!image->resource) {
+                        util_copy_image_view(&ctx->images[shader][start_slot+i], NULL);
+                        continue;
+                }
+
+                struct panfrost_resource *rsrc = pan_resource(image->resource);
+
+                /* Images don't work with AFBC, since they require pixel-level granularity */
+                if (drm_is_afbc(rsrc->layout.modifier)) {
+                        pan_resource_modifier_convert(ctx, rsrc,
+                                        DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED);
+                }
+
+                util_copy_image_view(&ctx->images[shader][start_slot+i], image);
+        }
+}
+
 static void *
 panfrost_create_vertex_elements_state(
         struct pipe_context *pctx,
@@ -1187,16 +1228,6 @@ panfrost_set_shader_buffers(
 }
 
 static void
-panfrost_set_shader_images(
-        struct pipe_context *pctx,
-        enum pipe_shader_type shader,
-        unsigned start, unsigned count,
-        const struct pipe_image_view *images)
-{
-        /* TODO */
-}
-
-static void
 panfrost_set_framebuffer_state(struct pipe_context *pctx,
                                const struct pipe_framebuffer_state *fb)
 {
index 39ee218..8a0ea8f 100644 (file)
@@ -156,6 +156,9 @@ struct panfrost_context {
         struct pipe_shader_buffer ssbo[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
         uint32_t ssbo_mask[PIPE_SHADER_TYPES];
 
+        struct pipe_image_view images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
+        uint32_t image_mask[PIPE_SHADER_TYPES];
+
         struct panfrost_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
         unsigned sampler_count[PIPE_SHADER_TYPES];