panfrost: XMLify Bifrost samplers
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 11 Aug 2020 22:25:03 +0000 (18:25 -0400)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Thu, 13 Aug 2020 06:55:16 +0000 (08:55 +0200)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6195>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/gallium/drivers/panfrost/pan_cmdstream.h
src/gallium/drivers/panfrost/pan_context.c
src/panfrost/include/panfrost-job.h
src/panfrost/lib/decode.c
src/panfrost/lib/midgard.xml

index 3d0a57aff24c0a560d8f70eb8e97c65ba0d051c1..97a5cff9626194d59ea54bbd007e2be1e0672aa5 100644 (file)
@@ -427,30 +427,25 @@ void panfrost_sampler_desc_init(const struct pipe_sampler_state *cso,
 }
 
 void panfrost_sampler_desc_init_bifrost(const struct pipe_sampler_state *cso,
-                                        uint32_t *_hw)
+                                        struct mali_bifrost_sampler_packed *hw)
 {
-        struct bifrost_sampler_descriptor *hw = (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,
-                .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),
-        };
+        pan_pack(hw, BIFROST_SAMPLER, cfg) {
+                cfg.magnify_linear = cso->mag_img_filter == PIPE_TEX_FILTER_LINEAR;
+                cfg.minify_linear = cso->min_img_filter == PIPE_TEX_FILTER_LINEAR;
+                cfg.mipmap_mode = pan_pipe_to_mipmode(cso->min_mip_filter);
+                cfg.normalized_coordinates = cso->normalized_coords;
 
-        /* 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) */
+                cfg.lod_bias = FIXED_16(cso->lod_bias, true);
+                cfg.minimum_lod = FIXED_16(cso->min_lod, false);
+                cfg.maximum_lod = FIXED_16(cso->max_lod, false);
 
-        if (cso->min_mip_filter == PIPE_TEX_MIPFILTER_NONE)
-                hw->max_lod = hw->min_lod + 1;
+                cfg.wrap_mode_s = translate_tex_wrap(cso->wrap_s);
+                cfg.wrap_mode_t = translate_tex_wrap(cso->wrap_t);
+                cfg.wrap_mode_r = translate_tex_wrap(cso->wrap_r);
+
+                cfg.compare_function = panfrost_sampler_compare_func(cso);
+                cfg.seamless_cube_map = cso->seamless_cube_map;
+        }
 }
 
 static void
@@ -1332,8 +1327,8 @@ panfrost_emit_sampler_descriptors(struct panfrost_batch *batch,
         if (!ctx->sampler_count[stage])
                 return;
 
-        size_t desc_size = sizeof(struct bifrost_sampler_descriptor);
-        assert(sizeof(struct bifrost_sampler_descriptor) == MALI_MIDGARD_SAMPLER_LENGTH);
+        size_t desc_size = MALI_BIFROST_SAMPLER_LENGTH;
+        assert(MALI_BIFROST_SAMPLER_LENGTH == MALI_MIDGARD_SAMPLER_LENGTH);
 
         size_t sz = desc_size * ctx->sampler_count[stage];
         struct panfrost_transfer T = panfrost_pool_alloc(&batch->pool, sz);
index 089f192cb84bee80aa3342fd086fba4aa90f79ea..e0425ba449c4a1710f8d39500e7cad46131e94b4 100644 (file)
@@ -33,7 +33,7 @@
 #include "pan_job.h"
 
 void panfrost_sampler_desc_init(const struct pipe_sampler_state *cso, struct mali_midgard_sampler_packed *hw);
-void panfrost_sampler_desc_init_bifrost(const struct pipe_sampler_state *cso, uint32_t *hw);
+void panfrost_sampler_desc_init_bifrost(const struct pipe_sampler_state *cso, struct mali_bifrost_sampler_packed *hw);
 
 void
 panfrost_vt_init(struct panfrost_context *ctx,
index 6b9166094860d449c3c4f3ea8e1e280a7174af87..6fd3f15d1f62d269f2820b0ed74608c660dc50e0 100644 (file)
@@ -605,7 +605,7 @@ panfrost_create_sampler_state(
         so->base = *cso;
 
         if (device->quirks & IS_BIFROST)
-                panfrost_sampler_desc_init_bifrost(cso, (uint32_t *) &so->hw);
+                panfrost_sampler_desc_init_bifrost(cso, (struct mali_bifrost_sampler_packed *) &so->hw);
         else
                 panfrost_sampler_desc_init(cso, &so->hw);
 
index 534e546254527d28ee42a8d2ee06acfe54a3b5cb..62067a557f159f171a9cf6b93275aad836a251d9 100644 (file)
@@ -1271,35 +1271,6 @@ FIXED_16(float x, bool allow_negative)
         return (int) (x * 256.0);
 }
 
-/* Bifrost sampler descriptors look pretty similar */
-
-#define BIFROST_SAMP_MIN_NEAREST        (1)
-#define BIFROST_SAMP_MAG_LINEAR         (1)
-
-struct bifrost_sampler_descriptor {
-        uint8_t unk1;
-
-        enum mali_wrap_mode wrap_r : 4;
-        enum mali_wrap_mode wrap_t : 4;
-        enum mali_wrap_mode wrap_s : 4;
-        uint8_t unk8 : 4;
-
-        uint8_t unk2 : 1;
-        uint8_t norm_coords : 1;
-        uint8_t unk3 : 1;
-        uint8_t min_filter : 1;
-        uint8_t zero1 : 1;
-        uint8_t mag_filter : 1;
-        uint8_t mip_filter : 1;
-
-        int16_t min_lod;
-        int16_t max_lod;
-
-        uint64_t zero2;
-        uint64_t zero3;
-        uint64_t zero4;
-} __attribute__((packed));
-
 /* From presentations, 16x16 tiles externally. Use shift for fast computation
  * of tile numbers. */
 
index b39aba081451c0656c2904fa39a7a0e304429ff9..4126ec546506a273217e682fb5380f3fa83d9993 100644 (file)
@@ -2422,56 +2422,12 @@ pandecode_textures(mali_ptr textures, unsigned texture_count, int job_no, bool i
 static void
 pandecode_samplers(mali_ptr samplers, unsigned sampler_count, int job_no, bool is_bifrost)
 {
-        struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(samplers);
-
-        if (!smem)
-                return;
-
-        if (is_bifrost) {
-                struct bifrost_sampler_descriptor *s;
-
-                for (int i = 0; i < sampler_count; ++i) {
-                        s = pandecode_fetch_gpu_mem(smem, samplers + sizeof(*s) * i, sizeof(*s));
-
-                        pandecode_log("struct bifrost_sampler_descriptor sampler_descriptor_%"PRIx64"_%d_%d = {\n", samplers + sizeof(*s) * i, job_no, i);
-                        pandecode_indent++;
-
-                        if (s->unk1 != 1) {
-                                pandecode_msg("XXX: unk1 tripped\n");
-                                pandecode_prop("unk1 = 0x%x", s->unk1);
-                        }
-
-                        pandecode_prop("wrap_s = %s", mali_wrap_mode_as_str(s->wrap_s));
-                        pandecode_prop("wrap_t = %s", mali_wrap_mode_as_str(s->wrap_t));
-                        pandecode_prop("wrap_r = %s", mali_wrap_mode_as_str(s->wrap_r));
-
-                        if (s->unk8 != 0x8) {
-                                pandecode_msg("XXX: unk8 tripped\n");
-                                pandecode_prop("unk8 = 0x%x", s->unk8);
-                        }
-
-                        pandecode_prop("unk2 = 0x%x", s->unk2);
-                        pandecode_prop("unk3 = 0x%x", s->unk3);
-                        pandecode_prop("min_filter = %s", s->min_filter ? "nearest" : "linear");
-                        pandecode_prop("norm_coords = 0x%x", s->norm_coords & 0x1);
-                        pandecode_prop("zero1 = 0x%x", s->zero1 & 0x1);
-                        pandecode_prop("mip_filter = %s", s->mip_filter ? "linear" : "nearest");
-                        pandecode_prop("mag_filter = %s", s->mag_filter ? "linear" : "nearest");
-
-                        pandecode_prop("min_lod = FIXED_16(%f)", DECODE_FIXED_16(s->min_lod));
-                        pandecode_prop("max_lod = FIXED_16(%f)", DECODE_FIXED_16(s->max_lod));
-
-                        if (s->zero1 || s->zero2 || s->zero3 || s->zero4) {
-                                pandecode_msg("XXX: sampler zero tripped\n");
-                                pandecode_prop("zero = 0x%" PRIx8 ", 0x%" PRIx64 ", 0x%" PRIx64 ", 0x%" PRIx64 "\n", s->zero1, s->zero2, s->zero3, s->zero4);
-                        }
-
-                        pandecode_indent--;
-                        pandecode_log("};\n");
-                }
-        } else {
-                for (int i = 0; i < sampler_count; ++i)
+        for (int i = 0; i < sampler_count; ++i) {
+                if (is_bifrost) {
+                        DUMP_ADDR("Sampler", BIFROST_SAMPLER, samplers + (MALI_BIFROST_SAMPLER_LENGTH * i), 1);
+                } else {
                         DUMP_ADDR("Sampler", MIDGARD_SAMPLER, samplers + (MALI_MIDGARD_SAMPLER_LENGTH * i), 1);
+                }
         }
 }
 
index 09191accec5ffc2be2c288f3342033ca6e389d23..7e4cf01c781ba446e060e2812fc513a51182dc70 100644 (file)
     <field name="Border Color A" size="32" start="7:0" type="float" default="0.0"/>
   </struct>
 
+  <struct name="Bifrost Sampler" size="8">
+    <field name="Type" size="4" start="0:0" type="uint" default="1"/>
+    <field name="Wrap Mode R" size="4" start="0:8" type="Wrap Mode" default="Clamp to Edge"/>
+    <field name="Wrap Mode T" size="4" start="0:12" type="Wrap Mode" default="Clamp to Edge"/>
+    <field name="Wrap Mode S" size="4" start="0:16" type="Wrap Mode" default="Clamp to Edge"/>
+    <field name="Seamless Cube Map" size="1" start="0:23" type="bool" default="true"/>
+    <field name="Normalized Coordinates" size="1" start="0:25" type="bool" default="true"/>
+    <field name="Minify Linear" size="1" start="0:27" type="bool" default="false"/>
+    <field name="Magnify Linear" size="1" start="0:28" type="bool" default="false"/>
+    <field name="Mipmap Mode" size="2" start="0:30" type="Mipmap Mode" default="Nearest"/>
+    <field name="Minimum LOD" size="13" start="1:0" type="uint" default="0"/>
+    <field name="Compare Function" size="3" start="1:13" type="Func" default="Never"/>
+    <field name="Maximum LOD" size="13" start="1:16" type="uint" default="0"/>
+    <field name="LOD bias" size="16" start="2:0" type="uint" default="0"/>
+  </struct>
+
   <struct name="Stencil">
     <field name="Reference Value" size="8" start="0" type="uint"/>
     <field name="Mask" size="8" start="8" type="uint" default="0xFF"/>