panfrost: XMLify blend equation
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 18 Aug 2020 22:15:45 +0000 (18:15 -0400)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Tue, 25 Aug 2020 15:05:34 +0000 (17:05 +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/6440>

src/gallium/drivers/panfrost/pan_blend.h
src/gallium/drivers/panfrost/pan_blend_cso.c
src/gallium/drivers/panfrost/pan_blending.c
src/gallium/drivers/panfrost/pan_blending.h
src/gallium/drivers/panfrost/pan_cmdstream.c
src/panfrost/include/panfrost-job.h
src/panfrost/lib/decode.c
src/panfrost/lib/midgard.xml
src/panfrost/lib/pan_blit.c

index a37d571c7d693e26fe8bd29a8e56e3683d183280..df1227bfd01b50cf8329f72469e3014ae319e792 100644 (file)
@@ -66,7 +66,7 @@ struct panfrost_blend_shader_final {
 };
 
 struct panfrost_blend_equation_final {
-        struct mali_blend_equation *equation;
+        struct mali_blend_equation_packed equation;
         float constant;
 };
 
@@ -75,7 +75,7 @@ struct panfrost_blend_rt {
          * fixed-function configuration for this blend state */
 
         bool has_fixed_function;
-        struct mali_blend_equation equation;
+        struct mali_blend_equation_packed equation;
 
         /* Mask of blend color components read */
         unsigned constant_mask;
index d600292e8a081e44d9cb23698cf9fe7b1572fcb5..4d90101366abf7f33a19734d4f4abb9192e75f82 100644 (file)
@@ -129,12 +129,8 @@ panfrost_create_blend_state(struct pipe_context *pipe,
                                         &rt->equation,
                                         &rt->constant_mask);
 
-                if (rt->has_fixed_function) {
-                        rt->opaque =
-                                (rt->equation.rgb_mode == 0x122) &&
-                                (rt->equation.alpha_mode == 0x122) &&
-                                (rt->equation.color_mask == 0xf);
-                }
+                if (rt->has_fixed_function)
+                        rt->opaque = (rt->equation.opaque[0] == 0xf0122122);
 
                 rt->load_dest = util_blend_uses_dest(pipe)
                         || pipe.colormask != 0xF;
@@ -241,12 +237,12 @@ panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rti)
                             rt->constant_mask)) {
                         struct panfrost_blend_final final = {
                                 .equation = {
-                                        .equation = &rt->equation,
+                                        .equation = rt->equation,
                                         .constant = constant
                                 },
                                 .load_dest = rt->load_dest,
                                 .opaque = rt->opaque,
-                                .no_colour = (rt->equation.color_mask == 0x0)
+                                .no_colour = rt->no_colour
                         };
 
                         return final;
index e1122880594b548ab720eda4ab167ab817e813cb..5a94975230db16bf3004c92e158bcc7a6942699d 100644 (file)
@@ -342,19 +342,17 @@ panfrost_constant_mask(unsigned *factors, unsigned num_factors)
 bool
 panfrost_make_fixed_blend_mode(
         struct pipe_rt_blend_state blend,
-        struct mali_blend_equation *out,
+        struct mali_blend_equation_packed *out,
         unsigned *constant_mask)
 {
-        /* Gallium and Mali represent colour masks identically. XXX: Static
-         * assert for future proof */
-
-        out->color_mask = blend.colormask;
-
         /* If no blending is enabled, default back on `replace` mode */
 
         if (!blend.blend_enable) {
-                out->rgb_mode = 0x122;
-                out->alpha_mode = 0x122;
+                pan_pack(out, BLEND_EQUATION, cfg) {
+                        cfg.color_mask = blend.colormask;
+                        cfg.rgb_mode = cfg.alpha_mode = 0x122;
+                }
+
                 return true;
         }
 
@@ -384,8 +382,11 @@ panfrost_make_fixed_blend_mode(
                     &alpha_mode))
                 return false;
 
-        out->rgb_mode = rgb_mode;
-        out->alpha_mode = alpha_mode;
+        pan_pack(out, BLEND_EQUATION, cfg) {
+                cfg.color_mask = blend.colormask;
+                cfg.rgb_mode = rgb_mode;
+                cfg.alpha_mode = alpha_mode;
+        }
 
         return true;
 }
index 123b1d13bf45c8352493986e796128b942fe48f8..c466e8d665ad40845c979fdb6c844c4396d08799 100644 (file)
@@ -34,7 +34,7 @@ struct panfrost_blend_state;
 bool
 panfrost_make_fixed_blend_mode(
         const struct pipe_rt_blend_state blend,
-        struct mali_blend_equation *out,
+        struct mali_blend_equation_packed *out,
         unsigned *constant_mask);
 
 bool
index 33a7b7abd3d312ef90743a0fb2f39a65c9056da6..99a119c4ed77a2785079f16da9b9e7dd7661d87a 100644 (file)
@@ -610,7 +610,7 @@ panfrost_frag_meta_blend_update(struct panfrost_context *ctx,
                         blend[0].is_shader);
 
                 if (!blend[0].is_shader) {
-                        fragmeta->blend.equation = *blend[0].equation.equation;
+                        fragmeta->blend.equation = blend[0].equation.equation;
                         fragmeta->blend.constant = blend[0].equation.constant;
                 }
 
@@ -684,7 +684,7 @@ panfrost_emit_blend(struct panfrost_batch *batch, void *rts,
                                 const struct util_format_description *format_desc;
                                 format_desc = util_format_description(format);
 
-                                brts[i].equation = *blend[i].equation.equation;
+                                brts[i].equation = blend[i].equation.equation;
 
                                 /* TODO: this is a bit more complicated */
                                 brts[i].constant = blend[i].equation.constant;
@@ -705,7 +705,7 @@ panfrost_emit_blend(struct panfrost_batch *batch, void *rts,
                         if (blend[i].is_shader) {
                                 mrts[i].blend.shader = blend[i].shader.gpu | blend[i].shader.first_tag;
                         } else {
-                                mrts[i].blend.equation = *blend[i].equation.equation;
+                                mrts[i].blend.equation = blend[i].equation.equation;
                                 mrts[i].blend.constant = blend[i].equation.constant;
                         }
                 }
index 3f227fdc8b7434ac4c1886a711f119f07f62a5cb..d5a48fd344b22939f3317c3e86158df1888c9302 100644 (file)
@@ -135,18 +135,6 @@ struct mali_blend_mode {
         unsigned complement_dominant : 1;
 } __attribute__((packed));
 
-struct mali_blend_equation {
-        /* Of type mali_blend_mode */
-        unsigned rgb_mode : 12;
-        unsigned alpha_mode : 12;
-
-        unsigned zero1 : 4;
-
-        /* Corresponds to MALI_MASK_* above and glColorMask arguments */
-
-        unsigned color_mask : 4;
-} __attribute__((packed));
-
 /* Compressed per-pixel formats. Each of these formats expands to one to four
  * floating-point or integer numbers, as defined by the OpenGL specification.
  * There are various places in OpenGL where the user can specify a compressed
@@ -281,7 +269,7 @@ union midgard_blend {
         mali_ptr shader;
 
         struct {
-                struct mali_blend_equation equation;
+                struct mali_blend_equation_packed equation;
                 float constant;
         };
 };
@@ -324,7 +312,7 @@ struct bifrost_blend_rt {
          */
         u16 constant;
 
-        struct mali_blend_equation equation;
+        struct mali_blend_equation_packed equation;
 
         /*
          * - 0x19 normally
index d8567f41d7ab776eb64566f3b0e20667e4ae437b..e7716aeb11c33d6646eca28643da01b52b39739c 100644 (file)
@@ -228,16 +228,6 @@ static const struct pandecode_flag_info clear_flag_info[] = {
 };
 #undef FLAG_INFO
 
-#define FLAG_INFO(flag) { MALI_MASK_##flag, "MALI_MASK_" #flag }
-static const struct pandecode_flag_info mask_flag_info[] = {
-        FLAG_INFO(R),
-        FLAG_INFO(G),
-        FLAG_INFO(B),
-        FLAG_INFO(A),
-        {}
-};
-#undef FLAG_INFO
-
 #define FLAG_INFO(flag) { MALI_##flag, "MALI_" #flag }
 static const struct pandecode_flag_info u3_flag_info[] = {
         FLAG_INFO(HAS_MSAA),
@@ -1147,26 +1137,6 @@ pandecode_shader_address(const char *name, mali_ptr ptr)
         return shader_ptr;
 }
 
-static void
-pandecode_blend_equation(const struct mali_blend_equation *blend)
-{
-        if (blend->zero1)
-                pandecode_msg("XXX: blend zero tripped: %X\n", blend->zero1);
-
-        pandecode_log(".equation = {\n");
-        pandecode_indent++;
-
-        pandecode_prop("rgb_mode = 0x%X", blend->rgb_mode);
-        pandecode_prop("alpha_mode = 0x%X", blend->alpha_mode);
-
-        pandecode_log(".color_mask = ");
-        pandecode_log_decoded_flags(mask_flag_info, blend->color_mask);
-        pandecode_log_cont(",\n");
-
-        pandecode_indent--;
-        pandecode_log("},\n");
-}
-
 /* Decodes a Bifrost blend constant. See the notes in bifrost_blend_rt */
 
 static unsigned
@@ -1192,7 +1162,7 @@ pandecode_bifrost_blend(void *descs, int job_no, int rt_no)
                        b->constant, decode_bifrost_constant(b->constant));
 
         /* TODO figure out blend shader enable bit */
-        pandecode_blend_equation(&b->equation);
+        DUMP_CL("Equation", BLEND_EQUATION, &b->equation, 2);
 
         pandecode_prop("unk2 = 0x%" PRIx16, b->unk2);
         pandecode_prop("index = 0x%" PRIx16, b->index);
@@ -1258,7 +1228,7 @@ pandecode_midgard_blend(union midgard_blend *blend, bool is_shader)
         if (is_shader) {
                 pandecode_shader_address("shader", blend->shader);
         } else {
-                pandecode_blend_equation(&blend->equation);
+                DUMP_CL("Equation", BLEND_EQUATION, &blend->equation, 2);
                 pandecode_prop("constant = %f", blend->constant);
         }
 
index 0a3b6b15f7fb0d683e14bf0753cab6dc4bcddb07..60782ae301ed5c82dc7f08d1a84a192888c76c12 100644 (file)
     <field name="Divisor" size="32" start="3:0" type="uint"/>
   </struct>
 
+  <struct name="Blend Equation" size="1">
+    <field name="RGB Mode" size="12" start="0" type="uint"/>
+    <field name="Alpha Mode" size="12" start="12" type="uint"/>
+    <field name="Color mask" size="4" start="28" type="uint" default="15"/>
+  </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"/>
index 0676b85f25f50d535cabd72d9da08c6c0244ced4..a9e6d6d0f0cd16570b09c693693db50d95a8176e 100644 (file)
@@ -216,12 +216,18 @@ panfrost_load_midg(
                 cfg.depth_pass = MALI_STENCIL_OP_REPLACE;
         };
 
+        struct mali_blend_equation_packed eq;
+
+        pan_pack(&eq, BLEND_EQUATION, cfg) {
+                cfg.rgb_mode = 0x122;
+                cfg.alpha_mode = 0x122;
+
+                if (loc < FRAG_RESULT_DATA0)
+                        cfg.color_mask = 0x0;
+        }
+
         union midgard_blend replace = {
-                .equation = {
-                        .rgb_mode = 0x122,
-                        .alpha_mode = 0x122,
-                        .color_mask = MALI_MASK_R | MALI_MASK_G | MALI_MASK_B | MALI_MASK_A,
-                }
+                .equation = eq
         };
 
         if (blend_shader)
@@ -269,9 +275,6 @@ panfrost_load_midg(
         if (pool->dev->quirks & MIDGARD_SFBD) {
                 shader_meta.unknown2_4 |= (0x10 | MALI_NO_DITHER);
                 shader_meta.blend = replace;
-
-                if (loc < FRAG_RESULT_DATA0)
-                        shader_meta.blend.equation.color_mask = 0x0;
         }
 
         if (loc == FRAG_RESULT_DEPTH) {