Module: Mesa
Branch: main
Commit: 6b0ff7da48ef3fc6fddf1bb75efa455a1241a387
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=6b0ff7da48ef3fc6fddf1bb75efa455a1241a387

Author: Alyssa Rosenzweig <[email protected]>
Date:   Wed May  4 09:35:22 2022 -0400

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 <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16697>

---

 src/panfrost/lib/pan_layout.c  | 20 +++++++++++++++-----
 src/panfrost/lib/pan_texture.h |  2 ++
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/panfrost/lib/pan_layout.c b/src/panfrost/lib/pan_layout.c
index 977f68874d3..2c414b52954 100644
--- a/src/panfrost/lib/pan_layout.c
+++ b/src/panfrost/lib/pan_layout.c
@@ -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;
diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h
index 0d963d4c206..c8c896929b1 100644
--- a/src/panfrost/lib/pan_texture.h
+++ b/src/panfrost/lib/pan_texture.h
@@ -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

Reply via email to