xref: /aosp_15_r20/external/mesa3d/src/panfrost/compiler/test/test-pack-formats.cpp (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (C) 2020 Collabora, Ltd.
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 FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #include "bi_test.h"
25 #include "compiler.h"
26 
27 #include <gtest/gtest.h>
28 #include "mesa-gtest-extras.h"
29 
30 class PackFormats : public testing::Test {
31  protected:
PackFormats()32    PackFormats()
33    {
34       util_dynarray_init(&result, NULL);
35    }
~PackFormats()36    ~PackFormats()
37    {
38       util_dynarray_fini(&result);
39    }
40 
result_as_u64_array()41    const uint64_t *result_as_u64_array()
42    {
43       return reinterpret_cast<uint64_t *>(result.data);
44    }
45 
46    struct util_dynarray result;
47 };
48 
49 TEST_F(PackFormats, 1)
50 {
51    /* Test case from the blob */
52    struct bi_packed_tuple tuples[] = {
53       {0x2380cb1c02200000, 0x10e0},
54    };
55 
56    uint64_t header = 0x021000011800;
57 
58    bi_pack_format(&result, 1, tuples, 1, header, 0, 0, true);
59 
60    const uint64_t expected[] = {
61       0x80cb1c022000004a,
62       0x10800008c000e023,
63    };
64 
65    ASSERT_EQ(result.size, 16);
66    ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 2);
67 }
68 
69 TEST_F(PackFormats, 2)
70 {
71    struct bi_packed_tuple tuples[] = {
72       {0x9380cb6044000044, 0xf65},
73       {0xaf8721a05c000081, 0x1831},
74    };
75 
76    bi_pack_format(&result, 0, tuples, 2, 0x52800011800, 0, 0, false);
77    bi_pack_format(&result, 2, tuples, 2, 0x52800011800, 0, 0, false);
78 
79    const uint64_t expected[] = {
80       0x80cb604400004429,
81       0x29400008c0076593,
82       0x8721a05c00008103,
83       0x60000000000031af,
84    };
85 
86    ASSERT_EQ(result.size, 32);
87    ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 4);
88 }
89 
90 TEST_F(PackFormats, 3)
91 {
92    struct bi_packed_tuple tuples[] = {
93       {0x93805b8040000000, 0xf65},
94       {0x93886db05c000000, 0xf65},
95       {0xb380cb180c000080, 0x18b1},
96    };
97 
98    bi_pack_format(&result, 0, tuples, 3, 0x3100000000, 0, 0, true);
99    bi_pack_format(&result, 3, tuples, 3, 0x3100000000, 0, 0, true);
100    bi_pack_format(&result, 4, tuples, 3, 0x3100000000, 0, 0, true);
101 
102    const uint64_t expected[] = {
103       0x805b804000000029, 0x0188000000076593, 0x886db05c00000021,
104       0x58c0600004076593, 0x0000000000000044, 0x60002c6ce0300000,
105    };
106 
107    ASSERT_EQ(result.size, 48);
108    ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 6);
109 }
110 
111 TEST_F(PackFormats, 4)
112 {
113    struct bi_packed_tuple tuples[] = {
114       {0xad8c87004000005f, 0x2f18},
115       {0xad8c87385c00004f, 0x2f18},
116       {0xad8c87385c00006e, 0x2f18},
117       {0xb380cb182c000080, 0x18b1},
118    };
119 
120    uint64_t EC0 = (0x10000001ff000000) >> 4;
121 
122    bi_pack_format(&result, 0, tuples, 4, 0x3100000000, EC0, 0, false);
123    bi_pack_format(&result, 3, tuples, 4, 0x3100000000, EC0, 0, false);
124    bi_pack_format(&result, 6, tuples, 4, 0x3100000000, EC0, 0, false);
125 
126    const uint64_t expected[] = {
127       0x8c87004000005f2d, 0x01880000000718ad, 0x8c87385c00004f25,
128       0x39c2e000037718ad, 0x80cb182c00008005, 0xac01c62b6320b1b3,
129    };
130 
131    ASSERT_EQ(result.size, 48);
132    ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 6);
133 }
134 
135 TEST_F(PackFormats, 5)
136 {
137    struct bi_packed_tuple tuples[] = {
138       {0x9380688040000000, 0xf65},  {0xd4057300c000040, 0xf26},
139       {0x1f80cb1858000000, 0x19ab}, {0x937401f85c000000, 0xf65},
140       {0xb380cb180c000080, 0x18a1},
141    };
142 
143    uint64_t EC0 = (0x183f800000) >> 4;
144 
145    bi_pack_format(&result, 0, tuples, 5, 0x3100000000, EC0, 0, true);
146    bi_pack_format(&result, 3, tuples, 5, 0x3100000000, EC0, 0, true);
147    bi_pack_format(&result, 7, tuples, 5, 0x3100000000, EC0, 0, true);
148    bi_pack_format(&result, 8, tuples, 5, 0x3100000000, EC0, 0, true);
149 
150    const uint64_t expected[] = {
151       0x8068804000000029, 0x0188000000076593, 0x4057300c00004021,
152       0x58c2c0000007260d, 0x7401f85c0000008b, 0x00006ac7e0376593,
153       0x80cb180c00008053, 0x000000183f80a1b3,
154    };
155 
156    ASSERT_EQ(result.size, 64);
157    ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 8);
158 }
159 
160 TEST_F(PackFormats, 6)
161 {
162    struct bi_packed_tuple tuples[] = {
163       {0xad8c870068000048, 0x2f18}, {0xad8c87385c000050, 0x2f18},
164       {0xad8c87385c00006a, 0x2f18}, {0xad8c87385c000074, 0x2f18},
165       {0xad8c87385c000020, 0x2f18}, {0xad8c87385c000030, 0x2f18},
166    };
167 
168    uint64_t EC0 = (0x345678912345670) >> 4;
169 
170    bi_pack_format(&result, 0, tuples, 6, 0x60000011800, EC0, 0, false);
171    bi_pack_format(&result, 3, tuples, 6, 0x60000011800, EC0, 0, false);
172    bi_pack_format(&result, 5, tuples, 6, 0x60000011800, EC0, 0, false);
173    bi_pack_format(&result, 9, tuples, 6, 0x60000011800, EC0, 0, false);
174    bi_pack_format(&result, 10, tuples, 6, 0x60000011800, EC0, 0, false);
175 
176    const uint64_t expected[] = {
177       0x8c8700680000482d, 0x30000008c00718ad, 0x8c87385c00005025,
178       0x39c2e000035718ad, 0x8c87385c00007401, 0xb401c62b632718ad,
179       0x8c87385c00002065, 0x39c2e000018718ad, 0x3456789123456706,
180       0xa001c62b63200000,
181    };
182 
183    ASSERT_EQ(result.size, 80);
184    ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 10);
185 }
186 
187 TEST_F(PackFormats, 7)
188 {
189    struct bi_packed_tuple tuples[] = {
190       {0x9020074040000083, 0xf65},  {0x90000d4058100080, 0xf65},
191       {0x90000a3058700082, 0xf65},  {0x9020074008114581, 0xf65},
192       {0x90000d0058000080, 0xf65},  {0x9000083058700082, 0xf65},
193       {0x2380cb199ac38400, 0x327a},
194    };
195 
196    bi_pack_format(&result, 0, tuples, 7, 0x3000100000, 0, 0, true);
197    bi_pack_format(&result, 3, tuples, 7, 0x3000100000, 0, 0, true);
198    bi_pack_format(&result, 5, tuples, 7, 0x3000100000, 0, 0, true);
199    bi_pack_format(&result, 9, tuples, 7, 0x3000100000, 0, 0, true);
200    bi_pack_format(&result, 11, tuples, 7, 0x3000100000, 0, 0, true);
201 
202    const uint64_t expected[] = {
203       0x2007404000008329, 0x0180008000076590, 0x000d405810008021,
204       0x5182c38004176590, 0x2007400811458101, 0x2401d96400076590,
205       0x000d005800008061, 0x4182c38004176590, 0x80cb199ac3840047,
206       0x3801d96400027a23,
207    };
208 
209    ASSERT_EQ(result.size, 80);
210    ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 10);
211 }
212 
213 TEST_F(PackFormats, 8)
214 {
215    struct bi_packed_tuple tuples[] = {
216       {0x442087037a2f8643, 0x3021}, {0x84008d0586100043, 0x200},
217       {0x7c008d0028014543, 0x0},    {0x1c00070058200081, 0x1980},
218       {0x1600dd878320400, 0x200},   {0x49709c1b08308900, 0x200},
219       {0x6c2007807881ca00, 0x40},   {0x8d70fc0d94900083, 0x800},
220    };
221 
222    uint64_t EC0 = (0x32e635d0) >> 4;
223 
224    bi_pack_format(&result, 0, tuples, 8, 0x61001311800, EC0, 0, true);
225    bi_pack_format(&result, 3, tuples, 8, 0x61001311800, EC0, 0, true);
226    bi_pack_format(&result, 5, tuples, 8, 0x61001311800, EC0, 0, true);
227    bi_pack_format(&result, 9, tuples, 8, 0x61001311800, EC0, 0, true);
228    bi_pack_format(&result, 12, tuples, 8, 0x61001311800, EC0, 0, true);
229    bi_pack_format(&result, 13, tuples, 8, 0x61001311800, EC0, 0, true);
230 
231    const uint64_t expected[] = {
232       0x2087037a2f86432e, 0x30800988c0002144, 0x008d058610004320,
233       0x6801400a2a1a0084, 0x0007005820008101, 0x0c00001f0021801c,
234       0x600dd87832040060, 0xe0d8418448020001, 0x2007807881ca00c0,
235       0xc6ba80125c20406c, 0x70fc0d9490008359, 0x0000000032e0008d,
236    };
237 
238    ASSERT_EQ(result.size, 96);
239    ASSERT_U64_ARRAY_EQUAL(expected, result_as_u64_array(), 12);
240 }
241