Debian Codegraph @

src/asahi/layout/tests/test-generated.cpp

raw
1 /*
2 * Copyright 2022 Alyssa Rosenzweig
3 * Copyright 2022 Asahi Lina
4 * SPDX-License-Identifier: MIT
5 */
6
7 #include <gtest/gtest.h>
8 #include "layout.h"
9
10 /*
11 * Test texture layouts with test cases extracted from texture structure dumps
12 * produced by Metal.
13 *
14 * The extracted test cases are stored in separate files which do not get
15 * clang-formatted. They do still get parsed as C code, though. They may be
16 * sorted with `sort -t"," -k1,1 -k2,5n | uniq`.
17 */
18 struct sizetest {
19 enum pipe_format format;
20 uint32_t width, height, depth;
21 uint8_t levels;
22 uint32_t size;
23 };
24
25 struct miptest {
26 enum pipe_format format;
27 uint32_t width, height;
28 uint8_t levels;
29 uint32_t offsets[16];
30 };
31
32 struct msaatest {
33 enum pipe_format format;
34 uint32_t width, height, depth;
35 uint8_t levels;
36 uint8_t samples;
37 bool is_compressed;
38 uint32_t meta_offset;
39 uint32_t size;
40 };
41
42 static struct sizetest comptests[] = {
43 #include "comp-twiddled.txt"
44 };
45
46 static struct sizetest sizetests[] = {
47 #include "uncomp-twiddled.txt"
48 };
49
50 static struct miptest miptests[] = {
51 #include "miptree.txt"
52 };
53
54 static struct msaatest msaatests[] = {
55 #include "msaa.txt"
56 };
57
58 TEST(Generated, CompTwiddled)
59 {
60 for (unsigned i = 0; i < ARRAY_SIZE(comptests); ++i) {
61 struct sizetest test = comptests[i];
62
63 struct ail_layout layout = {
64 .width_px = test.width,
65 .height_px = test.height,
66 .depth_px = test.depth,
67 .sample_count_sa = 1,
68 .levels = test.levels,
69 .tiling = AIL_TILING_GPU,
70 .compressed = true,
71 .format = test.format,
72 };
73
74 ail_make_miptree(&layout);
75
76 EXPECT_EQ(layout.size_B, test.size)
77 << test.width << "x" << test.height << "x" << test.depth << " "
78 << (int)test.levels << "L " << util_format_short_name(test.format)
79 << " compressed texture has wrong allocation size, off by "
80 << ((int)layout.size_B - (int)test.size);
81 }
82 }
83
84 TEST(Generated, UncompTwiddled)
85 {
86 for (unsigned i = 0; i < ARRAY_SIZE(sizetests); ++i) {
87 struct sizetest test = sizetests[i];
88
89 struct ail_layout layout = {
90 .width_px = test.width,
91 .height_px = test.height,
92 .depth_px = test.depth,
93 .sample_count_sa = 1,
94 .levels = test.levels,
95 .tiling = AIL_TILING_GPU,
96 .format = test.format,
97 };
98
99 ail_make_miptree(&layout);
100
101 EXPECT_EQ(layout.size_B, test.size)
102 << test.width << "x" << test.height << "x" << test.depth << " "
103 << (int)test.levels << "L " << util_format_short_name(test.format)
104 << " uncompressed texture has wrong allocation size, off by "
105 << ((int)layout.size_B - (int)test.size);
106 }
107 }
108
109 TEST(Generated, Miptree2D)
110 {
111 for (unsigned i = 0; i < ARRAY_SIZE(miptests); ++i) {
112 struct miptest test = miptests[i];
113
114 struct ail_layout layout = {
115 .width_px = test.width,
116 .height_px = test.height,
117 .depth_px = 1,
118 .sample_count_sa = 1,
119 .levels = test.levels,
120 .tiling = AIL_TILING_GPU,
121 .format = test.format,
122 };
123
124 ail_make_miptree(&layout);
125
126 for (unsigned l = 0; l < test.levels; ++l) {
127 EXPECT_EQ(ail_get_level_offset_B(&layout, l), test.offsets[l])
128 << test.width << "x" << test.height << " "
129 << util_format_short_name(test.format)
130 << " texture has wrong offset at level " << l << ", off by "
131 << test.offsets[l] - ail_get_level_offset_B(&layout, l);
132 }
133 }
134 }
135
136 TEST(Generated, MSAA)
137 {
138 for (unsigned i = 0; i < ARRAY_SIZE(msaatests); ++i) {
139 struct msaatest test = msaatests[i];
140
141 struct ail_layout layout = {
142 .width_px = test.width,
143 .height_px = test.height,
144 .depth_px = test.depth,
145 .sample_count_sa = test.samples,
146 .levels = test.levels,
147 .tiling = AIL_TILING_GPU,
148 .compressed = test.is_compressed,
149 .format = test.format,
150 };
151
152 ail_make_miptree(&layout);
153
154 EXPECT_EQ(layout.size_B, test.size)
155 << test.width << "x" << test.height << "x" << test.depth << " "
156 << (int)test.levels << "L " << (int)test.samples << "S "
157 << util_format_short_name(test.format)
158 << (test.is_compressed ? " " : " un")
159 << "compressed texture has wrong allocation size, off by "
160 << ((int)layout.size_B - (int)test.size);
161
162 if (test.is_compressed) {
163 EXPECT_EQ(layout.metadata_offset_B, test.meta_offset)
164 << test.width << "x" << test.height << "x" << test.depth << " "
165 << (int)test.levels << "L " << (int)test.samples << "S "
166 << util_format_short_name(test.format)
167 << "compressed texture has wrong metadata offset size, off by "
168 << ((int)layout.metadata_offset_B - (int)test.meta_offset);
169 }
170 }
171 }