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_VC4_PACKET_STORE_TILE_BUFFER_GENERAL(void *cl
, uint32_t offset
, uint32_t hw_offset
)
52 uint8_t *bytes
= cl
+ offset
;
53 uint32_t *addr
= cl
+ offset
+ 2;
55 const char *fullvg
= "";
56 const char *fullzs
= "";
57 const char *fullcolor
= "";
58 const char *buffer
= "???";
60 switch ((bytes
[0] & 0x7)){
79 fullcolor
= " !color";
87 const char *tiling
= "???";
88 switch ((bytes
[0] >> 4) & 7) {
100 const char *format
= "???";
101 switch (bytes
[1] & 3) {
106 format
= "BGR565_DITHER";
113 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s\n",
114 offset
+ 0, hw_offset
+ 0, bytes
[0],
117 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
118 offset
+ 1, hw_offset
+ 1, bytes
[1],
121 fprintf(stderr
, "0x%08x 0x%08x: addr 0x%08x %s%s%s%s\n",
122 offset
+ 2, hw_offset
+ 2, *addr
& ~15,
123 fullcolor
, fullzs
, fullvg
,
124 (*addr
& (1 << 3)) ? " EOF" : "");
128 dump_VC4_PACKET_FLAT_SHADE_FLAGS(void *cl
, uint32_t offset
, uint32_t hw_offset
)
130 uint32_t *bits
= cl
+ offset
;
132 fprintf(stderr
, "0x%08x 0x%08x: bits 0x%08x\n",
133 offset
, hw_offset
, *bits
);
137 dump_VC4_PACKET_VIEWPORT_OFFSET(void *cl
, uint32_t offset
, uint32_t hw_offset
)
139 uint16_t *o
= cl
+ offset
;
141 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%04x, 0x%04x)\n",
143 o
[0] / 16.0, o
[1] / 16.0,
148 dump_VC4_PACKET_CLIPPER_XY_SCALING(void *cl
, uint32_t offset
, uint32_t hw_offset
)
150 uint32_t *scale
= cl
+ offset
;
152 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (%f, %f, 0x%08x, 0x%08x)\n",
154 uif(scale
[0]) / 16.0, uif(scale
[1]) / 16.0,
155 uif(scale
[0]), uif(scale
[1]),
160 dump_VC4_PACKET_CLIPPER_Z_SCALING(void *cl
, uint32_t offset
, uint32_t hw_offset
)
162 uint32_t *translate
= cl
+ offset
;
163 uint32_t *scale
= cl
+ offset
+ 8;
165 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
167 uif(translate
[0]), uif(translate
[1]),
168 translate
[0], translate
[1]);
170 fprintf(stderr
, "0x%08x 0x%08x: %f, %f (0x%08x, 0x%08x)\n",
171 offset
+ 8, hw_offset
+ 8,
172 uif(scale
[0]), uif(scale
[1]),
177 dump_VC4_PACKET_TILE_BINNING_MODE_CONFIG(void *cl
, uint32_t offset
, uint32_t hw_offset
)
179 uint32_t *tile_alloc_addr
= cl
+ offset
;
180 uint32_t *tile_alloc_size
= cl
+ offset
+ 4;
181 uint32_t *tile_state_addr
= cl
+ offset
+ 8;
182 uint8_t *bin_x
= cl
+ offset
+ 12;
183 uint8_t *bin_y
= cl
+ offset
+ 13;
184 uint8_t *flags
= cl
+ offset
+ 14;
186 fprintf(stderr
, "0x%08x 0x%08x: tile alloc addr 0x%08x\n",
190 fprintf(stderr
, "0x%08x 0x%08x: tile alloc size %db\n",
191 offset
+ 4, hw_offset
+ 4,
194 fprintf(stderr
, "0x%08x 0x%08x: tile state addr 0x%08x\n",
195 offset
+ 8, hw_offset
+ 8,
198 fprintf(stderr
, "0x%08x 0x%08x: tiles (%d, %d)\n",
199 offset
+ 12, hw_offset
+ 12,
202 fprintf(stderr
, "0x%08x 0x%08x: flags 0x%02x\n",
203 offset
+ 14, hw_offset
+ 14,
208 dump_VC4_PACKET_TILE_RENDERING_MODE_CONFIG(void *cl
, uint32_t offset
, uint32_t hw_offset
)
210 uint32_t *render_offset
= cl
+ offset
;
211 uint16_t *shorts
= cl
+ offset
+ 4;
212 uint8_t *bytes
= cl
+ offset
+ 8;
214 fprintf(stderr
, "0x%08x 0x%08x: color offset 0x%08x\n",
218 fprintf(stderr
, "0x%08x 0x%08x: width %d\n",
219 offset
+ 4, hw_offset
+ 4,
222 fprintf(stderr
, "0x%08x 0x%08x: height %d\n",
223 offset
+ 6, hw_offset
+ 6,
226 const char *format
= "???";
227 switch ((bytes
[0] >> 2) & 3) {
229 format
= "BGR565_DITHERED";
238 if (shorts
[2] & VC4_RENDER_CONFIG_TILE_BUFFER_64BIT
)
241 const char *tiling
= "???";
242 switch ((bytes
[0] >> 6) & 3) {
254 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s %s %s\n",
255 offset
+ 8, hw_offset
+ 8,
258 (bytes
[0] & VC4_RENDER_CONFIG_MS_MODE_4X
) ? "ms" : "ss");
260 const char *earlyz
= "";
261 if (bytes
[1] & (1 << 3)) {
262 earlyz
= "early_z disabled";
264 if (bytes
[1] & (1 << 2))
265 earlyz
= "early_z >";
267 earlyz
= "early_z <";
270 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
271 offset
+ 9, hw_offset
+ 9,
277 dump_VC4_PACKET_TILE_COORDINATES(void *cl
, uint32_t offset
, uint32_t hw_offset
)
279 uint8_t *tilecoords
= cl
+ offset
;
281 fprintf(stderr
, "0x%08x 0x%08x: %d, %d\n",
282 offset
, hw_offset
, tilecoords
[0], tilecoords
[1]);
286 dump_VC4_PACKET_GEM_HANDLES(void *cl
, uint32_t offset
, uint32_t hw_offset
)
288 uint32_t *handles
= cl
+ offset
;
290 fprintf(stderr
, "0x%08x 0x%08x: handle 0: %d, handle 1: %d\n",
291 offset
, hw_offset
, handles
[0], handles
[1]);
294 #define PACKET_DUMP(name) [name] = { #name, name ## _SIZE, dump_##name }
295 #define PACKET(name) [name] = { #name, name ## _SIZE, NULL }
297 static const struct packet_info
{
300 void (*dump_func
)(void *cl
, uint32_t offset
, uint32_t hw_offset
);
302 PACKET(VC4_PACKET_HALT
),
303 PACKET(VC4_PACKET_NOP
),
305 PACKET(VC4_PACKET_FLUSH
),
306 PACKET(VC4_PACKET_FLUSH_ALL
),
307 PACKET(VC4_PACKET_START_TILE_BINNING
),
308 PACKET(VC4_PACKET_INCREMENT_SEMAPHORE
),
309 PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE
),
311 PACKET(VC4_PACKET_BRANCH
),
312 PACKET_DUMP(VC4_PACKET_BRANCH_TO_SUB_LIST
),
314 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER
),
315 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF
),
316 PACKET(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER
),
317 PACKET(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER
),
318 PACKET_DUMP(VC4_PACKET_STORE_TILE_BUFFER_GENERAL
),
319 PACKET(VC4_PACKET_LOAD_TILE_BUFFER_GENERAL
),
321 PACKET(VC4_PACKET_GL_INDEXED_PRIMITIVE
),
322 PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE
),
324 PACKET(VC4_PACKET_COMPRESSED_PRIMITIVE
),
325 PACKET(VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE
),
327 PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT
),
329 PACKET(VC4_PACKET_GL_SHADER_STATE
),
330 PACKET(VC4_PACKET_NV_SHADER_STATE
),
331 PACKET(VC4_PACKET_VG_SHADER_STATE
),
333 PACKET(VC4_PACKET_CONFIGURATION_BITS
),
334 PACKET_DUMP(VC4_PACKET_FLAT_SHADE_FLAGS
),
335 PACKET_DUMP(VC4_PACKET_POINT_SIZE
),
336 PACKET_DUMP(VC4_PACKET_LINE_WIDTH
),
337 PACKET(VC4_PACKET_RHT_X_BOUNDARY
),
338 PACKET(VC4_PACKET_DEPTH_OFFSET
),
339 PACKET(VC4_PACKET_CLIP_WINDOW
),
340 PACKET_DUMP(VC4_PACKET_VIEWPORT_OFFSET
),
341 PACKET(VC4_PACKET_Z_CLIPPING
),
342 PACKET_DUMP(VC4_PACKET_CLIPPER_XY_SCALING
),
343 PACKET_DUMP(VC4_PACKET_CLIPPER_Z_SCALING
),
345 PACKET_DUMP(VC4_PACKET_TILE_BINNING_MODE_CONFIG
),
346 PACKET_DUMP(VC4_PACKET_TILE_RENDERING_MODE_CONFIG
),
347 PACKET(VC4_PACKET_CLEAR_COLORS
),
348 PACKET_DUMP(VC4_PACKET_TILE_COORDINATES
),
350 PACKET_DUMP(VC4_PACKET_GEM_HANDLES
),
354 vc4_dump_cl(void *cl
, uint32_t size
, bool is_render
)
356 uint32_t offset
= 0, hw_offset
= 0;
359 while (offset
< size
) {
360 uint8_t header
= cmds
[offset
];
362 if (header
> ARRAY_SIZE(packet_info
) ||
363 !packet_info
[header
].name
) {
364 fprintf(stderr
, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
365 offset
, hw_offset
, header
, header
);
369 const struct packet_info
*p
= packet_info
+ header
;
370 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x %s\n",
372 header
!= VC4_PACKET_GEM_HANDLES
? hw_offset
: 0,
375 if (offset
+ p
->size
<= size
&&
377 p
->dump_func(cmds
, offset
+ 1, hw_offset
+ 1);
379 for (uint32_t i
= 1; i
< p
->size
; i
++) {
380 if (offset
+ i
>= size
) {
381 fprintf(stderr
, "0x%08x 0x%08x: CL overflow!\n",
382 offset
+ i
, hw_offset
+ i
);
385 fprintf(stderr
, "0x%08x 0x%08x: 0x%02x\n",
387 header
!= VC4_PACKET_GEM_HANDLES
? hw_offset
+ i
: 0,
393 case VC4_PACKET_HALT
:
394 case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF
:
401 if (header
!= VC4_PACKET_GEM_HANDLES
)
402 hw_offset
+= p
->size
;