• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,const struct fd_dev_id * dev_id)15 fdl_test_layout(const struct testcase *testcase, const struct fd_dev_id *dev_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 (fd_dev_gen(dev_id) >= 6) {
32       const struct fd_dev_info *dev_info = fd_dev_info_raw(dev_id);
33       fdl6_layout(&layout, dev_info, testcase->format,
34                   MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
35                   MAX2(testcase->layout.height0, 1),
36                   MAX2(testcase->layout.depth0, 1), mip_levels,
37                   MAX2(testcase->array_size, 1), testcase->is_3d, false, NULL);
38    } else {
39       assert(fd_dev_gen(dev_id) >= 5);
40       fdl5_layout(&layout, testcase->format,
41                   MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
42                   MAX2(testcase->layout.height0, 1),
43                   MAX2(testcase->layout.depth0, 1), mip_levels,
44                   MAX2(testcase->array_size, 1), testcase->is_3d);
45    }
46 
47    /* fdl lays out UBWC data before the color data, while all we have
48     * recorded in this testcase are the color offsets (other than the UBWC
49     * buffer sharing test).  Shift the fdl layout down so we can compare
50     * color offsets.
51     */
52    if (layout.ubwc && !testcase->layout.slices[0].offset) {
53       for (int l = 1; l < mip_levels; l++)
54          layout.slices[l].offset -= layout.slices[0].offset;
55       layout.slices[0].offset = 0;
56    }
57 
58    for (int l = 0; l < mip_levels; l++) {
59       if (layout.slices[l].offset != testcase->layout.slices[l].offset) {
60          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
61                  util_format_short_name(testcase->format), layout.width0,
62                  layout.height0, layout.depth0, layout.nr_samples, l,
63                  layout.slices[l].offset, testcase->layout.slices[l].offset);
64          ok = false;
65       }
66       if (fdl_pitch(&layout, l) != testcase->layout.slices[l].pitch) {
67          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
68                  util_format_short_name(testcase->format), layout.width0,
69                  layout.height0, layout.depth0, layout.nr_samples, l,
70                  fdl_pitch(&layout, l), testcase->layout.slices[l].pitch);
71          ok = false;
72       }
73 
74       /* Test optional requirement of the slice size.  Important for testing 3D
75        * layouts.
76        */
77       if (testcase->layout.slices[l].size0 && layout.slices[l].size0 !=
78           testcase->layout.slices[l].size0) {
79          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: slice size %d != %d\n",
80                  util_format_short_name(testcase->format), layout.width0,
81                  layout.height0, layout.depth0, layout.nr_samples, l,
82                  layout.slices[l].size0,
83                  testcase->layout.slices[l].size0);
84          ok = false;
85       }
86 
87       if (layout.ubwc_slices[l].offset !=
88           testcase->layout.ubwc_slices[l].offset) {
89          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC offset 0x%x != 0x%x\n",
90                  util_format_short_name(testcase->format), layout.width0,
91                  layout.height0, layout.depth0, layout.nr_samples, l,
92                  layout.ubwc_slices[l].offset,
93                  testcase->layout.ubwc_slices[l].offset);
94          ok = false;
95       }
96       if (fdl_ubwc_pitch(&layout, l) != testcase->layout.ubwc_slices[l].pitch) {
97          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC pitch %d != %d\n",
98                  util_format_short_name(testcase->format), layout.width0,
99                  layout.height0, layout.depth0, layout.nr_samples, l,
100                  fdl_ubwc_pitch(&layout, l),
101                  testcase->layout.ubwc_slices[l].pitch);
102          ok = false;
103       }
104    }
105 
106    if (!ok) {
107       fdl_dump_layout(&layout);
108       fprintf(stderr, "\n");
109    }
110 
111    return ok;
112 }
113