From e497a5ef4004afd59082fcf086cebe093fe7121a Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Thu, 26 Oct 2023 20:58:27 +0200 Subject: [PATCH] panfrost: Increase AFBC body alignment requirement on v6+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AFBC body is required to be aligned on 128 bytes on v6+ hardware. Cc: mesa-stable Signed-off-by: Boris Brezillon Reviewed-by: Lars-Ivar Hesselberg Simonsen Reviewed-by: Louis-Francis Ratté-Boulianne Acked-by: Erik Faye-Lund Part-of: (cherry picked from commit ca84b1e9b51a72b659a5c09895b300c1f7e55cfd) --- .pick_status.json | 2 +- src/gallium/drivers/panfrost/pan_resource.c | 2 +- src/panfrost/lib/pan_layout.c | 12 +++++++--- src/panfrost/lib/pan_texture.h | 2 +- src/panfrost/lib/tests/test-layout.cpp | 25 +++++++++++++++++++++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index ef561799fbc..61f1bac0685 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -534,7 +534,7 @@ "description": "panfrost: Increase AFBC body alignment requirement on v6+", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index c6210b40a09..2029a1cccc1 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -1651,7 +1651,7 @@ panfrost_pack_afbc(struct panfrost_context *ctx, dst_slice->afbc.nr_blocks = dst_stride * dst_height; dst_slice->afbc.header_size = ALIGN_POT(dst_stride * dst_height * AFBC_HEADER_BYTES_PER_TILE, - pan_afbc_body_align(dst_modifier)); + pan_afbc_body_align(dev->arch, dst_modifier)); dst_slice->afbc.body_size = offset; dst_slice->afbc.surface_stride = dst_slice->afbc.header_size + offset; diff --git a/src/panfrost/lib/pan_layout.c b/src/panfrost/lib/pan_layout.c index e8d7de31030..5e6ce6e4b6e 100644 --- a/src/panfrost/lib/pan_layout.c +++ b/src/panfrost/lib/pan_layout.c @@ -312,9 +312,15 @@ pan_slice_align(uint64_t modifier) * are required on all current GPUs. */ uint32_t -pan_afbc_body_align(uint64_t modifier) +pan_afbc_body_align(unsigned arch, uint64_t modifier) { - return (modifier & AFBC_FORMAT_MOD_TILED) ? 4096 : 64; + if (modifier & AFBC_FORMAT_MOD_TILED) + return 4096; + + if (arch >= 6) + return 128; + + return 64; } static inline unsigned @@ -555,7 +561,7 @@ pan_image_layout_init(unsigned arch, struct pan_image_layout *layout, slice->afbc.stride * (effective_height / block_size.height); slice->afbc.header_size = ALIGN_POT(slice->row_stride * (effective_height / align_h), - pan_afbc_body_align(layout->modifier)); + pan_afbc_body_align(arch, layout->modifier)); if (explicit_layout && explicit_layout->row_stride < slice->row_stride) { diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h index 9f382fdf1f7..3945d4f4f00 100644 --- a/src/panfrost/lib/pan_texture.h +++ b/src/panfrost/lib/pan_texture.h @@ -281,7 +281,7 @@ uint32_t pan_afbc_stride_blocks(uint64_t modifier, uint32_t row_stride_bytes); uint32_t pan_slice_align(uint64_t modifier); -uint32_t pan_afbc_body_align(uint64_t modifier); +uint32_t pan_afbc_body_align(unsigned arch, uint64_t modifier); /* AFRC */ diff --git a/src/panfrost/lib/tests/test-layout.cpp b/src/panfrost/lib/tests/test-layout.cpp index 08b57e73ad4..db25d43afd8 100644 --- a/src/panfrost/lib/tests/test-layout.cpp +++ b/src/panfrost/lib/tests/test-layout.cpp @@ -444,6 +444,31 @@ TEST(AFBCLayout, Linear16x16Minimal) EXPECT_EQ(l.slices[0].size, 64 + (32 * 8)); } +TEST(AFBCLayout, Linear16x16Minimalv6) +{ + uint64_t modifier = DRM_FORMAT_MOD_ARM_AFBC( + AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | AFBC_FORMAT_MOD_SPARSE); + + struct pan_image_layout l = {.modifier = modifier, + .format = PIPE_FORMAT_R8_UNORM, + .width = 1, + .height = 1, + .depth = 1, + .nr_samples = 1, + .dim = MALI_TEXTURE_DIMENSION_2D, + .nr_slices = 1}; + + ASSERT_TRUE(pan_image_layout_init(6, &l, NULL)); + + /* Image is 1x1 to test for correct alignment everywhere. */ + EXPECT_EQ(l.slices[0].offset, 0); + EXPECT_EQ(l.slices[0].row_stride, 16); + EXPECT_EQ(l.slices[0].afbc.header_size, 128); + EXPECT_EQ(l.slices[0].afbc.body_size, 32 * 8); + EXPECT_EQ(l.slices[0].surface_stride, 128 + (32 * 8)); + EXPECT_EQ(l.slices[0].size, 128 + (32 * 8)); +} + TEST(AFBCLayout, Tiled16x16Minimal) { uint64_t modifier =