[Mesa-dev] [PATCH 28/42] panfrost: Route format through fixed-function blending

Alyssa Rosenzweig alyssa.rosenzweig at collabora.com
Mon Jul 8 14:08:41 UTC 2019


Not all framebuffer formats are supported by the fixed-function blender.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
---
 src/gallium/drivers/panfrost/pan_blending.c | 41 ++++++++++++++++++++-
 src/gallium/drivers/panfrost/pan_blending.h |  7 +++-
 src/gallium/drivers/panfrost/pan_context.c  | 11 +++---
 3 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_blending.c b/src/gallium/drivers/panfrost/pan_blending.c
index 14f99f64edd..6bdc8395d18 100644
--- a/src/gallium/drivers/panfrost/pan_blending.c
+++ b/src/gallium/drivers/panfrost/pan_blending.c
@@ -26,6 +26,7 @@
 #include "pan_blending.h"
 #include "pan_context.h"
 #include "gallium/auxiliary/util/u_blend.h"
+#include "util/u_format.h"
 
 /*
  * Implements fixed-function blending on Midgard.
@@ -98,6 +99,34 @@
  * The following routines implement this fixed function blending encoding
  */
 
+/* Not all formats can be blended by fixed-function hardware */
+
+static bool
+panfrost_can_blend(enum pipe_format format)
+{
+        /* Fixed-function can handle sRGB */
+        format = util_format_linear(format);
+
+        /* Decompose the format */
+        const struct util_format_description *desc =
+                util_format_description(format);
+
+        /* Any 8-bit unorm is supported */
+        if (util_format_is_unorm8(desc))
+                return true;
+
+        /* Certain special formats are, too */
+        switch (format) {
+                case PIPE_FORMAT_B5G6R5_UNORM:
+                case PIPE_FORMAT_B4G4R4A4_UNORM:
+                case PIPE_FORMAT_B5G5R5A1_UNORM:
+                case PIPE_FORMAT_R10G10B10A2_UNORM:
+                        return true;
+                default:
+                        return false;
+        }
+}
+
 /* Helper to find the uncomplemented Gallium blend factor corresponding to a
  * complemented Gallium blend factor */
 
@@ -345,10 +374,20 @@ panfrost_make_constant(unsigned *factors, unsigned num_factors, const struct pip
  */
 
 bool
-panfrost_make_fixed_blend_mode(const struct pipe_rt_blend_state *blend, struct panfrost_blend_state *so, unsigned colormask, const struct pipe_blend_color *blend_color)
+panfrost_make_fixed_blend_mode(
+                const struct pipe_rt_blend_state *blend,
+                struct panfrost_blend_state *so,
+                unsigned colormask,
+                const struct pipe_blend_color *blend_color,
+                enum pipe_format format)
 {
         struct mali_blend_equation *out = &so->equation;
 
+        /* Check if the format supports fixed-function blending at all */
+
+        if (!panfrost_can_blend(format))
+                return false;
+
         /* Gallium and Mali represent colour masks identically. XXX: Static assert for future proof */
         out->color_mask = colormask;
 
diff --git a/src/gallium/drivers/panfrost/pan_blending.h b/src/gallium/drivers/panfrost/pan_blending.h
index 8ddd81147eb..4be0c4d4385 100644
--- a/src/gallium/drivers/panfrost/pan_blending.h
+++ b/src/gallium/drivers/panfrost/pan_blending.h
@@ -31,6 +31,11 @@
 
 struct panfrost_blend_state;
 
-bool panfrost_make_fixed_blend_mode(const struct pipe_rt_blend_state *blend, struct panfrost_blend_state *so, unsigned colormask, const struct pipe_blend_color *blend_color);
+bool panfrost_make_fixed_blend_mode(
+                const struct pipe_rt_blend_state *blend,
+                struct panfrost_blend_state *so,
+                unsigned colormask,
+                const struct pipe_blend_color *blend_color,
+                enum pipe_format format);
 
 #endif
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index be5d0a14cf5..c26a6dbaabb 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -2378,15 +2378,14 @@ panfrost_create_blend_state(struct pipe_context *pipe,
 
         /* Compile the blend state, first as fixed-function if we can */
 
-        if (panfrost_make_fixed_blend_mode(&blend->rt[0], so, blend->rt[0].colormask, &ctx->blend_color))
-                return so;
+        /* TODO: Key by format */
+        enum pipe_format format = ctx->pipe_framebuffer.nr_cbufs ?
+                ctx->pipe_framebuffer.cbufs[0]->format :
+                PIPE_FORMAT_R8G8B8A8_UNORM;
 
-        /* TODO: Key against framebuffer. TODO: MRT explicitly */
-        if (!ctx->pipe_framebuffer.nr_cbufs)
+        if (panfrost_make_fixed_blend_mode(&blend->rt[0], so, blend->rt[0].colormask, &ctx->blend_color, format))
                 return so;
 
-        enum pipe_format format = ctx->pipe_framebuffer.cbufs[0]->format;
-
         /* If we can't, compile a blend shader instead */
 
         panfrost_make_blend_shader(ctx, so, &ctx->blend_color, format);
-- 
2.20.1



More information about the mesa-dev mailing list