• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "fd_layout_test.h"
26 #include "adreno_common.xml.h"
27 #include "adreno_pm4.xml.h"
28 #include "a6xx.xml.h"
29 
30 #include <stdio.h>
31 
32 bool
fdl_test_layout(const struct testcase * testcase,int gpu_id)33 fdl_test_layout(const struct testcase *testcase, int gpu_id)
34 {
35    struct fdl_layout layout = {
36       .ubwc = testcase->layout.ubwc,
37       .tile_mode = testcase->layout.tile_mode,
38       .tile_all = testcase->layout.tile_all,
39    };
40    bool ok = true;
41 
42    int max_size = MAX2(testcase->layout.width0, testcase->layout.height0);
43    int mip_levels = 1;
44    while (max_size > 1 && testcase->layout.slices[mip_levels].pitch) {
45       mip_levels++;
46       max_size = u_minify(max_size, 1);
47    }
48 
49    if (gpu_id >= 600) {
50       fdl6_layout(&layout, testcase->format,
51                   MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
52                   MAX2(testcase->layout.height0, 1),
53                   MAX2(testcase->layout.depth0, 1), mip_levels,
54                   MAX2(testcase->array_size, 1), testcase->is_3d, NULL);
55    } else {
56       assert(gpu_id >= 500);
57       fdl5_layout(&layout, testcase->format,
58                   MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
59                   MAX2(testcase->layout.height0, 1),
60                   MAX2(testcase->layout.depth0, 1), mip_levels,
61                   MAX2(testcase->array_size, 1), testcase->is_3d);
62    }
63 
64    /* fdl lays out UBWC data before the color data, while all we have
65     * recorded in this testcase are the color offsets (other than the UBWC
66     * buffer sharing test).  Shift the fdl layout down so we can compare
67     * color offsets.
68     */
69    if (layout.ubwc && !testcase->layout.slices[0].offset) {
70       for (int l = 1; l < mip_levels; l++)
71          layout.slices[l].offset -= layout.slices[0].offset;
72       layout.slices[0].offset = 0;
73    }
74 
75    for (int l = 0; l < mip_levels; l++) {
76       if (layout.slices[l].offset != testcase->layout.slices[l].offset) {
77          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
78                  util_format_short_name(testcase->format), layout.width0,
79                  layout.height0, layout.depth0, layout.nr_samples, l,
80                  layout.slices[l].offset, testcase->layout.slices[l].offset);
81          ok = false;
82       }
83       if (fdl_pitch(&layout, l) != testcase->layout.slices[l].pitch) {
84          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
85                  util_format_short_name(testcase->format), layout.width0,
86                  layout.height0, layout.depth0, layout.nr_samples, l,
87                  fdl_pitch(&layout, l), testcase->layout.slices[l].pitch);
88          ok = false;
89       }
90 
91       /* Test optional requirement of the slice size.  Important for testing 3D
92        * layouts.
93        */
94       if (testcase->layout.slices[l].size0 && layout.slices[l].size0 !=
95           testcase->layout.slices[l].size0) {
96          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: slice size %d != %d\n",
97                  util_format_short_name(testcase->format), layout.width0,
98                  layout.height0, layout.depth0, layout.nr_samples, l,
99                  layout.slices[l].size0,
100                  testcase->layout.slices[l].size0);
101          ok = false;
102       }
103 
104       if (layout.ubwc_slices[l].offset !=
105           testcase->layout.ubwc_slices[l].offset) {
106          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC offset 0x%x != 0x%x\n",
107                  util_format_short_name(testcase->format), layout.width0,
108                  layout.height0, layout.depth0, layout.nr_samples, l,
109                  layout.ubwc_slices[l].offset,
110                  testcase->layout.ubwc_slices[l].offset);
111          ok = false;
112       }
113       if (fdl_ubwc_pitch(&layout, l) != testcase->layout.ubwc_slices[l].pitch) {
114          fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC pitch %d != %d\n",
115                  util_format_short_name(testcase->format), layout.width0,
116                  layout.height0, layout.depth0, layout.nr_samples, l,
117                  fdl_ubwc_pitch(&layout, l),
118                  testcase->layout.ubwc_slices[l].pitch);
119          ok = false;
120       }
121    }
122 
123    if (!ok) {
124       fdl_dump_layout(&layout);
125       fprintf(stderr, "\n");
126    }
127 
128    return ok;
129 }
130