pan/crc: Move CRC selection function closer to caller

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
This commit is contained in:
Loïc Molinari 2026-02-10 12:36:29 +01:00
parent 8c7adaf1ea
commit 789ae79688

View file

@ -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.