freedreno: Add the outline of a test for a6xx texture layout.
[mesa.git] / src / freedreno / fdl / fd6_layout_test.c
1 /*
2 * Copyright © 2020 Google LLC
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "freedreno_layout.h"
25 #include "adreno_common.xml.h"
26 #include "a6xx.xml.h"
27
28 #include <stdio.h>
29
30 struct testcase {
31 enum pipe_format format;
32
33 int array_size; /* Size for array textures, or 0 otherwise. */
34 bool is_3d;
35
36 /* Partially filled layout of input parameters and expected results. */
37 struct fdl_layout layout;
38 };
39
40 static const struct testcase testcases[] = {
41 /* A straightforward first testcase, linear, with an obvious format. */
42 {
43 .format = PIPE_FORMAT_R8G8B8A8_UNORM,
44 .layout = {
45 .width0 = 32, .height0 = 32,
46 .slices = {
47 { .offset = 0, .pitch = 256 },
48 { .offset = 8192, .pitch = 256 },
49 { .offset = 12288, .pitch = 256 },
50 { .offset = 14336, .pitch = 256 },
51 { .offset = 15360, .pitch = 256 },
52 { .offset = 15872, .pitch = 256 },
53 },
54 },
55 },
56
57 /* A tiled/ubwc layout from the blob driver, at a size where the a630 blob
58 * driver does something interesting for linear.
59 */
60 {
61 .format = PIPE_FORMAT_R8G8B8A8_UNORM,
62 .layout = {
63 .tile_mode = TILE6_3,
64 .ubwc = true,
65 .width0 = 1024, .height0 = 1,
66 .slices = {
67 { .offset = 0, .pitch = 4096 },
68 { .offset = 65536, .pitch = 2048 },
69 { .offset = 98304, .pitch = 1024 },
70 { .offset = 114688, .pitch = 512 },
71 { .offset = 122880, .pitch = 256 },
72 { .offset = 126976, .pitch = 256 },
73 { .offset = 131072, .pitch = 256 },
74 { .offset = 135168, .pitch = 256 },
75 { .offset = 139264, .pitch = 256 },
76 { .offset = 143360, .pitch = 256 },
77 { .offset = 147456, .pitch = 256 },
78 },
79 .ubwc_slices = {
80 { .offset = 0, .pitch = 64 },
81 { .offset = 4096, .pitch = 64 },
82 { .offset = 8192, .pitch = 64 },
83 { .offset = 12288, .pitch = 64 },
84 { .offset = 16384, .pitch = 64 },
85 { .offset = 20480, .pitch = 64 },
86 { .offset = 24576, .pitch = 64 },
87 { .offset = 28672, .pitch = 64 },
88 { .offset = 32768, .pitch = 64 },
89 { .offset = 36864, .pitch = 64 },
90 { .offset = 40960, .pitch = 64 },
91 },
92 },
93 },
94
95 /* An interesting layout from the blob driver on a630, showing that
96 * per-level pitch must be derived from level 0's pitch, not width0. We
97 * don't do this level 0 pitch disalignment (we pick 4096), so disabled
98 * this test for now.
99 */
100 #if 0
101 {
102 .format = PIPE_FORMAT_R8G8B8A8_UNORM,
103 .layout = {
104 .width0 = 1024, .height0 = 1,
105 .slices = {
106 { .offset = 0, .pitch = 5120 },
107 { .offset = 5120, .pitch = 2560 },
108 { .offset = 7680, .pitch = 1280 },
109 { .offset = 8960, .pitch = 768 },
110 { .offset = 9728, .pitch = 512 },
111 { .offset = 10240, .pitch = 256 },
112 { .offset = 10496, .pitch = 256 },
113 { .offset = 10752, .pitch = 256 },
114 { .offset = 11008, .pitch = 256 },
115 { .offset = 11264, .pitch = 256 },
116 { .offset = 11520, .pitch = 256 },
117 },
118 },
119 },
120 #endif
121 };
122
123 static bool test_layout(const struct testcase *testcase)
124 {
125 struct fdl_layout layout = {
126 .ubwc = testcase->layout.ubwc,
127 .tile_mode = testcase->layout.tile_mode,
128 };
129 bool ok = true;
130
131 int max_size = MAX2(testcase->layout.width0, testcase->layout.height0);
132 int mip_levels = 1;
133 while (max_size > 1) {
134 mip_levels++;
135 max_size = u_minify(max_size, 1);
136 }
137
138 fdl6_layout(&layout,
139 testcase->format,
140 MAX2(testcase->layout.nr_samples, 1),
141 testcase->layout.width0,
142 MAX2(testcase->layout.height0, 1),
143 MAX2(testcase->layout.depth0, 1),
144 mip_levels,
145 MAX2(testcase->array_size, 1),
146 testcase->is_3d);
147
148 /* Our pitch values in the testcases[] layouts are in bytes straight out
149 * of the traces, while fdl is in pixels. Rescale now.
150 */
151 for (int l = 0; l < mip_levels; l++)
152 layout.slices[l].pitch *= layout.cpp;
153
154 /* fdl lays out UBWC data before the color data, while all we have
155 * recorded in this testcase are the color offsets. Shift the fdl layout
156 * down so we can compare color offsets.
157 */
158 if (layout.ubwc) {
159 for (int l = 1; l < mip_levels; l++)
160 layout.slices[l].offset -= layout.slices[0].offset;
161 layout.slices[0].offset = 0;
162 }
163
164 for (int l = 0; l < mip_levels; l++) {
165 if (layout.slices[l].offset != testcase->layout.slices[l].offset) {
166 fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
167 util_format_short_name(testcase->format),
168 layout.width0, layout.height0, layout.depth0,
169 layout.nr_samples, l,
170 layout.slices[l].offset,
171 testcase->layout.slices[l].offset);
172 ok = false;
173 }
174 if (layout.slices[l].pitch != testcase->layout.slices[l].pitch) {
175 fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
176 util_format_short_name(testcase->format),
177 layout.width0, layout.height0, layout.depth0,
178 layout.nr_samples, l,
179 layout.slices[l].pitch,
180 testcase->layout.slices[l].pitch);
181 ok = false;
182 }
183
184 if (layout.ubwc_slices[l].offset != testcase->layout.ubwc_slices[l].offset) {
185 fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
186 util_format_short_name(testcase->format),
187 layout.width0, layout.height0, layout.depth0,
188 layout.nr_samples, l,
189 layout.ubwc_slices[l].offset,
190 testcase->layout.ubwc_slices[l].offset);
191 ok = false;
192 }
193 if (layout.ubwc_slices[l].pitch != testcase->layout.ubwc_slices[l].pitch) {
194 fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
195 util_format_short_name(testcase->format),
196 layout.width0, layout.height0, layout.depth0,
197 layout.nr_samples, l,
198 layout.ubwc_slices[l].pitch,
199 testcase->layout.ubwc_slices[l].pitch);
200 ok = false;
201 }
202 }
203
204 if (!ok)
205 fprintf(stderr, "\n");
206
207 return ok;
208 }
209
210 int
211 main(int argc, char **argv)
212 {
213 int ret = 0;
214
215 for (int i = 0; i < ARRAY_SIZE(testcases); i++) {
216 if (!test_layout(&testcases[i]))
217 ret = 1;
218 }
219
220 return ret;
221 }