xref: /aosp_15_r20/external/mesa3d/src/freedreno/fdl/fd_layout_test.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2020 Google LLC
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "freedreno_layout.h"
7 #include "fd_layout_test.h"
8 #include "adreno_common.xml.h"
9 #include "adreno_pm4.xml.h"
10 #include "a6xx.xml.h"
11 
12 #include <stdio.h>
13 
14 bool
fdl_test_layout(const struct testcase * testcase,int gpu_id)15 fdl_test_layout(const struct testcase *testcase, int gpu_id)
16 {
17    struct fdl_layout layout = {
18       .ubwc = testcase->layout.ubwc,
19       .tile_mode = testcase->layout.tile_mode,
20       .tile_all = testcase->layout.tile_all,
21    };
22    bool ok = true;
23 
24    int max_size = MAX2(testcase->layout.width0, testcase->layout.height0);
25    int mip_levels = 1;
26    while (max_size > 1 && testcase->layout.slices[mip_levels].pitch) {
27       mip_levels++;
28       max_size = u_minify(max_size, 1);
29    }
30 
31    if (gpu_id >= 600) {
32       fdl6_layout(&layout, testcase->format,
33                   MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
34                   MAX2(testcase->layout.height0, 1),
35                   MAX2(testcase->layout.depth0, 1), mip_levels,
36                   MAX2(testcase->array_size, 1), testcase->is_3d, NULL);
37    } else {
38       assert(gpu_id >= 500);
39       fdl5_layout(&layout, testcase->format,
40                   MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
41                   MAX2(testcase->layout.height0, 1),
42                   MAX2(testcase->layout.depth0, 1), mip_levels,
43                   MAX2(testcase->array_size, 1), testcase->is_3d);
44    }
45 
46    /* fdl lays out UBWC data before the color data, while all we have
47     * recorded in this testcase are the color offsets (other than the UBWC
48     * buffer sharing test).  Shift the fdl layout down so we can compare
49     * color offsets.
50     */
51    if (layout.ubwc && !testcase->layout.slices[0].offset) {
52       for (int l = 1; l < mip_levels; l++)
53          layout.slices[l].offset -= layout.slices[0].offset;
54       layout.slices[0].offset = 0;
55    }
56 
57    for (int l = 0; l < mip_levels; l++) {
58       if (layout.slices[l].offset != testcase->layout.slices[l].offset) {
59          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
60                  util_format_short_name(testcase->format), layout.width0,
61                  layout.height0, layout.depth0, layout.nr_samples, l,
62                  layout.slices[l].offset, testcase->layout.slices[l].offset);
63          ok = false;
64       }
65       if (fdl_pitch(&layout, l) != testcase->layout.slices[l].pitch) {
66          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
67                  util_format_short_name(testcase->format), layout.width0,
68                  layout.height0, layout.depth0, layout.nr_samples, l,
69                  fdl_pitch(&layout, l), testcase->layout.slices[l].pitch);
70          ok = false;
71       }
72 
73       /* Test optional requirement of the slice size.  Important for testing 3D
74        * layouts.
75        */
76       if (testcase->layout.slices[l].size0 && layout.slices[l].size0 !=
77           testcase->layout.slices[l].size0) {
78          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: slice size %d != %d\n",
79                  util_format_short_name(testcase->format), layout.width0,
80                  layout.height0, layout.depth0, layout.nr_samples, l,
81                  layout.slices[l].size0,
82                  testcase->layout.slices[l].size0);
83          ok = false;
84       }
85 
86       if (layout.ubwc_slices[l].offset !=
87           testcase->layout.ubwc_slices[l].offset) {
88          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC offset 0x%x != 0x%x\n",
89                  util_format_short_name(testcase->format), layout.width0,
90                  layout.height0, layout.depth0, layout.nr_samples, l,
91                  layout.ubwc_slices[l].offset,
92                  testcase->layout.ubwc_slices[l].offset);
93          ok = false;
94       }
95       if (fdl_ubwc_pitch(&layout, l) != testcase->layout.ubwc_slices[l].pitch) {
96          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC pitch %d != %d\n",
97                  util_format_short_name(testcase->format), layout.width0,
98                  layout.height0, layout.depth0, layout.nr_samples, l,
99                  fdl_ubwc_pitch(&layout, l),
100                  testcase->layout.ubwc_slices[l].pitch);
101          ok = false;
102       }
103    }
104 
105    if (!ok) {
106       fdl_dump_layout(&layout);
107       fprintf(stderr, "\n");
108    }
109 
110    return ok;
111 }
112