2 * Copyright © 2020 Google LLC
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:
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
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
24 #include "freedreno_layout.h"
25 #include "adreno_common.xml.h"
31 enum pipe_format format
;
33 int array_size
; /* Size for array textures, or 0 otherwise. */
36 /* Partially filled layout of input parameters and expected results. */
37 struct fdl_layout layout
;
40 static const struct testcase testcases
[] = {
41 /* A straightforward first testcase, linear, with an obvious format. */
43 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
45 .width0
= 32, .height0
= 32,
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 },
57 /* A tiled/ubwc layout from the blob driver, at a size where the a630 blob
58 * driver does something interesting for linear.
61 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
65 .width0
= 1024, .height0
= 1,
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 },
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 },
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
102 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
104 .width0
= 1024, .height0
= 1,
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 },
122 /* A layout that we failed on (129 wide has a surprise level 1 pitch
123 * increase), and the sizes bracketing it.
126 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
128 .width0
= 128, .height0
= 1,
130 { .offset
= 0, .pitch
= 512 },
131 { .offset
= 512, .pitch
= 256 },
132 { .offset
= 768, .pitch
= 256 },
133 { .offset
= 1024, .pitch
= 256 },
134 { .offset
= 1280, .pitch
= 256 },
135 { .offset
= 1536, .pitch
= 256 },
136 { .offset
= 1792, .pitch
= 256 },
137 { .offset
= 2048, .pitch
= 256 },
142 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
144 .width0
= 129, .height0
= 1,
146 { .offset
= 0, .pitch
= 768 },
147 { .offset
= 768, .pitch
= 512 },
148 { .offset
= 1280, .pitch
= 256 },
149 { .offset
= 1536, .pitch
= 256 },
150 { .offset
= 1792, .pitch
= 256 },
151 { .offset
= 2048, .pitch
= 256 },
152 { .offset
= 2304, .pitch
= 256 },
153 { .offset
= 2560, .pitch
= 256 },
158 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
160 .width0
= 130, .height0
= 1,
162 { .offset
= 0, .pitch
= 768 },
163 { .offset
= 768, .pitch
= 512 },
164 { .offset
= 1280, .pitch
= 256 },
165 { .offset
= 1536, .pitch
= 256 },
166 { .offset
= 1792, .pitch
= 256 },
167 { .offset
= 2048, .pitch
= 256 },
168 { .offset
= 2304, .pitch
= 256 },
169 { .offset
= 2560, .pitch
= 256 },
174 /* The 129 failure seems to be across formats, let's test some cpps */
176 .format
= PIPE_FORMAT_R8_UNORM
,
178 .width0
= 129, .height0
= 1,
180 { .offset
= 0, .pitch
= 192 },
181 { .offset
= 192, .pitch
= 128 },
182 { .offset
= 320, .pitch
= 64 },
183 { .offset
= 384, .pitch
= 64 },
184 { .offset
= 448, .pitch
= 64 },
185 { .offset
= 512, .pitch
= 64 },
186 { .offset
= 576, .pitch
= 64 },
187 { .offset
= 640, .pitch
= 64 },
192 .format
= PIPE_FORMAT_R16_UINT
,
194 .width0
= 129, .height0
= 1,
196 { .offset
= 0, .pitch
= 384 },
197 { .offset
= 384, .pitch
= 256 },
198 { .offset
= 640, .pitch
= 128 },
199 { .offset
= 768, .pitch
= 128 },
200 { .offset
= 896, .pitch
= 128 },
201 { .offset
= 1024, .pitch
= 128 },
202 { .offset
= 1152, .pitch
= 128 },
203 { .offset
= 1280, .pitch
= 128 },
208 .format
= PIPE_FORMAT_R32G32B32A32_FLOAT
,
210 .width0
= 129, .height0
= 1,
212 { .offset
= 0, .pitch
= 3072 },
213 { .offset
= 3072, .pitch
= 2048 },
214 { .offset
= 5120, .pitch
= 1024 },
215 { .offset
= 6144, .pitch
= 1024 },
216 { .offset
= 7168, .pitch
= 1024 },
217 { .offset
= 8192, .pitch
= 1024 },
218 { .offset
= 9216, .pitch
= 1024 },
219 { .offset
= 10240, .pitch
= 1024 },
224 /* The 129 failure replicated at every +256 pixels wide. Pick one of
225 * them, and this time increase the height as a new variable as well.
228 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
230 .width0
= 385, .height0
= 128,
232 { .offset
= 0, .pitch
= 1792 },
233 { .offset
= 229376, .pitch
= 1024 },
234 { .offset
= 294912, .pitch
= 512 },
235 { .offset
= 311296, .pitch
= 256 },
236 { .offset
= 315392, .pitch
= 256 },
237 { .offset
= 317440, .pitch
= 256 },
238 { .offset
= 318464, .pitch
= 256 },
239 { .offset
= 318976, .pitch
= 256 },
240 { .offset
= 319232, .pitch
= 256 },
245 /* At 257-259 (and replicated every +256 pixels) we had another failure. */
247 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
249 .width0
= 257, .height0
= 1,
251 { .offset
= 0, .pitch
= 1280 },
252 { .offset
= 1280, .pitch
= 768 },
253 { .offset
= 2048, .pitch
= 512 },
254 { .offset
= 2560, .pitch
= 256 },
255 { .offset
= 2816, .pitch
= 256 },
256 { .offset
= 3072, .pitch
= 256 },
257 { .offset
= 3328, .pitch
= 256 },
258 { .offset
= 3584, .pitch
= 256 },
259 { .offset
= 3840, .pitch
= 256 },
264 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
266 .width0
= 258, .height0
= 1,
268 { .offset
= 0, .pitch
= 1280 },
269 { .offset
= 1280, .pitch
= 768 },
270 { .offset
= 2048, .pitch
= 512 },
271 { .offset
= 2560, .pitch
= 256 },
272 { .offset
= 2816, .pitch
= 256 },
273 { .offset
= 3072, .pitch
= 256 },
274 { .offset
= 3328, .pitch
= 256 },
275 { .offset
= 3584, .pitch
= 256 },
276 { .offset
= 3840, .pitch
= 256 },
281 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
283 .width0
= 259, .height0
= 1,
285 { .offset
= 0, .pitch
= 1280 },
286 { .offset
= 1280, .pitch
= 768 },
287 { .offset
= 2048, .pitch
= 512 },
288 { .offset
= 2560, .pitch
= 256 },
289 { .offset
= 2816, .pitch
= 256 },
290 { .offset
= 3072, .pitch
= 256 },
291 { .offset
= 3328, .pitch
= 256 },
292 { .offset
= 3584, .pitch
= 256 },
293 { .offset
= 3840, .pitch
= 256 },
298 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
300 .width0
= 260, .height0
= 1,
302 { .offset
= 0, .pitch
= 1280 },
303 { .offset
= 1280, .pitch
= 768 },
304 { .offset
= 2048, .pitch
= 512 },
305 { .offset
= 2560, .pitch
= 256 },
306 { .offset
= 2816, .pitch
= 256 },
307 { .offset
= 3072, .pitch
= 256 },
308 { .offset
= 3328, .pitch
= 256 },
309 { .offset
= 3584, .pitch
= 256 },
310 { .offset
= 3840, .pitch
= 256 },
315 /* And, again for the 257-9 failure, test a replica with a larger size*/
317 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
319 .width0
= 513, .height0
= 32,
321 { .offset
= 0, .pitch
= 2304 },
322 { .offset
= 73728, .pitch
= 1280 },
323 { .offset
= 94208, .pitch
= 768 },
324 { .offset
= 100352, .pitch
= 512 },
325 { .offset
= 102400, .pitch
= 256 },
326 { .offset
= 102912, .pitch
= 256 },
327 { .offset
= 103168, .pitch
= 256 },
328 { .offset
= 103424, .pitch
= 256 },
329 { .offset
= 103680, .pitch
= 256 },
330 { .offset
= 103936, .pitch
= 256 },
335 /* Oh, look. The 513-517 failure extends up to 518 at the next texture
339 .format
= PIPE_FORMAT_R8G8B8A8_UNORM
,
341 .width0
= 518, .height0
= 1,
343 { .offset
= 0, .pitch
= 2304 },
344 { .offset
= 2304, .pitch
= 1280 },
345 { .offset
= 3584, .pitch
= 768 },
346 { .offset
= 4352, .pitch
= 512 },
347 { .offset
= 4864, .pitch
= 256 },
348 { .offset
= 5120, .pitch
= 256 },
349 { .offset
= 5376, .pitch
= 256 },
350 { .offset
= 5632, .pitch
= 256 },
351 { .offset
= 5888, .pitch
= 256 },
352 { .offset
= 6144, .pitch
= 256 },
357 /* Tiled mode testing of the unusual 1/2-bytes-per-pixel pitch alignment */
359 .format
= PIPE_FORMAT_R8_UNORM
,
361 .tile_mode
= TILE6_3
,
362 .width0
= 129, .height0
= 1,
364 { .offset
= 0, .pitch
= 256 },
365 { .offset
= 8192, .pitch
= 128 },
366 { .offset
= 12288, .pitch
= 128 },
367 { .offset
= 16384, .pitch
= 128 },
368 { .offset
= 20480, .pitch
= 64 },
369 { .offset
= 20544, .pitch
= 64 },
370 { .offset
= 20608, .pitch
= 64 },
371 { .offset
= 20672, .pitch
= 64 },
378 static bool test_layout(const struct testcase
*testcase
)
380 struct fdl_layout layout
= {
381 .ubwc
= testcase
->layout
.ubwc
,
382 .tile_mode
= testcase
->layout
.tile_mode
,
386 int max_size
= MAX2(testcase
->layout
.width0
, testcase
->layout
.height0
);
388 while (max_size
> 1) {
390 max_size
= u_minify(max_size
, 1);
395 MAX2(testcase
->layout
.nr_samples
, 1),
396 testcase
->layout
.width0
,
397 MAX2(testcase
->layout
.height0
, 1),
398 MAX2(testcase
->layout
.depth0
, 1),
400 MAX2(testcase
->array_size
, 1),
403 /* fdl lays out UBWC data before the color data, while all we have
404 * recorded in this testcase are the color offsets. Shift the fdl layout
405 * down so we can compare color offsets.
408 for (int l
= 1; l
< mip_levels
; l
++)
409 layout
.slices
[l
].offset
-= layout
.slices
[0].offset
;
410 layout
.slices
[0].offset
= 0;
413 for (int l
= 0; l
< mip_levels
; l
++) {
414 if (layout
.slices
[l
].offset
!= testcase
->layout
.slices
[l
].offset
) {
415 fprintf(stderr
, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
416 util_format_short_name(testcase
->format
),
417 layout
.width0
, layout
.height0
, layout
.depth0
,
418 layout
.nr_samples
, l
,
419 layout
.slices
[l
].offset
,
420 testcase
->layout
.slices
[l
].offset
);
423 if (layout
.slices
[l
].pitch
!= testcase
->layout
.slices
[l
].pitch
) {
424 fprintf(stderr
, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
425 util_format_short_name(testcase
->format
),
426 layout
.width0
, layout
.height0
, layout
.depth0
,
427 layout
.nr_samples
, l
,
428 layout
.slices
[l
].pitch
,
429 testcase
->layout
.slices
[l
].pitch
);
433 if (layout
.ubwc_slices
[l
].offset
!= testcase
->layout
.ubwc_slices
[l
].offset
) {
434 fprintf(stderr
, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
435 util_format_short_name(testcase
->format
),
436 layout
.width0
, layout
.height0
, layout
.depth0
,
437 layout
.nr_samples
, l
,
438 layout
.ubwc_slices
[l
].offset
,
439 testcase
->layout
.ubwc_slices
[l
].offset
);
442 if (layout
.ubwc_slices
[l
].pitch
!= testcase
->layout
.ubwc_slices
[l
].pitch
) {
443 fprintf(stderr
, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
444 util_format_short_name(testcase
->format
),
445 layout
.width0
, layout
.height0
, layout
.depth0
,
446 layout
.nr_samples
, l
,
447 layout
.ubwc_slices
[l
].pitch
,
448 testcase
->layout
.ubwc_slices
[l
].pitch
);
454 fprintf(stderr
, "\n");
460 main(int argc
, char **argv
)
464 for (int i
= 0; i
< ARRAY_SIZE(testcases
); i
++) {
465 if (!test_layout(&testcases
[i
]))