1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #include "ac_debug.h"
8 #include "sid.h"
9 #include "sid_tables.h"
10 #include "ac_vcn.h"
11 #include "ac_vcn_dec.h"
12 #include "ac_vcn_enc.h"
13
14 #include "util/compiler.h"
15 #include "util/hash_table.h"
16 #include "util/u_debug.h"
17 #include "util/u_math.h"
18 #include "util/memstream.h"
19 #include "util/u_string.h"
20
21 #include <stdlib.h>
22
23 #ifdef HAVE_VALGRIND
24 #include <memcheck.h>
25 #include <valgrind.h>
26 #endif
27
28 DEBUG_GET_ONCE_BOOL_OPTION(color, "AMD_COLOR", true);
29
30 /* Parsed IBs are difficult to read without colors. Use "less -R file" to
31 * read them, or use "aha -b -f file" to convert them to html.
32 */
33 #define COLOR_RESET "\033[0m"
34 #define COLOR_RED "\033[31m"
35 #define COLOR_GREEN "\033[1;32m"
36 #define COLOR_YELLOW "\033[1;33m"
37 #define COLOR_CYAN "\033[1;36m"
38 #define COLOR_PURPLE "\033[1;35m"
39
40 #define O_COLOR_RESET (debug_get_option_color() ? COLOR_RESET : "")
41 #define O_COLOR_RED (debug_get_option_color() ? COLOR_RED : "")
42 #define O_COLOR_GREEN (debug_get_option_color() ? COLOR_GREEN : "")
43 #define O_COLOR_YELLOW (debug_get_option_color() ? COLOR_YELLOW : "")
44 #define O_COLOR_CYAN (debug_get_option_color() ? COLOR_CYAN : "")
45 #define O_COLOR_PURPLE (debug_get_option_color() ? COLOR_PURPLE : "")
46
47 #define INDENT_PKT 8
48
49 static void parse_gfx_compute_ib(FILE *f, struct ac_ib_parser *ib);
50
print_spaces(FILE * f,unsigned num)51 static void print_spaces(FILE *f, unsigned num)
52 {
53 fprintf(f, "%*s", num, "");
54 }
55
print_value(FILE * file,uint32_t value,int bits)56 static void print_value(FILE *file, uint32_t value, int bits)
57 {
58 /* Guess if it's int or float */
59 if (value <= (1 << 15)) {
60 if (value <= 9)
61 fprintf(file, "%u\n", value);
62 else
63 fprintf(file, "%u (0x%0*x)\n", value, bits / 4, value);
64 } else {
65 float f = uif(value);
66
67 if (fabs(f) < 100000 && f * 10 == floor(f * 10))
68 fprintf(file, "%.1ff (0x%0*x)\n", f, bits / 4, value);
69 else
70 /* Don't print more leading zeros than there are bits. */
71 fprintf(file, "0x%0*x\n", bits / 4, value);
72 }
73 }
74
print_data_dword(FILE * file,uint32_t value,const char * comment)75 static void print_data_dword(FILE *file, uint32_t value, const char *comment)
76 {
77 print_spaces(file, INDENT_PKT);
78 fprintf(file, "(%s)\n", comment);
79 }
80
print_named_value(FILE * file,const char * name,uint32_t value,int bits)81 static void print_named_value(FILE *file, const char *name, uint32_t value, int bits)
82 {
83 print_spaces(file, INDENT_PKT);
84 fprintf(file, "%s%s%s <- ",
85 O_COLOR_YELLOW, name,
86 O_COLOR_RESET);
87 print_value(file, value, bits);
88 }
89
print_string_value(FILE * file,const char * name,const char * value)90 static void print_string_value(FILE *file, const char *name, const char *value)
91 {
92 print_spaces(file, INDENT_PKT);
93 fprintf(file, "%s%s%s <- ",
94 O_COLOR_YELLOW, name,
95 O_COLOR_RESET);
96 fprintf(file, "%s\n", value);
97 }
98
ac_dump_reg(FILE * file,enum amd_gfx_level gfx_level,enum radeon_family family,unsigned offset,uint32_t value,uint32_t field_mask)99 void ac_dump_reg(FILE *file, enum amd_gfx_level gfx_level, enum radeon_family family,
100 unsigned offset, uint32_t value, uint32_t field_mask)
101 {
102 const struct si_reg *reg = ac_find_register(gfx_level, family, offset);
103
104 if (reg) {
105 const char *reg_name = sid_strings + reg->name_offset;
106
107 print_spaces(file, INDENT_PKT);
108 fprintf(file, "%s%s%s <- ",
109 O_COLOR_YELLOW, reg_name,
110 O_COLOR_RESET);
111
112 print_value(file, value, 32);
113
114 for (unsigned f = 0; f < reg->num_fields; f++) {
115 const struct si_field *field = sid_fields_table + reg->fields_offset + f;
116 const int *values_offsets = sid_strings_offsets + field->values_offset;
117 uint32_t val = (value & field->mask) >> (ffs(field->mask) - 1);
118
119 if (!(field->mask & field_mask))
120 continue;
121
122 /* Indent the field. */
123 print_spaces(file, INDENT_PKT + strlen(reg_name) + 4);
124
125 /* Print the field. */
126 fprintf(file, "%s = ", sid_strings + field->name_offset);
127
128 if (val < field->num_values && values_offsets[val] >= 0)
129 fprintf(file, "%s\n", sid_strings + values_offsets[val]);
130 else
131 print_value(file, val, util_bitcount(field->mask));
132 }
133 return;
134 }
135
136 print_spaces(file, INDENT_PKT);
137 fprintf(file, "%s0x%05x%s <- 0x%08x\n",
138 O_COLOR_YELLOW, offset,
139 O_COLOR_RESET, value);
140 }
141
ac_ib_get(struct ac_ib_parser * ib)142 static uint32_t ac_ib_get(struct ac_ib_parser *ib)
143 {
144 uint32_t v = 0;
145
146 if (ib->cur_dw < ib->num_dw) {
147 v = ib->ib[ib->cur_dw];
148 #ifdef HAVE_VALGRIND
149 /* Help figure out where garbage data is written to IBs.
150 *
151 * Arguably we should do this already when the IBs are written,
152 * see RADEON_VALGRIND. The problem is that client-requests to
153 * Valgrind have an overhead even when Valgrind isn't running,
154 * and radeon_emit is performance sensitive...
155 */
156 if (VALGRIND_CHECK_VALUE_IS_DEFINED(v))
157 fprintf(ib->f, "%sValgrind: The next DWORD is garbage%s\n",
158 debug_get_option_color() ? COLOR_RED : "", O_COLOR_RESET);
159 #endif
160 fprintf(ib->f, "\n\035#%08x ", v);
161 } else {
162 fprintf(ib->f, "\n\035#???????? ");
163 }
164
165 ib->cur_dw++;
166 return v;
167 }
168
ac_ib_get64(struct ac_ib_parser * ib)169 static uint64_t ac_ib_get64(struct ac_ib_parser *ib)
170 {
171 uint32_t lo = ac_ib_get(ib);
172 uint32_t hi = ac_ib_get(ib);
173 return ((uint64_t)hi << 32) | lo;
174 }
175
ac_sext_addr48(uint64_t addr)176 static uint64_t ac_sext_addr48(uint64_t addr)
177 {
178 if (addr & (1llu << 47))
179 return addr | (0xFFFFllu << 48);
180 else
181 return addr & (~(0xFFFFllu << 48));
182 }
183
ac_parse_set_reg_packet(FILE * f,unsigned count,unsigned reg_offset,struct ac_ib_parser * ib)184 static void ac_parse_set_reg_packet(FILE *f, unsigned count, unsigned reg_offset,
185 struct ac_ib_parser *ib)
186 {
187 unsigned reg_dw = ac_ib_get(ib);
188 unsigned reg = ((reg_dw & 0xFFFF) << 2) + reg_offset;
189 unsigned index = reg_dw >> 28;
190 int i;
191
192 if (index != 0)
193 print_named_value(f, "INDEX", index, 32);
194
195 for (i = 0; i < count; i++)
196 ac_dump_reg(f, ib->gfx_level, ib->family, reg + i * 4, ac_ib_get(ib), ~0);
197 }
198
ac_parse_set_reg_pairs_packet(FILE * f,unsigned count,unsigned reg_base,struct ac_ib_parser * ib)199 static void ac_parse_set_reg_pairs_packet(FILE *f, unsigned count, unsigned reg_base,
200 struct ac_ib_parser *ib)
201 {
202 for (unsigned i = 0; i < (count + 1) / 2; i++) {
203 unsigned reg_offset = (ac_ib_get(ib) << 2) + reg_base;
204 ac_dump_reg(f, ib->gfx_level, ib->family, reg_offset, ac_ib_get(ib), ~0);
205 }
206 }
207
ac_parse_set_reg_pairs_packed_packet(FILE * f,unsigned count,unsigned reg_base,struct ac_ib_parser * ib)208 static void ac_parse_set_reg_pairs_packed_packet(FILE *f, unsigned count, unsigned reg_base,
209 struct ac_ib_parser *ib)
210 {
211 unsigned reg_offset0 = 0, reg_offset1 = 0;
212
213 print_named_value(f, "REG_COUNT", ac_ib_get(ib), 32);
214
215 for (unsigned i = 0; i < count; i++) {
216 if (i % 3 == 0) {
217 unsigned tmp = ac_ib_get(ib);
218 reg_offset0 = ((tmp & 0xffff) << 2) + reg_base;
219 reg_offset1 = ((tmp >> 16) << 2) + reg_base;
220 } else if (i % 3 == 1) {
221 ac_dump_reg(f, ib->gfx_level, ib->family, reg_offset0, ac_ib_get(ib), ~0);
222 } else {
223 ac_dump_reg(f, ib->gfx_level, ib->family, reg_offset1, ac_ib_get(ib), ~0);
224 }
225 }
226 }
227
228 #define AC_ADDR_SIZE_NOT_MEMORY 0xFFFFFFFF
229
print_addr(struct ac_ib_parser * ib,const char * name,uint64_t addr,uint32_t size)230 static void print_addr(struct ac_ib_parser *ib, const char *name, uint64_t addr, uint32_t size)
231 {
232 FILE *f = ib->f;
233
234 print_spaces(f, INDENT_PKT);
235 fprintf(f, "%s%s%s <- ",
236 O_COLOR_YELLOW, name,
237 O_COLOR_RESET);
238
239 fprintf(f, "0x%llx", (unsigned long long)addr);
240
241 if (ib->addr_callback && size != AC_ADDR_SIZE_NOT_MEMORY) {
242 struct ac_addr_info addr_info;
243 ib->addr_callback(ib->addr_callback_data, addr, &addr_info);
244
245 struct ac_addr_info addr_info2 = addr_info;
246 if (size)
247 ib->addr_callback(ib->addr_callback_data, addr + size - 1, &addr_info2);
248
249 uint32_t invalid_count = !addr_info.valid + !addr_info2.valid;
250
251 if (addr_info.use_after_free && addr_info2.use_after_free)
252 fprintf(f, " used after free");
253 else if (invalid_count == 2)
254 fprintf(f, " invalid");
255 else if (invalid_count == 1)
256 fprintf(f, " out of bounds");
257 }
258
259 fprintf(f, "\n");
260 }
261
ac_parse_packet3(FILE * f,uint32_t header,struct ac_ib_parser * ib,int * current_trace_id)262 static void ac_parse_packet3(FILE *f, uint32_t header, struct ac_ib_parser *ib,
263 int *current_trace_id)
264 {
265 unsigned first_dw = ib->cur_dw;
266 int count = PKT_COUNT_G(header);
267 unsigned op = PKT3_IT_OPCODE_G(header);
268 const char *shader_type = PKT3_SHADER_TYPE_G(header) ? "(shader_type=compute)" : "";
269 const char *predicated = PKT3_PREDICATE(header) ? "(predicated)" : "";
270 const char *reset_filter_cam = PKT3_RESET_FILTER_CAM_G(header) ? "(reset_filter_cam)" : "";
271 int i;
272 unsigned tmp;
273
274 /* Print the name first. */
275 for (i = 0; i < ARRAY_SIZE(packet3_table); i++)
276 if (packet3_table[i].op == op)
277 break;
278
279 char unknown_name[32];
280 const char *pkt_name;
281
282 if (i < ARRAY_SIZE(packet3_table)) {
283 pkt_name = sid_strings + packet3_table[i].name_offset;
284 } else {
285 snprintf(unknown_name, sizeof(unknown_name), "UNKNOWN(0x%02X)", op);
286 pkt_name = unknown_name;
287 }
288 const char *color;
289
290 if (strstr(pkt_name, "DRAW") || strstr(pkt_name, "DISPATCH"))
291 color = O_COLOR_PURPLE;
292 else if (strstr(pkt_name, "SET") == pkt_name && strstr(pkt_name, "REG"))
293 color = O_COLOR_CYAN;
294 else if (i >= ARRAY_SIZE(packet3_table))
295 color = O_COLOR_RED;
296 else
297 color = O_COLOR_GREEN;
298
299 fprintf(f, "%s%s%s%s%s%s:\n", color, pkt_name, O_COLOR_RESET,
300 shader_type, predicated, reset_filter_cam);
301
302 /* Print the contents. */
303 switch (op) {
304 case PKT3_SET_CONTEXT_REG:
305 ac_parse_set_reg_packet(f, count, SI_CONTEXT_REG_OFFSET, ib);
306 break;
307 case PKT3_SET_CONFIG_REG:
308 ac_parse_set_reg_packet(f, count, SI_CONFIG_REG_OFFSET, ib);
309 break;
310 case PKT3_SET_UCONFIG_REG:
311 case PKT3_SET_UCONFIG_REG_INDEX:
312 ac_parse_set_reg_packet(f, count, CIK_UCONFIG_REG_OFFSET, ib);
313 break;
314 case PKT3_SET_SH_REG:
315 case PKT3_SET_SH_REG_INDEX:
316 ac_parse_set_reg_packet(f, count, SI_SH_REG_OFFSET, ib);
317 break;
318 case PKT3_SET_UCONFIG_REG_PAIRS:
319 ac_parse_set_reg_pairs_packet(f, count, CIK_UCONFIG_REG_OFFSET, ib);
320 break;
321 case PKT3_SET_CONTEXT_REG_PAIRS:
322 ac_parse_set_reg_pairs_packet(f, count, SI_CONTEXT_REG_OFFSET, ib);
323 break;
324 case PKT3_SET_SH_REG_PAIRS:
325 ac_parse_set_reg_pairs_packet(f, count, SI_SH_REG_OFFSET, ib);
326 break;
327 case PKT3_SET_CONTEXT_REG_PAIRS_PACKED:
328 ac_parse_set_reg_pairs_packed_packet(f, count, SI_CONTEXT_REG_OFFSET, ib);
329 break;
330 case PKT3_SET_SH_REG_PAIRS_PACKED:
331 case PKT3_SET_SH_REG_PAIRS_PACKED_N:
332 ac_parse_set_reg_pairs_packed_packet(f, count, SI_SH_REG_OFFSET, ib);
333 break;
334 case PKT3_ACQUIRE_MEM:
335 if (ib->gfx_level >= GFX11) {
336 if (G_585_PWS_ENA(ib->ib[ib->cur_dw + 5])) {
337 ac_dump_reg(f, ib->gfx_level, ib->family, R_580_ACQUIRE_MEM_PWS_2, ac_ib_get(ib), ~0);
338 print_named_value(f, "GCR_SIZE", ac_ib_get(ib), 32);
339 print_named_value(f, "GCR_SIZE_HI", ac_ib_get(ib), 25);
340 print_named_value(f, "GCR_BASE_LO", ac_ib_get(ib), 32);
341 print_named_value(f, "GCR_BASE_HI", ac_ib_get(ib), 32);
342 ac_dump_reg(f, ib->gfx_level, ib->family, R_585_ACQUIRE_MEM_PWS_7, ac_ib_get(ib), ~0);
343 ac_dump_reg(f, ib->gfx_level, ib->family, R_586_GCR_CNTL, ac_ib_get(ib), ~0);
344 } else {
345 print_string_value(f, "ENGINE_SEL", ac_ib_get(ib) & 0x80000000 ? "ME" : "PFP");
346 print_named_value(f, "GCR_SIZE", ac_ib_get(ib), 32);
347 print_named_value(f, "GCR_SIZE_HI", ac_ib_get(ib), 25);
348 print_named_value(f, "GCR_BASE_LO", ac_ib_get(ib), 32);
349 print_named_value(f, "GCR_BASE_HI", ac_ib_get(ib), 32);
350 print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
351 ac_dump_reg(f, ib->gfx_level, ib->family, R_586_GCR_CNTL, ac_ib_get(ib), ~0);
352 }
353 } else {
354 tmp = ac_ib_get(ib);
355 ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F0_CP_COHER_CNTL, tmp, 0x7fffffff);
356 print_string_value(f, "ENGINE_SEL", tmp & 0x80000000 ? "ME" : "PFP");
357 ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F4_CP_COHER_SIZE, ac_ib_get(ib), ~0);
358 ac_dump_reg(f, ib->gfx_level, ib->family, R_030230_CP_COHER_SIZE_HI, ac_ib_get(ib), ~0);
359 ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F8_CP_COHER_BASE, ac_ib_get(ib), ~0);
360 ac_dump_reg(f, ib->gfx_level, ib->family, R_0301E4_CP_COHER_BASE_HI, ac_ib_get(ib), ~0);
361 print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
362 if (ib->gfx_level >= GFX10)
363 ac_dump_reg(f, ib->gfx_level, ib->family, R_586_GCR_CNTL, ac_ib_get(ib), ~0);
364 }
365 break;
366 case PKT3_SURFACE_SYNC:
367 if (ib->gfx_level >= GFX7) {
368 ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F0_CP_COHER_CNTL, ac_ib_get(ib), ~0);
369 ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F4_CP_COHER_SIZE, ac_ib_get(ib), ~0);
370 ac_dump_reg(f, ib->gfx_level, ib->family, R_0301F8_CP_COHER_BASE, ac_ib_get(ib), ~0);
371 } else {
372 ac_dump_reg(f, ib->gfx_level, ib->family, R_0085F0_CP_COHER_CNTL, ac_ib_get(ib), ~0);
373 ac_dump_reg(f, ib->gfx_level, ib->family, R_0085F4_CP_COHER_SIZE, ac_ib_get(ib), ~0);
374 ac_dump_reg(f, ib->gfx_level, ib->family, R_0085F8_CP_COHER_BASE, ac_ib_get(ib), ~0);
375 }
376 print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
377 break;
378 case PKT3_EVENT_WRITE: {
379 uint32_t event_dw = ac_ib_get(ib);
380 ac_dump_reg(f, ib->gfx_level, ib->family, R_028A90_VGT_EVENT_INITIATOR, event_dw,
381 S_028A90_EVENT_TYPE(~0));
382 print_named_value(f, "EVENT_INDEX", (event_dw >> 8) & 0xf, 4);
383 print_named_value(f, "INV_L2", (event_dw >> 20) & 0x1, 1);
384 if (count > 0)
385 print_addr(ib, "ADDR", ac_ib_get64(ib), 0);
386
387 break;
388 }
389 case PKT3_EVENT_WRITE_EOP: {
390 uint32_t event_dw = ac_ib_get(ib);
391 ac_dump_reg(f, ib->gfx_level, ib->family, R_028A90_VGT_EVENT_INITIATOR, event_dw,
392 S_028A90_EVENT_TYPE(~0));
393 print_named_value(f, "EVENT_INDEX", (event_dw >> 8) & 0xf, 4);
394 print_named_value(f, "TCL1_VOL_ACTION_ENA", (event_dw >> 12) & 0x1, 1);
395 print_named_value(f, "TC_VOL_ACTION_ENA", (event_dw >> 13) & 0x1, 1);
396 print_named_value(f, "TC_WB_ACTION_ENA", (event_dw >> 15) & 0x1, 1);
397 print_named_value(f, "TCL1_ACTION_ENA", (event_dw >> 16) & 0x1, 1);
398 print_named_value(f, "TC_ACTION_ENA", (event_dw >> 17) & 0x1, 1);
399 uint64_t addr = ac_ib_get64(ib);
400 uint32_t data_sel = addr >> 61;
401 uint32_t data_size;
402 switch (data_sel) {
403 case EOP_DATA_SEL_VALUE_32BIT:
404 data_size = 4;
405 break;
406 case EOP_DATA_SEL_VALUE_64BIT:
407 case EOP_DATA_SEL_TIMESTAMP:
408 data_size = 8;
409 break;
410 default:
411 data_size = AC_ADDR_SIZE_NOT_MEMORY;
412 break;
413 }
414 print_addr(ib, "ADDR", ac_sext_addr48(addr), data_size);
415 print_named_value(f, "DST_SEL", (addr >> 48) & 0x3, 2);
416 print_named_value(f, "INT_SEL", (addr >> 56) & 0x7, 3);
417 print_named_value(f, "DATA_SEL", data_sel, 3);
418 print_named_value(f, "DATA_LO", ac_ib_get(ib), 32);
419 print_named_value(f, "DATA_HI", ac_ib_get(ib), 32);
420 break;
421 }
422 case PKT3_RELEASE_MEM: {
423 uint32_t event_dw = ac_ib_get(ib);
424 if (ib->gfx_level >= GFX10) {
425 ac_dump_reg(f, ib->gfx_level, ib->family, R_490_RELEASE_MEM_OP, event_dw, ~0u);
426 } else {
427 ac_dump_reg(f, ib->gfx_level, ib->family, R_028A90_VGT_EVENT_INITIATOR, event_dw,
428 S_028A90_EVENT_TYPE(~0));
429 print_named_value(f, "EVENT_INDEX", (event_dw >> 8) & 0xf, 4);
430 print_named_value(f, "TCL1_VOL_ACTION_ENA", (event_dw >> 12) & 0x1, 1);
431 print_named_value(f, "TC_VOL_ACTION_ENA", (event_dw >> 13) & 0x1, 1);
432 print_named_value(f, "TC_WB_ACTION_ENA", (event_dw >> 15) & 0x1, 1);
433 print_named_value(f, "TCL1_ACTION_ENA", (event_dw >> 16) & 0x1, 1);
434 print_named_value(f, "TC_ACTION_ENA", (event_dw >> 17) & 0x1, 1);
435 print_named_value(f, "TC_NC_ACTION_ENA", (event_dw >> 19) & 0x1, 1);
436 print_named_value(f, "TC_WC_ACTION_ENA", (event_dw >> 20) & 0x1, 1);
437 print_named_value(f, "TC_MD_ACTION_ENA", (event_dw >> 21) & 0x1, 1);
438 }
439 uint32_t sel_dw = ac_ib_get(ib);
440 print_named_value(f, "DST_SEL", (sel_dw >> 16) & 0x3, 2);
441 print_named_value(f, "INT_SEL", (sel_dw >> 24) & 0x7, 3);
442 print_named_value(f, "DATA_SEL", sel_dw >> 29, 3);
443 print_named_value(f, "ADDRESS_LO", ac_ib_get(ib), 32);
444 print_named_value(f, "ADDRESS_HI", ac_ib_get(ib), 32);
445 print_named_value(f, "DATA_LO", ac_ib_get(ib), 32);
446 print_named_value(f, "DATA_HI", ac_ib_get(ib), 32);
447 print_named_value(f, "CTXID", ac_ib_get(ib), 32);
448 break;
449 }
450 case PKT3_WAIT_REG_MEM:
451 print_named_value(f, "OP", ac_ib_get(ib), 32);
452 print_named_value(f, "ADDRESS_LO", ac_ib_get(ib), 32);
453 print_named_value(f, "ADDRESS_HI", ac_ib_get(ib), 32);
454 print_named_value(f, "REF", ac_ib_get(ib), 32);
455 print_named_value(f, "MASK", ac_ib_get(ib), 32);
456 print_named_value(f, "POLL_INTERVAL", ac_ib_get(ib), 16);
457 break;
458 case PKT3_DRAW_INDEX_AUTO:
459 ac_dump_reg(f, ib->gfx_level, ib->family, R_030930_VGT_NUM_INDICES, ac_ib_get(ib), ~0);
460 ac_dump_reg(f, ib->gfx_level, ib->family, R_0287F0_VGT_DRAW_INITIATOR, ac_ib_get(ib), ~0);
461 break;
462 case PKT3_DRAW_INDEX_2:
463 ac_dump_reg(f, ib->gfx_level, ib->family, R_028A78_VGT_DMA_MAX_SIZE, ac_ib_get(ib), ~0);
464 print_addr(ib, "INDEX_ADDR", ac_ib_get64(ib), 0);
465 ac_dump_reg(f, ib->gfx_level, ib->family, R_030930_VGT_NUM_INDICES, ac_ib_get(ib), ~0);
466 ac_dump_reg(f, ib->gfx_level, ib->family, R_0287F0_VGT_DRAW_INITIATOR, ac_ib_get(ib), ~0);
467 break;
468 case PKT3_DRAW_INDIRECT:
469 case PKT3_DRAW_INDEX_INDIRECT:
470 print_named_value(f, "OFFSET", ac_ib_get(ib), 32);
471 print_named_value(f, "VERTEX_OFFSET_REG", ac_ib_get(ib), 32);
472 print_named_value(f, "START_INSTANCE_REG", ac_ib_get(ib), 32);
473 ac_dump_reg(f, ib->gfx_level, ib->family, R_0287F0_VGT_DRAW_INITIATOR, ac_ib_get(ib), ~0);
474 break;
475 case PKT3_DRAW_INDIRECT_MULTI:
476 case PKT3_DRAW_INDEX_INDIRECT_MULTI:
477 print_named_value(f, "OFFSET", ac_ib_get(ib), 32);
478 print_named_value(f, "VERTEX_OFFSET_REG", ac_ib_get(ib), 32);
479 print_named_value(f, "START_INSTANCE_REG", ac_ib_get(ib), 32);
480 tmp = ac_ib_get(ib);
481 print_named_value(f, "DRAW_ID_REG", tmp & 0xFFFF, 16);
482 print_named_value(f, "DRAW_ID_ENABLE", tmp >> 31, 1);
483 print_named_value(f, "COUNT_INDIRECT_ENABLE", (tmp >> 30) & 1, 1);
484 print_named_value(f, "DRAW_COUNT", ac_ib_get(ib), 32);
485 print_addr(ib, "COUNT_ADDR", ac_ib_get64(ib), 0);
486 print_named_value(f, "STRIDE", ac_ib_get(ib), 32);
487 ac_dump_reg(f, ib->gfx_level, ib->family, R_0287F0_VGT_DRAW_INITIATOR, ac_ib_get(ib), ~0);
488 break;
489 case PKT3_INDEX_BASE:
490 print_addr(ib, "ADDR", ac_ib_get64(ib), 0);
491 break;
492 case PKT3_INDEX_TYPE:
493 ac_dump_reg(f, ib->gfx_level, ib->family, R_028A7C_VGT_DMA_INDEX_TYPE, ac_ib_get(ib), ~0);
494 break;
495 case PKT3_NUM_INSTANCES:
496 ac_dump_reg(f, ib->gfx_level, ib->family, R_030934_VGT_NUM_INSTANCES, ac_ib_get(ib), ~0);
497 break;
498 case PKT3_WRITE_DATA: {
499 uint32_t control = ac_ib_get(ib);
500 ac_dump_reg(f, ib->gfx_level, ib->family, R_370_CONTROL, control, ~0);
501 uint32_t dst_sel = G_370_DST_SEL(control);
502 uint64_t addr = ac_ib_get64(ib);
503 uint32_t dword_count = first_dw + count + 1 - ib->cur_dw;
504 bool writes_memory = dst_sel == V_370_MEM_GRBM || dst_sel == V_370_TC_L2 || dst_sel == V_370_MEM;
505 print_addr(ib, "DST_ADDR", addr, writes_memory ? dword_count * 4 : AC_ADDR_SIZE_NOT_MEMORY);
506 for (uint32_t i = 0; i < dword_count; i++)
507 print_data_dword(f, ac_ib_get(ib), "data");
508 break;
509 }
510 case PKT3_CP_DMA:
511 ac_dump_reg(f, ib->gfx_level, ib->family, R_410_CP_DMA_WORD0, ac_ib_get(ib), ~0);
512 ac_dump_reg(f, ib->gfx_level, ib->family, R_411_CP_DMA_WORD1, ac_ib_get(ib), ~0);
513 ac_dump_reg(f, ib->gfx_level, ib->family, R_412_CP_DMA_WORD2, ac_ib_get(ib), ~0);
514 ac_dump_reg(f, ib->gfx_level, ib->family, R_413_CP_DMA_WORD3, ac_ib_get(ib), ~0);
515 ac_dump_reg(f, ib->gfx_level, ib->family, R_415_COMMAND, ac_ib_get(ib), ~0);
516 break;
517 case PKT3_DMA_DATA: {
518 uint32_t header = ac_ib_get(ib);
519 ac_dump_reg(f, ib->gfx_level, ib->family, R_501_DMA_DATA_WORD0, header, ~0);
520
521 uint64_t src_addr = ac_ib_get64(ib);
522 uint64_t dst_addr = ac_ib_get64(ib);
523
524 uint32_t command = ac_ib_get(ib);
525 uint32_t size = ib->gfx_level >= GFX9 ? G_415_BYTE_COUNT_GFX9(command)
526 : G_415_BYTE_COUNT_GFX6(command);
527
528 uint32_t src_sel = G_501_SRC_SEL(header);
529 bool src_mem = (src_sel == V_501_SRC_ADDR && G_415_SAS(command) == V_415_MEMORY) ||
530 src_sel == V_411_SRC_ADDR_TC_L2;
531
532 uint32_t dst_sel = G_501_DST_SEL(header);
533 bool dst_mem = (dst_sel == V_501_DST_ADDR && G_415_DAS(command) == V_415_MEMORY) ||
534 dst_sel == V_411_DST_ADDR_TC_L2;
535
536 print_addr(ib, "SRC_ADDR", src_addr, src_mem ? size : AC_ADDR_SIZE_NOT_MEMORY);
537 print_addr(ib, "DST_ADDR", dst_addr, dst_mem ? size : AC_ADDR_SIZE_NOT_MEMORY);
538 ac_dump_reg(f, ib->gfx_level, ib->family, R_415_COMMAND, command, ~0);
539 break;
540 }
541 case PKT3_INDIRECT_BUFFER_SI:
542 case PKT3_INDIRECT_BUFFER_CONST:
543 case PKT3_INDIRECT_BUFFER: {
544 uint32_t base_lo_dw = ac_ib_get(ib);
545 ac_dump_reg(f, ib->gfx_level, ib->family, R_3F0_IB_BASE_LO, base_lo_dw, ~0);
546 uint32_t base_hi_dw = ac_ib_get(ib);
547 ac_dump_reg(f, ib->gfx_level, ib->family, R_3F1_IB_BASE_HI, base_hi_dw, ~0);
548 uint32_t control_dw = ac_ib_get(ib);
549 ac_dump_reg(f, ib->gfx_level, ib->family, R_3F2_IB_CONTROL, control_dw, ~0);
550
551 if (!ib->addr_callback)
552 break;
553
554 uint64_t addr = ((uint64_t)base_hi_dw << 32) | base_lo_dw;
555 struct ac_addr_info addr_info;
556 ib->addr_callback(ib->addr_callback_data, addr, &addr_info);
557 void *data = addr_info.cpu_addr;
558 if (!data)
559 break;
560
561 if (G_3F2_CHAIN(control_dw)) {
562 ib->ib = data;
563 ib->num_dw = G_3F2_IB_SIZE(control_dw);
564 ib->cur_dw = 0;
565 return;
566 }
567
568 struct ac_ib_parser ib_recurse;
569 memcpy(&ib_recurse, ib, sizeof(ib_recurse));
570 ib_recurse.ib = data;
571 ib_recurse.num_dw = G_3F2_IB_SIZE(control_dw);
572 ib_recurse.cur_dw = 0;
573 if (ib_recurse.trace_id_count) {
574 if (*current_trace_id == *ib->trace_ids) {
575 ++ib_recurse.trace_ids;
576 --ib_recurse.trace_id_count;
577 } else {
578 ib_recurse.trace_id_count = 0;
579 }
580 }
581
582 fprintf(f, "\n\035>------------------ nested begin ------------------\n");
583 parse_gfx_compute_ib(f, &ib_recurse);
584 fprintf(f, "\n\035<------------------- nested end -------------------\n");
585 break;
586 }
587 case PKT3_CLEAR_STATE:
588 case PKT3_INCREMENT_DE_COUNTER:
589 case PKT3_PFP_SYNC_ME:
590 print_data_dword(f, ac_ib_get(ib), "reserved");
591 break;
592 case PKT3_NOP:
593 if (header == PKT3_NOP_PAD) {
594 count = -1; /* One dword NOP. */
595 } else if (count == 0 && ib->cur_dw < ib->num_dw && AC_IS_TRACE_POINT(ib->ib[ib->cur_dw])) {
596 unsigned packet_id = AC_GET_TRACE_POINT_ID(ib->ib[ib->cur_dw]);
597
598 print_spaces(f, INDENT_PKT);
599 fprintf(f, "%sTrace point ID: %u%s\n", O_COLOR_RED, packet_id, O_COLOR_RESET);
600
601 if (!ib->trace_id_count)
602 break; /* tracing was disabled */
603
604 *current_trace_id = packet_id;
605
606 print_spaces(f, INDENT_PKT);
607 if (packet_id < *ib->trace_ids) {
608 fprintf(f, "%sThis trace point was reached by the CP.%s\n",
609 O_COLOR_RED, O_COLOR_RESET);
610 } else if (packet_id == *ib->trace_ids) {
611 fprintf(f, "%s!!!!! This is the last trace point that "
612 "was reached by the CP !!!!!%s\n",
613 O_COLOR_RED, O_COLOR_RESET);
614 } else if (packet_id + 1 == *ib->trace_ids) {
615 fprintf(f, "%s!!!!! This is the first trace point that "
616 "was NOT been reached by the CP !!!!!%s\n",
617 O_COLOR_RED, O_COLOR_RESET);
618 } else {
619 fprintf(f, "%s!!!!! This trace point was NOT reached "
620 "by the CP !!!!!%s\n",
621 O_COLOR_RED, O_COLOR_RESET);
622 }
623 } else {
624 while (ib->cur_dw <= first_dw + count)
625 print_data_dword(f, ac_ib_get(ib), "unused");
626 }
627 break;
628 case PKT3_DISPATCH_DIRECT:
629 case PKT3_DISPATCH_DIRECT_INTERLEAVED:
630 ac_dump_reg(f, ib->gfx_level, ib->family, R_00B804_COMPUTE_DIM_X, ac_ib_get(ib), ~0);
631 ac_dump_reg(f, ib->gfx_level, ib->family, R_00B808_COMPUTE_DIM_Y, ac_ib_get(ib), ~0);
632 ac_dump_reg(f, ib->gfx_level, ib->family, R_00B80C_COMPUTE_DIM_Z, ac_ib_get(ib), ~0);
633 ac_dump_reg(f, ib->gfx_level, ib->family, R_00B800_COMPUTE_DISPATCH_INITIATOR,
634 ac_ib_get(ib), ~0);
635 break;
636 case PKT3_DISPATCH_INDIRECT:
637 case PKT3_DISPATCH_INDIRECT_INTERLEAVED:
638 if (count > 1)
639 print_addr(ib, "ADDR", ac_ib_get64(ib), 12);
640 else
641 print_named_value(f, "DATA_OFFSET", ac_ib_get(ib), 32);
642
643 ac_dump_reg(f, ib->gfx_level, ib->family, R_00B800_COMPUTE_DISPATCH_INITIATOR,
644 ac_ib_get(ib), ~0);
645 break;
646 case PKT3_SET_BASE:
647 tmp = ac_ib_get(ib);
648 print_string_value(f, "BASE_INDEX", tmp == 1 ? "INDIRECT_BASE" : COLOR_RED "UNKNOWN" COLOR_RESET);
649 print_addr(ib, "ADDR", ac_ib_get64(ib), 0);
650 break;
651 case PKT3_PRIME_UTCL2:
652 tmp = ac_ib_get(ib);
653 print_named_value(f, "CACHE_PERM[rwx]", tmp & 0x7, 3);
654 print_string_value(f, "PRIME_MODE", tmp & 0x8 ? "WAIT_FOR_XACK" : "DONT_WAIT_FOR_XACK");
655 print_named_value(f, "ENGINE_SEL", tmp >> 30, 2);
656 print_addr(ib, "ADDR", ac_ib_get64(ib), 0);
657 print_named_value(f, "REQUESTED_PAGES", ac_ib_get(ib), 14);
658 break;
659 case PKT3_ATOMIC_MEM:
660 tmp = ac_ib_get(ib);
661 print_named_value(f, "ATOMIC", tmp & 0x7f, 7);
662 print_named_value(f, "COMMAND", (tmp >> 8) & 0xf, 4);
663 print_named_value(f, "CACHE_POLICY", (tmp >> 25) & 0x3, 2);
664 print_named_value(f, "ENGINE_SEL", tmp >> 30, 2);
665 print_addr(ib, "ADDR", ac_ib_get64(ib), 8);
666 print_named_value(f, "SRC_DATA_LO", ac_ib_get(ib), 32);
667 print_named_value(f, "SRC_DATA_HI", ac_ib_get(ib), 32);
668 print_named_value(f, "CMP_DATA_LO", ac_ib_get(ib), 32);
669 print_named_value(f, "CMP_DATA_HI", ac_ib_get(ib), 32);
670 print_named_value(f, "LOOP_INTERVAL", ac_ib_get(ib) & 0x1fff, 13);
671 break;
672 case PKT3_INDEX_BUFFER_SIZE:
673 print_named_value(f, "COUNT", ac_ib_get(ib), 32);
674 break;
675 case PKT3_COND_EXEC: {
676 uint32_t size = ac_ib_get(ib) * 4;
677 print_addr(ib, "ADDR", ac_ib_get64(ib), size);
678 print_named_value(f, "SIZE", size, 32);
679 break;
680 }
681 case PKT3_DISPATCH_TASKMESH_GFX:
682 tmp = ac_ib_get(ib);
683 print_named_value(f, "RING_ENTRY_REG", (tmp >> 16) & 0xffff, 16);
684 print_named_value(f, "XYZ_DIM_REG", (tmp & 0xffff), 16);
685 tmp = ac_ib_get(ib);
686 print_named_value(f, "THREAD_TRACE_MARKER_ENABLE", (tmp >> 31) & 0x1, 1);
687 if (ib->gfx_level >= GFX11) {
688 print_named_value(f, "XYZ_DIM_ENABLE", (tmp >> 30) & 0x1, 1);
689 print_named_value(f, "MODE1_ENABLE", (tmp >> 29) & 0x1, 1);
690 print_named_value(f, "LINEAR_DISPATCH_ENABLED", (tmp >> 28) & 0x1, 1);
691 }
692 print_named_value(f, "DI_SRC_SEL_AUTO_INDEX", ac_ib_get(ib), ~0);
693 break;
694 case PKT3_DISPATCH_TASKMESH_DIRECT_ACE:
695 print_named_value(f, "X_DIM", ac_ib_get(ib), ~0);
696 print_named_value(f, "Y_DIM", ac_ib_get(ib), ~0);
697 print_named_value(f, "Z_DIM", ac_ib_get(ib), ~0);
698 ac_dump_reg(f, ib->gfx_level, ib->family, R_00B800_COMPUTE_DISPATCH_INITIATOR,
699 ac_ib_get(ib), ~0);
700 print_named_value(f, "RING_ENTRY_REG", ac_ib_get(ib), 16);
701 break;
702 }
703
704 /* print additional dwords */
705 while (ib->cur_dw <= first_dw + count)
706 ac_ib_get(ib);
707
708 if (ib->cur_dw > first_dw + count + 1)
709 fprintf(f, "%s !!!!! count in header too low !!!!!%s\n",
710 O_COLOR_RED, O_COLOR_RESET);
711 }
712
713 /**
714 * Parse and print an IB into a file.
715 */
parse_gfx_compute_ib(FILE * f,struct ac_ib_parser * ib)716 static void parse_gfx_compute_ib(FILE *f, struct ac_ib_parser *ib)
717 {
718 int current_trace_id = -1;
719
720 while (ib->cur_dw < ib->num_dw) {
721 if (ib->annotations) {
722 struct hash_entry *marker = _mesa_hash_table_search(ib->annotations, ib->ib + ib->cur_dw);
723 if (marker)
724 fprintf(f, "\n%s:", (char *)marker->data);
725 }
726
727 uint32_t header = ac_ib_get(ib);
728 unsigned type = PKT_TYPE_G(header);
729
730 switch (type) {
731 case 3:
732 ac_parse_packet3(f, header, ib, ¤t_trace_id);
733 break;
734 case 2:
735 /* type-2 nop */
736 if (header == 0x80000000) {
737 fprintf(f, "%sNOP (type 2)%s\n",
738 O_COLOR_GREEN, O_COLOR_RESET);
739 break;
740 }
741 FALLTHROUGH;
742 default:
743 fprintf(f, "Unknown packet type %i\n", type);
744 break;
745 }
746 }
747 }
748
format_ib_output(FILE * f,char * out)749 static void format_ib_output(FILE *f, char *out)
750 {
751 unsigned depth = 0;
752
753 for (;;) {
754 char op = 0;
755
756 if (out[0] == '\n' && out[1] == '\035')
757 out++;
758 if (out[0] == '\035') {
759 op = out[1];
760 out += 2;
761 }
762
763 if (op == '<')
764 depth--;
765
766 unsigned indent = 4 * depth;
767 if (op != '#')
768 indent += 9;
769
770 if (indent)
771 print_spaces(f, indent);
772
773 char *end = strchrnul(out, '\n');
774 fwrite(out, end - out, 1, f);
775 fputc('\n', f); /* always end with a new line */
776 if (!*end)
777 break;
778
779 out = end + 1;
780
781 if (op == '>')
782 depth++;
783 }
784 }
785
parse_sdma_ib(FILE * f,struct ac_ib_parser * ib)786 static void parse_sdma_ib(FILE *f, struct ac_ib_parser *ib)
787 {
788 while (ib->cur_dw < ib->num_dw) {
789 const uint32_t header = ac_ib_get(ib);
790 const uint32_t opcode = header & 0xff;
791 const uint32_t sub_op = (header >> 8) & 0xff;
792
793 switch (opcode) {
794 case SDMA_OPCODE_NOP: {
795 fprintf(f, "NOP\n");
796
797 const uint32_t count = header >> 16;
798 for (unsigned i = 0; i < count; ++i) {
799 ac_ib_get(ib);
800 fprintf(f, "\n");
801 }
802 break;
803 }
804 case SDMA_OPCODE_CONSTANT_FILL: {
805 fprintf(f, "CONSTANT_FILL\n");
806 uint32_t fill_va_lo = ac_ib_get(ib);
807 fprintf(f, " fill va lo = %08x\n", fill_va_lo);
808 uint32_t fill_va_hi = ac_ib_get(ib);
809 fprintf(f, " fill va hi = %08x\n", fill_va_hi);
810 uint32_t value = ac_ib_get(ib);
811 fprintf(f, " fill value = %u\n", value);
812 uint32_t byte_count = ac_ib_get(ib) + 1;
813 fprintf(f, " fill byte count = %u\n", byte_count);
814 break;
815 }
816 case SDMA_OPCODE_WRITE: {
817 fprintf(f, "WRITE\n");
818
819 /* VA */
820 uint32_t va_lo = ac_ib_get(ib);
821 fprintf(f, " va lo = %08x\n", va_lo);
822 uint32_t va_hi = ac_ib_get(ib);
823 fprintf(f, " va hi = %08x\n", va_hi);
824
825 uint32_t dwords = ac_ib_get(ib) + 1;
826 fprintf(f, " written dword count = %u\n", dwords);
827
828 for (unsigned i = 0; i < dwords; ++i) {
829 ac_ib_get(ib);
830 fprintf(f, "\n");
831 }
832
833 break;
834 }
835 case SDMA_OPCODE_COPY: {
836 switch (sub_op) {
837 case SDMA_COPY_SUB_OPCODE_LINEAR: {
838 fprintf(f, "COPY LINEAR\n");
839
840 uint32_t copy_bytes = ac_ib_get(ib) + (ib->gfx_level >= GFX9 ? 1 : 0);
841 fprintf(f, " copy bytes: %u\n", copy_bytes);
842 ac_ib_get(ib);
843 fprintf(f, "\n");
844 ac_ib_get(ib);
845 fprintf(f, " src VA low\n");
846 ac_ib_get(ib);
847 fprintf(f, " src VA high\n");
848 ac_ib_get(ib);
849 fprintf(f, " dst VA low\n");
850 ac_ib_get(ib);
851 fprintf(f, " dst VA high\n");
852
853 break;
854 }
855 case SDMA_COPY_SUB_OPCODE_LINEAR_SUB_WINDOW: {
856 fprintf(f, "COPY LINEAR_SUB_WINDOW\n");
857
858 for (unsigned i = 0; i < 12; ++i) {
859 ac_ib_get(ib);
860 fprintf(f, "\n");
861 }
862 break;
863 }
864 case SDMA_COPY_SUB_OPCODE_TILED_SUB_WINDOW: {
865 fprintf(f, "COPY TILED_SUB_WINDOW %s\n", header >> 31 ? "t2l" : "l2t");
866 uint32_t dcc = (header >> 19) & 1;
867
868 /* Tiled VA */
869 ac_ib_get(ib);
870 fprintf(f, " tiled VA low\n");
871 ac_ib_get(ib);
872 fprintf(f, " tiled VA high\n");
873
874 uint32_t dw3 = ac_ib_get(ib);
875 fprintf(f, " tiled offset x = %u, y=%u\n", dw3 & 0xffff, dw3 >> 16);
876 uint32_t dw4 = ac_ib_get(ib);
877 fprintf(f, " tiled offset z = %u, tiled width = %u\n", dw4 & 0xffff, (dw4 >> 16) + 1);
878 uint32_t dw5 = ac_ib_get(ib);
879 fprintf(f, " tiled height = %u, tiled depth = %u\n", (dw5 & 0xffff) + 1, (dw5 >> 16) + 1);
880
881 /* Tiled image info */
882 ac_ib_get(ib);
883 fprintf(f, " (tiled image info)\n");
884
885 /* Linear VA */
886 ac_ib_get(ib);
887 fprintf(f, " linear VA low\n");
888 ac_ib_get(ib);
889 fprintf(f, " linear VA high\n");
890
891 uint32_t dw9 = ac_ib_get(ib);
892 fprintf(f, " linear offset x = %u, y=%u\n", dw9 & 0xffff, dw9 >> 16);
893 uint32_t dw10 = ac_ib_get(ib);
894 fprintf(f, " linear offset z = %u, linear pitch = %u\n", dw10 & 0xffff, (dw10 >> 16) + 1);
895 uint32_t dw11 = ac_ib_get(ib);
896 fprintf(f, " linear slice pitch = %u\n", dw11 + 1);
897 uint32_t dw12 = ac_ib_get(ib);
898 fprintf(f, " copy width = %u, copy height = %u\n", (dw12 & 0xffff) + 1, (dw12 >> 16) + 1);
899 uint32_t dw13 = ac_ib_get(ib);
900 fprintf(f, " copy depth = %u\n", dw13 + 1);
901
902 if (dcc) {
903 ac_ib_get(ib);
904 fprintf(f, " metadata VA low\n");
905 ac_ib_get(ib);
906 fprintf(f, " metadata VA high\n");
907 ac_ib_get(ib);
908 fprintf(f, " (metadata config)\n");
909 }
910 break;
911 }
912 case SDMA_COPY_SUB_OPCODE_T2T_SUB_WINDOW: {
913 fprintf(f, "COPY T2T_SUB_WINDOW\n");
914 uint32_t dcc = (header >> 19) & 1;
915
916 for (unsigned i = 0; i < 14; ++i) {
917 ac_ib_get(ib);
918 fprintf(f, "\n");
919 }
920
921 if (dcc) {
922 ac_ib_get(ib);
923 fprintf(f, " metadata VA low\n");
924 ac_ib_get(ib);
925 fprintf(f, " metadata VA high\n");
926 ac_ib_get(ib);
927 fprintf(f, " (metadata config)\n");
928 }
929 break;
930 }
931 default:
932 fprintf(f, "(unrecognized COPY sub op)\n");
933 break;
934 }
935 break;
936 }
937 default:
938 fprintf(f, " (unrecognized opcode)\n");
939 break;
940 }
941 }
942 }
943
print_vcn_unrecognized_params(FILE * f,struct ac_ib_parser * ib,uint32_t start_dw,uint32_t size)944 static void print_vcn_unrecognized_params(FILE *f, struct ac_ib_parser *ib, uint32_t start_dw, uint32_t size)
945 {
946 int32_t remaining = size / 4 - (ib->cur_dw - start_dw);
947 if (remaining < 0) {
948 fprintf(f, "%s%d incorrectly parsed DWORDs%s\n",
949 O_COLOR_RED, remaining * -1, O_COLOR_RESET);
950 ib->cur_dw += remaining;
951 } else {
952 while (remaining--) {
953 ac_ib_get(ib);
954 fprintf(f, " %s(unrecognized)%s\n", O_COLOR_RED, O_COLOR_RESET);
955 }
956 }
957 }
958
vcn_picture_type(uint32_t type)959 static const char *vcn_picture_type(uint32_t type)
960 {
961 switch (type) {
962 case RENCODE_PICTURE_TYPE_B:
963 return "B";
964 case RENCODE_PICTURE_TYPE_P:
965 return "P";
966 case RENCODE_PICTURE_TYPE_I:
967 return "I";
968 case RENCODE_PICTURE_TYPE_P_SKIP:
969 return "P SKIP";
970 default:
971 return "???";
972 }
973 }
974
vcn_picture_structure(uint32_t structure)975 static const char *vcn_picture_structure(uint32_t structure)
976 {
977 switch (structure) {
978 case RENCODE_H264_PICTURE_STRUCTURE_FRAME:
979 return "FRAME";
980 case RENCODE_H264_PICTURE_STRUCTURE_TOP_FIELD:
981 return "TOP FIELD";
982 case RENCODE_H264_PICTURE_STRUCTURE_BOTTOM_FIELD:
983 return "BOTTOM FIELD";
984 default:
985 return "???";
986 }
987 }
988
vcn_color_volume(uint32_t color_volume)989 static const char *vcn_color_volume(uint32_t color_volume)
990 {
991 switch (color_volume) {
992 case RENCODE_COLOR_VOLUME_G22_BT709:
993 return "G22 BT.709";
994 default:
995 return "???";
996 }
997 }
998
vcn_color_range(uint32_t color_range)999 static const char *vcn_color_range(uint32_t color_range)
1000 {
1001 switch (color_range) {
1002 case RENCODE_COLOR_RANGE_FULL:
1003 return "FULL";
1004 case RENCODE_COLOR_RANGE_STUDIO:
1005 return "STUDIO";
1006 default:
1007 return "???";
1008 }
1009 }
1010
vcn_chroma_subsampling(uint32_t chroma_subsampling)1011 static const char *vcn_chroma_subsampling(uint32_t chroma_subsampling)
1012 {
1013 switch (chroma_subsampling) {
1014 case RENCODE_CHROMA_SUBSAMPLING_4_2_0:
1015 return "4:2:0";
1016 case RENCODE_CHROMA_SUBSAMPLING_4_4_4:
1017 return "4:4:4";
1018 default:
1019 return "???";
1020 }
1021 }
1022
vcn_chroma_location(uint32_t chroma_location)1023 static const char *vcn_chroma_location(uint32_t chroma_location)
1024 {
1025 switch (chroma_location) {
1026 case RENCODE_CHROMA_LOCATION_INTERSTITIAL:
1027 return "INTERSTITIAL";
1028 default:
1029 return "???";
1030 }
1031 }
1032
vcn_color_bit_depth(uint32_t bit_depth)1033 static const char *vcn_color_bit_depth(uint32_t bit_depth)
1034 {
1035 switch (bit_depth) {
1036 case RENCODE_COLOR_BIT_DEPTH_8_BIT:
1037 return "8 BIT";
1038 case RENCODE_COLOR_BIT_DEPTH_10_BIT:
1039 return "10 BIT";
1040 default:
1041 return "???";
1042 }
1043 }
1044
print_vcn_addr(FILE * f,struct ac_ib_parser * ib,const char * prefix_format,...)1045 static void print_vcn_addr(FILE *f, struct ac_ib_parser *ib, const char *prefix_format, ...)
1046 {
1047 uint32_t high = ac_ib_get(ib);
1048 fprintf(f, "\n");
1049 uint32_t low = ac_ib_get(ib);
1050
1051 va_list args;
1052 va_start(args, prefix_format);
1053 vfprintf(f, prefix_format, args);
1054 va_end(args);
1055
1056 fprintf(f, " VA = 0x%"PRIx64"\n", ((uint64_t)high << 32) | low);
1057 }
1058
print_vcn_ref_pic_info(FILE * f,struct ac_ib_parser * ib,const char * prefix)1059 static void print_vcn_ref_pic_info(FILE *f, struct ac_ib_parser *ib, const char *prefix)
1060 {
1061 uint32_t pic_type = ac_ib_get(ib);
1062 fprintf(f, "%s picture type = %s\n", prefix, vcn_picture_type(pic_type));
1063 uint32_t long_term = ac_ib_get(ib);
1064 fprintf(f, "%s is long term = %u\n", prefix, long_term);
1065 uint32_t pic_structure = ac_ib_get(ib);
1066 fprintf(f, "%s picture structure = %s\n", prefix, vcn_picture_structure(pic_structure));
1067 uint32_t pic_order_cnt = ac_ib_get(ib);
1068 fprintf(f, "%s pic order cnt = %u\n", prefix, pic_order_cnt);
1069 }
1070
print_vcn_reconstructed_picture(FILE * f,struct ac_ib_parser * ib,bool valid,const char * prefix_format,...)1071 static void print_vcn_reconstructed_picture(FILE *f, struct ac_ib_parser *ib, bool valid, const char *prefix_format, ...)
1072 {
1073 char prefix[128];
1074 va_list args;
1075 va_start(args, prefix_format);
1076 vsnprintf(prefix, sizeof(prefix), prefix_format, args);
1077 va_end(args);
1078
1079 if (ib->vcn_version >= VCN_5_0_0) {
1080 if (valid) {
1081 print_vcn_addr(f, ib, "%s luma", prefix);
1082 uint32_t luma_pitch = ac_ib_get(ib);
1083 fprintf(f, "%s luma pitch = %u\n", prefix, luma_pitch);
1084 print_vcn_addr(f, ib, "%s chroma", prefix);
1085 uint32_t chroma_pitch = ac_ib_get(ib);
1086 fprintf(f, "%s chroma pitch = %u\n", prefix, chroma_pitch);
1087 print_vcn_addr(f, ib, "%s chroma V", prefix);
1088 uint32_t chroma_v_pitch = ac_ib_get(ib);
1089 fprintf(f, "%s chroma V pitch = %u\n", prefix, chroma_v_pitch);
1090 uint32_t swizzle = ac_ib_get(ib);
1091 fprintf(f, "%s swizzle mode = %u\n", prefix, swizzle);
1092 print_vcn_addr(f, ib, "%s frame context buffer", prefix);
1093 uint32_t frame_context_offset = ac_ib_get(ib);
1094 fprintf(f, "%s AV1 cdf frame context offset / colloc buffer offset = %u\n", prefix, frame_context_offset);
1095 uint32_t cdef_offset = ac_ib_get(ib);
1096 fprintf(f, "%s AV1 cdef algorithm context offset = %u\n", prefix, cdef_offset);
1097 uint32_t metadata_offset = ac_ib_get(ib);
1098 fprintf(f, "%s encode metadata offset = %u\n", prefix, metadata_offset);
1099 } else {
1100 ib->cur_dw += 15;
1101 }
1102 } else {
1103 if (valid) {
1104 uint32_t luma_offset = ac_ib_get(ib);
1105 fprintf(f, "%s luma offset = %u\n", prefix, luma_offset);
1106 uint32_t chroma_offset = ac_ib_get(ib);
1107 fprintf(f, "%s chroma offset = %u\n", prefix, chroma_offset);
1108 } else {
1109 ib->cur_dw += 2;
1110 }
1111 if (ib->vcn_version >= VCN_4_0_0) {
1112 if (valid) {
1113 uint32_t frame_context_offset = ac_ib_get(ib);
1114 fprintf(f, "%s AV1 cdf frame context offset = %u\n", prefix, frame_context_offset);
1115 uint32_t cdef_offset = ac_ib_get(ib);
1116 fprintf(f, "%s AV1 cdef algorithm context offset = %u\n", prefix, cdef_offset);
1117 } else {
1118 ib->cur_dw += 2;
1119 }
1120 }
1121 }
1122 }
1123
print_vcn_preencode_input_picture(FILE * f,struct ac_ib_parser * ib,const char * prefix)1124 static void print_vcn_preencode_input_picture(FILE *f, struct ac_ib_parser *ib, const char *prefix)
1125 {
1126 uint32_t r_offset = ac_ib_get(ib);
1127 fprintf(f, "%s luma offset / red offset = %u\n", prefix, r_offset);
1128 uint32_t g_offset = ac_ib_get(ib);
1129 fprintf(f, "%s chroma offset / green offset = %u\n", prefix, g_offset);
1130 uint32_t b_offset = ac_ib_get(ib);
1131 fprintf(f, "%s blue offset = %u\n", prefix, b_offset);
1132 }
1133
parse_vcn_enc_ib(FILE * f,struct ac_ib_parser * ib)1134 static void parse_vcn_enc_ib(FILE *f, struct ac_ib_parser *ib)
1135 {
1136 rvcn_enc_cmd_t cmd = {};
1137 ac_vcn_enc_init_cmds(&cmd, ib->vcn_version);
1138
1139 while (ib->cur_dw < ib->num_dw) {
1140 const uint32_t start_dw = ib->cur_dw;
1141 const uint32_t size = ac_ib_get(ib);
1142 const uint32_t op = ac_ib_get(ib);
1143
1144 if (op == RENCODE_IB_OP_INITIALIZE) {
1145 fprintf(f, "%sINITIALIZE%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1146 } else if (op == RENCODE_IB_OP_CLOSE_SESSION) {
1147 fprintf(f, "%sCLOSE_SESSION%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1148 } else if (op == RENCODE_IB_OP_ENCODE) {
1149 fprintf(f, "%sENCODE%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1150 } else if (op == RENCODE_IB_OP_INIT_RC) {
1151 fprintf(f, "%sINIT_RC%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1152 } else if (op == RENCODE_IB_OP_INIT_RC_VBV_BUFFER_LEVEL) {
1153 fprintf(f, "%sINIT_RC_VBV_BUFFER_LEVEL%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1154 } else if (op == RENCODE_IB_OP_SET_SPEED_ENCODING_MODE) {
1155 fprintf(f, "%sSET_SPEED_ENCODING_MODE%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1156 } else if (op == RENCODE_IB_OP_SET_BALANCE_ENCODING_MODE) {
1157 fprintf(f, "%sSET_BALANCE_ENCODING_MODE%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1158 } else if (op == RENCODE_IB_OP_SET_QUALITY_ENCODING_MODE) {
1159 fprintf(f, "%sSET_QUALITY_ENCODING_MODE%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1160 } else if (op == RENCODE_IB_OP_SET_HIGH_QUALITY_ENCODING_MODE) {
1161 fprintf(f, "%sSET_HIGH_QUALITY_ENCODING_MODE%s\n", O_COLOR_PURPLE, O_COLOR_RESET);
1162 } else if (op == cmd.session_info) {
1163 fprintf(f, "%sSESSION_INFO%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1164 uint32_t version = ac_ib_get(ib);
1165 fprintf(f, " interface version = %u.%u\n",
1166 (version & RENCODE_IF_MAJOR_VERSION_MASK) >> RENCODE_IF_MAJOR_VERSION_SHIFT,
1167 (version & RENCODE_IF_MINOR_VERSION_MASK) >> RENCODE_IF_MINOR_VERSION_SHIFT);
1168 print_vcn_addr(f, ib, " sw context");
1169 if (ib->vcn_version < VCN_3_0_0) {
1170 uint32_t engine = ac_ib_get(ib);
1171 fprintf(f, " engine type = %s\n",
1172 engine == RENCODE_ENGINE_TYPE_ENCODE ? "ENCODE" :
1173 "???");
1174 }
1175 } else if (op == cmd.task_info) {
1176 fprintf(f, "%sTASK_INFO%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1177 uint32_t total_size = ac_ib_get(ib);
1178 fprintf(f, " size of all packages = %u\n", total_size);
1179 uint32_t task_id = ac_ib_get(ib);
1180 fprintf(f, " task id = %u\n", task_id);
1181 uint32_t num_feedbacks = ac_ib_get(ib);
1182 fprintf(f, " allowed max num feedbacks = %u\n", num_feedbacks);
1183 } else if (op == cmd.session_init) {
1184 fprintf(f, "%sSESSION_INIT%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1185 uint32_t standard = ac_ib_get(ib);
1186 fprintf(f, " encode standard = %s\n",
1187 standard == RENCODE_ENCODE_STANDARD_H264 ? "H264" :
1188 standard == RENCODE_ENCODE_STANDARD_HEVC ? "HEVC" :
1189 standard == RENCODE_ENCODE_STANDARD_AV1 ? "AV1" :
1190 "???");
1191 uint32_t pic_width = ac_ib_get(ib);
1192 fprintf(f, " aligned picture width = %u\n", pic_width);
1193 uint32_t pic_height = ac_ib_get(ib);
1194 fprintf(f, " aligned picture height = %u\n", pic_height);
1195 uint32_t padding_width = ac_ib_get(ib);
1196 fprintf(f, " padding width = %u\n", padding_width);
1197 uint32_t padding_height = ac_ib_get(ib);
1198 fprintf(f, " padding height = %u\n", padding_height);
1199 uint32_t preenc = ac_ib_get(ib);
1200 fprintf(f, " preencode mode = %s\n",
1201 preenc == RENCODE_PREENCODE_MODE_NONE ? "NONE" :
1202 preenc == RENCODE_PREENCODE_MODE_1X ? "1X" :
1203 preenc == RENCODE_PREENCODE_MODE_2X ? "2X" :
1204 preenc == RENCODE_PREENCODE_MODE_4X ? "4X" :
1205 "???");
1206 uint32_t preenc_chroma = ac_ib_get(ib);
1207 fprintf(f, " preencode chroma enabled = %u\n", preenc_chroma);
1208 if (ib->vcn_version >= VCN_3_0_0) {
1209 uint32_t slice_output = ac_ib_get(ib);
1210 fprintf(f, " slice output enabled = %u\n", slice_output);
1211 }
1212 uint32_t display_remote = ac_ib_get(ib);
1213 fprintf(f, " display remote = %u\n", display_remote);
1214 if (ib->vcn_version >= VCN_4_0_0 && ib->vcn_version < VCN_5_0_0) {
1215 uint32_t wa_flags = ac_ib_get(ib);
1216 fprintf(f, " WA flags = %u\n", wa_flags);
1217 }
1218 } else if (op == cmd.layer_control) {
1219 fprintf(f, "%sLAYER_CONTROL%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1220 uint32_t max_num_layers = ac_ib_get(ib);
1221 fprintf(f, " max num temporal layers = %u\n", max_num_layers);
1222 uint32_t num_layers = ac_ib_get(ib);
1223 fprintf(f, " num temporal layers = %u\n", num_layers);
1224 } else if (op == cmd.layer_select) {
1225 fprintf(f, "%sLAYER_SELECT%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1226 uint32_t index = ac_ib_get(ib);
1227 fprintf(f, " temporal layer index = %u\n", index);
1228 } else if (op == cmd.rc_session_init) {
1229 fprintf(f, "%sRATE_CONTROL_SESSION_INIT%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1230 uint32_t method = ac_ib_get(ib);
1231 fprintf(f, " rate control method = %s\n",
1232 method == RENCODE_RATE_CONTROL_METHOD_NONE ? "NONE" :
1233 method == RENCODE_RATE_CONTROL_METHOD_LATENCY_CONSTRAINED_VBR ? "LATENCY CONSTRAINED VBR" :
1234 method == RENCODE_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR ? "PEAK CONSTRAINED VBR" :
1235 method == RENCODE_RATE_CONTROL_METHOD_CBR ? "CBR" :
1236 method == RENCODE_RATE_CONTROL_METHOD_QUALITY_VBR ? "QUALITY VBR" :
1237 "???");
1238 uint32_t buf_lvl = ac_ib_get(ib);
1239 fprintf(f, " vbv buffer level = %u\n", buf_lvl);
1240 } else if (op == cmd.rc_layer_init) {
1241 fprintf(f, "%sRATE_CONTROL_LAYER_INIT%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1242 uint32_t target_bitrate = ac_ib_get(ib);
1243 fprintf(f, " target bitrate = %u\n", target_bitrate);
1244 uint32_t peak_bitrate = ac_ib_get(ib);
1245 fprintf(f, " peak bitrate = %u\n", peak_bitrate);
1246 uint32_t frame_rate_num = ac_ib_get(ib);
1247 fprintf(f, " frame rate numerator = %u\n", frame_rate_num);
1248 uint32_t frame_rate_den = ac_ib_get(ib);
1249 fprintf(f, " frame rate denominator = %u\n", frame_rate_den);
1250 uint32_t vbv_size = ac_ib_get(ib);
1251 fprintf(f, " vbv buffer size = %u\n", vbv_size);
1252 uint32_t avg_bits = ac_ib_get(ib);
1253 fprintf(f, " average target bits per picture = %u\n", avg_bits);
1254 uint32_t peak_bits_integer = ac_ib_get(ib);
1255 fprintf(f, " peak bits per picture (integer) = %u\n", peak_bits_integer);
1256 uint32_t peak_bits_fractional = ac_ib_get(ib);
1257 fprintf(f, " peak bits per picture (fractional) = %u\n", peak_bits_fractional);
1258 } else if (op == cmd.quality_params) {
1259 fprintf(f, "%sQUALITY_PARAMS%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1260 uint32_t vbaq_mode = ac_ib_get(ib);
1261 fprintf(f, " VBAQ mode = %s\n",
1262 vbaq_mode == RENCODE_VBAQ_NONE ? "NONE" :
1263 vbaq_mode == RENCODE_VBAQ_AUTO ? "AUTO" :
1264 "???");
1265 uint32_t scene_change_sens = ac_ib_get(ib);
1266 fprintf(f, " scene change sensitivity = %u\n", scene_change_sens);
1267 uint32_t scene_change_interval = ac_ib_get(ib);
1268 fprintf(f, " scene change min IDR interval = %u\n", scene_change_interval);
1269 uint32_t search_map_mode = ac_ib_get(ib);
1270 fprintf(f, " 2-pass search center map mode = %u\n", search_map_mode);
1271 if (ib->vcn_version >= VCN_2_0_0) {
1272 uint32_t vbaq_strength = ac_ib_get(ib);
1273 fprintf(f, " VBAQ strength = %u\n", vbaq_strength);
1274 }
1275 } else if (op == cmd.slice_control_hevc) {
1276 fprintf(f, "%sHEVC_SLICE_CONTROL%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1277 uint32_t mode = ac_ib_get(ib);
1278 fprintf(f, " slice control mode = %s\n",
1279 mode == RENCODE_HEVC_SLICE_CONTROL_MODE_FIXED_CTBS ? "FIXED CTBS" :
1280 mode == RENCODE_HEVC_SLICE_CONTROL_MODE_FIXED_BITS ? "FIXED BITS" :
1281 "???");
1282 uint32_t per_slice = ac_ib_get(ib);
1283 fprintf(f, " num %s per slice = %u\n",
1284 mode == RENCODE_HEVC_SLICE_CONTROL_MODE_FIXED_CTBS ? "ctbs" : "bits", per_slice);
1285 uint32_t per_slice_segment = ac_ib_get(ib);
1286 fprintf(f, " num %s per slice segment = %u\n",
1287 mode == RENCODE_HEVC_SLICE_CONTROL_MODE_FIXED_CTBS ? "ctbs" : "bits", per_slice_segment);
1288 } else if (op == cmd.spec_misc_hevc) {
1289 fprintf(f, "%sHEVC_SPEC_MISC%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1290 uint32_t min_coding_block_size = ac_ib_get(ib);
1291 fprintf(f, " log2_min_luma_coding_block_size_minus3 = %u\n", min_coding_block_size);
1292 uint32_t amp_disabled = ac_ib_get(ib);
1293 fprintf(f, " amp disabled = %u\n", amp_disabled);
1294 uint32_t intra_smooth = ac_ib_get(ib);
1295 fprintf(f, " strong_intra_smoothing_enabled_flag = %u\n", intra_smooth);
1296 uint32_t constrained_intra = ac_ib_get(ib);
1297 fprintf(f, " constrained_intra_pred_flag = %u\n", constrained_intra);
1298 uint32_t cabac_init_flag = ac_ib_get(ib);
1299 fprintf(f, " cabac_init_flag = %u\n", cabac_init_flag);
1300 uint32_t half_pel_enabled = ac_ib_get(ib);
1301 fprintf(f, " half pel motion estimation = %u\n", half_pel_enabled);
1302 uint32_t quarter_pel_enabled = ac_ib_get(ib);
1303 fprintf(f, " quarter pel motion estimation = %u\n", quarter_pel_enabled);
1304 if (ib->vcn_version >= VCN_3_0_0) {
1305 uint32_t transform_skip_disabled = ac_ib_get(ib);
1306 fprintf(f, " transform skip disabled = %u\n", transform_skip_disabled);
1307 if (ib->vcn_version >= VCN_5_0_0) {
1308 uint32_t transquant_bypass = ac_ib_get(ib);
1309 fprintf(f, " transquant bypass enabled = %u\n", transquant_bypass);
1310 }
1311 }
1312 if (ib->vcn_version >= VCN_2_0_0) {
1313 uint32_t cu_qp_delta = ac_ib_get(ib);
1314 fprintf(f, " cu_qp_delta_enabled_flag = %u\n", cu_qp_delta);
1315 }
1316 } else if (op == cmd.deblocking_filter_hevc) {
1317 fprintf(f, "%sHEVC_DEBLOCKING_FILTER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1318 uint32_t across_slices = ac_ib_get(ib);
1319 fprintf(f, " loop filter across slices enabled = %u\n", across_slices);
1320 uint32_t deblock_disabled = ac_ib_get(ib);
1321 fprintf(f, " deblocking filter disabled = %u\n", deblock_disabled);
1322 uint32_t beta_offset = ac_ib_get(ib);
1323 fprintf(f, " beta offset div2 = %u\n", beta_offset);
1324 uint32_t tc_offset = ac_ib_get(ib);
1325 fprintf(f, " tc offset div2 = %u\n", tc_offset);
1326 uint32_t cb_qp_offset = ac_ib_get(ib);
1327 fprintf(f, " cb_qp_offset = %u\n", cb_qp_offset);
1328 uint32_t cr_qp_offset = ac_ib_get(ib);
1329 fprintf(f, " cr_qp_offset = %u\n", cr_qp_offset);
1330 if (ib->vcn_version >= VCN_2_0_0) {
1331 uint32_t disable_sao = ac_ib_get(ib);
1332 fprintf(f, " force disable SAO = %u\n", disable_sao);
1333 }
1334 } else if (op == cmd.slice_control_h264) {
1335 fprintf(f, "%sH264_SLICE_CONTROL%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1336 uint32_t mode = ac_ib_get(ib);
1337 fprintf(f, " slice control mode = %s\n",
1338 mode == RENCODE_H264_SLICE_CONTROL_MODE_FIXED_MBS ? "FIXED MBS" :
1339 mode == RENCODE_H264_SLICE_CONTROL_MODE_FIXED_BITS ? "FIXED BITS" :
1340 "???");
1341 uint32_t per_slice = ac_ib_get(ib);
1342 fprintf(f, " num %s per slice = %u\n",
1343 mode == RENCODE_H264_SLICE_CONTROL_MODE_FIXED_MBS ? "mbs" : "bits", per_slice);
1344 } else if (op == cmd.spec_misc_h264) {
1345 fprintf(f, "%sH264_SPEC_MISC%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1346 uint32_t constrained_intra = ac_ib_get(ib);
1347 fprintf(f, " constrained_intra_pred_flag = %u\n", constrained_intra);
1348 uint32_t cabac_enable = ac_ib_get(ib);
1349 fprintf(f, " cabac enable = %u\n", cabac_enable);
1350 uint32_t cabac_init_idc = ac_ib_get(ib);
1351 fprintf(f, " cabac_init_idc = %u\n", cabac_init_idc);
1352 if (ib->vcn_version >= VCN_5_0_0) {
1353 uint32_t transform8x8 = ac_ib_get(ib);
1354 fprintf(f, " transform 8x8 enable = %u\n", transform8x8);
1355 }
1356 uint32_t half_pel_enabled = ac_ib_get(ib);
1357 fprintf(f, " half pel motion estimation = %u\n", half_pel_enabled);
1358 uint32_t quarter_pel_enabled = ac_ib_get(ib);
1359 fprintf(f, " quarter pel motion estimation = %u\n", quarter_pel_enabled);
1360 uint32_t profile_idc = ac_ib_get(ib);
1361 fprintf(f, " profile_idc = %u\n", profile_idc);
1362 uint32_t level_idc = ac_ib_get(ib);
1363 fprintf(f, " level_idc = %u\n", level_idc);
1364 if (ib->vcn_version >= VCN_3_0_0) {
1365 uint32_t b_pic = ac_ib_get(ib);
1366 fprintf(f, " B picture enabled = %u\n", b_pic);
1367 uint32_t weighted_bipred = ac_ib_get(ib);
1368 fprintf(f, " weighted_bipred_idc = %u\n", weighted_bipred);
1369 }
1370 } else if (op == cmd.enc_params_h264) {
1371 fprintf(f, "%sH264_ENCODE_PARAMS%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1372 uint32_t input_structure = ac_ib_get(ib);
1373 fprintf(f, " input picture structure = %s\n", vcn_picture_structure(input_structure));
1374 if (ib->vcn_version >= VCN_3_0_0) {
1375 uint32_t pic_order_cnt = ac_ib_get(ib);
1376 fprintf(f, " input pic order cnt = %u\n", pic_order_cnt);
1377 if (ib->vcn_version >= VCN_5_0_0) {
1378 uint32_t ref = ac_ib_get(ib);
1379 fprintf(f, " is reference = %u\n", ref);
1380 uint32_t long_term = ac_ib_get(ib);
1381 fprintf(f, " is long term reference = %u\n", long_term);
1382 }
1383 }
1384 uint32_t interlaced_mode = ac_ib_get(ib);
1385 fprintf(f, " interlaced mode = %s\n",
1386 interlaced_mode == RENCODE_H264_INTERLACING_MODE_PROGRESSIVE ? "PROGRESSIVE" :
1387 interlaced_mode == RENCODE_H264_INTERLACING_MODE_INTERLACED_STACKED ? "INTERLACED STACKED" :
1388 interlaced_mode == RENCODE_H264_INTERLACING_MODE_INTERLACED_INTERLEAVED ? "INTERLACED INTERLEAVED" :
1389 "???");
1390 if (ib->vcn_version < VCN_3_0_0) {
1391 uint32_t ref_pic_structure = ac_ib_get(ib);
1392 fprintf(f, " reference picture structure = %s\n", vcn_picture_structure(ref_pic_structure));
1393 uint32_t ref_pic1_index = ac_ib_get(ib);
1394 fprintf(f, " reference picture1 index = %u\n", ref_pic1_index);
1395 } else if (ib->vcn_version < VCN_5_0_0) {
1396 print_vcn_ref_pic_info(f, ib, " l0[0] reference");
1397 uint32_t l0_pic1_idx = ac_ib_get(ib);
1398 fprintf(f, " l0[1] reference picture index = %u\n", l0_pic1_idx);
1399 print_vcn_ref_pic_info(f, ib, " l0[1] reference");
1400 uint32_t l1_pic0_idx = ac_ib_get(ib);
1401 fprintf(f, " l1[0] reference picture index = %u\n", l1_pic0_idx);
1402 print_vcn_ref_pic_info(f, ib, " l1[0] reference");
1403 uint32_t ref = ac_ib_get(ib);
1404 fprintf(f, " is reference = %u\n", ref);
1405 } else if (ib->vcn_version >= VCN_5_0_0) {
1406 for (uint32_t i = 0; i < RENCODE_H264_MAX_REFERENCE_LIST_SIZE; i++) {
1407 uint32_t idx = ac_ib_get(ib);
1408 fprintf(f, " ref_list0[%u] = %u\n", i, idx);
1409 }
1410 uint32_t num_refs0 = ac_ib_get(ib);
1411 fprintf(f, " num active references l0 = %u\n", num_refs0);
1412 for (uint32_t i = 0; i < RENCODE_H264_MAX_REFERENCE_LIST_SIZE; i++) {
1413 uint32_t idx = ac_ib_get(ib);
1414 fprintf(f, " ref_list1[%u] = %u\n", i, idx);
1415 }
1416 uint32_t num_refs1 = ac_ib_get(ib);
1417 fprintf(f, " num active references l1 = %u\n", num_refs1);
1418 for (uint32_t i = 0; i < 2; i++) {
1419 uint32_t list = ac_ib_get(ib);
1420 fprintf(f, " lsm_reference_pictures[%u].list = %u\n", i, list);
1421 uint32_t list_index = ac_ib_get(ib);
1422 fprintf(f, " lsm_reference_pictures[%u].list_index = %u\n", i, list_index);
1423 }
1424 }
1425 } else if (op == cmd.deblocking_filter_h264) {
1426 fprintf(f, "%sH264_DEBLOCKING_FILTER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1427 uint32_t disable_filter = ac_ib_get(ib);
1428 fprintf(f, " disable_deblocking_filter_idc = %u\n", disable_filter);
1429 uint32_t alpha_offset = ac_ib_get(ib);
1430 fprintf(f, " alpha c0 offset div2 = %u\n", alpha_offset);
1431 uint32_t beta_offset = ac_ib_get(ib);
1432 fprintf(f, " beta offset div2 = %u\n", beta_offset);
1433 uint32_t cb_qp_offset = ac_ib_get(ib);
1434 fprintf(f, " cb_qp_offset = %u\n", cb_qp_offset);
1435 uint32_t cr_qp_offset = ac_ib_get(ib);
1436 fprintf(f, " cr_qp_offset = %u\n", cr_qp_offset);
1437 } else if (ib->vcn_version < VCN_5_0_0 && op == cmd.rc_per_pic) {
1438 fprintf(f, "%sRATE_CONTROL_PER_PICTURE%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1439 uint32_t qp = ac_ib_get(ib);
1440 fprintf(f, " QP = %u\n", qp);
1441 uint32_t min_qp = ac_ib_get(ib);
1442 fprintf(f, " min QP = %u\n", min_qp);
1443 uint32_t max_qp = ac_ib_get(ib);
1444 fprintf(f, " max QP = %u\n", max_qp);
1445 uint32_t max_au_size = ac_ib_get(ib);
1446 fprintf(f, " max access unit size = %u\n", max_au_size);
1447 uint32_t filler_data = ac_ib_get(ib);
1448 fprintf(f, " filler data enabled = %u\n", filler_data);
1449 uint32_t skip_frame = ac_ib_get(ib);
1450 fprintf(f, " skip frame enabled = %u\n", skip_frame);
1451 uint32_t enforce_hrd = ac_ib_get(ib);
1452 fprintf(f, " enforce HRD = %u\n", enforce_hrd);
1453 } else if ((ib->vcn_version >= VCN_5_0_0 && op == cmd.rc_per_pic) ||
1454 (ib->vcn_version < VCN_5_0_0 && op == cmd.rc_per_pic_ex)) {
1455 fprintf(f, "%sRATE_CONTROL_PER_PICTURE%s%s\n", O_COLOR_GREEN, ib->vcn_version < VCN_5_0_0 ? "_EX" : "", O_COLOR_RESET);
1456 uint32_t qp_i = ac_ib_get(ib);
1457 fprintf(f, " QP I = %u\n", qp_i);
1458 uint32_t qp_p = ac_ib_get(ib);
1459 fprintf(f, " QP P = %u\n", qp_p);
1460 uint32_t qp_b = ac_ib_get(ib);
1461 fprintf(f, " QP B = %u\n", qp_b);
1462 uint32_t min_qp_i = ac_ib_get(ib);
1463 fprintf(f, " min QP I = %u\n", min_qp_i);
1464 uint32_t max_qp_i = ac_ib_get(ib);
1465 fprintf(f, " max QP I = %u\n", max_qp_i);
1466 uint32_t min_qp_p = ac_ib_get(ib);
1467 fprintf(f, " min QP P = %u\n", min_qp_p);
1468 uint32_t max_qp_p = ac_ib_get(ib);
1469 fprintf(f, " max QP P = %u\n", max_qp_p);
1470 uint32_t min_qp_b = ac_ib_get(ib);
1471 fprintf(f, " min QP B = %u\n", min_qp_b);
1472 uint32_t max_qp_b = ac_ib_get(ib);
1473 fprintf(f, " max QP B = %u\n", max_qp_b);
1474 uint32_t max_au_size_i = ac_ib_get(ib);
1475 fprintf(f, " max access unit size I = %u\n", max_au_size_i);
1476 uint32_t max_au_size_p = ac_ib_get(ib);
1477 fprintf(f, " max access unit size P = %u\n", max_au_size_p);
1478 uint32_t max_au_size_b = ac_ib_get(ib);
1479 fprintf(f, " max access unit size B = %u\n", max_au_size_b);
1480 uint32_t filler_data = ac_ib_get(ib);
1481 fprintf(f, " filler data enabled = %u\n", filler_data);
1482 uint32_t skip_frame = ac_ib_get(ib);
1483 fprintf(f, " skip frame enabled = %u\n", skip_frame);
1484 uint32_t enforce_hrd = ac_ib_get(ib);
1485 fprintf(f, " enforce HRD = %u\n", enforce_hrd);
1486 if (ib->vcn_version >= VCN_3_0_0) {
1487 uint32_t qvbr_level = ac_ib_get(ib);
1488 fprintf(f, " QVBR quality level = %u\n", qvbr_level);
1489 }
1490 } else if (op == cmd.slice_header) {
1491 fprintf(f, "%sSLICE_HEADER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1492 for (uint32_t i = 0; i < RENCODE_SLICE_HEADER_TEMPLATE_MAX_TEMPLATE_SIZE_IN_DWORDS; i++) {
1493 uint32_t value = ac_ib_get(ib);
1494 fprintf(f, " %s\n", value ? "bitstream template" : "");
1495 }
1496 bool at_end = false;
1497 for (uint32_t i = 0; i < RENCODE_SLICE_HEADER_TEMPLATE_MAX_NUM_INSTRUCTIONS; i++) {
1498 if (at_end) {
1499 ib->cur_dw += 2;
1500 continue;
1501 }
1502 uint32_t instruction = ac_ib_get(ib);
1503 fprintf(f, " instruction = %s\n",
1504 instruction == RENCODE_HEADER_INSTRUCTION_END ? "END" :
1505 instruction == RENCODE_HEADER_INSTRUCTION_COPY ? "COPY" :
1506 instruction == RENCODE_HEVC_HEADER_INSTRUCTION_DEPENDENT_SLICE_END ? "DEPENDENT SLICE END" :
1507 instruction == RENCODE_HEVC_HEADER_INSTRUCTION_FIRST_SLICE ? "FIRST SLICE" :
1508 instruction == RENCODE_HEVC_HEADER_INSTRUCTION_SLICE_SEGMENT ? "SLICE SEGMENT" :
1509 instruction == RENCODE_HEVC_HEADER_INSTRUCTION_SLICE_QP_DELTA ? "SLICE QP DELTA" :
1510 instruction == RENCODE_HEVC_HEADER_INSTRUCTION_SAO_ENABLE ? "SAO ENABLE" :
1511 instruction == RENCODE_HEVC_HEADER_INSTRUCTION_LOOP_FILTER_ACROSS_SLICES_ENABLE ? "LOOP FILTER ACROSS SLICES ENABLE" :
1512 instruction == RENCODE_H264_HEADER_INSTRUCTION_FIRST_MB ? "FIRST MB" :
1513 instruction == RENCODE_H264_HEADER_INSTRUCTION_SLICE_QP_DELTA ? "SLICE QP DELTA" :
1514 "???");
1515 uint32_t bits = ac_ib_get(ib);
1516 if (instruction == RENCODE_HEADER_INSTRUCTION_COPY)
1517 fprintf(f, " num bits = %u\n", bits);
1518 else
1519 fprintf(f, "\n");
1520 at_end = instruction == RENCODE_HEADER_INSTRUCTION_END;
1521 }
1522 } else if (op == cmd.enc_params) {
1523 fprintf(f, "%sENCODE_PARAMS%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1524 uint32_t pic_type = ac_ib_get(ib);
1525 fprintf(f, " picture type = %s\n", vcn_picture_type(pic_type));
1526 uint32_t bs_size = ac_ib_get(ib);
1527 fprintf(f, " allowed max bitstream size = %u\n", bs_size);
1528 print_vcn_addr(f, ib, " input picture luma");
1529 print_vcn_addr(f, ib, " input picture chroma");
1530 uint32_t luma_pitch = ac_ib_get(ib);
1531 fprintf(f, " input picture luma pitch = %u\n", luma_pitch);
1532 uint32_t chroma_pitch = ac_ib_get(ib);
1533 fprintf(f, " input picture chroma pitch = %u\n", chroma_pitch);
1534 uint32_t swizzle = ac_ib_get(ib);
1535 fprintf(f, " input picture swizzle mode = %s\n",
1536 swizzle == RENCODE_INPUT_SWIZZLE_MODE_LINEAR ? "LINEAR" :
1537 swizzle == RENCODE_INPUT_SWIZZLE_MODE_256B_S ? "256B S" :
1538 swizzle == RENCODE_INPUT_SWIZZLE_MODE_4kB_S ? "4kB S" :
1539 swizzle == RENCODE_INPUT_SWIZZLE_MODE_64kB_S ? "64kB S" :
1540 "???");
1541 if (ib->vcn_version < VCN_5_0_0) {
1542 uint32_t ref_pic_idx = ac_ib_get(ib);
1543 fprintf(f, " reference picture index = %u\n", ref_pic_idx);
1544 }
1545 uint32_t recon_pic_idx = ac_ib_get(ib);
1546 fprintf(f, " reconstructed picture index = %u\n", recon_pic_idx);
1547 } else if (op == cmd.intra_refresh) {
1548 fprintf(f, "%sINTRA_REFRESH%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1549 uint32_t mode = ac_ib_get(ib);
1550 fprintf(f, " intra refresh mode = %s\n",
1551 mode == RENCODE_INTRA_REFRESH_MODE_NONE ? "NONE" :
1552 mode == RENCODE_INTRA_REFRESH_MODE_CTB_MB_ROWS ? "CTB MB ROWS" :
1553 mode == RENCODE_INTRA_REFRESH_MODE_CTB_MB_COLUMNS ? "CTB MB COLUMNS" :
1554 "???");
1555 uint32_t offset = ac_ib_get(ib);
1556 fprintf(f, " offset = %u\n", offset);
1557 uint32_t region_size = ac_ib_get(ib);
1558 fprintf(f, " region size = %u\n", region_size);
1559 } else if (op == cmd.ctx) {
1560 fprintf(f, "%sENCODE_CONTEXT_BUFFER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1561 print_vcn_addr(f, ib, " encode context buffer");
1562 if (ib->vcn_version < VCN_5_0_0) {
1563 uint32_t swizzle = ac_ib_get(ib);
1564 fprintf(f, " swizzle mode = %s\n",
1565 swizzle == RENCODE_REC_SWIZZLE_MODE_LINEAR ? "LINEAR" :
1566 (ib->vcn_version < VCN_5_0_0 && swizzle == RENCODE_REC_SWIZZLE_MODE_256B_D) ||
1567 (ib->vcn_version >= VCN_5_0_0 && swizzle == RENCODE_REC_SWIZZLE_MODE_256B_D_VCN5) ? "256B D" :
1568 swizzle == RENCODE_REC_SWIZZLE_MODE_256B_S ? "256B S" :
1569 swizzle == RENCODE_REC_SWIZZLE_MODE_8x8_1D_THIN_12_24BPP ? "8x8 1D THIN 12 24BPP" :
1570 "???");
1571 uint32_t luma_pitch = ac_ib_get(ib);
1572 fprintf(f, " reconstructed surface luma pitch = %u\n", luma_pitch);
1573 uint32_t chroma_pitch = ac_ib_get(ib);
1574 fprintf(f, " reconstructed surface chroma pitch = %u\n", chroma_pitch);
1575 }
1576 uint32_t num_recons = ac_ib_get(ib);
1577 fprintf(f, " num reconstructed pictures = %u\n", num_recons);
1578 for (uint32_t i = 0; i < RENCODE_MAX_NUM_RECONSTRUCTED_PICTURES; i++)
1579 print_vcn_reconstructed_picture(f, ib, i < num_recons, " recon[%u]", i);
1580 if (ib->vcn_version >= VCN_3_0_0 && ib->vcn_version < VCN_4_0_0) {
1581 uint32_t colloc_offset = ac_ib_get(ib);
1582 fprintf(f, " collocated buffer offset = %u\n", colloc_offset);
1583 }
1584 if (ib->vcn_version < VCN_5_0_0) {
1585 uint32_t luma_pitch = ac_ib_get(ib);
1586 fprintf(f, " preencode reconstructed surface luma pitch = %u\n", luma_pitch);
1587 uint32_t chroma_pitch = ac_ib_get(ib);
1588 fprintf(f, " preencode reconstructed surface chroma pitch = %u\n", chroma_pitch);
1589 }
1590 for (uint32_t i = 0; i < RENCODE_MAX_NUM_RECONSTRUCTED_PICTURES; i++)
1591 print_vcn_reconstructed_picture(f, ib, i < num_recons, " preenc recon[%u]", i);
1592 if (ib->vcn_version >= VCN_5_0_0) {
1593 uint32_t luma_pitch = ac_ib_get(ib);
1594 fprintf(f, " preencode input surface luma pitch = %u\n", luma_pitch);
1595 uint32_t chroma_pitch = ac_ib_get(ib);
1596 fprintf(f, " preencode input surface chroma pitch = %u\n", chroma_pitch);
1597 }
1598 if (ib->vcn_version < VCN_2_0_0)
1599 print_vcn_reconstructed_picture(f, ib, true, " preencode input");
1600 else if (ib->vcn_version < VCN_3_0_0)
1601 print_vcn_reconstructed_picture(f, ib, true, " preencode input old");
1602 else
1603 print_vcn_preencode_input_picture(f, ib, " preencode input");
1604 if (ib->vcn_version < VCN_5_0_0) {
1605 uint32_t search_offset = ac_ib_get(ib);
1606 fprintf(f, " 2-pass search center map offset = %u\n", search_offset);
1607 }
1608 if (ib->vcn_version >= VCN_2_0_0 && ib->vcn_version < VCN_3_0_0)
1609 print_vcn_preencode_input_picture(f, ib, " preencode input");
1610 if (ib->vcn_version >= VCN_4_0_0 && ib->vcn_version < VCN_5_0_0) {
1611 uint32_t colloc_offset = ac_ib_get(ib);
1612 fprintf(f, " colloc buffer offset / AV1 sdb intermediate context offset = %u\n", colloc_offset);
1613 } else if (ib->vcn_version >= VCN_5_0_0) {
1614 uint32_t sdb_offset = ac_ib_get(ib);
1615 fprintf(f, " AV1 sdb intermediate context offset = %u\n", sdb_offset);
1616 }
1617 } else if (op == cmd.bitstream) {
1618 fprintf(f, "%sVIDEO_BITSTREAM_BUFFER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1619 uint32_t mode = ac_ib_get(ib);
1620 fprintf(f, " mode = %s\n",
1621 mode == RENCODE_VIDEO_BITSTREAM_BUFFER_MODE_LINEAR ? "LINEAR" :
1622 mode == RENCODE_VIDEO_BITSTREAM_BUFFER_MODE_CIRCULAR ? "CIRCULAR" :
1623 "???");
1624 print_vcn_addr(f, ib, " video bitstream buffer");
1625 uint32_t size = ac_ib_get(ib);
1626 fprintf(f, " video bitstream buffer size = %u\n", size);
1627 uint32_t offset = ac_ib_get(ib);
1628 fprintf(f, " video bitstream buffer data offset = %u\n", offset);
1629 } else if (op == cmd.feedback) {
1630 fprintf(f, "%sFEEDBACK_BUFFER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1631 uint32_t mode = ac_ib_get(ib);
1632 fprintf(f, " mode = %s\n",
1633 mode == RENCODE_FEEDBACK_BUFFER_MODE_LINEAR ? "LINEAR" :
1634 mode == RENCODE_FEEDBACK_BUFFER_MODE_CIRCULAR ? "CIRCULAR" :
1635 "???");
1636 print_vcn_addr(f, ib, " feedback buffer");
1637 uint32_t size = ac_ib_get(ib);
1638 fprintf(f, " feedback buffer size = %u\n", size);
1639 uint32_t data_size = ac_ib_get(ib);
1640 fprintf(f, " feedback buffer data size = %u\n", data_size);
1641 } else if (op == cmd.enc_qp_map) {
1642 fprintf(f, "%sQP_MAP%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1643 uint32_t type = ac_ib_get(ib);
1644 fprintf(f, " QP map type = %s\n",
1645 type == RENCODE_QP_MAP_TYPE_NONE ? "NONE" :
1646 type == RENCODE_QP_MAP_TYPE_DELTA ? "DELTA" :
1647 type == RENCODE_QP_MAP_TYPE_MAP_PA ? "PA" :
1648 "???");
1649 print_vcn_addr(f, ib, " QP map buffer");
1650 uint32_t pitch = ac_ib_get(ib);
1651 fprintf(f, " QP map buffer pitch = %u\n", pitch);
1652 } else if (op == cmd.enc_statistics) {
1653 fprintf(f, "%sENCODE_STATISTICS%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1654 uint32_t type = ac_ib_get(ib);
1655 fprintf(f, " encode statistics type = %u\n", type);
1656 print_vcn_addr(f, ib, " encode statistics buffer");
1657 } else if (op == cmd.enc_latency) {
1658 fprintf(f, "%sENCODE_LATENCY%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1659 uint32_t latency = ac_ib_get(ib);
1660 fprintf(f, " encode latency = %u\n", latency);
1661 } else if (op == cmd.input_format) {
1662 fprintf(f, "%sINPUT_FORMAT%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1663 uint32_t color_volume = ac_ib_get(ib);
1664 fprintf(f, " color volume = %s\n", vcn_color_volume(color_volume));
1665 uint32_t color_space = ac_ib_get(ib);
1666 fprintf(f, " color space = %s\n",
1667 color_space == RENCODE_COLOR_SPACE_RGB ? "RGB" :
1668 color_space == RENCODE_COLOR_SPACE_YUV ? "YUV" :
1669 "???");
1670 uint32_t color_range = ac_ib_get(ib);
1671 fprintf(f, " color range = %s\n", vcn_color_range(color_range));
1672 uint32_t chroma_subsampling = ac_ib_get(ib);
1673 fprintf(f, " chroma subsampling = %s\n", vcn_chroma_subsampling(chroma_subsampling));
1674 uint32_t chroma_location = ac_ib_get(ib);
1675 fprintf(f, " chroma location = %s\n", vcn_chroma_location(chroma_location));
1676 uint32_t bit_depth = ac_ib_get(ib);
1677 fprintf(f, " color bit depth = %s\n", vcn_color_bit_depth(bit_depth));
1678 uint32_t packing_format = ac_ib_get(ib);
1679 fprintf(f, " packing format = %s\n",
1680 packing_format == RENCODE_COLOR_PACKING_FORMAT_NV12 ? "NV12" :
1681 packing_format == RENCODE_COLOR_PACKING_FORMAT_P010 ? "P010" :
1682 packing_format == RENCODE_COLOR_PACKING_FORMAT_A8R8G8B8 ? "A8R8G8B8" :
1683 packing_format == RENCODE_COLOR_PACKING_FORMAT_A2R10G10B10 ? "A2R10G10B10" :
1684 packing_format == RENCODE_COLOR_PACKING_FORMAT_A8B8G8R8 ? "A8B8G8R8" :
1685 packing_format == RENCODE_COLOR_PACKING_FORMAT_A2B10G10R10 ? "A2B10G10R10" :
1686 "???");
1687 } else if (op == cmd.output_format) {
1688 fprintf(f, "%sOUTPUT_FORMAT%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1689 uint32_t color_volume = ac_ib_get(ib);
1690 fprintf(f, " color volume = %s\n", vcn_color_volume(color_volume));
1691 uint32_t color_range = ac_ib_get(ib);
1692 fprintf(f, " color range = %s\n", vcn_color_range(color_range));
1693 uint32_t chroma_location = ac_ib_get(ib);
1694 if (ib->vcn_version >= VCN_5_0_0) {
1695 uint32_t chroma_subsampling = ac_ib_get(ib);
1696 fprintf(f, " chroma subsampling = %s\n", vcn_chroma_subsampling(chroma_subsampling));
1697 }
1698 fprintf(f, " chroma location = %s\n", vcn_chroma_location(chroma_location));
1699 uint32_t bit_depth = ac_ib_get(ib);
1700 fprintf(f, " color bit depth = %s\n", vcn_color_bit_depth(bit_depth));
1701 } else if (op == cmd.cdf_default_table_av1) {
1702 fprintf(f, "%sCDF_DEFAULT_TABLE_BUFFER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1703 uint32_t use_default = ac_ib_get(ib);
1704 fprintf(f, " use cdf default = %u\n", use_default);
1705 ac_ib_get(ib);
1706 fprintf(f, " cdf default buffer VA low\n");
1707 ac_ib_get(ib);
1708 fprintf(f, " cdf default buffer VA high\n");
1709 } else if (op == cmd.spec_misc_av1) {
1710 fprintf(f, "%sAV1_SPEC_MISC%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1711 uint32_t palette = ac_ib_get(ib);
1712 fprintf(f, " palette mode enable = %u\n", palette);
1713 uint32_t mv_precision = ac_ib_get(ib);
1714 fprintf(f, " motion vector precision = %s\n",
1715 mv_precision == RENCODE_AV1_MV_PRECISION_ALLOW_HIGH_PRECISION ? "ALLOW HIGH PRECISION" :
1716 mv_precision == RENCODE_AV1_MV_PRECISION_DISALLOW_HIGH_PRECISION ? "DISALLOW HIGH PRECISION" :
1717 mv_precision == RENCODE_AV1_MV_PRECISION_FORCE_INTEGER_MV ? "FORCE INTEGER MV" :
1718 "???");
1719 uint32_t cdef_mode = ac_ib_get(ib);
1720 fprintf(f, " cdef mode = %s\n",
1721 cdef_mode == RENCODE_AV1_CDEF_MODE_DISABLE ? "DISABLE" :
1722 cdef_mode == RENCODE_AV1_CDEF_MODE_DEFAULT ? "DEFAULT" :
1723 cdef_mode == RENCODE_AV1_CDEF_MODE_EXPLICIT ? "EXPLICIT" :
1724 "???");
1725 if (ib->vcn_version >= VCN_5_0_0) {
1726 uint32_t cdef_bits = ac_ib_get(ib);
1727 fprintf(f, " cdef_bits = %u\n", cdef_bits);
1728 uint32_t cdef_damping_minus_3 = ac_ib_get(ib);
1729 fprintf(f, " cdef_damping_minus_3 = %u\n", cdef_damping_minus_3);
1730 for (uint32_t i = 0; i < RENCODE_AV1_CDEF_MAX_NUM; i++) {
1731 uint32_t cdef_y_pri_strength = ac_ib_get(ib);
1732 fprintf(f, " cdef_y_pri_strength[%u] = %u\n", i, cdef_y_pri_strength);
1733 }
1734 for (uint32_t i = 0; i < RENCODE_AV1_CDEF_MAX_NUM; i++) {
1735 uint32_t cdef_y_sec_strength = ac_ib_get(ib);
1736 fprintf(f, " cdef_y_sec_strength[%u] = %u\n", i, cdef_y_sec_strength);
1737 }
1738 for (uint32_t i = 0; i < RENCODE_AV1_CDEF_MAX_NUM; i++) {
1739 uint32_t cdef_uv_pri_strength = ac_ib_get(ib);
1740 fprintf(f, " cdef_uv_pri_strength[%u] = %u\n", i, cdef_uv_pri_strength);
1741 }
1742 for (uint32_t i = 0; i < RENCODE_AV1_CDEF_MAX_NUM; i++) {
1743 uint32_t cdef_uv_sec_strength = ac_ib_get(ib);
1744 fprintf(f, " cdef_uv_sec_strength[%u] = %u\n", i, cdef_uv_sec_strength);
1745 }
1746 uint32_t intrabc = ac_ib_get(ib);
1747 fprintf(f, " allow intrabc = %u\n", intrabc);
1748 }
1749 uint32_t cdf_update = ac_ib_get(ib);
1750 fprintf(f, " disable cdf update = %u\n", cdf_update);
1751 uint32_t frame_end_update = ac_ib_get(ib);
1752 fprintf(f, " disable frame end update cdf = %u\n", frame_end_update);
1753 if (ib->vcn_version >= VCN_5_0_0) {
1754 uint32_t skip_mode = ac_ib_get(ib);
1755 fprintf(f, " disallow skip mode = %u\n", skip_mode);
1756 uint32_t delta_q_y_dc = ac_ib_get(ib);
1757 fprintf(f, " delta QYDc = %u\n", delta_q_y_dc);
1758 uint32_t delta_q_u_dc = ac_ib_get(ib);
1759 fprintf(f, " delta QUDc = %u\n", delta_q_u_dc);
1760 uint32_t delta_q_u_ac = ac_ib_get(ib);
1761 fprintf(f, " delta QUAc = %u\n", delta_q_u_ac);
1762 uint32_t delta_q_v_dc = ac_ib_get(ib);
1763 fprintf(f, " delta QVDc = %u\n", delta_q_v_dc);
1764 uint32_t delta_q_v_ac = ac_ib_get(ib);
1765 fprintf(f, " delta QVAc = %u\n", delta_q_v_ac);
1766 } else {
1767 uint32_t num_tiles = ac_ib_get(ib);
1768 fprintf(f, " num tiles per picture = %u\n", num_tiles);
1769 }
1770 uint32_t screen_content_detect = ac_ib_get(ib);
1771 fprintf(f, " enable screen content auto detection = %u\n", screen_content_detect);
1772 uint32_t screen_content_threshold = ac_ib_get(ib);
1773 fprintf(f, " screen content frame percentage threshold = %u\n", screen_content_threshold);
1774 } else if (op == cmd.bitstream_instruction_av1) {
1775 fprintf(f, "%sAV1_BITSTREAM_INSTRUCTION%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1776 while (true) {
1777 ac_ib_get(ib); /* size */
1778 fprintf(f, "\n");
1779 uint32_t type = ac_ib_get(ib);
1780 fprintf(f, " type = %s\n",
1781 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_END ? "END" :
1782 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_COPY ? "COPY" :
1783 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_OBU_START ? "OBU START" :
1784 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_OBU_SIZE ? "OBU SIZE" :
1785 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_OBU_END ? "OBU END" :
1786 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_ALLOW_HIGH_PRECISION_MV ? "ALLOW HIGH PRECISION MV" :
1787 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_DELTA_LF_PARAMS ? "DELTA LF PARAMS" :
1788 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_READ_INTERPOLATION_FILTER ? "READ INTERPOLATION FILTER" :
1789 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_LOOP_FILTER_PARAMS ? "LOOP FILTER PARAMS" :
1790 (ib->vcn_version >= VCN_5_0_0 &&
1791 type == RENCODE_V5_AV1_BITSTREAM_INSTRUCTION_CONTEXT_UPDATE_TILE_ID) ? "CONTEXT UPDATE TILE ID" :
1792 (ib->vcn_version >= VCN_5_0_0 &&
1793 type == RENCODE_V5_AV1_BITSTREAM_INSTRUCTION_BASE_Q_IDX) ? "BASE Q IDX" :
1794 type == RENCODE_V4_AV1_BITSTREAM_INSTRUCTION_TILE_INFO ? "TILE INFO" :
1795 type == RENCODE_V4_AV1_BITSTREAM_INSTRUCTION_QUANTIZATION_PARAMS ? "QUANTIZATION PARAMS" :
1796 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_DELTA_Q_PARAMS ? "DELTA Q PARAMS" :
1797 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_CDEF_PARAMS ? "CDEF PARAMS" :
1798 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_READ_TX_MODE ? "READ TX MODE" :
1799 type == RENCODE_AV1_BITSTREAM_INSTRUCTION_TILE_GROUP_OBU ? "TILE GROUP OBU" :
1800 "???");
1801 if (type == RENCODE_AV1_BITSTREAM_INSTRUCTION_COPY) {
1802 uint32_t num_bits = ac_ib_get(ib);
1803 fprintf(f, " num bits = %u\n", num_bits);
1804 for (uint32_t i = 0; i < num_bits; i += 32) {
1805 ac_ib_get(ib);
1806 fprintf(f, " bitstream data\n");
1807 }
1808 } else if (type == RENCODE_AV1_BITSTREAM_INSTRUCTION_OBU_START) {
1809 uint32_t type = ac_ib_get(ib);
1810 fprintf(f, " OBU type = %s\n",
1811 type == RENCODE_OBU_START_TYPE_FRAME ? "FRAME" :
1812 type == RENCODE_OBU_START_TYPE_FRAME_HEADER ? "FRAME HEADER" :
1813 type == RENCODE_OBU_START_TYPE_TILE_GROUP ? "TILE GROUP" :
1814 "???");
1815 } else if (type == RENCODE_AV1_BITSTREAM_INSTRUCTION_END) {
1816 break;
1817 }
1818 }
1819 } else if (op == cmd.metadata) {
1820 fprintf(f, "%sMETADATA_BUFFER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1821 print_vcn_addr(f, ib, " metadata buffer");
1822 uint32_t search_offset = ac_ib_get(ib);
1823 fprintf(f, " 2-pass search center map offset = %u\n", search_offset);
1824 } else if (op == cmd.enc_params_hevc) {
1825 fprintf(f, "%sHEVC_ENCODE_PARAMS%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1826 for (uint32_t i = 0; i < RENCODE_HEVC_MAX_REFERENCE_LIST_SIZE; i++) {
1827 uint32_t ref = ac_ib_get(ib);
1828 fprintf(f, " ref list[%u] = %u\n", i, ref);
1829 }
1830 uint32_t num_active = ac_ib_get(ib);
1831 fprintf(f, " num active references l0 = %u\n", num_active);
1832 uint32_t lsm_idx = ac_ib_get(ib);
1833 fprintf(f, " lsm reference picture list index = %u\n", lsm_idx);
1834 } else if (op == cmd.tile_config_av1) {
1835 fprintf(f, "%sAV1_TILE_CONFIG%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1836 uint32_t num_cols = ac_ib_get(ib);
1837 fprintf(f, " num tile columns = %u\n", num_cols);
1838 uint32_t num_rows = ac_ib_get(ib);
1839 fprintf(f, " num tile rows = %u\n", num_rows);
1840 for (uint32_t i = 0; i < RENCODE_AV1_TILE_CONFIG_MAX_NUM_COLS; i++) {
1841 uint32_t w = ac_ib_get(ib);
1842 fprintf(f, " tile width[%u] = %u\n", i, w);
1843 }
1844 for (uint32_t i = 0; i < RENCODE_AV1_TILE_CONFIG_MAX_NUM_ROWS; i++) {
1845 uint32_t h = ac_ib_get(ib);
1846 fprintf(f, " tile height[%u] = %u\n", i, h);
1847 }
1848 uint32_t num_groups = ac_ib_get(ib);
1849 fprintf(f, " num tile groups = %u\n", num_groups);
1850 for (uint32_t i = 0; i < RENCODE_AV1_TILE_CONFIG_MAX_NUM_COLS * RENCODE_AV1_TILE_CONFIG_MAX_NUM_ROWS; i++) {
1851 uint32_t start = ac_ib_get(ib);
1852 fprintf(f, " tile group[%u] start = %u\n", i, start);
1853 uint32_t end = ac_ib_get(ib);
1854 fprintf(f, " tile group[%u] end = %u\n", i, end);
1855 }
1856 uint32_t tile_id_mode = ac_ib_get(ib);
1857 fprintf(f, " context update tile id mode = %s\n",
1858 tile_id_mode == RENCODE_AV1_CONTEXT_UPDATE_TILE_ID_MODE_CUSTOMIZED ? "CUSTOMIZED" :
1859 tile_id_mode == RENCODE_AV1_CONTEXT_UPDATE_TILE_ID_MODE_DEFAULT ? "DEFAULT" :
1860 "???");
1861 uint32_t tile_id = ac_ib_get(ib);
1862 fprintf(f, " context_update_tile_id = %u\n", tile_id);
1863 uint32_t tile_size_bytes = ac_ib_get(ib);
1864 fprintf(f, " tile_size_bytes_minus_1 = %u\n", tile_size_bytes);
1865 } else if (op == cmd.enc_params_av1) {
1866 fprintf(f, "%sAV1_ENCODE_PARAMS%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1867 for (uint32_t i = 0; i < RENCODE_AV1_REFS_PER_FRAME; i++) {
1868 uint32_t ref = ac_ib_get(ib);
1869 fprintf(f, " ref frame[%u] = %u\n", i, ref);
1870 }
1871 for (uint32_t i = 0; i < 2; i++) {
1872 uint32_t idx = ac_ib_get(ib);
1873 fprintf(f, " lsm reference frame index[%u] = %u\n", i, idx);
1874 }
1875 } else {
1876 fprintf(f, "%sUNRECOGNIZED%s\n", O_COLOR_RED, O_COLOR_RESET);
1877 }
1878 print_vcn_unrecognized_params(f, ib, start_dw, size);
1879 }
1880 }
1881
parse_vcn_ib(FILE * f,struct ac_ib_parser * ib)1882 static void parse_vcn_ib(FILE *f, struct ac_ib_parser *ib)
1883 {
1884 uint32_t engine = 0;
1885
1886 if (ib->vcn_version >= VCN_4_0_0) {
1887 while (ib->cur_dw < ib->num_dw) {
1888 const uint32_t start_dw = ib->cur_dw;
1889 const uint32_t size = ac_ib_get(ib);
1890 const uint32_t op = ac_ib_get(ib);
1891
1892 switch (op) {
1893 case RADEON_VCN_ENGINE_INFO: {
1894 fprintf(f, "%sENGINE_INFO%s\n", O_COLOR_CYAN, O_COLOR_RESET);
1895 engine = ac_ib_get(ib);
1896 fprintf(f, " engine = %s\n",
1897 engine == RADEON_VCN_ENGINE_TYPE_COMMON ? "COMMON" :
1898 engine == RADEON_VCN_ENGINE_TYPE_ENCODE ? "ENCODE" :
1899 engine == RADEON_VCN_ENGINE_TYPE_DECODE ? "DECODE" :
1900 "???");
1901 uint32_t total_size = ac_ib_get(ib);
1902 fprintf(f, " size of all packages = %u\n", total_size);
1903 break;
1904 }
1905 case RADEON_VCN_SIGNATURE: {
1906 fprintf(f, "%sSIGNATURE%s\n", O_COLOR_CYAN, O_COLOR_RESET);
1907 ac_ib_get(ib);
1908 fprintf(f, " checksum\n");
1909 uint32_t num_dwords = ac_ib_get(ib);
1910 fprintf(f, " num dwords = %u\n", num_dwords);
1911 break;
1912 }
1913 case RADEON_VCN_IB_COMMON_OP_WRITEMEMORY: {
1914 fprintf(f, "%sOP_WRITEMEMORY%s\n", O_COLOR_CYAN, O_COLOR_RESET);
1915 print_vcn_addr(f, ib, " dest");
1916 uint32_t data = ac_ib_get(ib);
1917 fprintf(f, " data = %u\n", data);
1918 break;
1919 }
1920 case RDECODE_IB_PARAM_DECODE_BUFFER: {
1921 fprintf(f, "%sDECODE_BUFFER%s\n", O_COLOR_GREEN, O_COLOR_RESET);
1922 uint32_t valid = ac_ib_get(ib);
1923 fprintf(f, " valid =\n");
1924 for (uint32_t i = 0; i < 32; i++) {
1925 uint32_t buf = 1 << i;
1926 if ((valid & buf) != buf)
1927 continue;
1928 fprintf(f, " ");
1929 switch (buf) {
1930 case RDECODE_CMDBUF_FLAGS_MSG_BUFFER:
1931 fprintf(f, "MSG BUFFER\n");
1932 break;
1933 case RDECODE_CMDBUF_FLAGS_DPB_BUFFER:
1934 fprintf(f, "DPB BUFFER\n");
1935 break;
1936 case RDECODE_CMDBUF_FLAGS_BITSTREAM_BUFFER:
1937 fprintf(f, "BITSTREAM BUFFER\n");
1938 break;
1939 case RDECODE_CMDBUF_FLAGS_DECODING_TARGET_BUFFER:
1940 fprintf(f, "DECODING TARGET BUFFER\n");
1941 break;
1942 case RDECODE_CMDBUF_FLAGS_FEEDBACK_BUFFER:
1943 fprintf(f, "FEEDBACK BUFFER\n");
1944 break;
1945 case RDECODE_CMDBUF_FLAGS_PICTURE_PARAM_BUFFER:
1946 fprintf(f, "PICTURE PARAM BUFFER\n");
1947 break;
1948 case RDECODE_CMDBUF_FLAGS_MB_CONTROL_BUFFER:
1949 fprintf(f, "MB CONTROL BUFFER\n");
1950 break;
1951 case RDECODE_CMDBUF_FLAGS_IDCT_COEF_BUFFER:
1952 fprintf(f, "IDCT COEFF BUFFER\n");
1953 break;
1954 case RDECODE_CMDBUF_FLAGS_PREEMPT_BUFFER:
1955 fprintf(f, "PREEMPT BUFFER\n");
1956 break;
1957 case RDECODE_CMDBUF_FLAGS_IT_SCALING_BUFFER:
1958 fprintf(f, "IT SCALING BUFFER\n");
1959 break;
1960 case RDECODE_CMDBUF_FLAGS_SCALER_TARGET_BUFFER:
1961 fprintf(f, "SCALER TARGET BUFFER\n");
1962 break;
1963 case RDECODE_CMDBUF_FLAGS_CONTEXT_BUFFER:
1964 fprintf(f, "CONTEXT BUFFER\n");
1965 break;
1966 case RDECODE_CMDBUF_FLAGS_PROB_TBL_BUFFER:
1967 fprintf(f, "PROB TBL BUFFER\n");
1968 break;
1969 case RDECODE_CMDBUF_FLAGS_QUERY_BUFFER:
1970 fprintf(f, "QUERY BUFFER\n");
1971 break;
1972 case RDECODE_CMDBUF_FLAGS_PREDICATION_BUFFER:
1973 fprintf(f, "PREDICATION BUFFER\n");
1974 break;
1975 case RDECODE_CMDBUF_FLAGS_SCLR_COEF_BUFFER:
1976 fprintf(f, "SCRL COEF BUFFER\n");
1977 break;
1978 case RDECODE_CMDBUF_FLAGS_RECORD_TIMESTAMP:
1979 fprintf(f, "RECORD TIMESTAMP\n");
1980 break;
1981 case RDECODE_CMDBUF_FLAGS_REPORT_EVENT_STATUS:
1982 fprintf(f, "REPORT EVENT STATUS\n");
1983 break;
1984 case RDECODE_CMDBUF_FLAGS_RESERVED_SIZE_INFO_BUFFER:
1985 fprintf(f, "RESERVED SIZE INFO BUFFER\n");
1986 break;
1987 case RDECODE_CMDBUF_FLAGS_LUMA_HIST_BUFFER:
1988 fprintf(f, "LUMA HIST BUFFER\n");
1989 break;
1990 case RDECODE_CMDBUF_FLAGS_SESSION_CONTEXT_BUFFER:
1991 fprintf(f, "SESSION CONTEXT BUFFER\n");
1992 break;
1993 default:
1994 fprintf(f, "%s(UNRECOGNIZED)%s\n", O_COLOR_RED, O_COLOR_RESET);
1995 break;
1996 }
1997 }
1998 print_vcn_addr(f, ib, " msg buffer");
1999 print_vcn_addr(f, ib, " dpb buffer");
2000 print_vcn_addr(f, ib, " target buffer");
2001 print_vcn_addr(f, ib, " session context buffer");
2002 print_vcn_addr(f, ib, " bitstream buffer");
2003 print_vcn_addr(f, ib, " context buffer");
2004 print_vcn_addr(f, ib, " feedback buffer");
2005 print_vcn_addr(f, ib, " luma hist buffer");
2006 print_vcn_addr(f, ib, " prob tbl buffer");
2007 print_vcn_addr(f, ib, " sclr coeff buffer");
2008 print_vcn_addr(f, ib, " it sclr table buffer");
2009 print_vcn_addr(f, ib, " sclr target buffer");
2010 print_vcn_addr(f, ib, " reserved size info buffer");
2011 print_vcn_addr(f, ib, " mpeg2 pic param buffer");
2012 print_vcn_addr(f, ib, " mpeg2 mb control buffer");
2013 print_vcn_addr(f, ib, " mpeg2 idct coeff buffer");
2014 break;
2015 }
2016 default:
2017 fprintf(f, "%sUNRECOGNIZED%s\n", O_COLOR_RED, O_COLOR_RESET);
2018 break;
2019 }
2020 print_vcn_unrecognized_params(f, ib, start_dw, size);
2021
2022 if (engine == RADEON_VCN_ENGINE_TYPE_ENCODE) {
2023 parse_vcn_enc_ib(f, ib);
2024 return;
2025 }
2026 }
2027 } else {
2028 if (ib->ip_type == AMD_IP_VCN_ENC) {
2029 parse_vcn_enc_ib(f, ib);
2030 return;
2031 }
2032 }
2033 }
2034
2035 /**
2036 * Parse and print an IB into a file.
2037 *
2038 * \param f file
2039 * \param ib_ptr IB
2040 * \param num_dw size of the IB
2041 * \param gfx_level gfx level
2042 * \param vcn_version vcn version
2043 * \param family chip family
2044 * \param ip_type IP type
2045 * \param trace_ids the last trace IDs that are known to have been reached
2046 * and executed by the CP, typically read from a buffer
2047 * \param trace_id_count The number of entries in the trace_ids array.
2048 * \param addr_callback Get a mapped pointer of the IB at a given address. Can
2049 * be NULL.
2050 * \param addr_callback_data user data for addr_callback
2051 */
ac_parse_ib_chunk(struct ac_ib_parser * ib)2052 void ac_parse_ib_chunk(struct ac_ib_parser *ib)
2053 {
2054 struct ac_ib_parser tmp_ib = *ib;
2055
2056 char *out;
2057 size_t outsize;
2058 struct u_memstream mem;
2059 u_memstream_open(&mem, &out, &outsize);
2060 FILE *const memf = u_memstream_get(&mem);
2061 tmp_ib.f = memf;
2062
2063 if (ib->ip_type == AMD_IP_GFX || ib->ip_type == AMD_IP_COMPUTE)
2064 parse_gfx_compute_ib(memf, &tmp_ib);
2065 else if (ib->ip_type == AMD_IP_SDMA)
2066 parse_sdma_ib(memf, &tmp_ib);
2067 else if (ib->ip_type == AMD_IP_VCN_DEC || ib->ip_type == AMD_IP_VCN_ENC)
2068 parse_vcn_ib(memf, &tmp_ib);
2069 else
2070 unreachable("unsupported IP type");
2071
2072 u_memstream_close(&mem);
2073
2074 if (out) {
2075 format_ib_output(ib->f, out);
2076 free(out);
2077 }
2078
2079 if (tmp_ib.cur_dw > tmp_ib.num_dw) {
2080 printf("\nPacket ends after the end of IB.\n");
2081 exit(1);
2082 }
2083 }
2084
2085 /**
2086 * Parse and print an IB into a file.
2087 *
2088 * \param f file
2089 * \param ib IB
2090 * \param num_dw size of the IB
2091 * \param gfx_level gfx level
2092 * \param family chip family
2093 * \param ip_type IP type
2094 * \param trace_ids the last trace IDs that are known to have been reached
2095 * and executed by the CP, typically read from a buffer
2096 * \param trace_id_count The number of entries in the trace_ids array.
2097 * \param addr_callback Get a mapped pointer of the IB at a given address. Can
2098 * be NULL.
2099 * \param addr_callback_data user data for addr_callback
2100 */
ac_parse_ib(struct ac_ib_parser * ib,const char * name)2101 void ac_parse_ib(struct ac_ib_parser *ib, const char *name)
2102 {
2103 fprintf(ib->f, "------------------ %s begin - %s ------------------\n", name,
2104 ac_get_ip_type_string(NULL, ib->ip_type));
2105
2106 ac_parse_ib_chunk(ib);
2107
2108 fprintf(ib->f, "------------------- %s end - %s -------------------\n\n", name,
2109 ac_get_ip_type_string(NULL, ib->ip_type));
2110 }
2111