panfrost: Honour load_dest/opaque flags
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 18 Aug 2020 21:51:22 +0000 (17:51 -0400)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Tue, 25 Aug 2020 15:05:33 +0000 (17:05 +0200)
Let's split them out and work out the metadata at CSO time.

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_cmdstream.c

index 22993dd94a97e2024a216c0fd7bd42878811673a..a37d571c7d693e26fe8bd29a8e56e3683d183280 100644 (file)
@@ -80,6 +80,9 @@ struct panfrost_blend_rt {
         /* Mask of blend color components read */
         unsigned constant_mask;
 
+        /* Properties of the blend mode */
+        bool opaque, load_dest, no_colour;
+
         /* Regardless of fixed-function blending, this is a map of pipe_format
          * to panfrost_blend_shader */
 
@@ -99,8 +102,11 @@ struct panfrost_blend_final {
         /* Set for a shader, clear for an equation */
         bool is_shader;
 
-        /* Clear if the destination needs to be loaded from the tilebuffer */
-        bool no_blending;
+        /* Set if this is the replace mode */
+        bool opaque;
+
+        /* Set if destination is loaded */
+        bool load_dest;
 
         /* Set if the colour mask is 0x0 (nothing is written) */
         bool no_colour;
index 1d0b2bad5c9ecdaf151c083cfaf57b6cc5a48f71..d600292e8a081e44d9cb23698cf9fe7b1572fcb5 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <stdio.h>
 #include "util/u_memory.h"
+#include "gallium/auxiliary/util/u_blend.h"
 #include "pan_blend_shaders.h"
 #include "pan_blending.h"
 #include "pan_bo.h"
@@ -118,6 +119,7 @@ panfrost_create_blend_state(struct pipe_context *pipe,
 
                 /* Logic ops are always shader */
                 if (blend->logicop_enable) {
+                        rt->load_dest = true;
                         continue;
                 }
 
@@ -127,10 +129,17 @@ panfrost_create_blend_state(struct pipe_context *pipe,
                                         &rt->equation,
                                         &rt->constant_mask);
 
-                /* Regardless if that works, we also need to initialize
-                 * the blend shaders */
+                if (rt->has_fixed_function) {
+                        rt->opaque =
+                                (rt->equation.rgb_mode == 0x122) &&
+                                (rt->equation.alpha_mode == 0x122) &&
+                                (rt->equation.color_mask == 0xf);
+                }
 
-                rt->shaders = _mesa_hash_table_u64_create(so);
+                rt->load_dest = util_blend_uses_dest(pipe)
+                        || pipe.colormask != 0xF;
+
+                rt->no_colour = pipe.colormask == 0x0;
         }
 
         return so;
@@ -230,17 +239,13 @@ panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rti)
                             &constant,
                             ctx->blend_color.color,
                             rt->constant_mask)) {
-                        bool no_blending =
-                                (rt->equation.rgb_mode == 0x122) &&
-                                (rt->equation.alpha_mode == 0x122) &&
-                                (rt->equation.color_mask == 0xf);
-
                         struct panfrost_blend_final final = {
                                 .equation = {
                                         .equation = &rt->equation,
                                         .constant = constant
                                 },
-                                .no_blending = no_blending,
+                                .load_dest = rt->load_dest,
+                                .opaque = rt->opaque,
                                 .no_colour = (rt->equation.color_mask == 0x0)
                         };
 
@@ -273,7 +278,8 @@ panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rti)
                         .work_count = shader->work_count,
                         .first_tag = shader->first_tag,
                         .gpu = bo->gpu,
-                }
+                },
+                .load_dest = rt->load_dest,
         };
 
         return final;
index f57d240748a5dd1fbe76cadc17975df0f9ac0010..33a7b7abd3d312ef90743a0fb2f39a65c9056da6 100644 (file)
@@ -615,7 +615,7 @@ panfrost_frag_meta_blend_update(struct panfrost_context *ctx,
                 }
 
                 SET_BIT(fragmeta->unknown2_3, MALI_CAN_DISCARD,
-                        !blend[0].no_blending || fs->can_discard); 
+                        blend[0].load_dest);
 
                 batch->draws |= PIPE_CLEAR_COLOR0;
                 return;
@@ -625,7 +625,7 @@ panfrost_frag_meta_blend_update(struct panfrost_context *ctx,
                 bool no_blend = true;
 
                 for (unsigned i = 0; i < rt_count; ++i)
-                        no_blend &= (blend[i].no_blending | blend[i].no_colour);
+                        no_blend &= (!blend[i].load_dest | blend[i].no_colour);
 
                 SET_BIT(fragmeta->bifrost1.unk1, MALI_BIFROST_EARLY_Z,
                         !fs->can_discard && !fs->writes_depth && no_blend);
@@ -652,13 +652,15 @@ panfrost_emit_blend(struct panfrost_batch *batch, void *rts,
                 unsigned flags = 0;
 
                 pan_pack(&flags, BLEND_FLAGS, cfg) {
-                        if (blend[i].no_colour)
+                        if (blend[i].no_colour) {
+                                cfg.enable = false;
                                 break;
+                        }
 
                         batch->draws |= (PIPE_CLEAR_COLOR0 << i);
 
                         cfg.srgb = util_format_is_srgb(batch->key.cbufs[i]->format);
-                        cfg.load_destination = !blend[i].no_blending; /* XXX */
+                        cfg.load_destination = blend[i].load_dest;
                         cfg.dither_disable = !batch->ctx->blend->base.dither;
 
                         if (!(dev->quirks & IS_BIFROST))
@@ -693,7 +695,7 @@ panfrost_emit_blend(struct panfrost_batch *batch, void *rts,
                                  * mode (equivalent to rgb_mode = alpha_mode =
                                  * x122, colour mask = 0xF). 0x1a allows
                                  * blending. */
-                                brts[i].unk2 = blend[i].no_blending ? 0x19 : 0x1a;
+                                brts[i].unk2 = blend[i].opaque ? 0x19 : 0x1a;
 
                                 brts[i].shader_type = fs->blend_types[i];
                         }