vc4: Add dumping of VC4_PACKET_GL_INDEXED_PRIMITIVE.
[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/u_prim.h"
26 #include "util/macros.h"
27 #include "vc4_context.h"
28
29 #define dump_VC4_PACKET_LINE_WIDTH dump_float
30 #define dump_VC4_PACKET_POINT_SIZE dump_float
31
32 static void
33 dump_float(void *cl, uint32_t offset, uint32_t hw_offset)
34 {
35 void *f = cl + offset;
36
37 fprintf(stderr, "0x%08x 0x%08x: %f (0x%08x)\n",
38 offset, hw_offset, uif(*(uint32_t *)f), *(uint32_t *)f);
39 }
40
41 static void
42 dump_VC4_PACKET_BRANCH_TO_SUB_LIST(void *cl, uint32_t offset, uint32_t hw_offset)
43 {
44 uint32_t *addr = cl + offset;
45
46 fprintf(stderr, "0x%08x 0x%08x: addr 0x%08x\n",
47 offset, hw_offset, *addr);
48 }
49
50 static void
51 dump_loadstore_full(void *cl, uint32_t offset, uint32_t hw_offset)
52 {
53 uint32_t bits = *(uint32_t *)(cl + offset);
54
55 fprintf(stderr, "0x%08x 0x%08x: addr 0x%08x%s%s%s%s\n",
56 offset, hw_offset,
57 bits & ~0xf,
58 (bits & VC4_LOADSTORE_FULL_RES_DISABLE_CLEAR_ALL) ? "" : " clear",
59 (bits & VC4_LOADSTORE_FULL_RES_DISABLE_ZS) ? "" : " zs",
60 (bits & VC4_LOADSTORE_FULL_RES_DISABLE_COLOR) ? "" : " color",
61 (bits & VC4_LOADSTORE_FULL_RES_EOF) ? " eof" : "");
62 }
63
64 static void
65 dump_VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER(void *cl, uint32_t offset, uint32_t hw_offset)
66 {
67 dump_loadstore_full(cl, offset, hw_offset);
68 }
69
70 static void
71 dump_VC4_PACKET_STORE_FULL_RES_TILE_BUFFER(void *cl, uint32_t offset, uint32_t hw_offset)
72 {
73 dump_loadstore_full(cl, offset, hw_offset);
74 }
75
76 static void
77 dump_loadstore_general(void *cl, uint32_t offset, uint32_t hw_offset)
78 {
79 uint8_t *bytes = cl + offset;
80 uint32_t *addr = cl + offset + 2;
81
82 const char *fullvg = "";
83 const char *fullzs = "";
84 const char *fullcolor = "";
85 const char *buffer = "???";
86
87 switch ((bytes[0] & 0x7)){
88 case 0:
89 buffer = "none";
90 break;
91 case 1:
92 buffer = "color";
93 break;
94 case 2:
95 buffer = "zs";
96 break;
97 case 3:
98 buffer = "z";
99 break;
100 case 4:
101 buffer = "vgmask";
102 break;
103 case 5:
104 buffer = "full";
105 if (*addr & (1 << 0))
106 fullcolor = " !color";
107 if (*addr & (1 << 1))
108 fullzs = " !zs";
109 if (*addr & (1 << 2))
110 fullvg = " !vgmask";
111 break;
112 }
113
114 const char *tiling = "???";
115 switch ((bytes[0] >> 4) & 7) {
116 case 0:
117 tiling = "linear";
118 break;
119 case 1:
120 tiling = "T";
121 break;
122 case 2:
123 tiling = "LT";
124 break;
125 }
126
127 const char *format = "???";
128 switch (bytes[1] & 3) {
129 case 0:
130 format = "RGBA8888";
131 break;
132 case 1:
133 format = "BGR565_DITHER";
134 break;
135 case 2:
136 format = "BGR565";
137 break;
138 }
139
140 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s %s\n",
141 offset + 0, hw_offset + 0, bytes[0],
142 buffer, tiling);
143
144 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
145 offset + 1, hw_offset + 1, bytes[1],
146 format);
147
148 fprintf(stderr, "0x%08x 0x%08x: addr 0x%08x %s%s%s%s\n",
149 offset + 2, hw_offset + 2, *addr & ~15,
150 fullcolor, fullzs, fullvg,
151 (*addr & (1 << 3)) ? " EOF" : "");
152 }
153
154 static void
155 dump_VC4_PACKET_STORE_TILE_BUFFER_GENERAL(void *cl, uint32_t offset, uint32_t hw_offset)
156 {
157 dump_loadstore_general(cl, offset, hw_offset);
158 }
159
160 static void
161 dump_VC4_PACKET_LOAD_TILE_BUFFER_GENERAL(void *cl, uint32_t offset, uint32_t hw_offset)
162 {
163 dump_loadstore_general(cl, offset, hw_offset);
164 }
165
166 static void
167 dump_VC4_PACKET_GL_INDEXED_PRIMITIVE(void *cl, uint32_t offset, uint32_t hw_offset)
168 {
169 uint8_t *b = cl + offset;
170 uint32_t *count = cl + offset + 1;
171 uint32_t *ib_offset = cl + offset + 5;
172 uint32_t *max_index = cl + offset + 9;
173
174 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s %s\n",
175 offset, hw_offset,
176 b[0], (b[0] & VC4_INDEX_BUFFER_U16) ? "16-bit" : "8-bit",
177 u_prim_name(b[0] & 0x7));
178 fprintf(stderr, "0x%08x 0x%08x: %d verts\n",
179 offset + 1, hw_offset + 1, *count);
180 fprintf(stderr, "0x%08x 0x%08x: 0x%08x IB offset\n",
181 offset + 5, hw_offset + 5, *ib_offset);
182 fprintf(stderr, "0x%08x 0x%08x: 0x%08x max index\n",
183 offset + 9, hw_offset + 9, *max_index);
184 }
185
186 static void
187 dump_VC4_PACKET_FLAT_SHADE_FLAGS(void *cl, uint32_t offset, uint32_t hw_offset)
188 {
189 uint32_t *bits = cl + offset;
190
191 fprintf(stderr, "0x%08x 0x%08x: bits 0x%08x\n",
192 offset, hw_offset, *bits);
193 }
194
195 static void
196 dump_VC4_PACKET_VIEWPORT_OFFSET(void *cl, uint32_t offset, uint32_t hw_offset)
197 {
198 uint16_t *o = cl + offset;
199
200 fprintf(stderr, "0x%08x 0x%08x: %f, %f (0x%04x, 0x%04x)\n",
201 offset, hw_offset,
202 o[0] / 16.0, o[1] / 16.0,
203 o[0], o[1]);
204 }
205
206 static void
207 dump_VC4_PACKET_CLIPPER_XY_SCALING(void *cl, uint32_t offset, uint32_t hw_offset)
208 {
209 uint32_t *scale = cl + offset;
210
211 fprintf(stderr, "0x%08x 0x%08x: %f, %f (%f, %f, 0x%08x, 0x%08x)\n",
212 offset, hw_offset,
213 uif(scale[0]) / 16.0, uif(scale[1]) / 16.0,
214 uif(scale[0]), uif(scale[1]),
215 scale[0], scale[1]);
216 }
217
218 static void
219 dump_VC4_PACKET_CLIPPER_Z_SCALING(void *cl, uint32_t offset, uint32_t hw_offset)
220 {
221 uint32_t *translate = cl + offset;
222 uint32_t *scale = cl + offset + 8;
223
224 fprintf(stderr, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
225 offset, hw_offset,
226 uif(translate[0]), uif(translate[1]),
227 translate[0], translate[1]);
228
229 fprintf(stderr, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
230 offset + 8, hw_offset + 8,
231 uif(scale[0]), uif(scale[1]),
232 scale[0], scale[1]);
233 }
234
235 static void
236 dump_VC4_PACKET_TILE_BINNING_MODE_CONFIG(void *cl, uint32_t offset, uint32_t hw_offset)
237 {
238 uint32_t *tile_alloc_addr = cl + offset;
239 uint32_t *tile_alloc_size = cl + offset + 4;
240 uint32_t *tile_state_addr = cl + offset + 8;
241 uint8_t *bin_x = cl + offset + 12;
242 uint8_t *bin_y = cl + offset + 13;
243 uint8_t *flags = cl + offset + 14;
244
245 fprintf(stderr, "0x%08x 0x%08x: tile alloc addr 0x%08x\n",
246 offset, hw_offset,
247 *tile_alloc_addr);
248
249 fprintf(stderr, "0x%08x 0x%08x: tile alloc size %db\n",
250 offset + 4, hw_offset + 4,
251 *tile_alloc_size);
252
253 fprintf(stderr, "0x%08x 0x%08x: tile state addr 0x%08x\n",
254 offset + 8, hw_offset + 8,
255 *tile_state_addr);
256
257 fprintf(stderr, "0x%08x 0x%08x: tiles (%d, %d)\n",
258 offset + 12, hw_offset + 12,
259 *bin_x, *bin_y);
260
261 fprintf(stderr, "0x%08x 0x%08x: flags 0x%02x\n",
262 offset + 14, hw_offset + 14,
263 *flags);
264 }
265
266 static void
267 dump_VC4_PACKET_TILE_RENDERING_MODE_CONFIG(void *cl, uint32_t offset, uint32_t hw_offset)
268 {
269 uint32_t *render_offset = cl + offset;
270 uint16_t *shorts = cl + offset + 4;
271 uint8_t *bytes = cl + offset + 8;
272
273 fprintf(stderr, "0x%08x 0x%08x: color offset 0x%08x\n",
274 offset, hw_offset,
275 *render_offset);
276
277 fprintf(stderr, "0x%08x 0x%08x: width %d\n",
278 offset + 4, hw_offset + 4,
279 shorts[0]);
280
281 fprintf(stderr, "0x%08x 0x%08x: height %d\n",
282 offset + 6, hw_offset + 6,
283 shorts[1]);
284
285 const char *format = "???";
286 switch (VC4_GET_FIELD(shorts[2], VC4_RENDER_CONFIG_FORMAT)) {
287 case VC4_RENDER_CONFIG_FORMAT_BGR565_DITHERED:
288 format = "BGR565_DITHERED";
289 break;
290 case VC4_RENDER_CONFIG_FORMAT_RGBA8888:
291 format = "RGBA8888";
292 break;
293 case VC4_RENDER_CONFIG_FORMAT_BGR565:
294 format = "BGR565";
295 break;
296 }
297 if (shorts[2] & VC4_RENDER_CONFIG_TILE_BUFFER_64BIT)
298 format = "64bit";
299
300 const char *tiling = "???";
301 switch (VC4_GET_FIELD(shorts[2], VC4_RENDER_CONFIG_MEMORY_FORMAT)) {
302 case VC4_TILING_FORMAT_LINEAR:
303 tiling = "linear";
304 break;
305 case VC4_TILING_FORMAT_T:
306 tiling = "T";
307 break;
308 case VC4_TILING_FORMAT_LT:
309 tiling = "LT";
310 break;
311 }
312
313 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s %s %s %s\n",
314 offset + 8, hw_offset + 8,
315 bytes[0],
316 format, tiling,
317 (shorts[2] & VC4_RENDER_CONFIG_MS_MODE_4X) ? "ms" : "ss",
318 (shorts[2] & VC4_RENDER_CONFIG_DECIMATE_MODE_4X) ?
319 "ms_decimate" : "ss_decimate");
320
321 const char *earlyz = "";
322 if (shorts[2] & VC4_RENDER_CONFIG_EARLY_Z_COVERAGE_DISABLE) {
323 earlyz = "early_z disabled";
324 } else {
325 if (shorts[2] & VC4_RENDER_CONFIG_EARLY_Z_DIRECTION_G)
326 earlyz = "early_z >";
327 else
328 earlyz = "early_z <";
329 }
330
331 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
332 offset + 9, hw_offset + 9,
333 bytes[1],
334 earlyz);
335 }
336
337 static void
338 dump_VC4_PACKET_TILE_COORDINATES(void *cl, uint32_t offset, uint32_t hw_offset)
339 {
340 uint8_t *tilecoords = cl + offset;
341
342 fprintf(stderr, "0x%08x 0x%08x: %d, %d\n",
343 offset, hw_offset, tilecoords[0], tilecoords[1]);
344 }
345
346 static void
347 dump_VC4_PACKET_GEM_HANDLES(void *cl, uint32_t offset, uint32_t hw_offset)
348 {
349 uint32_t *handles = cl + offset;
350
351 fprintf(stderr, "0x%08x 0x%08x: handle 0: %d, handle 1: %d\n",
352 offset, hw_offset, handles[0], handles[1]);
353 }
354
355 #define PACKET_DUMP(name) [name] = { #name, name ## _SIZE, dump_##name }
356 #define PACKET(name) [name] = { #name, name ## _SIZE, NULL }
357
358 static const struct packet_info {
359 const char *name;
360 uint8_t size;
361 void (*dump_func)(void *cl, uint32_t offset, uint32_t hw_offset);
362 } packet_info[] = {
363 PACKET(VC4_PACKET_HALT),
364 PACKET(VC4_PACKET_NOP),
365
366 PACKET(VC4_PACKET_FLUSH),
367 PACKET(VC4_PACKET_FLUSH_ALL),
368 PACKET(VC4_PACKET_START_TILE_BINNING),
369 PACKET(VC4_PACKET_INCREMENT_SEMAPHORE),
370 PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE),
371
372 PACKET(VC4_PACKET_BRANCH),
373 PACKET_DUMP(VC4_PACKET_BRANCH_TO_SUB_LIST),
374
375 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER),
376 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF),
377 PACKET_DUMP(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER),
378 PACKET_DUMP(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER),
379 PACKET_DUMP(VC4_PACKET_STORE_TILE_BUFFER_GENERAL),
380 PACKET_DUMP(VC4_PACKET_LOAD_TILE_BUFFER_GENERAL),
381
382 PACKET_DUMP(VC4_PACKET_GL_INDEXED_PRIMITIVE),
383 PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE),
384
385 PACKET(VC4_PACKET_COMPRESSED_PRIMITIVE),
386 PACKET(VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE),
387
388 PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT),
389
390 PACKET(VC4_PACKET_GL_SHADER_STATE),
391 PACKET(VC4_PACKET_NV_SHADER_STATE),
392 PACKET(VC4_PACKET_VG_SHADER_STATE),
393
394 PACKET(VC4_PACKET_CONFIGURATION_BITS),
395 PACKET_DUMP(VC4_PACKET_FLAT_SHADE_FLAGS),
396 PACKET_DUMP(VC4_PACKET_POINT_SIZE),
397 PACKET_DUMP(VC4_PACKET_LINE_WIDTH),
398 PACKET(VC4_PACKET_RHT_X_BOUNDARY),
399 PACKET(VC4_PACKET_DEPTH_OFFSET),
400 PACKET(VC4_PACKET_CLIP_WINDOW),
401 PACKET_DUMP(VC4_PACKET_VIEWPORT_OFFSET),
402 PACKET(VC4_PACKET_Z_CLIPPING),
403 PACKET_DUMP(VC4_PACKET_CLIPPER_XY_SCALING),
404 PACKET_DUMP(VC4_PACKET_CLIPPER_Z_SCALING),
405
406 PACKET_DUMP(VC4_PACKET_TILE_BINNING_MODE_CONFIG),
407 PACKET_DUMP(VC4_PACKET_TILE_RENDERING_MODE_CONFIG),
408 PACKET(VC4_PACKET_CLEAR_COLORS),
409 PACKET_DUMP(VC4_PACKET_TILE_COORDINATES),
410
411 PACKET_DUMP(VC4_PACKET_GEM_HANDLES),
412 };
413
414 void
415 vc4_dump_cl(void *cl, uint32_t size, bool is_render)
416 {
417 uint32_t offset = 0, hw_offset = 0;
418 uint8_t *cmds = cl;
419
420 while (offset < size) {
421 uint8_t header = cmds[offset];
422
423 if (header >= ARRAY_SIZE(packet_info) ||
424 !packet_info[header].name) {
425 fprintf(stderr, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
426 offset, hw_offset, header, header);
427 return;
428 }
429
430 const struct packet_info *p = packet_info + header;
431 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
432 offset,
433 header != VC4_PACKET_GEM_HANDLES ? hw_offset : 0,
434 header, p->name);
435
436 if (offset + p->size <= size &&
437 p->dump_func) {
438 p->dump_func(cmds, offset + 1, hw_offset + 1);
439 } else {
440 for (uint32_t i = 1; i < p->size; i++) {
441 if (offset + i >= size) {
442 fprintf(stderr, "0x%08x 0x%08x: CL overflow!\n",
443 offset + i, hw_offset + i);
444 return;
445 }
446 fprintf(stderr, "0x%08x 0x%08x: 0x%02x\n",
447 offset + i,
448 header != VC4_PACKET_GEM_HANDLES ? hw_offset + i : 0,
449 cmds[offset + i]);
450 }
451 }
452
453 switch (header) {
454 case VC4_PACKET_HALT:
455 case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF:
456 return;
457 default:
458 break;
459 }
460
461 offset += p->size;
462 if (header != VC4_PACKET_GEM_HANDLES)
463 hw_offset += p->size;
464 }
465 }
466