'asahi_layout_tests',
files(
'tests/test-layout.cpp',
- 'tests/test-miptree.cpp',
- 'tests/test-comp-twiddled.cpp',
- 'tests/test-uncomp-twiddled.cpp',
+ 'tests/test-generated.cpp',
),
c_args : [c_msvc_compat_args, no_override_init_args],
gnu_symbol_visibility : 'hidden',
-/*
- * Copyright 2022 Asahi Lina
- * SPDX-License-Identifier: MIT
- */
-
-#include <gtest/gtest.h>
-#include "layout.h"
-
-/*
- * Test compressed texture sizes. All test cases in this file are extracted from
- * texture structure dumps in Metal.
- */
-struct sizetest {
- enum pipe_format format;
- uint32_t width, height, depth;
- uint8_t levels;
- uint32_t size;
-};
-
-/* clang-format off */
-/* Sort: `sort -t"," -k1,1 -k2,5n | uniq` */
-static struct sizetest comptests[] = {
{ PIPE_FORMAT_R16G16B16A16_UNORM, 16, 16, 1, 1, 0x880 },
{ PIPE_FORMAT_R16G16B16A16_UNORM, 16, 24, 1, 1, 0x1080 },
{ PIPE_FORMAT_R16G16B16A16_UNORM, 16, 32, 1, 1, 0x1080 },
{ PIPE_FORMAT_Z32_FLOAT, 4097, 4097, 1, 13, 0x5cbeb00 },
{ PIPE_FORMAT_Z32_FLOAT, 4097, 4097, 2, 1, 0x8808000 },
{ PIPE_FORMAT_Z32_FLOAT, 4097, 4097, 2, 13, 0xb97d600 },
-};
-/* clang-format on */
-
-TEST(CompTwiddled, SizeTests)
-{
- for (unsigned i = 0; i < ARRAY_SIZE(comptests); ++i) {
- struct sizetest test = comptests[i];
-
- struct ail_layout layout = {
- .width_px = test.width,
- .height_px = test.height,
- .depth_px = test.depth,
- .sample_count_sa = 1,
- .levels = test.levels,
- .tiling = AIL_TILING_TWIDDLED_COMPRESSED,
- .format = test.format,
- };
-
- ail_make_miptree(&layout);
-
- EXPECT_EQ(layout.size_B, test.size)
- << test.width << "x" << test.height << "x" << test.depth << " "
- << (int)test.levels << "L " << util_format_short_name(test.format)
- << " compressed texture has wrong allocation size, off by "
- << ((int)layout.size_B - (int)test.size);
- }
-}
-/*
- * Copyright (C) 2022 Alyssa Rosenzweig
- *
- * 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 <gtest/gtest.h>
-#include "layout.h"
-
-/*
- * Test miptree layouts. All test cases in this file are extracted from memory
- * dumps of a test pattern ran through Metal.
- */
-struct miptest {
- enum pipe_format format;
- uint32_t width, height;
- uint8_t levels;
- uint32_t offsets[16];
-};
-
-/* clang-format off */
-static struct miptest miptests[] = {
{
PIPE_FORMAT_R8G8B8A8_UNORM,
1024,
0x32D700,
}
},
-};
-/* clang-format on */
-
-TEST(Miptree, Tests2D)
-{
- for (unsigned i = 0; i < ARRAY_SIZE(miptests); ++i) {
- struct miptest test = miptests[i];
-
- struct ail_layout layout = {
- .width_px = test.width,
- .height_px = test.height,
- .depth_px = 1,
- .sample_count_sa = 1,
- .levels = test.levels,
- .tiling = AIL_TILING_TWIDDLED,
- .format = test.format,
- };
-
- ail_make_miptree(&layout);
-
- for (unsigned l = 0; l < test.levels; ++l) {
- EXPECT_EQ(ail_get_level_offset_B(&layout, l), test.offsets[l])
- << test.width << "x" << test.height << " "
- << util_format_short_name(test.format)
- << " texture has wrong offset at level " << l << ", off by "
- << test.offsets[l] - ail_get_level_offset_B(&layout, l);
- }
- }
-}
--- /dev/null
+/*
+ * Copyright 2022 Alyssa Rosenzweig
+ * Copyright 2022 Asahi Lina
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <gtest/gtest.h>
+#include "layout.h"
+
+/*
+ * Test texture layouts with test cases extracted from texture structure dumps
+ * produced by Metal.
+ *
+ * The extracted test cases are stored in separate files which do not get
+ * clang-formatted. They do still get parsed as C code, though. They may be
+ * sorted with `sort -t"," -k1,1 -k2,5n | uniq`.
+ */
+struct sizetest {
+ enum pipe_format format;
+ uint32_t width, height, depth;
+ uint8_t levels;
+ uint32_t size;
+};
+
+struct miptest {
+ enum pipe_format format;
+ uint32_t width, height;
+ uint8_t levels;
+ uint32_t offsets[16];
+};
+
+static struct sizetest comptests[] = {
+#include "comp-twiddled.txt"
+};
+
+static struct sizetest sizetests[] = {
+#include "uncomp-twiddled.txt"
+};
+
+static struct miptest miptests[] = {
+#include "miptree.txt"
+};
+
+TEST(Generated, CompTwiddled)
+{
+ for (unsigned i = 0; i < ARRAY_SIZE(comptests); ++i) {
+ struct sizetest test = comptests[i];
+
+ struct ail_layout layout = {
+ .width_px = test.width,
+ .height_px = test.height,
+ .depth_px = test.depth,
+ .sample_count_sa = 1,
+ .levels = test.levels,
+ .tiling = AIL_TILING_TWIDDLED_COMPRESSED,
+ .format = test.format,
+ };
+
+ ail_make_miptree(&layout);
+
+ EXPECT_EQ(layout.size_B, test.size)
+ << test.width << "x" << test.height << "x" << test.depth << " "
+ << (int)test.levels << "L " << util_format_short_name(test.format)
+ << " compressed texture has wrong allocation size, off by "
+ << ((int)layout.size_B - (int)test.size);
+ }
+}
+
+TEST(Generated, UncompTwiddled)
+{
+ for (unsigned i = 0; i < ARRAY_SIZE(sizetests); ++i) {
+ struct sizetest test = sizetests[i];
+
+ struct ail_layout layout = {
+ .width_px = test.width,
+ .height_px = test.height,
+ .depth_px = test.depth,
+ .sample_count_sa = 1,
+ .levels = test.levels,
+ .tiling = AIL_TILING_TWIDDLED,
+ .format = test.format,
+ };
+
+ ail_make_miptree(&layout);
+
+ EXPECT_EQ(layout.size_B, test.size)
+ << test.width << "x" << test.height << "x" << test.depth << " "
+ << (int)test.levels << "L " << util_format_short_name(test.format)
+ << " uncompressed texture has wrong allocation size, off by "
+ << ((int)layout.size_B - (int)test.size);
+ }
+}
+
+TEST(Generated, Miptree2D)
+{
+ for (unsigned i = 0; i < ARRAY_SIZE(miptests); ++i) {
+ struct miptest test = miptests[i];
+
+ struct ail_layout layout = {
+ .width_px = test.width,
+ .height_px = test.height,
+ .depth_px = 1,
+ .sample_count_sa = 1,
+ .levels = test.levels,
+ .tiling = AIL_TILING_TWIDDLED,
+ .format = test.format,
+ };
+
+ ail_make_miptree(&layout);
+
+ for (unsigned l = 0; l < test.levels; ++l) {
+ EXPECT_EQ(ail_get_level_offset_B(&layout, l), test.offsets[l])
+ << test.width << "x" << test.height << " "
+ << util_format_short_name(test.format)
+ << " texture has wrong offset at level " << l << ", off by "
+ << test.offsets[l] - ail_get_level_offset_B(&layout, l);
+ }
+ }
+}
-/*
- * Copyright 2022 Asahi Lina
- * SPDX-License-Identifier: MIT
- */
-
-#include <gtest/gtest.h>
-#include "layout.h"
-
-/*
- * Test uncompressed texture sizes. All test cases in this file are extracted
- * from texture structure dumps in Metal.
- */
-struct sizetest {
- enum pipe_format format;
- uint32_t width, height, depth;
- uint8_t levels;
- uint32_t size;
-};
-
-/* clang-format off */
-/* Sort: `sort -t"," -k1,1 -k2,5n | uniq` */
-static struct sizetest sizetests[] = {
{ PIPE_FORMAT_R8_UNORM, 1, 1, 1, 1, 0x80 },
{ PIPE_FORMAT_R8_UNORM, 1, 1, 2, 1, 0x100 },
{ PIPE_FORMAT_R8_UNORM, 1, 2, 1, 2, 0x100 },
{ PIPE_FORMAT_Z32_FLOAT, 4097, 15, 1, 13, 0xac000 },
{ PIPE_FORMAT_Z32_FLOAT, 4097, 15, 2, 1, 0x100000 },
{ PIPE_FORMAT_Z32_FLOAT, 4097, 15, 2, 13, 0x158000 },
-};
-/* clang-format on */
-
-TEST(UncompTwiddled, SizeTests)
-{
- for (unsigned i = 0; i < ARRAY_SIZE(sizetests); ++i) {
- struct sizetest test = sizetests[i];
-
- struct ail_layout layout = {
- .width_px = test.width,
- .height_px = test.height,
- .depth_px = test.depth,
- .sample_count_sa = 1,
- .levels = test.levels,
- .tiling = AIL_TILING_TWIDDLED,
- .format = test.format,
- };
-
- ail_make_miptree(&layout);
-
- EXPECT_EQ(layout.size_B, test.size)
- << test.width << "x" << test.height << "x" << test.depth << " "
- << (int)test.levels << "L " << util_format_short_name(test.format)
- << " uncompressed texture has wrong allocation size, off by "
- << ((int)layout.size_B - (int)test.size);
- }
-}