panfrost: Emit texture descriptor on bifrost
authorTomeu Vizoso <tomeu.vizoso@collabora.com>
Fri, 17 Apr 2020 12:23:49 +0000 (14:23 +0200)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Fri, 24 Apr 2020 04:53:42 +0000 (06:53 +0200)
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4680>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h
src/panfrost/encoder/pan_texture.c
src/panfrost/encoder/pan_texture.h

index aae4880086ad9a9cec3c326ec881ae010c4a7502..dfc5174bef5894fbde961f1051f4b27dc54983f2 100644 (file)
@@ -1243,11 +1243,11 @@ panfrost_get_tex_desc(struct panfrost_batch *batch,
                               PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
                               panfrost_bo_access_for_stage(st));
 
-        panfrost_batch_add_bo(batch, view->bo,
+        panfrost_batch_add_bo(batch, view->midgard_bo,
                               PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
                               panfrost_bo_access_for_stage(st));
 
-        return view->bo->gpu;
+        return view->midgard_bo->gpu;
 }
 
 void
@@ -1256,20 +1256,45 @@ panfrost_emit_texture_descriptors(struct panfrost_batch *batch,
                                   struct mali_vertex_tiler_postfix *postfix)
 {
         struct panfrost_context *ctx = batch->ctx;
+        struct panfrost_device *device = pan_device(ctx->base.screen);
 
         if (!ctx->sampler_view_count[stage])
                 return;
 
-        uint64_t trampolines[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+        if (device->quirks & IS_BIFROST) {
+                struct bifrost_texture_descriptor *descriptors;
+
+                descriptors = malloc(sizeof(struct bifrost_texture_descriptor) *
+                                     ctx->sampler_view_count[stage]);
+
+                for (int i = 0; i < ctx->sampler_view_count[stage]; ++i) {
+                        struct panfrost_sampler_view *view = ctx->sampler_views[stage][i];
+                        struct pipe_sampler_view *pview = &view->base;
+                        struct panfrost_resource *rsrc = pan_resource(pview->texture);
+
+                        panfrost_batch_add_bo(batch, rsrc->bo,
+                                              PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
+                                              panfrost_bo_access_for_stage(stage));
 
-         for (int i = 0; i < ctx->sampler_view_count[stage]; ++i)
-                trampolines[i] = panfrost_get_tex_desc(batch, stage,
-                                                       ctx->sampler_views[stage][i]);
+                        memcpy(&descriptors[i], view->bifrost_descriptor, sizeof(*view->bifrost_descriptor));
+                }
+
+                postfix->textures = panfrost_upload_transient(batch,
+                                                              descriptors,
+                                                              sizeof(struct bifrost_texture_descriptor) *
+                                                                      ctx->sampler_view_count[stage]);
+        } else {
+                uint64_t trampolines[PIPE_MAX_SHADER_SAMPLER_VIEWS];
 
-         postfix->texture_trampoline = panfrost_upload_transient(batch,
-                                                                 trampolines,
-                                                                 sizeof(uint64_t) *
-                                                                 ctx->sampler_view_count[stage]);
+                for (int i = 0; i < ctx->sampler_view_count[stage]; ++i)
+                        trampolines[i] = panfrost_get_tex_desc(batch, stage,
+                                                               ctx->sampler_views[stage][i]);
+
+                postfix->textures = panfrost_upload_transient(batch,
+                                                              trampolines,
+                                                              sizeof(uint64_t) *
+                                                              ctx->sampler_view_count[stage]);
+        }
 }
 
 void
index a918659157803071f66443f4398831d62e977876..d8bcdd28fa5b428a4b35f0c25e4164846f996570 100644 (file)
@@ -929,29 +929,47 @@ panfrost_create_sampler_view(
         enum mali_texture_type type =
                 panfrost_translate_texture_type(template->target);
 
-        unsigned size = panfrost_estimate_texture_size(
-                        template->u.tex.first_level,
-                        template->u.tex.last_level,
-                        template->u.tex.first_layer,
-                        template->u.tex.last_layer,
-                        type, prsrc->layout);
-
-        so->bo = pan_bo_create(device, size, 0);
-
-        panfrost_new_texture(
-                        so->bo->cpu,
-                        texture->width0, texture->height0,
-                        texture->depth0, array_size,
-                        template->format,
-                        type, prsrc->layout,
-                        template->u.tex.first_level,
-                        template->u.tex.last_level,
-                        template->u.tex.first_layer,
-                        template->u.tex.last_layer,
-                        prsrc->cubemap_stride,
-                        panfrost_translate_swizzle_4(user_swizzle),
-                        prsrc->bo->gpu,
-                        prsrc->slices);
+        if (device->quirks & IS_BIFROST) {
+                so->bifrost_descriptor = rzalloc(pctx, struct bifrost_texture_descriptor);
+                panfrost_new_texture_bifrost(
+                                so->bifrost_descriptor,
+                                texture->width0, texture->height0,
+                                texture->depth0, array_size,
+                                template->format,
+                                type, prsrc->layout,
+                                template->u.tex.first_level,
+                                template->u.tex.last_level,
+                                template->u.tex.first_layer,
+                                template->u.tex.last_layer,
+                                prsrc->cubemap_stride,
+                                panfrost_translate_swizzle_4(user_swizzle),
+                                prsrc->bo->gpu,
+                                prsrc->slices);
+        } else {
+                unsigned size = panfrost_estimate_texture_size(
+                                template->u.tex.first_level,
+                                template->u.tex.last_level,
+                                template->u.tex.first_layer,
+                                template->u.tex.last_layer,
+                                type, prsrc->layout);
+
+                so->midgard_bo = pan_bo_create(device, size, 0);
+
+                panfrost_new_texture(
+                                so->midgard_bo->cpu,
+                                texture->width0, texture->height0,
+                                texture->depth0, array_size,
+                                template->format,
+                                type, prsrc->layout,
+                                template->u.tex.first_level,
+                                template->u.tex.last_level,
+                                template->u.tex.first_layer,
+                                template->u.tex.last_layer,
+                                prsrc->cubemap_stride,
+                                panfrost_translate_swizzle_4(user_swizzle),
+                                prsrc->bo->gpu,
+                                prsrc->slices);
+        }
 
         return (struct pipe_sampler_view *) so;
 }
index bc952b4ec306e63be853b7f272682633d0181eb7..7a4315036f9c9a98f127860d2070ee6b2b42ecfb 100644 (file)
@@ -256,7 +256,8 @@ struct panfrost_sampler_state {
 
 struct panfrost_sampler_view {
         struct pipe_sampler_view base;
-        struct panfrost_bo *bo;
+        struct panfrost_bo *midgard_bo;
+        struct bifrost_texture_descriptor *bifrost_descriptor;
 };
 
 static inline struct panfrost_context *
index 0c92464af084c3f051ffcdd334c347f616c98265..b0b630c7b934e1108dde201e69dcc7ae56978df3 100644 (file)
@@ -242,6 +242,47 @@ panfrost_new_texture(
         }
 }
 
+void
+panfrost_new_texture_bifrost(
+        struct bifrost_texture_descriptor *descriptor,
+        uint16_t width, uint16_t height,
+        uint16_t depth, uint16_t array_size,
+        enum pipe_format format,
+        enum mali_texture_type type,
+        enum mali_texture_layout layout,
+        unsigned first_level, unsigned last_level,
+        unsigned first_layer, unsigned last_layer,
+        unsigned cube_stride,
+        unsigned swizzle,
+        mali_ptr base,
+        struct panfrost_slice *slices)
+{
+        const struct util_format_description *desc =
+                util_format_description(format);
+
+        enum mali_format mali_format = panfrost_find_format(desc);
+
+        descriptor->format_unk = 0x2;
+        descriptor->type = type;
+        descriptor->format_unk2 = 0x100;
+        descriptor->format = mali_format;
+        descriptor->srgb = (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB);
+        descriptor->format_unk3 = 0x0;
+        descriptor->width = MALI_POSITIVE(u_minify(width, first_level));
+        descriptor->height = MALI_POSITIVE(u_minify(height, first_level));
+        descriptor->swizzle = swizzle;
+        descriptor->unk0 = 0x1;
+        descriptor->levels = last_level - first_level;
+        descriptor->unk1 = 0x0;
+        descriptor->levels_unk = 0;
+        descriptor->level_2 = 0;
+        descriptor->payload = base;
+        descriptor->array_size = MALI_POSITIVE(array_size);
+        descriptor->unk4 = 0x0;
+        descriptor->depth = MALI_POSITIVE(u_minify(depth, first_level));
+        descriptor->unk5 = 0x0;
+}
+
 /* Computes sizes for checksumming, which is 8 bytes per 16x16 tile.
  * Checksumming is believed to be a CRC variant (CRC64 based on the size?).
  * This feature is also known as "transaction elimination". */
index 241e1f8b4e67052b86c8d922da773b16206f0b59..77c0eaaf049d1045cadc41b99b5cc24fc40e9e4e 100644 (file)
@@ -87,6 +87,21 @@ panfrost_new_texture(
         mali_ptr base,
         struct panfrost_slice *slices);
 
+void
+panfrost_new_texture_bifrost(
+        struct bifrost_texture_descriptor *descriptor,
+        uint16_t width, uint16_t height,
+        uint16_t depth, uint16_t array_size,
+        enum pipe_format format,
+        enum mali_texture_type type,
+        enum mali_texture_layout layout,
+        unsigned first_level, unsigned last_level,
+        unsigned first_layer, unsigned last_layer,
+        unsigned cube_stride,
+        unsigned swizzle,
+        mali_ptr base,
+        struct panfrost_slice *slices);
+
 
 unsigned
 panfrost_get_layer_stride(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level);