Mesa (main): panfrost: Unit test block size queries

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 26 18:19:26 UTC 2022


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

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Sat Apr 16 11:48:24 2022 -0400

panfrost: Unit test block size queries

Simple interface, make sure we don't screw it up.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15991>

---

 src/panfrost/lib/meson.build           |  16 ++++
 src/panfrost/lib/pan_layout.c          |   2 +-
 src/panfrost/lib/pan_texture.h         |  11 +++
 src/panfrost/lib/tests/test-layout.cpp | 163 +++++++++++++++++++++++++++++++++
 4 files changed, 191 insertions(+), 1 deletion(-)

diff --git a/src/panfrost/lib/meson.build b/src/panfrost/lib/meson.build
index 2c27d429fa6..d77573d8e3b 100644
--- a/src/panfrost/lib/meson.build
+++ b/src/panfrost/lib/meson.build
@@ -129,4 +129,20 @@ if with_tests
     ),
     suite : ['panfrost'],
   )
+
+  test(
+    'panfrost_layout',
+    executable(
+      'panfrost_layout',
+      files(
+        'tests/test-layout.cpp',
+      ),
+      c_args : [c_msvc_compat_args, no_override_init_args],
+      gnu_symbol_visibility : 'hidden',
+      include_directories : [inc_include, inc_src, inc_mesa, inc_panfrost, inc_gallium],
+      dependencies: [idep_gtest, libpanfrost_dep],
+    ),
+    suite : ['panfrost'],
+    protocol : gtest_test_protocol,
+  )
 endif
diff --git a/src/panfrost/lib/pan_layout.c b/src/panfrost/lib/pan_layout.c
index ce04cf352cf..ffc57478ff7 100644
--- a/src/panfrost/lib/pan_layout.c
+++ b/src/panfrost/lib/pan_layout.c
@@ -119,7 +119,7 @@ panfrost_u_interleaved_tile_size(enum pipe_format format)
  * the tile size. For AFBC, this is the superblock size. For linear textures,
  * this is trivially 1x1.
  */
-static inline struct pan_block_size
+struct pan_block_size
 panfrost_block_size(uint64_t modifier, enum pipe_format format)
 {
         if (modifier == DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED)
diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h
index 53fd71d76be..8b18e2d40d6 100644
--- a/src/panfrost/lib/pan_texture.h
+++ b/src/panfrost/lib/pan_texture.h
@@ -40,6 +40,10 @@
 #include "pan_util.h"
 #include "pan_format.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define PAN_MODIFIER_COUNT 4
 extern uint64_t pan_best_modifiers[PAN_MODIFIER_COUNT];
 
@@ -179,6 +183,9 @@ unsigned panfrost_afbc_superblock_height(uint64_t modifier);
 
 unsigned panfrost_afbc_is_wide(uint64_t modifier);
 
+struct pan_block_size
+panfrost_block_size(uint64_t modifier, enum pipe_format format);
+
 #ifdef PAN_ARCH
 unsigned
 GENX(panfrost_estimate_texture_payload_size)(const struct pan_image_view *iview);
@@ -239,4 +246,8 @@ pan_iview_get_surface(const struct pan_image_view *iview,
                       unsigned level, unsigned layer, unsigned sample,
                       struct pan_surface *surf);
 
+#ifdef __cplusplus
+} /* extern C */
+#endif
+
 #endif
diff --git a/src/panfrost/lib/tests/test-layout.cpp b/src/panfrost/lib/tests/test-layout.cpp
new file mode 100644
index 00000000000..932f91cd4e0
--- /dev/null
+++ b/src/panfrost/lib/tests/test-layout.cpp
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2022 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "pan_texture.h"
+
+#include <gtest/gtest.h>
+
+TEST(BlockSize, Linear)
+{
+   enum pipe_format format[] = {
+      PIPE_FORMAT_R32G32B32_FLOAT,
+      PIPE_FORMAT_R8G8B8_UNORM,
+      PIPE_FORMAT_ETC2_RGB8,
+      PIPE_FORMAT_ASTC_5x5
+   };
+
+   for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) {
+      struct pan_block_size blk = panfrost_block_size(DRM_FORMAT_MOD_LINEAR, format[i]);
+
+      EXPECT_EQ(blk.width, 1);
+      EXPECT_EQ(blk.height, 1);
+   }
+}
+
+TEST(BlockSize, UInterleavedRegular)
+{
+   enum pipe_format format[] = {
+      PIPE_FORMAT_R32G32B32_FLOAT,
+      PIPE_FORMAT_R8G8B8_UNORM,
+   };
+
+   for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) {
+      struct pan_block_size blk = panfrost_block_size(DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED, format[i]);
+
+      EXPECT_EQ(blk.width, 16);
+      EXPECT_EQ(blk.height, 16);
+   }
+}
+
+TEST(BlockSize, UInterleavedBlockCompressed)
+{
+   enum pipe_format format[] = {
+      PIPE_FORMAT_ETC2_RGB8,
+      PIPE_FORMAT_ASTC_5x5
+   };
+
+   for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) {
+      struct pan_block_size blk = panfrost_block_size(DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED, format[i]);
+
+      EXPECT_EQ(blk.width, 4);
+      EXPECT_EQ(blk.height, 4);
+   }
+}
+
+TEST(BlockSize, AFBCFormatInvariant16x16)
+{
+   enum pipe_format format[] = {
+      PIPE_FORMAT_R32G32B32_FLOAT,
+      PIPE_FORMAT_R8G8B8_UNORM,
+      PIPE_FORMAT_ETC2_RGB8,
+      PIPE_FORMAT_ASTC_5x5
+   };
+
+   uint64_t modifier = DRM_FORMAT_MOD_ARM_AFBC(
+                AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
+                AFBC_FORMAT_MOD_SPARSE |
+                AFBC_FORMAT_MOD_YTR);
+
+   for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) {
+      struct pan_block_size blk = panfrost_block_size(modifier, format[i]);
+
+      EXPECT_EQ(blk.width, 16);
+      EXPECT_EQ(blk.height, 16);
+   }
+}
+
+TEST(BlockSize, AFBCFormatInvariant32x8)
+{
+   enum pipe_format format[] = {
+      PIPE_FORMAT_R32G32B32_FLOAT,
+      PIPE_FORMAT_R8G8B8_UNORM,
+      PIPE_FORMAT_ETC2_RGB8,
+      PIPE_FORMAT_ASTC_5x5
+   };
+
+   uint64_t modifier = DRM_FORMAT_MOD_ARM_AFBC(
+                AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 |
+                AFBC_FORMAT_MOD_SPARSE |
+                AFBC_FORMAT_MOD_YTR);
+
+   for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) {
+      struct pan_block_size blk = panfrost_block_size(modifier, format[i]);
+
+      EXPECT_EQ(blk.width, 32);
+      EXPECT_EQ(blk.height, 8);
+   }
+}
+
+TEST(BlockSize, AFBCSuperblock16x16)
+{
+   uint64_t modifier = DRM_FORMAT_MOD_ARM_AFBC(
+                AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
+                AFBC_FORMAT_MOD_SPARSE |
+                AFBC_FORMAT_MOD_YTR);
+
+   EXPECT_EQ(panfrost_afbc_superblock_size(modifier).width, 16);
+   EXPECT_EQ(panfrost_afbc_superblock_width(modifier), 16);
+
+   EXPECT_EQ(panfrost_afbc_superblock_size(modifier).height, 16);
+   EXPECT_EQ(panfrost_afbc_superblock_height(modifier), 16);
+
+   EXPECT_FALSE(panfrost_afbc_is_wide(modifier));
+}
+
+TEST(BlockSize, AFBCSuperblock32x8)
+{
+   uint64_t modifier = DRM_FORMAT_MOD_ARM_AFBC(
+                AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 |
+                AFBC_FORMAT_MOD_SPARSE);
+
+   EXPECT_EQ(panfrost_afbc_superblock_size(modifier).width, 32);
+   EXPECT_EQ(panfrost_afbc_superblock_width(modifier), 32);
+
+   EXPECT_EQ(panfrost_afbc_superblock_size(modifier).height, 8);
+   EXPECT_EQ(panfrost_afbc_superblock_height(modifier), 8);
+
+   EXPECT_TRUE(panfrost_afbc_is_wide(modifier));
+}
+
+TEST(BlockSize, AFBCSuperblock64x4)
+{
+   uint64_t modifier = DRM_FORMAT_MOD_ARM_AFBC(
+                AFBC_FORMAT_MOD_BLOCK_SIZE_64x4 |
+                AFBC_FORMAT_MOD_SPARSE);
+
+   EXPECT_EQ(panfrost_afbc_superblock_size(modifier).width, 64);
+   EXPECT_EQ(panfrost_afbc_superblock_width(modifier), 64);
+
+   EXPECT_EQ(panfrost_afbc_superblock_size(modifier).height, 4);
+   EXPECT_EQ(panfrost_afbc_superblock_height(modifier), 4);
+
+   EXPECT_TRUE(panfrost_afbc_is_wide(modifier));
+}



More information about the mesa-commit mailing list