panfrost: Extract pan_afbc_row_stride helper
authorAlyssa Rosenzweig <alyssa@collabora.com>
Wed, 4 May 2022 13:35:22 +0000 (09:35 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 26 May 2022 15:56:32 +0000 (15:56 +0000)
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>

src/panfrost/lib/pan_layout.c
src/panfrost/lib/pan_texture.h

index 977f688..2c414b5 100644 (file)
@@ -131,6 +131,19 @@ panfrost_block_size(uint64_t modifier, enum pipe_format format)
 }
 
 /*
+ * 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
  * header tile
@@ -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;
index 0d963d4..c8c8969 100644 (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