vc4: Make some assertions about how many flushes/EOFs the simulator sees.
[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 PACKET(name, size) [name] = { #name, size }
29
30 static const struct packet_info {
31 const char *name;
32 uint8_t size;
33 } packet_info[] = {
34 PACKET(VC4_PACKET_HALT, 1),
35 PACKET(VC4_PACKET_NOP, 1),
36
37 PACKET(VC4_PACKET_FLUSH, 1),
38 PACKET(VC4_PACKET_FLUSH_ALL, 1),
39 PACKET(VC4_PACKET_START_TILE_BINNING, 1),
40 PACKET(VC4_PACKET_INCREMENT_SEMAPHORE, 1),
41 PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE, 1),
42
43 PACKET(VC4_PACKET_BRANCH, 5),
44 PACKET(VC4_PACKET_BRANCH_TO_SUB_LIST, 5),
45
46 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER, 1),
47 PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF, 1),
48 PACKET(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER, 5),
49 PACKET(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER, 5),
50 PACKET(VC4_PACKET_STORE_TILE_BUFFER_GENERAL, 7),
51 PACKET(VC4_PACKET_LOAD_TILE_BUFFER_GENERAL, 7),
52
53 PACKET(VC4_PACKET_GL_INDEXED_PRIMITIVE, 14),
54 PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE, 10),
55
56 PACKET(VC4_PACKET_COMPRESSED_PRIMITIVE, 48),
57 PACKET(VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE, 49),
58
59 PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT, 2),
60
61 PACKET(VC4_PACKET_GL_SHADER_STATE, 5),
62 PACKET(VC4_PACKET_NV_SHADER_STATE, 5),
63 PACKET(VC4_PACKET_VG_SHADER_STATE, 5),
64
65 PACKET(VC4_PACKET_CONFIGURATION_BITS, 4),
66 PACKET(VC4_PACKET_FLAT_SHADE_FLAGS, 5),
67 PACKET(VC4_PACKET_POINT_SIZE, 5),
68 PACKET(VC4_PACKET_LINE_WIDTH, 5),
69 PACKET(VC4_PACKET_RHT_X_BOUNDARY, 3),
70 PACKET(VC4_PACKET_DEPTH_OFFSET, 5),
71 PACKET(VC4_PACKET_CLIP_WINDOW, 9),
72 PACKET(VC4_PACKET_VIEWPORT_OFFSET, 5),
73 PACKET(VC4_PACKET_Z_CLIPPING, 9),
74 PACKET(VC4_PACKET_CLIPPER_XY_SCALING, 9),
75 PACKET(VC4_PACKET_CLIPPER_Z_SCALING, 9),
76
77 PACKET(VC4_PACKET_TILE_BINNING_MODE_CONFIG, 16),
78 PACKET(VC4_PACKET_TILE_RENDERING_MODE_CONFIG, 11),
79 PACKET(VC4_PACKET_CLEAR_COLORS, 14),
80 PACKET(VC4_PACKET_TILE_COORDINATES, 3),
81
82 PACKET(VC4_PACKET_GEM_HANDLES, 9),
83 };
84
85 void
86 vc4_dump_cl(void *cl, uint32_t size, bool is_render)
87 {
88 uint32_t offset = 0, hw_offset = 0;
89 uint8_t *cmds = cl;
90
91 while (offset < size) {
92 uint8_t header = cmds[offset];
93
94 if (header > ARRAY_SIZE(packet_info) ||
95 !packet_info[header].name) {
96 fprintf(stderr, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
97 offset, hw_offset, header, header);
98 return;
99 }
100
101 const struct packet_info *p = packet_info + header;
102 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
103 offset,
104 header != VC4_PACKET_GEM_HANDLES ? hw_offset : 0,
105 header, p->name);
106
107 for (uint32_t i = 1; i < p->size; i++) {
108 if (offset + i >= size) {
109 fprintf(stderr, "0x%08x 0x%08x: CL overflow!\n",
110 offset + i, hw_offset + i);
111 return;
112 }
113 fprintf(stderr, "0x%08x 0x%08x: 0x%02x\n",
114 offset + i,
115 header != VC4_PACKET_GEM_HANDLES ? hw_offset + i : 0,
116 cmds[offset + i]);
117 }
118
119 switch (header) {
120 case VC4_PACKET_HALT:
121 case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF:
122 return;
123 default:
124 break;
125 }
126
127 offset += p->size;
128 if (header != VC4_PACKET_GEM_HANDLES)
129 hw_offset += p->size;
130 }
131 }
132