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