From c2207d27c27ce6de93c3c0ad13c0246d537177fc Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 17 May 2022 14:25:58 -0400 Subject: [PATCH] panfrost: Add pan_afbc_compression_mode on Valhall Map a canonical format (a hardware-independent pipe_format) to a compression mode (Valhall-specific hardware enum defined in GenXML). To be used for packing plane descriptors and render target descriptors when AFBC is in use on Valhall. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/lib/pan_cs.c | 26 ++++++++++++++++++++++++++ src/panfrost/lib/pan_texture.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/src/panfrost/lib/pan_cs.c b/src/panfrost/lib/pan_cs.c index 4353980d806..35747a84633 100644 --- a/src/panfrost/lib/pan_cs.c +++ b/src/panfrost/lib/pan_cs.c @@ -397,6 +397,32 @@ pan_rt_init_format(const struct pan_image_view *rt, cfg->swizzle = panfrost_translate_swizzle_4(swizzle); } +#if PAN_ARCH >= 9 +enum mali_afbc_compression_mode +pan_afbc_compression_mode(enum pipe_format format) +{ + /* There's a special case for texturing the stencil part from a combined + * depth/stencil texture, handle it separately. + */ + if (format == PIPE_FORMAT_X24S8_UINT) + return MALI_AFBC_COMPRESSION_MODE_X24S8; + + /* Otherwise, map canonical formats to the hardware enum. This only + * needs to handle the subset of formats returned by + * panfrost_afbc_format. + */ + switch (panfrost_afbc_format(PAN_ARCH, format)) { + case PIPE_FORMAT_R8G8_UNORM: return MALI_AFBC_COMPRESSION_MODE_R8G8; + case PIPE_FORMAT_R8G8B8_UNORM: return MALI_AFBC_COMPRESSION_MODE_R8G8B8; + case PIPE_FORMAT_R8G8B8A8_UNORM: return MALI_AFBC_COMPRESSION_MODE_R8G8B8A8; + case PIPE_FORMAT_R5G6B5_UNORM: return MALI_AFBC_COMPRESSION_MODE_R5G6B5; + case PIPE_FORMAT_S8_UINT: return MALI_AFBC_COMPRESSION_MODE_S8; + case PIPE_FORMAT_NONE: unreachable("invalid format for AFBC"); + default: unreachable("unknown canonical AFBC format"); + } +} +#endif + static void pan_prepare_rt(const struct pan_fb_info *fb, unsigned idx, unsigned cbuf_offset, diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h index e148c0b9617..bd773fa374e 100644 --- a/src/panfrost/lib/pan_texture.h +++ b/src/panfrost/lib/pan_texture.h @@ -263,6 +263,12 @@ pan_iview_get_surface(const struct pan_image_view *iview, unsigned level, unsigned layer, unsigned sample, struct pan_surface *surf); + +#if PAN_ARCH >= 9 +enum mali_afbc_compression_mode +pan_afbc_compression_mode(enum pipe_format format); +#endif + #ifdef __cplusplus } /* extern C */ #endif