panfrost: Emit sampler descriptor on bifrost
authorTomeu Vizoso <tomeu.vizoso@collabora.com>
Fri, 17 Apr 2020 12:23:39 +0000 (14:23 +0200)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Fri, 24 Apr 2020 04:53:39 +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_cmdstream.h
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h

index d07e7ae278adff9f16f95f10017c7579e7c42789..aae4880086ad9a9cec3c326ec881ae010c4a7502 100644 (file)
@@ -483,6 +483,33 @@ void panfrost_sampler_desc_init(const struct pipe_sampler_state *cso,
                 hw->max_lod = hw->min_lod + 1;
 }
 
+void panfrost_sampler_desc_init_bifrost(const struct pipe_sampler_state *cso,
+                                        struct bifrost_sampler_descriptor *hw)
+{
+        *hw = (struct bifrost_sampler_descriptor) {
+                .unk1 = 0x1,
+                .wrap_s = translate_tex_wrap(cso->wrap_s),
+                .wrap_t = translate_tex_wrap(cso->wrap_t),
+                .wrap_r = translate_tex_wrap(cso->wrap_r),
+                .unk8 = 0x8,
+                .unk2 = 0x2,
+                .min_filter = cso->min_img_filter == PIPE_TEX_FILTER_NEAREST,
+                .norm_coords = cso->normalized_coords,
+                .mip_filter = cso->min_mip_filter == PIPE_TEX_MIPFILTER_LINEAR,
+                .mag_filter = cso->mag_img_filter == PIPE_TEX_FILTER_LINEAR,
+                .min_lod = FIXED_16(cso->min_lod, false), /* clamp at 0 */
+                .max_lod = FIXED_16(cso->max_lod, false),
+        };
+
+        /* If necessary, we disable mipmapping in the sampler descriptor by
+         * clamping the LOD as tight as possible (from 0 to epsilon,
+         * essentially -- remember these are fixed point numbers, so
+         * epsilon=1/256) */
+
+        if (cso->min_mip_filter == PIPE_TEX_MIPFILTER_NONE)
+                hw->max_lod = hw->min_lod + 1;
+}
+
 static void
 panfrost_make_stencil_state(const struct pipe_stencil_state *in,
                             struct mali_stencil_test *out)
@@ -1251,20 +1278,34 @@ panfrost_emit_sampler_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_count[stage])
                 return;
 
-        size_t desc_size = sizeof(struct mali_sampler_descriptor);
-        size_t transfer_size = desc_size * ctx->sampler_count[stage];
-        struct panfrost_transfer transfer = panfrost_allocate_transient(batch,
-                                                                        transfer_size);
-        struct mali_sampler_descriptor *desc = (struct mali_sampler_descriptor *)transfer.cpu;
+        if (device->quirks & IS_BIFROST) {
+                size_t desc_size = sizeof(struct bifrost_sampler_descriptor);
+                size_t transfer_size = desc_size * ctx->sampler_count[stage];
+                struct panfrost_transfer transfer = panfrost_allocate_transient(batch,
+                                                                                transfer_size);
+                struct bifrost_sampler_descriptor *desc = (struct bifrost_sampler_descriptor *)transfer.cpu;
+
+                for (int i = 0; i < ctx->sampler_count[stage]; ++i)
+                        desc[i] = ctx->samplers[stage][i]->bifrost_hw;
 
-        for (int i = 0; i < ctx->sampler_count[stage]; ++i)
-                desc[i] = ctx->samplers[stage][i]->hw;
+                postfix->sampler_descriptor = transfer.gpu;
+        } else {
+                size_t desc_size = sizeof(struct mali_sampler_descriptor);
+                size_t transfer_size = desc_size * ctx->sampler_count[stage];
+                struct panfrost_transfer transfer = panfrost_allocate_transient(batch,
+                                                                                transfer_size);
+                struct mali_sampler_descriptor *desc = (struct mali_sampler_descriptor *)transfer.cpu;
+
+                for (int i = 0; i < ctx->sampler_count[stage]; ++i)
+                        desc[i] = ctx->samplers[stage][i]->midgard_hw;
 
-        postfix->sampler_descriptor = transfer.gpu;
+                postfix->sampler_descriptor = transfer.gpu;
+        }
 }
 
 void
index e56fb4a44c3159eada9e6dd0996cc5c467bda73f..908aa1f6b9ecaa6b0e23015c718aac95e896f64a 100644 (file)
@@ -35,6 +35,9 @@
 void panfrost_sampler_desc_init(const struct pipe_sampler_state *cso,
                                 struct mali_sampler_descriptor *hw);
 
+void panfrost_sampler_desc_init_bifrost(const struct pipe_sampler_state *cso,
+                                        struct bifrost_sampler_descriptor *hw);
+
 void
 panfrost_vt_init(struct panfrost_context *ctx,
                  enum pipe_shader_type stage,
index 90171c70097d6b10994bd551d39fca042148a1c4..a918659157803071f66443f4398831d62e977876 100644 (file)
@@ -592,9 +592,14 @@ panfrost_create_sampler_state(
         const struct pipe_sampler_state *cso)
 {
         struct panfrost_sampler_state *so = CALLOC_STRUCT(panfrost_sampler_state);
+        struct panfrost_device *device = pan_device(pctx->screen);
+
         so->base = *cso;
 
-        panfrost_sampler_desc_init(cso, &so->hw);
+        if (device->quirks & IS_BIFROST)
+                panfrost_sampler_desc_init_bifrost(cso, &so->bifrost_hw);
+        else
+                panfrost_sampler_desc_init(cso, &so->midgard_hw);
 
         return so;
 }
@@ -986,7 +991,9 @@ panfrost_sampler_view_destroy(
         struct panfrost_sampler_view *view = (struct panfrost_sampler_view *) pview;
 
         pipe_resource_reference(&pview->texture, NULL);
-        panfrost_bo_unreference(view->bo);
+        panfrost_bo_unreference(view->midgard_bo);
+        if (view->bifrost_descriptor)
+                ralloc_free(view->bifrost_descriptor);
         ralloc_free(view);
 }
 
index c8108d585b36b23af1e5f51ec5aa4ff3adde93fb..bc952b4ec306e63be853b7f272682633d0181eb7 100644 (file)
@@ -248,7 +248,8 @@ struct panfrost_vertex_state {
 
 struct panfrost_sampler_state {
         struct pipe_sampler_state base;
-        struct mali_sampler_descriptor hw;
+        struct mali_sampler_descriptor midgard_hw;
+        struct bifrost_sampler_descriptor bifrost_hw;
 };
 
 /* Misnomer: Sampler view corresponds to textures, not samplers */