From 789ae79688c9413185f681aed3dcfb7098e5d06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Tue, 10 Feb 2026 12:36:29 +0100 Subject: [PATCH] pan/crc: Move CRC selection function closer to caller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Loïc Molinari --- src/panfrost/lib/pan_desc.c | 148 ++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/src/panfrost/lib/pan_desc.c b/src/panfrost/lib/pan_desc.c index 84591545736..921afbf4698 100644 --- a/src/panfrost/lib/pan_desc.c +++ b/src/panfrost/lib/pan_desc.c @@ -92,80 +92,6 @@ pan_warn_on_afbc_reverse_issue_order(const struct pan_attachment_info *att, } #endif -static bool -pan_fb_color_attachment_should_crc(const struct pan_fb_color_attachment *rt, - unsigned tile_size) -{ - uint64_t mod; - struct pan_image_block_size renderblk_sz; - - if (!rt->view || rt->discard || !pan_image_view_has_crc(rt->view)) - return false; - - mod = pan_image_view_get_first_plane(rt->view).image->props.modifier; - - if (!drm_is_afbc(mod)) - return true; - - /* AFBC-P images are read only. */ - if (!(mod & AFBC_FORMAT_MOD_SPARSE)) - return false; - - /* AFBC render block size must fit in a single pass. */ - renderblk_sz = pan_afbc_renderblock_size(mod); - if (tile_size < renderblk_sz.width * renderblk_sz.height) - return false; - - return true; -} - -int -GENX(pan_select_crc_rt)(const struct pan_fb_info *fb, unsigned tile_size) -{ - int best_rt = -1; - - /* Disable CRC when the tile size is smaller than 16x16. In the hardware, - * CRC tiles are the same size as the tiles of the framebuffer. However, - * our code only handles 16x16 tiles. Therefore under the current - * implementation, we must disable CRC when 16x16 tiles are not used. - * - * This may hurt performance. However, smaller tile sizes are rare, and - * CRCs are more expensive at smaller tile sizes, reducing the benefit. - * Restricting CRC to 16x16 should work in practice. - */ - if (tile_size < 16 * 16) - return best_rt; - -#if PAN_ARCH <= 6 - if (fb->rt_count > 1) - return best_rt; -#endif - - for (unsigned i = 0; i < fb->rt_count; i++) { - /* Skip unusable RTs. */ - if (!pan_fb_color_attachment_should_crc(&fb->rts[i], tile_size)) - continue; - - /* Select the first RT with a valid CRC buffer. */ - if (*fb->rts[i].crc_valid) { - best_rt = i; - break; - } - - /* Store the first usable RT otherwise. */ - if (best_rt == -1) - best_rt = i; - } - - /* The selected RT must be fully covered for now in order to correctly - * initialize the CRC buffer. */ - if (best_rt != -1 && !*fb->rts[best_rt].crc_valid && - !pan_fb_info_is_fully_covered(fb)) - best_rt = -1; - - return best_rt; -} - static enum mali_zs_format translate_zs_format(enum pipe_format in) { @@ -1092,6 +1018,80 @@ pan_fix_frame_shader_mode(enum mali_pre_post_frame_shader_mode mode, } #endif +static bool +pan_fb_color_attachment_should_crc(const struct pan_fb_color_attachment *rt, + unsigned tile_size) +{ + uint64_t mod; + struct pan_image_block_size renderblk_sz; + + if (!rt->view || rt->discard || !pan_image_view_has_crc(rt->view)) + return false; + + mod = pan_image_view_get_first_plane(rt->view).image->props.modifier; + + if (!drm_is_afbc(mod)) + return true; + + /* AFBC-P images are read only. */ + if (!(mod & AFBC_FORMAT_MOD_SPARSE)) + return false; + + /* AFBC render block size must fit in a single pass. */ + renderblk_sz = pan_afbc_renderblock_size(mod); + if (tile_size < renderblk_sz.width * renderblk_sz.height) + return false; + + return true; +} + +int +GENX(pan_select_crc_rt)(const struct pan_fb_info *fb, unsigned tile_size) +{ + int best_rt = -1; + + /* Disable CRC when the tile size is smaller than 16x16. In the hardware, + * CRC tiles are the same size as the tiles of the framebuffer. However, + * our code only handles 16x16 tiles. Therefore under the current + * implementation, we must disable CRC when 16x16 tiles are not used. + * + * This may hurt performance. However, smaller tile sizes are rare, and + * CRCs are more expensive at smaller tile sizes, reducing the benefit. + * Restricting CRC to 16x16 should work in practice. + */ + if (tile_size < 16 * 16) + return best_rt; + +#if PAN_ARCH <= 6 + if (fb->rt_count > 1) + return best_rt; +#endif + + for (unsigned i = 0; i < fb->rt_count; i++) { + /* Skip unusable RTs. */ + if (!pan_fb_color_attachment_should_crc(&fb->rts[i], tile_size)) + continue; + + /* Select the first RT with a valid CRC buffer. */ + if (*fb->rts[i].crc_valid) { + best_rt = i; + break; + } + + /* Store the first usable RT otherwise. */ + if (best_rt == -1) + best_rt = i; + } + + /* The selected RT must be fully covered for now in order to correctly + * initialize the CRC buffer. */ + if (best_rt != -1 && !*fb->rts[best_rt].crc_valid && + !pan_fb_info_is_fully_covered(fb)) + best_rt = -1; + + return best_rt; +} + /* Clean tiles must be written back for AFBC buffers (color, z/s) when either * one of the effective tile size dimension is smaller than the superblock * dimension.