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_context.h"
29 #define dump_VC4_PACKET_LINE_WIDTH dump_float
30 #define dump_VC4_PACKET_POINT_SIZE dump_float
33 dump_float(void *cl
, uint32_t offset
, uint32_t hw_offset
)
35 void *f
= cl
+ offset
;
37 fprintf(stderr
, "0x%08x 0x%08x: %f (0x%08x)\n",
38 offset
, hw_offset
, uif(*(uint32_t *)f
), *(uint32_t *)f
);
42 dump_VC4_PACKET_BRANCH_TO_SUB_LIST(void *cl
, uint32_t offset
, uint32_t hw_offset
)
44 uint32_t *addr
= cl
+ offset
;
46 fprintf(stderr
, "0x%08x 0x%08x: addr 0x%08x\n",
47 offset
, hw_offset
, *addr
);
51 dump_loadstore_full(void *cl
, uint32_t offset
, uint32_t hw_offset
)
53 uint32_t bits
= *(uint32_t *)(cl
+ offset
);
55 fprintf(stderr
, "0x%08x 0x%08x: addr 0x%08x%s%s%s%s\n",
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" : "");
65 dump_VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER(void *cl
, uint32_t offset
, uint32_t hw_offset
)
67 dump_loadstore_full(cl
, offset
, hw_offset
);
71 dump_VC4_PACKET_STORE_FULL_RES_TILE_BUFFER(void *cl
, uint32_t offset
, uint32_t hw_offset
)
73 dump_loadstore_full(cl
, offset
, hw_offset
);
77 dump_loadstore_general(void *cl
, uint32_t offset
, uint32_t hw_offset
)
79 uint8_t *bytes
= cl
+ offset
;
80 uint32_t *addr
= cl
+ offset
+ 2;
82 const char *fullvg
= "";
83 const char *fullzs
= "";
84 const char *fullcolor
= "";
85 const char *buffer
= "???";
87 switch ((bytes
[0] & 0x7)){
105 if (*addr
& (1 << 0))
106 fullcolor
= " !color";
107 if (*addr
& (1 << 1))
109 if (*addr
& (1 << 2))
114 const char *tiling
= "???";
115 switch ((bytes
[0] >> 4) & 7) {
127 const char *format
= "???";
128 switch (bytes
[1] & 3) {
133 format
= "BGR565_DITHER";
140 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s\n",
141 offset
+ 0, hw_offset
+ 0, bytes
[0],
144 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
145 offset
+ 1, hw_offset
+ 1, bytes
[1],
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" : "");
155 dump_VC4_PACKET_STORE_TILE_BUFFER_GENERAL(void *cl
, uint32_t offset
, uint32_t hw_offset
)
157 dump_loadstore_general(cl
, offset
, hw_offset
);
161 dump_VC4_PACKET_LOAD_TILE_BUFFER_GENERAL(void *cl
, uint32_t offset
, uint32_t hw_offset
)
163 dump_loadstore_general(cl
, offset
, hw_offset
);
167 dump_VC4_PACKET_GL_INDEXED_PRIMITIVE(void *cl
, uint32_t offset
, uint32_t hw_offset
)
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;
174 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s\n",
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
);
187 dump_VC4_PACKET_FLAT_SHADE_FLAGS(void *cl
, uint32_t offset
, uint32_t hw_offset
)
189 uint32_t *bits
= cl
+ offset
;
191 fprintf(stderr
, "0x%08x 0x%08x: bits 0x%08x\n",
192 offset
, hw_offset
, *bits
);
196 dump_VC4_PACKET_VIEWPORT_OFFSET(void *cl
, uint32_t offset
, uint32_t hw_offset
)
198 uint16_t *o
= cl
+ offset
;
200 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%04x, 0x%04x)\n",
202 o
[0] / 16.0, o
[1] / 16.0,
207 dump_VC4_PACKET_CLIPPER_XY_SCALING(void *cl
, uint32_t offset
, uint32_t hw_offset
)
209 uint32_t *scale
= cl
+ offset
;
211 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (%f, %f, 0x%08x, 0x%08x)\n",
213 uif(scale
[0]) / 16.0, uif(scale
[1]) / 16.0,
214 uif(scale
[0]), uif(scale
[1]),
219 dump_VC4_PACKET_CLIPPER_Z_SCALING(void *cl
, uint32_t offset
, uint32_t hw_offset
)
221 uint32_t *translate
= cl
+ offset
;
222 uint32_t *scale
= cl
+ offset
+ 8;
224 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
226 uif(translate
[0]), uif(translate
[1]),
227 translate
[0], translate
[1]);
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]),
236 dump_VC4_PACKET_TILE_BINNING_MODE_CONFIG(void *cl
, uint32_t offset
, uint32_t hw_offset
)
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;
245 fprintf(stderr
, "0x%08x 0x%08x: tile alloc addr 0x%08x\n",
249 fprintf(stderr
, "0x%08x 0x%08x: tile alloc size %db\n",
250 offset
+ 4, hw_offset
+ 4,
253 fprintf(stderr
, "0x%08x 0x%08x: tile state addr 0x%08x\n",
254 offset
+ 8, hw_offset
+ 8,
257 fprintf(stderr
, "0x%08x 0x%08x: tiles (%d, %d)\n",
258 offset
+ 12, hw_offset
+ 12,
261 fprintf(stderr
, "0x%08x 0x%08x: flags 0x%02x\n",
262 offset
+ 14, hw_offset
+ 14,
267 dump_VC4_PACKET_TILE_RENDERING_MODE_CONFIG(void *cl
, uint32_t offset
, uint32_t hw_offset
)
269 uint32_t *render_offset
= cl
+ offset
;
270 uint16_t *shorts
= cl
+ offset
+ 4;
271 uint8_t *bytes
= cl
+ offset
+ 8;
273 fprintf(stderr
, "0x%08x 0x%08x: color offset 0x%08x\n",
277 fprintf(stderr
, "0x%08x 0x%08x: width %d\n",
278 offset
+ 4, hw_offset
+ 4,
281 fprintf(stderr
, "0x%08x 0x%08x: height %d\n",
282 offset
+ 6, hw_offset
+ 6,
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";
290 case VC4_RENDER_CONFIG_FORMAT_RGBA8888
:
293 case VC4_RENDER_CONFIG_FORMAT_BGR565
:
297 if (shorts
[2] & VC4_RENDER_CONFIG_TILE_BUFFER_64BIT
)
300 const char *tiling
= "???";
301 switch (VC4_GET_FIELD(shorts
[2], VC4_RENDER_CONFIG_MEMORY_FORMAT
)) {
302 case VC4_TILING_FORMAT_LINEAR
:
305 case VC4_TILING_FORMAT_T
:
308 case VC4_TILING_FORMAT_LT
:
313 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s %s %s\n",
314 offset
+ 8, hw_offset
+ 8,
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");
321 const char *earlyz
= "";
322 if (shorts
[2] & VC4_RENDER_CONFIG_EARLY_Z_COVERAGE_DISABLE
) {
323 earlyz
= "early_z disabled";
325 if (shorts
[2] & VC4_RENDER_CONFIG_EARLY_Z_DIRECTION_G
)
326 earlyz
= "early_z >";
328 earlyz
= "early_z <";
331 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
332 offset
+ 9, hw_offset
+ 9,
338 dump_VC4_PACKET_TILE_COORDINATES(void *cl
, uint32_t offset
, uint32_t hw_offset
)
340 uint8_t *tilecoords
= cl
+ offset
;
342 fprintf(stderr
, "0x%08x 0x%08x: %d, %d\n",
343 offset
, hw_offset
, tilecoords
[0], tilecoords
[1]);
347 dump_VC4_PACKET_GEM_HANDLES(void *cl
, uint32_t offset
, uint32_t hw_offset
)
349 uint32_t *handles
= cl
+ offset
;
351 fprintf(stderr
, "0x%08x 0x%08x: handle 0: %d, handle 1: %d\n",
352 offset
, hw_offset
, handles
[0], handles
[1]);
355 #define PACKET_DUMP(name) [name] = { #name, name ## _SIZE, dump_##name }
356 #define PACKET(name) [name] = { #name, name ## _SIZE, NULL }
358 static const struct packet_info
{
361 void (*dump_func
)(void *cl
, uint32_t offset
, uint32_t hw_offset
);
363 PACKET(VC4_PACKET_HALT
),
364 PACKET(VC4_PACKET_NOP
),
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
),
372 PACKET(VC4_PACKET_BRANCH
),
373 PACKET_DUMP(VC4_PACKET_BRANCH_TO_SUB_LIST
),
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
),
382 PACKET_DUMP(VC4_PACKET_GL_INDEXED_PRIMITIVE
),
383 PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE
),
385 PACKET(VC4_PACKET_COMPRESSED_PRIMITIVE
),
386 PACKET(VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE
),
388 PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT
),
390 PACKET(VC4_PACKET_GL_SHADER_STATE
),
391 PACKET(VC4_PACKET_NV_SHADER_STATE
),
392 PACKET(VC4_PACKET_VG_SHADER_STATE
),
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
),
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
),
411 PACKET_DUMP(VC4_PACKET_GEM_HANDLES
),
415 vc4_dump_cl(void *cl
, uint32_t size
, bool is_render
)
417 uint32_t offset
= 0, hw_offset
= 0;
420 while (offset
< size
) {
421 uint8_t header
= cmds
[offset
];
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
);
430 const struct packet_info
*p
= packet_info
+ header
;
431 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
433 header
!= VC4_PACKET_GEM_HANDLES
? hw_offset
: 0,
436 if (offset
+ p
->size
<= size
&&
438 p
->dump_func(cmds
, offset
+ 1, hw_offset
+ 1);
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
);
446 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x\n",
448 header
!= VC4_PACKET_GEM_HANDLES
? hw_offset
+ i
: 0,
454 case VC4_PACKET_HALT
:
455 case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF
:
462 if (header
!= VC4_PACKET_GEM_HANDLES
)
463 hw_offset
+= p
->size
;