panfrost: XMLify blend flags

Shared between Midgard/Bifrost. We get printing this way!

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/6440>
diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c
index 538c6ee..f57d240 100644
--- a/src/gallium/drivers/panfrost/pan_cmdstream.c
+++ b/src/gallium/drivers/panfrost/pan_cmdstream.c
@@ -651,16 +651,18 @@
         for (unsigned i = 0; i < rt_count; ++i) {
                 unsigned flags = 0;
 
-                if (!blend[i].no_colour) {
-                        flags = 0x200;
+                pan_pack(&flags, BLEND_FLAGS, cfg) {
+                        if (blend[i].no_colour)
+                                break;
+
                         batch->draws |= (PIPE_CLEAR_COLOR0 << i);
 
-                        bool is_srgb = util_format_is_srgb(batch->key.cbufs[i]->format);
+                        cfg.srgb = util_format_is_srgb(batch->key.cbufs[i]->format);
+                        cfg.load_destination = !blend[i].no_blending; /* XXX */
+                        cfg.dither_disable = !batch->ctx->blend->base.dither;
 
-                        SET_BIT(flags, MALI_BLEND_MRT_SHADER, blend[i].is_shader);
-                        SET_BIT(flags, MALI_BLEND_LOAD_TIB, !blend[i].no_blending);
-                        SET_BIT(flags, MALI_BLEND_SRGB, is_srgb);
-                        SET_BIT(flags, MALI_BLEND_NO_DITHER, !batch->ctx->blend->base.dither);
+                        if (!(dev->quirks & IS_BIFROST))
+                                cfg.midgard_blend_shader = blend[i].is_shader;
                 }
 
                 if (dev->quirks & IS_BIFROST) {
@@ -696,7 +698,7 @@
                                 brts[i].shader_type = fs->blend_types[i];
                         }
                 } else {
-                        mrts[i].flags = flags;
+                        memcpy(&mrts[i].flags, &flags, sizeof(flags));
 
                         if (blend[i].is_shader) {
                                 mrts[i].blend.shader = blend[i].shader.gpu | blend[i].shader.first_tag;
diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h
index 057aed2..3f227fd 100644
--- a/src/panfrost/include/panfrost-job.h
+++ b/src/panfrost/include/panfrost-job.h
@@ -286,30 +286,9 @@
         };
 };
 
-/* We need to load the tilebuffer to blend (i.e. the destination factor is not
- * ZERO) */
-
-#define MALI_BLEND_LOAD_TIB (0x1)
-
-/* A blend shader is used to blend this render target */
-#define MALI_BLEND_MRT_SHADER (0x2)
-
-/* On MRT Midgard systems (using an MFBD), each render target gets its own
- * blend descriptor */
-
-#define MALI_BLEND_SRGB (0x400)
-
-/* Dithering is specified here for MFBD, otherwise NO_DITHER for SFBD */
-#define MALI_BLEND_NO_DITHER (0x800)
-
 struct midgard_blend_rt {
-        /* Flags base value of 0x200 to enable the render target.
-         * OR with 0x1 for blending (anything other than REPLACE).
-         * OR with 0x2 for programmable blending
-         * OR with MALI_BLEND_SRGB for implicit sRGB
-         */
-
-        u64 flags;
+        struct mali_blend_flags_packed flags;
+        u32 zero;
         union midgard_blend blend;
 } __attribute__((packed));
 
diff --git a/src/panfrost/lib/decode.c b/src/panfrost/lib/decode.c
index f2f5df9..d8567f4 100644
--- a/src/panfrost/lib/decode.c
+++ b/src/panfrost/lib/decode.c
@@ -1276,12 +1276,12 @@
                 ((struct midgard_blend_rt *) descs) + rt_no;
 
         /* Flags determine presence of blend shader */
-        bool is_shader = (b->flags & 0xF) >= 0x2;
+        bool is_shader = b->flags.opaque[0] & 0x2;
 
         pandecode_log("struct midgard_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
         pandecode_indent++;
 
-        pandecode_prop("flags = 0x%" PRIx64, b->flags);
+        DUMP_CL("Flags", BLEND_FLAGS, &b->flags, 2);
 
         union midgard_blend blend = b->blend;
         mali_ptr shader = pandecode_midgard_blend(&blend, is_shader);
diff --git a/src/panfrost/lib/midgard.xml b/src/panfrost/lib/midgard.xml
index 30a6423..0a3b6b1 100644
--- a/src/panfrost/lib/midgard.xml
+++ b/src/panfrost/lib/midgard.xml
@@ -256,6 +256,14 @@
     <field name="Divisor" size="32" start="3:0" type="uint"/>
   </struct>
 
+  <struct name="Blend Flags" size="1">
+    <field name="Load destination" size="1" start="0" type="bool" default="false"/>
+    <field name="Midgard blend shader" size="1" start="1" type="bool" default="false"/>
+    <field name="Enable" size="1" start="9" type="bool" default="true"/>
+    <field name="sRGB" size="1" start="10" type="bool" default="false"/>
+    <field name="Dither disable" size="1" start="11" type="bool" default="false"/>
+  </struct>
+
   <struct name="Midgard Sampler">
     <field name="Magnify Nearest" size="1" start="0" type="bool" default="true"/>
     <field name="Minify Nearest" size="1" start="1" type="bool" default="true"/>
diff --git a/src/panfrost/lib/pan_blit.c b/src/panfrost/lib/pan_blit.c
index 7494b0a..0676b85 100644
--- a/src/panfrost/lib/pan_blit.c
+++ b/src/panfrost/lib/pan_blit.c
@@ -322,17 +322,19 @@
 
                 if (loc == (FRAG_RESULT_DATA0 + i)) {
                         struct midgard_blend_rt blend_rt = {
-                                .flags = 0x200 | MALI_BLEND_NO_DITHER,
                                 .blend = replace,
                         };
 
-                        if (util_format_is_srgb(image->format))
-                                blend_rt.flags |= MALI_BLEND_SRGB;
-
-                        if (blend_shader) {
-                                blend_rt.flags |= MALI_BLEND_MRT_SHADER;
-                                blend_rt.blend.shader = blend_shader;
+                        unsigned flags = 0;
+                        pan_pack(&flags, BLEND_FLAGS, cfg) {
+                                cfg.dither_disable = true;
+                                cfg.srgb = util_format_is_srgb(image->format);
+                                cfg.midgard_blend_shader = blend_shader;
                         }
+                        blend_rt.flags.opaque[0] = flags;
+
+                        if (blend_shader)
+                                blend_rt.blend.shader = blend_shader;
 
                         memcpy(dest, &blend_rt, sizeof(struct midgard_blend_rt));
                 } else {