From 44155fa661c300a69dc1edc74edc7c15ef33f743 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 27 Oct 2020 21:10:27 -0400 Subject: [PATCH] panfrost: Complete format_to_bifrost_blend Instead of matching on the PIPE format directly, match on the internal format of the tile buffer and pick the pixel format that corresponds to the internal tile buffer format (which differs from the format written back to memory in the general case). We add a number of missing formats to accomodate this, including the AU/PU variants of each tilebuffer pixel format, where the AU formats use the extra bits to store extra precision for dithering but the PU formats simply pad the extra bits with zeroes. For the moment we use AU everywhere. I'm not sure if there's a cost associated. Signed-off-by: Alyssa Rosenzweig Tested-by: Christian Hewitt Reviewed-by: Boris Brezillon Part-of: --- .../drivers/panfrost/pan_blend_shaders.c | 31 +-------------- src/gallium/drivers/panfrost/pan_cmdstream.c | 2 +- src/panfrost/lib/midgard.xml | 21 +++++++--- src/panfrost/lib/pan_blit.c | 2 +- src/panfrost/lib/pan_format.c | 38 +++++++++++++------ src/panfrost/lib/pan_texture.h | 2 +- 6 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c index 24c0d6f7e5f..c4e04986ca9 100644 --- a/src/gallium/drivers/panfrost/pan_blend_shaders.c +++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c @@ -261,35 +261,8 @@ bifrost_get_blend_desc(enum pipe_format fmt, unsigned rt) cfg.fixed_function.conversion.memory_format.srgb = desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB; - if (util_format_is_unorm8(desc)) { - cfg.fixed_function.conversion.memory_format.format = MALI_RGBA8_2; - continue; - } - - enum pipe_format linearized = util_format_linear(fmt); - switch (linearized) { - case PIPE_FORMAT_B5G6R5_UNORM: - cfg.fixed_function.conversion.memory_format.format = MALI_R5G6B5; - break; - case PIPE_FORMAT_A4B4G4R4_UNORM: - case PIPE_FORMAT_B4G4R4A4_UNORM: - case PIPE_FORMAT_R4G4B4A4_UNORM: - cfg.fixed_function.conversion.memory_format.format = MALI_RGBA4; - break; - case PIPE_FORMAT_R10G10B10A2_UNORM: - case PIPE_FORMAT_B10G10R10A2_UNORM: - case PIPE_FORMAT_R10G10B10X2_UNORM: - case PIPE_FORMAT_B10G10R10X2_UNORM: - cfg.fixed_function.conversion.memory_format.format = MALI_RGB10_A2_2; - break; - case PIPE_FORMAT_B5G5R5A1_UNORM: - case PIPE_FORMAT_R5G5B5A1_UNORM: - case PIPE_FORMAT_B5G5R5X1_UNORM: - cfg.fixed_function.conversion.memory_format.format = MALI_RGB5_A1; - break; - default: - unreachable("Invalid format"); - } + cfg.fixed_function.conversion.memory_format.format = + panfrost_format_to_bifrost_blend(desc, true); } return res; diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 6345d8d7ec7..40d1bc45392 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -298,7 +298,7 @@ panfrost_emit_bifrost_blend(struct panfrost_batch *batch, cfg.bifrost.internal.fixed_function.num_comps = format_desc->nr_channels; cfg.bifrost.internal.fixed_function.conversion.memory_format.format = - panfrost_format_to_bifrost_blend(format_desc); + panfrost_format_to_bifrost_blend(format_desc, true); if (dev->quirks & HAS_SWIZZLES) { cfg.bifrost.internal.fixed_function.conversion.memory_format.swizzle = panfrost_get_default_swizzle(4); diff --git a/src/panfrost/lib/midgard.xml b/src/panfrost/lib/midgard.xml index bbe131e6e3f..9d152fa0b8b 100644 --- a/src/panfrost/lib/midgard.xml +++ b/src/panfrost/lib/midgard.xml @@ -173,11 +173,22 @@ - - - - - + + + + + + + + + + + + + + + + diff --git a/src/panfrost/lib/pan_blit.c b/src/panfrost/lib/pan_blit.c index 5e0d7aa6061..0a15161f609 100644 --- a/src/panfrost/lib/pan_blit.c +++ b/src/panfrost/lib/pan_blit.c @@ -575,7 +575,7 @@ bifrost_load_emit_blend_rt(struct pan_pool *pool, void *out, cfg.bifrost.equation.color_mask = 0xf; cfg.bifrost.internal.fixed_function.num_comps = format_desc->nr_channels; cfg.bifrost.internal.fixed_function.conversion.memory_format.format = - panfrost_format_to_bifrost_blend(format_desc); + panfrost_format_to_bifrost_blend(format_desc, true); cfg.bifrost.internal.fixed_function.conversion.register_format = blit_type_to_reg_fmt(T); diff --git a/src/panfrost/lib/pan_format.c b/src/panfrost/lib/pan_format.c index 481a538ad9c..acd7b37438a 100644 --- a/src/panfrost/lib/pan_format.c +++ b/src/panfrost/lib/pan_format.c @@ -445,21 +445,35 @@ panfrost_invert_swizzle(const unsigned char *in, unsigned char *out) } enum mali_format -panfrost_format_to_bifrost_blend(const struct util_format_description *desc) +panfrost_format_to_bifrost_blend(const struct util_format_description *desc, bool dither) { - enum mali_format format = panfrost_pipe_format_table[desc->format].hw; - assert(format); + struct pan_blendable_format fmt = panfrost_blend_format(desc->format); - switch (format) { - case MALI_RGBA4_UNORM: - return MALI_RGBA4; - case MALI_RGBA8_UNORM: - case MALI_RGB8_UNORM: - return MALI_RGBA8_2; - case MALI_RGB10_A2_UNORM: - return MALI_RGB10_A2_2; + /* Formats requiring blend shaders are stored raw in the tilebuffer */ + if (!fmt.internal) + return desc->format; + + /* Else, pick the pixel format matching the tilebuffer format */ + switch (fmt.internal) { + case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A8: + return MALI_RGBA8_TB; + + case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R10G10B10A2: + return MALI_RGB10_A2_TB; + + case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A2: + return dither ? MALI_RGB8_A2_AU : MALI_RGB8_A2_PU; + + case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R4G4B4A4: + return dither ? MALI_RGBA4_AU : MALI_RGBA4_PU; + + case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G6B5A0: + return dither ? MALI_R5G6B5_AU : MALI_R5G6B5_PU; + + case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G5B5A1: + return dither ? MALI_RGB5_A1_AU : MALI_RGB5_A1_PU; default: - return format; + unreachable("invalid internal blendable"); } } diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h index 337641a022a..70f2ca211d6 100644 --- a/src/panfrost/lib/pan_texture.h +++ b/src/panfrost/lib/pan_texture.h @@ -194,7 +194,7 @@ panfrost_bifrost_swizzle(unsigned components) } enum mali_format -panfrost_format_to_bifrost_blend(const struct util_format_description *desc); +panfrost_format_to_bifrost_blend(const struct util_format_description *desc, bool dither); struct pan_pool; struct pan_scoreboard;