vc4: Add dumping for the TILE_RENDERING_MODE_CONFIG packet.
[mesa.git] / src / gallium / drivers / vc4 / vc4_cl_dump.c
1 /*
2 * Copyright © 2014 Broadcom
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 "util/u_math.h"
25 #include "util/macros.h"
26 #include "vc4_context.h"
27
28 #define dump_VC4_PACKET_LINE_WIDTH dump_float
29 #define dump_VC4_PACKET_POINT_SIZE dump_float
30
31 static void
32 dump_float(void *cl, uint32_t offset, uint32_t hw_offset)
33 {
34 void *f = cl + offset;
35
36 fprintf(stderr, "0x%08x 0x%08x: %f (0x%08x)\n",
37 offset, hw_offset, *(float *)f, *(uint32_t *)f);
38 }
39
40 static void
41 dump_VC4_PACKET_BRANCH_TO_SUB_LIST(void *cl, uint32_t offset, uint32_t hw_offset)
42 {
43 uint32_t *addr = cl + offset;
44
45 fprintf(stderr, "0x%08x 0x%08x: addr 0x%08x\n",
46 offset, hw_offset, *addr);
47 }
48
49 static void
50 dump_VC4_PACKET_FLAT_SHADE_FLAGS(void *cl, uint32_t offset, uint32_t hw_offset)
51 {
52 uint32_t *bits = cl + offset;
53
54 fprintf(stderr, "0x%08x 0x%08x: bits 0x%08x\n",
55 offset, hw_offset, *bits);
56 }
57
58 static void
59 dump_VC4_PACKET_VIEWPORT_OFFSET(void *cl, uint32_t offset, uint32_t hw_offset)
60 {
61 uint16_t *o = cl + offset;
62
63 fprintf(stderr, "0x%08x 0x%08x: %f, %f (0x%04x, 0x%04x)\n",
64 offset, hw_offset,
65 o[0] / 16.0, o[1] / 16.0,
66 o[0], o[1]);
67 }
68
69 static void
70 dump_VC4_PACKET_CLIPPER_XY_SCALING(void *cl, uint32_t offset, uint32_t hw_offset)
71 {
72 uint32_t *scale = cl + offset;
73
74 fprintf(stderr, "0x%08x 0x%08x: %f, %f (%f, %f, 0x%08x, 0x%08x)\n",
75 offset, hw_offset,
76 uif(scale[0]) / 16.0, uif(scale[1]) / 16.0,
77 uif(scale[0]), uif(scale[1]),
78 scale[0], scale[1]);
79 }
80
81 static void
82 dump_VC4_PACKET_CLIPPER_Z_SCALING(void *cl, uint32_t offset, uint32_t hw_offset)
83 {
84 uint32_t *translate = cl + offset;
85 uint32_t *scale = cl + offset + 8;
86
87 fprintf(stderr, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
88 offset, hw_offset,
89 uif(translate[0]), uif(translate[1]),
90 translate[0], translate[1]);
91
92 fprintf(stderr, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
93 offset + 8, hw_offset + 8,
94 uif(scale[0]), uif(scale[1]),
95 scale[0], scale[1]);
96 }
97
98 static void
99 dump_VC4_PACKET_TILE_RENDERING_MODE_CONFIG(void *cl, uint32_t offset, uint32_t hw_offset)
100 {
101 uint32_t *render_offset = cl + offset;
102 uint16_t *shorts = cl + offset + 4;
103 uint8_t *bytes = cl + offset + 8;
104
105 fprintf(stderr, "0x%08x 0x%08x: color offset 0x%08x\n",
106 offset, hw_offset,
107 *render_offset);
108
109 fprintf(stderr, "0x%08x 0x%08x: width %d\n",
110 offset + 4, hw_offset + 4,
111 shorts[0]);
112
113 fprintf(stderr, "0x%08x 0x%08x: height %d\n",
114 offset + 6, hw_offset + 6,
115 shorts[1]);
116
117 const char *format = "???";
118 switch ((bytes[0] >> 2) & 3) {
119 case 0:
120 format = "BGR565_DITHERED";
121 break;
122 case 1:
123 format = "RGBA8888";
124 break;
125 case 2:
126 format = "BGR565";
127 break;
128 }
129 if (shorts[2] & VC4_RENDER_CONFIG_TILE_BUFFER_64BIT)
130 format = "64bit";
131
132 const char *tiling = "???";
133 switch ((bytes[0] >> 6) & 3) {
134 case 0:
135 tiling = "linear";
136 break;
137 case 1:
138 tiling = "T";
139 break;
140 case 2:
141 tiling = "LT";
142 break;
143 }
144
145 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s %s %s\n",
146 offset + 8, hw_offset + 8,
147 bytes[0],
148 format, tiling,
149 (bytes[0] & VC4_RENDER_CONFIG_MS_MODE_4X) ? "ms" : "ss");
150
151 const char *earlyz = "";
152 if (bytes[1] & (1 << 3)) {
153 earlyz = "early_z disabled";
154 } else {
155 if (bytes[1] & (1 << 2))
156 earlyz = "early_z >";
157 else
158 earlyz = "early_z <";
159 }
160
161 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
162 offset + 9, hw_offset + 9,
163 bytes[1],
164 earlyz);
165 }
166
167 static void
168 dump_VC4_PACKET_TILE_COORDINATES(void *cl, uint32_t offset, uint32_t hw_offset)
169 {
170 uint8_t *tilecoords = cl + offset;
171
172 fprintf(stderr, "0x%08x 0x%08x: %d, %d\n",
173 offset, hw_offset, tilecoords[0], tilecoords[1]);
174 }
175
176 static void
177 dump_VC4_PACKET_GEM_HANDLES(void *cl, uint32_t offset, uint32_t hw_offset)
178 {
179 uint32_t *handles = cl + offset;
180
181 fprintf(stderr, "0x%08x 0x%08x: handle 0: %d, handle 1: %d\n",
182 offset, hw_offset, handles[0], handles[1]);
183 }
184
185 #define PACKET_DUMP(name, size) [name] = { #name, size, dump_##name }
186 #define PACKET(name, size) [name] = { #name, size, NULL }
187
188 static const struct packet_info {
189 const char *name;
190 uint8_t size;
191 void (*dump_func)(void *cl, uint32_t offset, uint32_t hw_offset);
192 } packet_info[] = {
193 PACKET(VC4_PACKET_HALT, 1),
194 PACKET(VC4_PACKET_NOP, 1),
195
196 PACKET(VC4_PACKET_FLUSH, 1),
197 PACKET(VC4_PACKET_FLUSH_ALL, 1),
198 PACKET(VC4_PACKET_START_TILE_BINNING, 1),
199 PACKET(VC4_PACKET_INCREMENT_SEMAPHORE, 1),
200 PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE, 1),
201
202 PACKET(VC4_PACKET_BRANCH, 5),
203 PACKET_DUMP(VC4_PACKET_BRANCH_TO_SUB_LIST, 5),
204
205 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER, 1),
206 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF, 1),
207 PACKET(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER, 5),
208 PACKET(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER, 5),
209 PACKET(VC4_PACKET_STORE_TILE_BUFFER_GENERAL, 7),
210 PACKET(VC4_PACKET_LOAD_TILE_BUFFER_GENERAL, 7),
211
212 PACKET(VC4_PACKET_GL_INDEXED_PRIMITIVE, 14),
213 PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE, 10),
214
215 PACKET(VC4_PACKET_COMPRESSED_PRIMITIVE, 48),
216 PACKET(VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE, 49),
217
218 PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT, 2),
219
220 PACKET(VC4_PACKET_GL_SHADER_STATE, 5),
221 PACKET(VC4_PACKET_NV_SHADER_STATE, 5),
222 PACKET(VC4_PACKET_VG_SHADER_STATE, 5),
223
224 PACKET(VC4_PACKET_CONFIGURATION_BITS, 4),
225 PACKET_DUMP(VC4_PACKET_FLAT_SHADE_FLAGS, 5),
226 PACKET_DUMP(VC4_PACKET_POINT_SIZE, 5),
227 PACKET_DUMP(VC4_PACKET_LINE_WIDTH, 5),
228 PACKET(VC4_PACKET_RHT_X_BOUNDARY, 3),
229 PACKET(VC4_PACKET_DEPTH_OFFSET, 5),
230 PACKET(VC4_PACKET_CLIP_WINDOW, 9),
231 PACKET_DUMP(VC4_PACKET_VIEWPORT_OFFSET, 5),
232 PACKET(VC4_PACKET_Z_CLIPPING, 9),
233 PACKET_DUMP(VC4_PACKET_CLIPPER_XY_SCALING, 9),
234 PACKET_DUMP(VC4_PACKET_CLIPPER_Z_SCALING, 9),
235
236 PACKET(VC4_PACKET_TILE_BINNING_MODE_CONFIG, 16),
237 PACKET_DUMP(VC4_PACKET_TILE_RENDERING_MODE_CONFIG, 11),
238 PACKET(VC4_PACKET_CLEAR_COLORS, 14),
239 PACKET_DUMP(VC4_PACKET_TILE_COORDINATES, 3),
240
241 PACKET_DUMP(VC4_PACKET_GEM_HANDLES, 9),
242 };
243
244 void
245 vc4_dump_cl(void *cl, uint32_t size, bool is_render)
246 {
247 uint32_t offset = 0, hw_offset = 0;
248 uint8_t *cmds = cl;
249
250 while (offset < size) {
251 uint8_t header = cmds[offset];
252
253 if (header > ARRAY_SIZE(packet_info) ||
254 !packet_info[header].name) {
255 fprintf(stderr, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
256 offset, hw_offset, header, header);
257 return;
258 }
259
260 const struct packet_info *p = packet_info + header;
261 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
262 offset,
263 header != VC4_PACKET_GEM_HANDLES ? hw_offset : 0,
264 header, p->name);
265
266 if (offset + p->size <= size &&
267 p->dump_func) {
268 p->dump_func(cmds, offset + 1, hw_offset + 1);
269 } else {
270 for (uint32_t i = 1; i < p->size; i++) {
271 if (offset + i >= size) {
272 fprintf(stderr, "0x%08x 0x%08x: CL overflow!\n",
273 offset + i, hw_offset + i);
274 return;
275 }
276 fprintf(stderr, "0x%08x 0x%08x: 0x%02x\n",
277 offset + i,
278 header != VC4_PACKET_GEM_HANDLES ? hw_offset + i : 0,
279 cmds[offset + i]);
280 }
281 }
282
283 switch (header) {
284 case VC4_PACKET_HALT:
285 case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF:
286 return;
287 default:
288 break;
289 }
290
291 offset += p->size;
292 if (header != VC4_PACKET_GEM_HANDLES)
293 hw_offset += p->size;
294 }
295 }
296