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/macros.h"
26 #include "vc4_context.h"
28 #define dump_VC4_PACKET_LINE_WIDTH dump_float
29 #define dump_VC4_PACKET_POINT_SIZE dump_float
32 dump_float(void *cl
, uint32_t offset
, uint32_t hw_offset
)
34 void *f
= cl
+ offset
;
36 fprintf(stderr
, "0x%08x 0x%08x: %f (0x%08x)\n",
37 offset
, hw_offset
, *(float *)f
, *(uint32_t *)f
);
41 dump_VC4_PACKET_BRANCH_TO_SUB_LIST(void *cl
, uint32_t offset
, uint32_t hw_offset
)
43 uint32_t *addr
= cl
+ offset
;
45 fprintf(stderr
, "0x%08x 0x%08x: addr 0x%08x\n",
46 offset
, hw_offset
, *addr
);
50 dump_loadstore_full(void *cl
, uint32_t offset
, uint32_t hw_offset
)
52 uint32_t bits
= *(uint32_t *)(cl
+ offset
);
54 fprintf(stderr
, "0x%08x 0x%08x: addr 0x%08x%s%s%s%s\n",
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" : "");
64 dump_VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER(void *cl
, uint32_t offset
, uint32_t hw_offset
)
66 dump_loadstore_full(cl
, offset
, hw_offset
);
70 dump_VC4_PACKET_STORE_FULL_RES_TILE_BUFFER(void *cl
, uint32_t offset
, uint32_t hw_offset
)
72 dump_loadstore_full(cl
, offset
, hw_offset
);
76 dump_VC4_PACKET_STORE_TILE_BUFFER_GENERAL(void *cl
, uint32_t offset
, uint32_t hw_offset
)
78 uint8_t *bytes
= cl
+ offset
;
79 uint32_t *addr
= cl
+ offset
+ 2;
81 const char *fullvg
= "";
82 const char *fullzs
= "";
83 const char *fullcolor
= "";
84 const char *buffer
= "???";
86 switch ((bytes
[0] & 0x7)){
104 if (*addr
& (1 << 0))
105 fullcolor
= " !color";
106 if (*addr
& (1 << 1))
108 if (*addr
& (1 << 2))
113 const char *tiling
= "???";
114 switch ((bytes
[0] >> 4) & 7) {
126 const char *format
= "???";
127 switch (bytes
[1] & 3) {
132 format
= "BGR565_DITHER";
139 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s\n",
140 offset
+ 0, hw_offset
+ 0, bytes
[0],
143 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
144 offset
+ 1, hw_offset
+ 1, bytes
[1],
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" : "");
154 dump_VC4_PACKET_FLAT_SHADE_FLAGS(void *cl
, uint32_t offset
, uint32_t hw_offset
)
156 uint32_t *bits
= cl
+ offset
;
158 fprintf(stderr
, "0x%08x 0x%08x: bits 0x%08x\n",
159 offset
, hw_offset
, *bits
);
163 dump_VC4_PACKET_VIEWPORT_OFFSET(void *cl
, uint32_t offset
, uint32_t hw_offset
)
165 uint16_t *o
= cl
+ offset
;
167 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%04x, 0x%04x)\n",
169 o
[0] / 16.0, o
[1] / 16.0,
174 dump_VC4_PACKET_CLIPPER_XY_SCALING(void *cl
, uint32_t offset
, uint32_t hw_offset
)
176 uint32_t *scale
= cl
+ offset
;
178 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (%f, %f, 0x%08x, 0x%08x)\n",
180 uif(scale
[0]) / 16.0, uif(scale
[1]) / 16.0,
181 uif(scale
[0]), uif(scale
[1]),
186 dump_VC4_PACKET_CLIPPER_Z_SCALING(void *cl
, uint32_t offset
, uint32_t hw_offset
)
188 uint32_t *translate
= cl
+ offset
;
189 uint32_t *scale
= cl
+ offset
+ 8;
191 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
193 uif(translate
[0]), uif(translate
[1]),
194 translate
[0], translate
[1]);
196 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
197 offset
+ 8, hw_offset
+ 8,
198 uif(scale
[0]), uif(scale
[1]),
203 dump_VC4_PACKET_TILE_BINNING_MODE_CONFIG(void *cl
, uint32_t offset
, uint32_t hw_offset
)
205 uint32_t *tile_alloc_addr
= cl
+ offset
;
206 uint32_t *tile_alloc_size
= cl
+ offset
+ 4;
207 uint32_t *tile_state_addr
= cl
+ offset
+ 8;
208 uint8_t *bin_x
= cl
+ offset
+ 12;
209 uint8_t *bin_y
= cl
+ offset
+ 13;
210 uint8_t *flags
= cl
+ offset
+ 14;
212 fprintf(stderr
, "0x%08x 0x%08x: tile alloc addr 0x%08x\n",
216 fprintf(stderr
, "0x%08x 0x%08x: tile alloc size %db\n",
217 offset
+ 4, hw_offset
+ 4,
220 fprintf(stderr
, "0x%08x 0x%08x: tile state addr 0x%08x\n",
221 offset
+ 8, hw_offset
+ 8,
224 fprintf(stderr
, "0x%08x 0x%08x: tiles (%d, %d)\n",
225 offset
+ 12, hw_offset
+ 12,
228 fprintf(stderr
, "0x%08x 0x%08x: flags 0x%02x\n",
229 offset
+ 14, hw_offset
+ 14,
234 dump_VC4_PACKET_TILE_RENDERING_MODE_CONFIG(void *cl
, uint32_t offset
, uint32_t hw_offset
)
236 uint32_t *render_offset
= cl
+ offset
;
237 uint16_t *shorts
= cl
+ offset
+ 4;
238 uint8_t *bytes
= cl
+ offset
+ 8;
240 fprintf(stderr
, "0x%08x 0x%08x: color offset 0x%08x\n",
244 fprintf(stderr
, "0x%08x 0x%08x: width %d\n",
245 offset
+ 4, hw_offset
+ 4,
248 fprintf(stderr
, "0x%08x 0x%08x: height %d\n",
249 offset
+ 6, hw_offset
+ 6,
252 const char *format
= "???";
253 switch ((bytes
[0] >> 2) & 3) {
255 format
= "BGR565_DITHERED";
264 if (shorts
[2] & VC4_RENDER_CONFIG_TILE_BUFFER_64BIT
)
267 const char *tiling
= "???";
268 switch ((bytes
[0] >> 6) & 3) {
280 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s %s\n",
281 offset
+ 8, hw_offset
+ 8,
284 (bytes
[0] & VC4_RENDER_CONFIG_MS_MODE_4X
) ? "ms" : "ss");
286 const char *earlyz
= "";
287 if (bytes
[1] & (1 << 3)) {
288 earlyz
= "early_z disabled";
290 if (bytes
[1] & (1 << 2))
291 earlyz
= "early_z >";
293 earlyz
= "early_z <";
296 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
297 offset
+ 9, hw_offset
+ 9,
303 dump_VC4_PACKET_TILE_COORDINATES(void *cl
, uint32_t offset
, uint32_t hw_offset
)
305 uint8_t *tilecoords
= cl
+ offset
;
307 fprintf(stderr
, "0x%08x 0x%08x: %d, %d\n",
308 offset
, hw_offset
, tilecoords
[0], tilecoords
[1]);
312 dump_VC4_PACKET_GEM_HANDLES(void *cl
, uint32_t offset
, uint32_t hw_offset
)
314 uint32_t *handles
= cl
+ offset
;
316 fprintf(stderr
, "0x%08x 0x%08x: handle 0: %d, handle 1: %d\n",
317 offset
, hw_offset
, handles
[0], handles
[1]);
320 #define PACKET_DUMP(name) [name] = { #name, name ## _SIZE, dump_##name }
321 #define PACKET(name) [name] = { #name, name ## _SIZE, NULL }
323 static const struct packet_info
{
326 void (*dump_func
)(void *cl
, uint32_t offset
, uint32_t hw_offset
);
328 PACKET(VC4_PACKET_HALT
),
329 PACKET(VC4_PACKET_NOP
),
331 PACKET(VC4_PACKET_FLUSH
),
332 PACKET(VC4_PACKET_FLUSH_ALL
),
333 PACKET(VC4_PACKET_START_TILE_BINNING
),
334 PACKET(VC4_PACKET_INCREMENT_SEMAPHORE
),
335 PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE
),
337 PACKET(VC4_PACKET_BRANCH
),
338 PACKET_DUMP(VC4_PACKET_BRANCH_TO_SUB_LIST
),
340 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER
),
341 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF
),
342 PACKET_DUMP(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER
),
343 PACKET_DUMP(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER
),
344 PACKET_DUMP(VC4_PACKET_STORE_TILE_BUFFER_GENERAL
),
345 PACKET(VC4_PACKET_LOAD_TILE_BUFFER_GENERAL
),
347 PACKET(VC4_PACKET_GL_INDEXED_PRIMITIVE
),
348 PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE
),
350 PACKET(VC4_PACKET_COMPRESSED_PRIMITIVE
),
351 PACKET(VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE
),
353 PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT
),
355 PACKET(VC4_PACKET_GL_SHADER_STATE
),
356 PACKET(VC4_PACKET_NV_SHADER_STATE
),
357 PACKET(VC4_PACKET_VG_SHADER_STATE
),
359 PACKET(VC4_PACKET_CONFIGURATION_BITS
),
360 PACKET_DUMP(VC4_PACKET_FLAT_SHADE_FLAGS
),
361 PACKET_DUMP(VC4_PACKET_POINT_SIZE
),
362 PACKET_DUMP(VC4_PACKET_LINE_WIDTH
),
363 PACKET(VC4_PACKET_RHT_X_BOUNDARY
),
364 PACKET(VC4_PACKET_DEPTH_OFFSET
),
365 PACKET(VC4_PACKET_CLIP_WINDOW
),
366 PACKET_DUMP(VC4_PACKET_VIEWPORT_OFFSET
),
367 PACKET(VC4_PACKET_Z_CLIPPING
),
368 PACKET_DUMP(VC4_PACKET_CLIPPER_XY_SCALING
),
369 PACKET_DUMP(VC4_PACKET_CLIPPER_Z_SCALING
),
371 PACKET_DUMP(VC4_PACKET_TILE_BINNING_MODE_CONFIG
),
372 PACKET_DUMP(VC4_PACKET_TILE_RENDERING_MODE_CONFIG
),
373 PACKET(VC4_PACKET_CLEAR_COLORS
),
374 PACKET_DUMP(VC4_PACKET_TILE_COORDINATES
),
376 PACKET_DUMP(VC4_PACKET_GEM_HANDLES
),
380 vc4_dump_cl(void *cl
, uint32_t size
, bool is_render
)
382 uint32_t offset
= 0, hw_offset
= 0;
385 while (offset
< size
) {
386 uint8_t header
= cmds
[offset
];
388 if (header
> ARRAY_SIZE(packet_info
) ||
389 !packet_info
[header
].name
) {
390 fprintf(stderr
, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
391 offset
, hw_offset
, header
, header
);
395 const struct packet_info
*p
= packet_info
+ header
;
396 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
398 header
!= VC4_PACKET_GEM_HANDLES
? hw_offset
: 0,
401 if (offset
+ p
->size
<= size
&&
403 p
->dump_func(cmds
, offset
+ 1, hw_offset
+ 1);
405 for (uint32_t i
= 1; i
< p
->size
; i
++) {
406 if (offset
+ i
>= size
) {
407 fprintf(stderr
, "0x%08x 0x%08x: CL overflow!\n",
408 offset
+ i
, hw_offset
+ i
);
411 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x\n",
413 header
!= VC4_PACKET_GEM_HANDLES
? hw_offset
+ i
: 0,
419 case VC4_PACKET_HALT
:
420 case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF
:
427 if (header
!= VC4_PACKET_GEM_HANDLES
)
428 hw_offset
+= p
->size
;