2 * Copyright © 2014 Broadcom
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:
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
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
24 #include "util/u_math.h"
25 #include "util/u_prim.h"
26 #include "util/macros.h"
27 #include "vc4_cl_dump.h"
28 #include "vc4_packet.h"
30 #define __gen_user_data void
31 #define __gen_address_type uint32_t
32 #define __gen_address_offset(reloc) (*reloc)
33 #define __gen_emit_reloc(cl, reloc)
34 #define __gen_unpack_address __gen_unpack_uint
36 #include "broadcom/cle/v3d_packet_v21_pack.h"
38 #define dump_VC4_PACKET_LINE_WIDTH dump_float
39 #define dump_VC4_PACKET_POINT_SIZE dump_float
42 dump_float(void *cl
, uint32_t offset
, uint32_t hw_offset
)
44 void *f
= cl
+ offset
;
46 fprintf(stderr
, "0x%08x 0x%08x: %f (0x%08x)\n",
47 offset
, hw_offset
, uif(*(uint32_t *)f
), *(uint32_t *)f
);
51 dump_VC4_PACKET_BRANCH_TO_SUB_LIST(void *cl
, uint32_t offset
, uint32_t hw_offset
)
53 uint32_t *addr
= cl
+ offset
;
55 fprintf(stderr
, "0x%08x 0x%08x: addr 0x%08x\n",
56 offset
, hw_offset
, *addr
);
60 dump_loadstore_full(void *cl
, uint32_t offset
, uint32_t hw_offset
)
62 uint32_t bits
= *(uint32_t *)(cl
+ offset
);
64 fprintf(stderr
, "0x%08x 0x%08x: addr 0x%08x%s%s%s%s\n",
67 (bits
& VC4_LOADSTORE_FULL_RES_DISABLE_CLEAR_ALL
) ? "" : " clear",
68 (bits
& VC4_LOADSTORE_FULL_RES_DISABLE_ZS
) ? "" : " zs",
69 (bits
& VC4_LOADSTORE_FULL_RES_DISABLE_COLOR
) ? "" : " color",
70 (bits
& VC4_LOADSTORE_FULL_RES_EOF
) ? " eof" : "");
74 dump_VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER(void *cl
, uint32_t offset
, uint32_t hw_offset
)
76 dump_loadstore_full(cl
, offset
, hw_offset
);
80 dump_VC4_PACKET_STORE_FULL_RES_TILE_BUFFER(void *cl
, uint32_t offset
, uint32_t hw_offset
)
82 dump_loadstore_full(cl
, offset
, hw_offset
);
86 dump_loadstore_general(void *cl
, uint32_t offset
, uint32_t hw_offset
)
88 uint8_t *bytes
= cl
+ offset
;
89 uint32_t *addr
= cl
+ offset
+ 2;
91 const char *fullvg
= "";
92 const char *fullzs
= "";
93 const char *fullcolor
= "";
94 const char *buffer
= "???";
96 switch ((bytes
[0] & 0x7)){
114 if (*addr
& (1 << 0))
115 fullcolor
= " !color";
116 if (*addr
& (1 << 1))
118 if (*addr
& (1 << 2))
123 const char *tiling
= "???";
124 switch ((bytes
[0] >> 4) & 7) {
136 const char *format
= "???";
137 switch (bytes
[1] & 3) {
142 format
= "BGR565_DITHER";
149 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s\n",
150 offset
+ 0, hw_offset
+ 0, bytes
[0],
153 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
154 offset
+ 1, hw_offset
+ 1, bytes
[1],
157 fprintf(stderr
, "0x%08x 0x%08x: addr 0x%08x %s%s%s%s\n",
158 offset
+ 2, hw_offset
+ 2, *addr
& ~15,
159 fullcolor
, fullzs
, fullvg
,
160 (*addr
& (1 << 3)) ? " EOF" : "");
164 dump_VC4_PACKET_STORE_TILE_BUFFER_GENERAL(void *cl
, uint32_t offset
, uint32_t hw_offset
)
166 dump_loadstore_general(cl
, offset
, hw_offset
);
170 dump_VC4_PACKET_LOAD_TILE_BUFFER_GENERAL(void *cl
, uint32_t offset
, uint32_t hw_offset
)
172 dump_loadstore_general(cl
, offset
, hw_offset
);
176 dump_VC4_PACKET_GL_INDEXED_PRIMITIVE(void *cl
, uint32_t offset
, uint32_t hw_offset
)
178 uint8_t *b
= cl
+ offset
;
179 uint32_t *count
= cl
+ offset
+ 1;
180 uint32_t *ib_offset
= cl
+ offset
+ 5;
181 uint32_t *max_index
= cl
+ offset
+ 9;
183 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s\n",
185 b
[0], (b
[0] & VC4_INDEX_BUFFER_U16
) ? "16-bit" : "8-bit",
186 u_prim_name(b
[0] & 0x7));
187 fprintf(stderr
, "0x%08x 0x%08x: %d verts\n",
188 offset
+ 1, hw_offset
+ 1, *count
);
189 fprintf(stderr
, "0x%08x 0x%08x: 0x%08x IB offset\n",
190 offset
+ 5, hw_offset
+ 5, *ib_offset
);
191 fprintf(stderr
, "0x%08x 0x%08x: 0x%08x max index\n",
192 offset
+ 9, hw_offset
+ 9, *max_index
);
196 dump_VC4_PACKET_GL_ARRAY_PRIMITIVE(void *cl
, uint32_t offset
, uint32_t hw_offset
)
198 uint8_t *b
= cl
+ offset
;
200 struct V3D21_VERTEX_ARRAY_PRIMITIVES values
;
201 V3D21_VERTEX_ARRAY_PRIMITIVES_unpack(cl
+ offset
- 1, &values
);
203 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
204 offset
, hw_offset
, b
[0], u_prim_name(values
.primitive_mode
));
205 fprintf(stderr
, "0x%08x 0x%08x: %d verts\n",
206 offset
+ 1, hw_offset
+ 1, values
.length
);
207 fprintf(stderr
, "0x%08x 0x%08x: 0x%08x start\n",
208 offset
+ 5, hw_offset
+ 5, values
.index_of_first_vertex
);
212 dump_VC4_PACKET_FLAT_SHADE_FLAGS(void *cl
, uint32_t offset
, uint32_t hw_offset
)
214 uint32_t *bits
= cl
+ offset
;
216 fprintf(stderr
, "0x%08x 0x%08x: bits 0x%08x\n",
217 offset
, hw_offset
, *bits
);
221 dump_VC4_PACKET_VIEWPORT_OFFSET(void *cl
, uint32_t offset
, uint32_t hw_offset
)
223 uint16_t *o
= cl
+ offset
;
225 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%04x, 0x%04x)\n",
227 o
[0] / 16.0, o
[1] / 16.0,
232 dump_VC4_PACKET_CLIPPER_XY_SCALING(void *cl
, uint32_t offset
, uint32_t hw_offset
)
234 uint32_t *scale
= cl
+ offset
;
236 struct V3D21_CLIPPER_XY_SCALING values
;
237 V3D21_CLIPPER_XY_SCALING_unpack(cl
+ offset
- 1, &values
);
239 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (%f, %f, 0x%08x, 0x%08x)\n",
241 values
.viewport_half_width_in_1_16th_of_pixel
/ 16.0,
242 values
.viewport_half_height_in_1_16th_of_pixel
/ 16.0,
243 values
.viewport_half_width_in_1_16th_of_pixel
,
244 values
.viewport_half_height_in_1_16th_of_pixel
,
249 dump_VC4_PACKET_CLIPPER_Z_SCALING(void *cl
, uint32_t offset
, uint32_t hw_offset
)
251 uint32_t *translate
= cl
+ offset
;
252 uint32_t *scale
= cl
+ offset
+ 8;
254 struct V3D21_CLIPPER_Z_SCALE_AND_OFFSET values
;
255 V3D21_CLIPPER_Z_SCALE_AND_OFFSET_unpack(cl
+ offset
- 1, &values
);
257 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
259 values
.viewport_z_scale_zc_to_zs
,
260 values
.viewport_z_offset_zc_to_zs
,
261 translate
[0], translate
[1]);
263 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
264 offset
+ 8, hw_offset
+ 8,
265 uif(scale
[0]), uif(scale
[1]),
270 dump_VC4_PACKET_TILE_BINNING_MODE_CONFIG(void *cl
, uint32_t offset
, uint32_t hw_offset
)
272 uint8_t *flags
= cl
+ offset
+ 14;
274 struct V3D21_TILE_BINNING_MODE_CONFIGURATION values
;
275 V3D21_TILE_BINNING_MODE_CONFIGURATION_unpack(cl
+ offset
- 1, &values
);
277 fprintf(stderr
, "0x%08x 0x%08x: tile alloc addr 0x%08x\n",
279 values
.tile_allocation_memory_address
);
281 fprintf(stderr
, "0x%08x 0x%08x: tile alloc size %db\n",
282 offset
+ 4, hw_offset
+ 4,
283 values
.tile_allocation_memory_size
);
285 fprintf(stderr
, "0x%08x 0x%08x: tile state addr 0x%08x\n",
286 offset
+ 8, hw_offset
+ 8,
287 values
.tile_state_data_array_address
);
289 fprintf(stderr
, "0x%08x 0x%08x: tiles (%d, %d)\n",
290 offset
+ 12, hw_offset
+ 12,
291 values
.width_in_tiles
, values
.height_in_tiles
);
293 fprintf(stderr
, "0x%08x 0x%08x: flags 0x%02x\n",
294 offset
+ 14, hw_offset
+ 14,
299 dump_VC4_PACKET_TILE_RENDERING_MODE_CONFIG(void *cl
, uint32_t offset
, uint32_t hw_offset
)
301 uint32_t *render_offset
= cl
+ offset
;
302 uint16_t *shorts
= cl
+ offset
+ 4;
303 uint8_t *bytes
= cl
+ offset
+ 8;
305 fprintf(stderr
, "0x%08x 0x%08x: color offset 0x%08x\n",
309 fprintf(stderr
, "0x%08x 0x%08x: width %d\n",
310 offset
+ 4, hw_offset
+ 4,
313 fprintf(stderr
, "0x%08x 0x%08x: height %d\n",
314 offset
+ 6, hw_offset
+ 6,
317 const char *format
= "???";
318 switch (VC4_GET_FIELD(shorts
[2], VC4_RENDER_CONFIG_FORMAT
)) {
319 case VC4_RENDER_CONFIG_FORMAT_BGR565_DITHERED
:
320 format
= "BGR565_DITHERED";
322 case VC4_RENDER_CONFIG_FORMAT_RGBA8888
:
325 case VC4_RENDER_CONFIG_FORMAT_BGR565
:
329 if (shorts
[2] & VC4_RENDER_CONFIG_TILE_BUFFER_64BIT
)
332 const char *tiling
= "???";
333 switch (VC4_GET_FIELD(shorts
[2], VC4_RENDER_CONFIG_MEMORY_FORMAT
)) {
334 case VC4_TILING_FORMAT_LINEAR
:
337 case VC4_TILING_FORMAT_T
:
340 case VC4_TILING_FORMAT_LT
:
345 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s %s %s\n",
346 offset
+ 8, hw_offset
+ 8,
349 (shorts
[2] & VC4_RENDER_CONFIG_MS_MODE_4X
) ? "ms" : "ss",
350 (shorts
[2] & VC4_RENDER_CONFIG_DECIMATE_MODE_4X
) ?
351 "ms_decimate" : "ss_decimate");
353 const char *earlyz
= "";
354 if (shorts
[2] & VC4_RENDER_CONFIG_EARLY_Z_COVERAGE_DISABLE
) {
355 earlyz
= "early_z disabled";
357 if (shorts
[2] & VC4_RENDER_CONFIG_EARLY_Z_DIRECTION_G
)
358 earlyz
= "early_z >";
360 earlyz
= "early_z <";
363 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
364 offset
+ 9, hw_offset
+ 9,
370 dump_VC4_PACKET_TILE_COORDINATES(void *cl
, uint32_t offset
, uint32_t hw_offset
)
372 uint8_t *tilecoords
= cl
+ offset
;
374 fprintf(stderr
, "0x%08x 0x%08x: %d, %d\n",
375 offset
, hw_offset
, tilecoords
[0], tilecoords
[1]);
379 dump_VC4_PACKET_GEM_HANDLES(void *cl
, uint32_t offset
, uint32_t hw_offset
)
381 uint32_t *handles
= cl
+ offset
;
383 fprintf(stderr
, "0x%08x 0x%08x: handle 0: %d, handle 1: %d\n",
384 offset
, hw_offset
, handles
[0], handles
[1]);
387 #define PACKET_DUMP(name) [name] = { #name, name ## _SIZE, dump_##name }
388 #define PACKET(name) [name] = { #name, name ## _SIZE, NULL }
390 static const struct packet_info
{
393 void (*dump_func
)(void *cl
, uint32_t offset
, uint32_t hw_offset
);
395 PACKET(VC4_PACKET_HALT
),
396 PACKET(VC4_PACKET_NOP
),
398 PACKET(VC4_PACKET_FLUSH
),
399 PACKET(VC4_PACKET_FLUSH_ALL
),
400 PACKET(VC4_PACKET_START_TILE_BINNING
),
401 PACKET(VC4_PACKET_INCREMENT_SEMAPHORE
),
402 PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE
),
404 PACKET(VC4_PACKET_BRANCH
),
405 PACKET_DUMP(VC4_PACKET_BRANCH_TO_SUB_LIST
),
407 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER
),
408 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF
),
409 PACKET_DUMP(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER
),
410 PACKET_DUMP(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER
),
411 PACKET_DUMP(VC4_PACKET_STORE_TILE_BUFFER_GENERAL
),
412 PACKET_DUMP(VC4_PACKET_LOAD_TILE_BUFFER_GENERAL
),
414 PACKET_DUMP(VC4_PACKET_GL_INDEXED_PRIMITIVE
),
415 PACKET_DUMP(VC4_PACKET_GL_ARRAY_PRIMITIVE
),
417 PACKET(VC4_PACKET_COMPRESSED_PRIMITIVE
),
418 PACKET(VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE
),
420 PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT
),
422 PACKET(VC4_PACKET_GL_SHADER_STATE
),
423 PACKET(VC4_PACKET_NV_SHADER_STATE
),
424 PACKET(VC4_PACKET_VG_SHADER_STATE
),
426 PACKET(VC4_PACKET_CONFIGURATION_BITS
),
427 PACKET_DUMP(VC4_PACKET_FLAT_SHADE_FLAGS
),
428 PACKET_DUMP(VC4_PACKET_POINT_SIZE
),
429 PACKET_DUMP(VC4_PACKET_LINE_WIDTH
),
430 PACKET(VC4_PACKET_RHT_X_BOUNDARY
),
431 PACKET(VC4_PACKET_DEPTH_OFFSET
),
432 PACKET(VC4_PACKET_CLIP_WINDOW
),
433 PACKET_DUMP(VC4_PACKET_VIEWPORT_OFFSET
),
434 PACKET(VC4_PACKET_Z_CLIPPING
),
435 PACKET_DUMP(VC4_PACKET_CLIPPER_XY_SCALING
),
436 PACKET_DUMP(VC4_PACKET_CLIPPER_Z_SCALING
),
438 PACKET_DUMP(VC4_PACKET_TILE_BINNING_MODE_CONFIG
),
439 PACKET_DUMP(VC4_PACKET_TILE_RENDERING_MODE_CONFIG
),
440 PACKET(VC4_PACKET_CLEAR_COLORS
),
441 PACKET_DUMP(VC4_PACKET_TILE_COORDINATES
),
443 PACKET_DUMP(VC4_PACKET_GEM_HANDLES
),
447 vc4_dump_cl(void *cl
, uint32_t size
, bool is_render
)
449 uint32_t offset
= 0, hw_offset
= 0;
452 while (offset
< size
) {
453 uint8_t header
= cmds
[offset
];
455 if (header
>= ARRAY_SIZE(packet_info
) ||
456 !packet_info
[header
].name
) {
457 fprintf(stderr
, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
458 offset
, hw_offset
, header
, header
);
462 const struct packet_info
*p
= packet_info
+ header
;
463 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
465 header
!= VC4_PACKET_GEM_HANDLES
? hw_offset
: 0,
468 if (offset
+ p
->size
<= size
&&
470 p
->dump_func(cmds
, offset
+ 1, hw_offset
+ 1);
472 for (uint32_t i
= 1; i
< p
->size
; i
++) {
473 if (offset
+ i
>= size
) {
474 fprintf(stderr
, "0x%08x 0x%08x: CL overflow!\n",
475 offset
+ i
, hw_offset
+ i
);
478 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x\n",
480 header
!= VC4_PACKET_GEM_HANDLES
? hw_offset
+ i
: 0,
486 case VC4_PACKET_HALT
:
487 case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF
:
494 if (header
!= VC4_PACKET_GEM_HANDLES
)
495 hw_offset
+= p
->size
;