From f2a678ed45dcc35eaeaa815cf46ae8152762897c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Tue, 10 Feb 2026 12:04:16 +0100 Subject: [PATCH] pan/crc: Simplify CRC buffer selection logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit doesn't really change the selection logic but tries to make the reasoning more straightforward and prepare for future commits where the CRC state will be cached. A usable RT must pass a few conditional checks like the availability of a CRC buffer. A selected RT must be usable and either have a valid CRC buffer or be fully covered. In the MRT case, the first usable RT with a valid CRC buffer is selected. If no RT has a CRC buffer initialized, then the first usable RT is selected at the condition it's fully covered. Signed-off-by: Loïc Molinari --- src/panfrost/lib/pan_desc.c | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/panfrost/lib/pan_desc.c b/src/panfrost/lib/pan_desc.c index 090a47bc3f0..e9f43917bae 100644 --- a/src/panfrost/lib/pan_desc.c +++ b/src/panfrost/lib/pan_desc.c @@ -109,6 +109,8 @@ renderblock_fits_in_single_pass(const struct pan_image_view *view, 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 @@ -119,42 +121,40 @@ GENX(pan_select_crc_rt)(const struct pan_fb_info *fb, unsigned tile_size) * Restricting CRC to 16x16 should work in practice. */ if (tile_size < 16 * 16) - return -1; + return best_rt; #if PAN_ARCH <= 6 if (fb->rt_count == 1 && fb->rts[0].view && !fb->rts[0].discard && pan_image_view_has_crc(fb->rts[0].view) && - renderblock_fits_in_single_pass(fb->rts[0].view, tile_size) && - (*(fb->rts[0].crc_valid) || pan_fb_is_fully_covered(fb))) - return 0; - - return -1; + renderblock_fits_in_single_pass(fb->rts[0].view, tile_size)) + best_rt = 0; #else - bool best_rt_valid = false; - int best_rt = -1; - for (unsigned i = 0; i < fb->rt_count; i++) { + /* Skip unusable RT. */ if (!fb->rts[i].view || fb->rts[i].discard || !pan_image_view_has_crc(fb->rts[i].view) || !renderblock_fits_in_single_pass(fb->rts[i].view, tile_size)) continue; - bool valid = *(fb->rts[i].crc_valid); - bool full = pan_fb_is_fully_covered(fb); - if (!full && !valid) - continue; - - if (best_rt < 0 || (valid && !best_rt_valid)) { + /* Select the first RT with a valid CRC buffer. */ + if (*fb->rts[i].crc_valid) { best_rt = i; - best_rt_valid = valid; + break; } - if (valid) - break; + /* Store the first usable RT otherwise. */ + if (best_rt == -1) + best_rt = i; } +#endif + + /* 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_is_fully_covered(fb)) + best_rt = -1; return best_rt; -#endif } static enum mali_zs_format