panfrost: Extract pan_afbc_row_stride helper

Extract a helper for calculating AFBC strides. This is used in two places in
pan_layout. It will need extension for tiled AFBC, and the extended version
could benefit from unit testing.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16697>
This commit is contained in:
Alyssa Rosenzweig
2022-05-04 09:35:22 -04:00
committed by Marge Bot
parent d8a4c9b505
commit 6b0ff7da48
2 changed files with 17 additions and 5 deletions

View File

@@ -130,6 +130,19 @@ panfrost_block_size(uint64_t modifier, enum pipe_format format)
return (struct pan_block_size) { 1, 1 };
}
/*
* Determine the number of bytes between header rows for an AFBC image. For an
* image with linear headers, this is simply the number of header blocks
* (=superblocks) per row times the numbers of bytes per header block.
*/
uint32_t
pan_afbc_row_stride(uint64_t modifier, uint32_t width)
{
unsigned block_width = panfrost_afbc_superblock_width(modifier);
return (width / block_width) * AFBC_HEADER_BYTES_PER_TILE;
}
/*
* Determine the number of header blocks between header rows. This is equal to
* the number of bytes between header rows divided by the bytes per blocks of a
@@ -204,7 +217,7 @@ panfrost_from_legacy_stride(unsigned legacy_stride,
if (drm_is_afbc(modifier)) {
unsigned width = legacy_stride / util_format_get_blocksize(format);
return (width / block_size.width) * AFBC_HEADER_BYTES_PER_TILE;
return pan_afbc_row_stride(modifier, width);
} else {
return legacy_stride * block_size.height;
}
@@ -292,11 +305,8 @@ pan_image_layout_init(struct pan_image_layout *layout,
if (afbc) {
slice->afbc.header_size =
panfrost_afbc_header_size(width, height);
/* Stride between two rows of AFBC headers */
slice->row_stride =
(effective_width / block_size.width) *
AFBC_HEADER_BYTES_PER_TILE;
pan_afbc_row_stride(layout->modifier, effective_width);
if (explicit_layout && explicit_layout->row_stride < slice->row_stride)
return false;

View File

@@ -194,6 +194,8 @@ unsigned panfrost_afbc_superblock_height(uint64_t modifier);
unsigned panfrost_afbc_is_wide(uint64_t modifier);
uint32_t pan_afbc_row_stride(uint64_t modifier, uint32_t width);
uint32_t pan_afbc_stride_blocks(uint32_t row_stride_bytes);
struct pan_block_size