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