2 * Copyright © 2017 Intel Corporation
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
26 #include "util/macros.h"
28 #include "aubinator_viewer.h"
31 aub_viewer_decode_ctx_init(struct aub_viewer_decode_ctx
*ctx
,
32 struct aub_viewer_cfg
*cfg
,
33 struct aub_viewer_decode_cfg
*decode_cfg
,
34 struct gen_spec
*spec
,
35 struct gen_disasm
*disasm
,
36 struct gen_batch_decode_bo (*get_bo
)(void *, uint64_t),
37 unsigned (*get_state_size
)(void *, uint32_t),
40 memset(ctx
, 0, sizeof(*ctx
));
43 ctx
->get_state_size
= get_state_size
;
44 ctx
->user_data
= user_data
;
47 ctx
->decode_cfg
= decode_cfg
;
53 aub_viewer_print_group(struct aub_viewer_decode_ctx
*ctx
,
54 struct gen_group
*group
,
55 uint64_t address
, const void *map
)
57 struct gen_field_iterator iter
;
59 const uint32_t *p
= (const uint32_t *) map
;
61 gen_field_iterator_init(&iter
, group
, p
, 0, false);
62 while (gen_field_iterator_next(&iter
)) {
63 if (ctx
->decode_cfg
->show_dwords
) {
64 int iter_dword
= iter
.end_bit
/ 32;
65 if (last_dword
!= iter_dword
) {
66 for (int i
= last_dword
+ 1; i
<= iter_dword
; i
++) {
67 ImGui::TextColored(ctx
->cfg
->dwords_color
,
68 "0x%08" PRIx64
": 0x%08x : Dword %d",
69 address
+ 4 * i
, iter
.p
[i
], i
);
71 last_dword
= iter_dword
;
74 if (!gen_field_is_header(iter
.field
)) {
75 if (ctx
->decode_cfg
->field_filter
.PassFilter(iter
.name
)) {
76 ImGui::Text("%s: %s", iter
.name
, iter
.value
);
77 if (iter
.struct_desc
) {
78 int struct_dword
= iter
.start_bit
/ 32;
79 uint64_t struct_address
= address
+ 4 * struct_dword
;
80 aub_viewer_print_group(ctx
, iter
.struct_desc
, struct_address
,
88 static struct gen_batch_decode_bo
89 ctx_get_bo(struct aub_viewer_decode_ctx
*ctx
, uint64_t addr
)
91 if (gen_spec_get_gen(ctx
->spec
) >= gen_make_gen(8,0)) {
92 /* On Broadwell and above, we have 48-bit addresses which consume two
93 * dwords. Some packets require that these get stored in a "canonical
94 * form" which means that bit 47 is sign-extended through the upper
95 * bits. In order to correctly handle those aub dumps, we need to mask
96 * off the top 16 bits.
98 addr
&= (~0ull >> 16);
101 struct gen_batch_decode_bo bo
= ctx
->get_bo(ctx
->user_data
, addr
);
103 if (gen_spec_get_gen(ctx
->spec
) >= gen_make_gen(8,0))
104 bo
.addr
&= (~0ull >> 16);
106 /* We may actually have an offset into the bo */
107 if (bo
.map
!= NULL
) {
108 assert(bo
.addr
<= addr
);
109 uint64_t offset
= addr
- bo
.addr
;
110 bo
.map
= (const uint8_t *)bo
.map
+ offset
;
119 update_count(struct aub_viewer_decode_ctx
*ctx
,
120 uint32_t offset_from_dsba
,
121 unsigned element_dwords
,
126 if (ctx
->get_state_size
)
127 size
= ctx
->get_state_size(ctx
->user_data
, offset_from_dsba
);
130 return size
/ (sizeof(uint32_t) * element_dwords
);
132 /* In the absence of any information, just guess arbitrarily. */
137 ctx_disassemble_program(struct aub_viewer_decode_ctx
*ctx
,
138 uint32_t ksp
, const char *type
)
140 uint64_t addr
= ctx
->instruction_base
+ ksp
;
141 struct gen_batch_decode_bo bo
= ctx_get_bo(ctx
, addr
);
143 ImGui::TextColored(ctx
->cfg
->missing_color
, "Shader unavailable");
148 if (ImGui::Button(type
) && ctx
->display_shader
)
149 ctx
->display_shader(ctx
->user_data
, type
, addr
);
154 handle_state_base_address(struct aub_viewer_decode_ctx
*ctx
,
155 struct gen_group
*inst
,
158 struct gen_field_iterator iter
;
159 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
161 while (gen_field_iterator_next(&iter
)) {
162 if (strcmp(iter
.name
, "Surface State Base Address") == 0) {
163 ctx
->surface_base
= iter
.raw_value
;
164 } else if (strcmp(iter
.name
, "Dynamic State Base Address") == 0) {
165 ctx
->dynamic_base
= iter
.raw_value
;
166 } else if (strcmp(iter
.name
, "Instruction Base Address") == 0) {
167 ctx
->instruction_base
= iter
.raw_value
;
173 dump_binding_table(struct aub_viewer_decode_ctx
*ctx
, uint32_t offset
, int count
)
175 struct gen_group
*strct
=
176 gen_spec_find_struct(ctx
->spec
, "RENDER_SURFACE_STATE");
178 ImGui::TextColored(ctx
->cfg
->missing_color
, "did not find RENDER_SURFACE_STATE info");
183 count
= update_count(ctx
, offset
, 1, 8);
185 if (offset
% 32 != 0 || offset
>= UINT16_MAX
) {
186 ImGui::TextColored(ctx
->cfg
->missing_color
, "invalid binding table pointer");
190 struct gen_batch_decode_bo bind_bo
=
191 ctx_get_bo(ctx
, ctx
->surface_base
+ offset
);
193 if (bind_bo
.map
== NULL
) {
194 ImGui::TextColored(ctx
->cfg
->missing_color
,
195 "binding table unavailable addr=0x%08" PRIx64
,
196 ctx
->surface_base
+ offset
);
200 const uint32_t *pointers
= (const uint32_t *) bind_bo
.map
;
201 for (int i
= 0; i
< count
; i
++) {
202 if (pointers
[i
] == 0)
205 uint64_t addr
= ctx
->surface_base
+ pointers
[i
];
206 struct gen_batch_decode_bo bo
= ctx_get_bo(ctx
, addr
);
207 uint32_t size
= strct
->dw_length
* 4;
209 if (pointers
[i
] % 32 != 0 ||
210 addr
< bo
.addr
|| addr
+ size
>= bo
.addr
+ bo
.size
) {
211 ImGui::TextColored(ctx
->cfg
->missing_color
,
212 "pointer %u: %08x <not valid>", i
, pointers
[i
]);
216 ImGui::Text("pointer %u: %08x", i
, pointers
[i
]);
217 aub_viewer_print_group(ctx
, strct
, addr
, (const uint8_t *) bo
.map
+ (addr
- bo
.addr
));
222 dump_samplers(struct aub_viewer_decode_ctx
*ctx
, uint32_t offset
, int count
)
224 struct gen_group
*strct
= gen_spec_find_struct(ctx
->spec
, "SAMPLER_STATE");
227 count
= update_count(ctx
, offset
, strct
->dw_length
, 4);
229 uint64_t state_addr
= ctx
->dynamic_base
+ offset
;
230 struct gen_batch_decode_bo bo
= ctx_get_bo(ctx
, state_addr
);
231 const uint8_t *state_map
= (const uint8_t *) bo
.map
;
233 if (state_map
== NULL
) {
234 ImGui::TextColored(ctx
->cfg
->missing_color
,
235 "samplers unavailable addr=0x%08" PRIx64
, state_addr
);
239 if (offset
% 32 != 0 || state_addr
- bo
.addr
>= bo
.size
) {
240 ImGui::TextColored(ctx
->cfg
->missing_color
, "invalid sampler state pointer");
244 for (int i
= 0; i
< count
; i
++) {
245 ImGui::Text("sampler state %d", i
);
246 aub_viewer_print_group(ctx
, strct
, state_addr
, state_map
);
253 handle_media_interface_descriptor_load(struct aub_viewer_decode_ctx
*ctx
,
254 struct gen_group
*inst
,
257 struct gen_group
*desc
=
258 gen_spec_find_struct(ctx
->spec
, "INTERFACE_DESCRIPTOR_DATA");
260 struct gen_field_iterator iter
;
261 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
262 uint32_t descriptor_offset
= 0;
263 int descriptor_count
= 0;
264 while (gen_field_iterator_next(&iter
)) {
265 if (strcmp(iter
.name
, "Interface Descriptor Data Start Address") == 0) {
266 descriptor_offset
= strtol(iter
.value
, NULL
, 16);
267 } else if (strcmp(iter
.name
, "Interface Descriptor Total Length") == 0) {
269 strtol(iter
.value
, NULL
, 16) / (desc
->dw_length
* 4);
273 uint64_t desc_addr
= ctx
->dynamic_base
+ descriptor_offset
;
274 struct gen_batch_decode_bo bo
= ctx_get_bo(ctx
, desc_addr
);
275 const uint32_t *desc_map
= (const uint32_t *) bo
.map
;
277 if (desc_map
== NULL
) {
278 ImGui::TextColored(ctx
->cfg
->missing_color
,
279 "interface descriptors unavailable addr=0x%08" PRIx64
, desc_addr
);
283 for (int i
= 0; i
< descriptor_count
; i
++) {
284 ImGui::Text("descriptor %d: %08x", i
, descriptor_offset
);
286 aub_viewer_print_group(ctx
, desc
, desc_addr
, desc_map
);
288 gen_field_iterator_init(&iter
, desc
, desc_map
, 0, false);
290 uint32_t sampler_offset
= 0, sampler_count
= 0;
291 uint32_t binding_table_offset
= 0, binding_entry_count
= 0;
292 while (gen_field_iterator_next(&iter
)) {
293 if (strcmp(iter
.name
, "Kernel Start Pointer") == 0) {
294 ksp
= strtoll(iter
.value
, NULL
, 16);
295 } else if (strcmp(iter
.name
, "Sampler State Pointer") == 0) {
296 sampler_offset
= strtol(iter
.value
, NULL
, 16);
297 } else if (strcmp(iter
.name
, "Sampler Count") == 0) {
298 sampler_count
= strtol(iter
.value
, NULL
, 10);
299 } else if (strcmp(iter
.name
, "Binding Table Pointer") == 0) {
300 binding_table_offset
= strtol(iter
.value
, NULL
, 16);
301 } else if (strcmp(iter
.name
, "Binding Table Entry Count") == 0) {
302 binding_entry_count
= strtol(iter
.value
, NULL
, 10);
306 ctx_disassemble_program(ctx
, ksp
, "compute shader");
308 dump_samplers(ctx
, sampler_offset
, sampler_count
);
309 dump_binding_table(ctx
, binding_table_offset
, binding_entry_count
);
311 desc_map
+= desc
->dw_length
;
312 desc_addr
+= desc
->dw_length
* 4;
317 handle_3dstate_vertex_buffers(struct aub_viewer_decode_ctx
*ctx
,
318 struct gen_group
*inst
,
321 struct gen_group
*vbs
= gen_spec_find_struct(ctx
->spec
, "VERTEX_BUFFER_STATE");
323 struct gen_batch_decode_bo vb
= {};
324 uint32_t vb_size
= 0;
329 struct gen_field_iterator iter
;
330 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
331 while (gen_field_iterator_next(&iter
)) {
332 if (iter
.struct_desc
!= vbs
)
335 uint64_t buffer_addr
;
337 struct gen_field_iterator vbs_iter
;
338 gen_field_iterator_init(&vbs_iter
, vbs
, &iter
.p
[iter
.start_bit
/ 32], 0, false);
339 while (gen_field_iterator_next(&vbs_iter
)) {
340 if (strcmp(vbs_iter
.name
, "Vertex Buffer Index") == 0) {
341 index
= vbs_iter
.raw_value
;
342 } else if (strcmp(vbs_iter
.name
, "Buffer Pitch") == 0) {
343 pitch
= vbs_iter
.raw_value
;
344 } else if (strcmp(vbs_iter
.name
, "Buffer Starting Address") == 0) {
345 buffer_addr
= vbs_iter
.raw_value
;
346 vb
= ctx_get_bo(ctx
, buffer_addr
);
347 } else if (strcmp(vbs_iter
.name
, "Buffer Size") == 0) {
348 vb_size
= vbs_iter
.raw_value
;
350 } else if (strcmp(vbs_iter
.name
, "End Address") == 0) {
351 if (vb
.map
&& vbs_iter
.raw_value
>= vb
.addr
)
352 vb_size
= vbs_iter
.raw_value
- vb
.addr
;
361 ImGui::Text("vertex buffer %d, size %d", index
, vb_size
);
363 if (vb
.map
== NULL
) {
364 ImGui::TextColored(ctx
->cfg
->missing_color
,
365 "buffer contents unavailable addr=0x%08" PRIx64
, buffer_addr
);
369 if (vb
.map
== 0 || vb_size
== 0)
382 handle_3dstate_index_buffer(struct aub_viewer_decode_ctx
*ctx
,
383 struct gen_group
*inst
,
386 struct gen_batch_decode_bo ib
= {};
387 uint64_t buffer_addr
= 0;
388 uint32_t ib_size
= 0;
391 struct gen_field_iterator iter
;
392 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
393 while (gen_field_iterator_next(&iter
)) {
394 if (strcmp(iter
.name
, "Index Format") == 0) {
395 format
= iter
.raw_value
;
396 } else if (strcmp(iter
.name
, "Buffer Starting Address") == 0) {
397 buffer_addr
= iter
.raw_value
;
398 ib
= ctx_get_bo(ctx
, buffer_addr
);
399 } else if (strcmp(iter
.name
, "Buffer Size") == 0) {
400 ib_size
= iter
.raw_value
;
404 if (ib
.map
== NULL
) {
405 ImGui::TextColored(ctx
->cfg
->missing_color
,
406 "buffer contents unavailable addr=0x%08" PRIx64
,
411 const uint8_t *m
= (const uint8_t *) ib
.map
;
412 const uint8_t *ib_end
= m
+ MIN2(ib
.size
, ib_size
);
413 for (int i
= 0; m
< ib_end
&& i
< 10; i
++) {
429 decode_single_ksp(struct aub_viewer_decode_ctx
*ctx
,
430 struct gen_group
*inst
,
434 bool is_simd8
= false; /* vertex shaders on Gen8+ only */
435 bool is_enabled
= true;
437 struct gen_field_iterator iter
;
438 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
439 while (gen_field_iterator_next(&iter
)) {
440 if (strcmp(iter
.name
, "Kernel Start Pointer") == 0) {
441 ksp
= iter
.raw_value
;
442 } else if (strcmp(iter
.name
, "SIMD8 Dispatch Enable") == 0) {
443 is_simd8
= iter
.raw_value
;
444 } else if (strcmp(iter
.name
, "Dispatch Mode") == 0) {
445 is_simd8
= strcmp(iter
.value
, "SIMD8") == 0;
446 } else if (strcmp(iter
.name
, "Dispatch Enable") == 0) {
447 is_simd8
= strcmp(iter
.value
, "SIMD8") == 0;
448 } else if (strcmp(iter
.name
, "Enable") == 0) {
449 is_enabled
= iter
.raw_value
;
454 strcmp(inst
->name
, "VS_STATE") == 0 ? "vertex shader" :
455 strcmp(inst
->name
, "GS_STATE") == 0 ? "geometry shader" :
456 strcmp(inst
->name
, "SF_STATE") == 0 ? "strips and fans shader" :
457 strcmp(inst
->name
, "CLIP_STATE") == 0 ? "clip shader" :
458 strcmp(inst
->name
, "3DSTATE_DS") == 0 ? "tessellation evaluation shader" :
459 strcmp(inst
->name
, "3DSTATE_HS") == 0 ? "tessellation control shader" :
460 strcmp(inst
->name
, "3DSTATE_VS") == 0 ? (is_simd8
? "SIMD8 vertex shader" : "vec4 vertex shader") :
461 strcmp(inst
->name
, "3DSTATE_GS") == 0 ? (is_simd8
? "SIMD8 geometry shader" : "vec4 geometry shader") :
465 ctx_disassemble_program(ctx
, ksp
, type
);
469 decode_ps_kernels(struct aub_viewer_decode_ctx
*ctx
,
470 struct gen_group
*inst
,
473 uint64_t ksp
[3] = {0, 0, 0};
474 bool enabled
[3] = {false, false, false};
476 struct gen_field_iterator iter
;
477 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
478 while (gen_field_iterator_next(&iter
)) {
479 if (strncmp(iter
.name
, "Kernel Start Pointer ",
480 strlen("Kernel Start Pointer ")) == 0) {
481 int idx
= iter
.name
[strlen("Kernel Start Pointer ")] - '0';
482 ksp
[idx
] = strtol(iter
.value
, NULL
, 16);
483 } else if (strcmp(iter
.name
, "8 Pixel Dispatch Enable") == 0) {
484 enabled
[0] = strcmp(iter
.value
, "true") == 0;
485 } else if (strcmp(iter
.name
, "16 Pixel Dispatch Enable") == 0) {
486 enabled
[1] = strcmp(iter
.value
, "true") == 0;
487 } else if (strcmp(iter
.name
, "32 Pixel Dispatch Enable") == 0) {
488 enabled
[2] = strcmp(iter
.value
, "true") == 0;
492 /* Reorder KSPs to be [8, 16, 32] instead of the hardware order. */
493 if (enabled
[0] + enabled
[1] + enabled
[2] == 1) {
497 } else if (enabled
[2]) {
502 uint64_t tmp
= ksp
[1];
508 ctx_disassemble_program(ctx
, ksp
[0], "SIMD8 fragment shader");
510 ctx_disassemble_program(ctx
, ksp
[1], "SIMD16 fragment shader");
512 ctx_disassemble_program(ctx
, ksp
[2], "SIMD32 fragment shader");
516 decode_3dstate_constant(struct aub_viewer_decode_ctx
*ctx
,
517 struct gen_group
*inst
,
520 struct gen_group
*body
=
521 gen_spec_find_struct(ctx
->spec
, "3DSTATE_CONSTANT_BODY");
523 uint32_t read_length
[4] = {0};
524 uint64_t read_addr
[4];
526 struct gen_field_iterator outer
;
527 gen_field_iterator_init(&outer
, inst
, p
, 0, false);
528 while (gen_field_iterator_next(&outer
)) {
529 if (outer
.struct_desc
!= body
)
532 struct gen_field_iterator iter
;
533 gen_field_iterator_init(&iter
, body
, &outer
.p
[outer
.start_bit
/ 32],
536 while (gen_field_iterator_next(&iter
)) {
538 if (sscanf(iter
.name
, "Read Length[%d]", &idx
) == 1) {
539 read_length
[idx
] = iter
.raw_value
;
540 } else if (sscanf(iter
.name
, "Buffer[%d]", &idx
) == 1) {
541 read_addr
[idx
] = iter
.raw_value
;
545 for (int i
= 0; i
< 4; i
++) {
546 if (read_length
[i
] == 0)
549 struct gen_batch_decode_bo buffer
= ctx_get_bo(ctx
, read_addr
[i
]);
551 ImGui::TextColored(ctx
->cfg
->missing_color
,
552 "constant buffer %d unavailable addr=0x%08" PRIx64
,
557 unsigned size
= read_length
[i
] * 32;
558 ImGui::Text("constant buffer %d, size %u", i
, size
);
560 if (ctx
->edit_address
) {
561 if (ImGui::Button("Show/Edit buffer"))
562 ctx
->edit_address(ctx
->user_data
, read_addr
[i
], size
);
569 decode_3dstate_binding_table_pointers(struct aub_viewer_decode_ctx
*ctx
,
570 struct gen_group
*inst
,
573 dump_binding_table(ctx
, p
[1], -1);
577 decode_3dstate_sampler_state_pointers(struct aub_viewer_decode_ctx
*ctx
,
578 struct gen_group
*inst
,
581 dump_samplers(ctx
, p
[1], -1);
585 decode_3dstate_sampler_state_pointers_gen6(struct aub_viewer_decode_ctx
*ctx
,
586 struct gen_group
*inst
,
589 dump_samplers(ctx
, p
[1], -1);
590 dump_samplers(ctx
, p
[2], -1);
591 dump_samplers(ctx
, p
[3], -1);
595 str_ends_with(const char *str
, const char *end
)
597 int offset
= strlen(str
) - strlen(end
);
601 return strcmp(str
+ offset
, end
) == 0;
605 decode_dynamic_state_pointers(struct aub_viewer_decode_ctx
*ctx
,
606 struct gen_group
*inst
, const uint32_t *p
,
607 const char *struct_type
, int count
)
609 struct gen_group
*state
= gen_spec_find_struct(ctx
->spec
, struct_type
);
611 uint32_t state_offset
= 0;
613 struct gen_field_iterator iter
;
614 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
615 while (gen_field_iterator_next(&iter
)) {
616 if (str_ends_with(iter
.name
, "Pointer")) {
617 state_offset
= iter
.raw_value
;
622 uint64_t state_addr
= ctx
->dynamic_base
+ state_offset
;
623 struct gen_batch_decode_bo bo
= ctx_get_bo(ctx
, state_addr
);
624 const uint8_t *state_map
= (const uint8_t *) bo
.map
;
626 if (state_map
== NULL
) {
627 ImGui::TextColored(ctx
->cfg
->missing_color
,
628 "dynamic %s state unavailable addr=0x%08" PRIx64
,
629 struct_type
, state_addr
);
633 for (int i
= 0; i
< count
; i
++) {
634 ImGui::Text("%s %d", struct_type
, i
);
635 aub_viewer_print_group(ctx
, state
, state_offset
, state_map
);
637 state_addr
+= state
->dw_length
* 4;
638 state_map
+= state
->dw_length
;
643 decode_3dstate_viewport_state_pointers_cc(struct aub_viewer_decode_ctx
*ctx
,
644 struct gen_group
*inst
,
647 decode_dynamic_state_pointers(ctx
, inst
, p
, "CC_VIEWPORT", 4);
651 decode_3dstate_viewport_state_pointers_sf_clip(struct aub_viewer_decode_ctx
*ctx
,
652 struct gen_group
*inst
,
655 decode_dynamic_state_pointers(ctx
, inst
, p
, "SF_CLIP_VIEWPORT", 4);
659 decode_3dstate_blend_state_pointers(struct aub_viewer_decode_ctx
*ctx
,
660 struct gen_group
*inst
,
663 decode_dynamic_state_pointers(ctx
, inst
, p
, "BLEND_STATE", 1);
667 decode_3dstate_cc_state_pointers(struct aub_viewer_decode_ctx
*ctx
,
668 struct gen_group
*inst
,
671 decode_dynamic_state_pointers(ctx
, inst
, p
, "COLOR_CALC_STATE", 1);
675 decode_3dstate_scissor_state_pointers(struct aub_viewer_decode_ctx
*ctx
,
676 struct gen_group
*inst
,
679 decode_dynamic_state_pointers(ctx
, inst
, p
, "SCISSOR_RECT", 1);
683 decode_load_register_imm(struct aub_viewer_decode_ctx
*ctx
,
684 struct gen_group
*inst
,
687 struct gen_group
*reg
= gen_spec_find_register(ctx
->spec
, p
[1]);
690 ImGui::TreeNodeEx(&p
[1], ImGuiTreeNodeFlags_Framed
,
692 reg
->name
, reg
->register_offset
, p
[2])) {
693 aub_viewer_print_group(ctx
, reg
, reg
->register_offset
, &p
[2]);
699 decode_3dprimitive(struct aub_viewer_decode_ctx
*ctx
,
700 struct gen_group
*inst
,
703 if (ctx
->display_urb
) {
704 if (ImGui::Button("Show URB"))
705 ctx
->display_urb(ctx
->user_data
, ctx
->urb_stages
);
710 handle_urb(struct aub_viewer_decode_ctx
*ctx
,
711 struct gen_group
*inst
,
714 struct gen_field_iterator iter
;
715 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
716 while (gen_field_iterator_next(&iter
)) {
717 if (strstr(iter
.name
, "URB Starting Address")) {
718 ctx
->urb_stages
[ctx
->stage
].start
= iter
.raw_value
* 8192;
719 } else if (strstr(iter
.name
, "URB Entry Allocation Size")) {
720 ctx
->urb_stages
[ctx
->stage
].size
= (iter
.raw_value
+ 1) * 64;
721 } else if (strstr(iter
.name
, "Number of URB Entries")) {
722 ctx
->urb_stages
[ctx
->stage
].n_entries
= iter
.raw_value
;
726 ctx
->end_urb_offset
= MAX2(ctx
->urb_stages
[ctx
->stage
].start
+
727 ctx
->urb_stages
[ctx
->stage
].n_entries
*
728 ctx
->urb_stages
[ctx
->stage
].size
,
729 ctx
->end_urb_offset
);
733 handle_urb_read(struct aub_viewer_decode_ctx
*ctx
,
734 struct gen_group
*inst
,
737 struct gen_field_iterator iter
;
738 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
739 while (gen_field_iterator_next(&iter
)) {
740 /* Workaround the "Force * URB Entry Read Length" fields */
741 if (iter
.end_bit
- iter
.start_bit
< 2)
744 if (strstr(iter
.name
, "URB Entry Read Offset")) {
745 ctx
->urb_stages
[ctx
->stage
].rd_offset
= iter
.raw_value
* 32;
746 } else if (strstr(iter
.name
, "URB Entry Read Length")) {
747 ctx
->urb_stages
[ctx
->stage
].rd_length
= iter
.raw_value
* 32;
748 } else if (strstr(iter
.name
, "URB Entry Output Read Offset")) {
749 ctx
->urb_stages
[ctx
->stage
].wr_offset
= iter
.raw_value
* 32;
750 } else if (strstr(iter
.name
, "URB Entry Output Length")) {
751 ctx
->urb_stages
[ctx
->stage
].wr_length
= iter
.raw_value
* 32;
757 handle_urb_constant(struct aub_viewer_decode_ctx
*ctx
,
758 struct gen_group
*inst
,
761 struct gen_group
*body
=
762 gen_spec_find_struct(ctx
->spec
, "3DSTATE_CONSTANT_BODY");
764 struct gen_field_iterator outer
;
765 gen_field_iterator_init(&outer
, inst
, p
, 0, false);
766 while (gen_field_iterator_next(&outer
)) {
767 if (outer
.struct_desc
!= body
)
770 struct gen_field_iterator iter
;
771 gen_field_iterator_init(&iter
, body
, &outer
.p
[outer
.start_bit
/ 32],
774 ctx
->urb_stages
[ctx
->stage
].const_rd_length
= 0;
775 while (gen_field_iterator_next(&iter
)) {
777 if (sscanf(iter
.name
, "Read Length[%d]", &idx
) == 1) {
778 ctx
->urb_stages
[ctx
->stage
].const_rd_length
+= iter
.raw_value
* 32;
784 struct custom_decoder
{
785 const char *cmd_name
;
786 void (*decode
)(struct aub_viewer_decode_ctx
*ctx
,
787 struct gen_group
*inst
,
789 enum aub_decode_stage stage
;
790 } display_decoders
[] = {
791 { "STATE_BASE_ADDRESS", handle_state_base_address
},
792 { "MEDIA_INTERFACE_DESCRIPTOR_LOAD", handle_media_interface_descriptor_load
},
793 { "3DSTATE_VERTEX_BUFFERS", handle_3dstate_vertex_buffers
},
794 { "3DSTATE_INDEX_BUFFER", handle_3dstate_index_buffer
},
795 { "3DSTATE_VS", decode_single_ksp
, AUB_DECODE_STAGE_VS
, },
796 { "3DSTATE_GS", decode_single_ksp
, AUB_DECODE_STAGE_GS
, },
797 { "3DSTATE_DS", decode_single_ksp
, AUB_DECODE_STAGE_DS
, },
798 { "3DSTATE_HS", decode_single_ksp
, AUB_DECODE_STAGE_HS
, },
799 { "3DSTATE_PS", decode_ps_kernels
, AUB_DECODE_STAGE_PS
, },
800 { "3DSTATE_CONSTANT_VS", decode_3dstate_constant
, AUB_DECODE_STAGE_VS
, },
801 { "3DSTATE_CONSTANT_GS", decode_3dstate_constant
, AUB_DECODE_STAGE_GS
, },
802 { "3DSTATE_CONSTANT_DS", decode_3dstate_constant
, AUB_DECODE_STAGE_DS
, },
803 { "3DSTATE_CONSTANT_HS", decode_3dstate_constant
, AUB_DECODE_STAGE_HS
, },
804 { "3DSTATE_CONSTANT_PS", decode_3dstate_constant
, AUB_DECODE_STAGE_PS
, },
806 { "3DSTATE_BINDING_TABLE_POINTERS_VS", decode_3dstate_binding_table_pointers
, AUB_DECODE_STAGE_VS
, },
807 { "3DSTATE_BINDING_TABLE_POINTERS_GS", decode_3dstate_binding_table_pointers
, AUB_DECODE_STAGE_GS
, },
808 { "3DSTATE_BINDING_TABLE_POINTERS_HS", decode_3dstate_binding_table_pointers
, AUB_DECODE_STAGE_HS
, },
809 { "3DSTATE_BINDING_TABLE_POINTERS_DS", decode_3dstate_binding_table_pointers
, AUB_DECODE_STAGE_DS
, },
810 { "3DSTATE_BINDING_TABLE_POINTERS_PS", decode_3dstate_binding_table_pointers
, AUB_DECODE_STAGE_PS
, },
812 { "3DSTATE_SAMPLER_STATE_POINTERS_VS", decode_3dstate_sampler_state_pointers
, AUB_DECODE_STAGE_VS
, },
813 { "3DSTATE_SAMPLER_STATE_POINTERS_GS", decode_3dstate_sampler_state_pointers
, AUB_DECODE_STAGE_GS
, },
814 { "3DSTATE_SAMPLER_STATE_POINTERS_DS", decode_3dstate_sampler_state_pointers
, AUB_DECODE_STAGE_DS
, },
815 { "3DSTATE_SAMPLER_STATE_POINTERS_HS", decode_3dstate_sampler_state_pointers
, AUB_DECODE_STAGE_HS
, },
816 { "3DSTATE_SAMPLER_STATE_POINTERS_PS", decode_3dstate_sampler_state_pointers
, AUB_DECODE_STAGE_PS
, },
817 { "3DSTATE_SAMPLER_STATE_POINTERS", decode_3dstate_sampler_state_pointers_gen6
},
819 { "3DSTATE_VIEWPORT_STATE_POINTERS_CC", decode_3dstate_viewport_state_pointers_cc
},
820 { "3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP", decode_3dstate_viewport_state_pointers_sf_clip
},
821 { "3DSTATE_BLEND_STATE_POINTERS", decode_3dstate_blend_state_pointers
},
822 { "3DSTATE_CC_STATE_POINTERS", decode_3dstate_cc_state_pointers
},
823 { "3DSTATE_SCISSOR_STATE_POINTERS", decode_3dstate_scissor_state_pointers
},
824 { "MI_LOAD_REGISTER_IMM", decode_load_register_imm
},
825 { "3DPRIMITIVE", decode_3dprimitive
},
828 struct custom_decoder info_decoders
[] = {
829 { "STATE_BASE_ADDRESS", handle_state_base_address
},
830 { "3DSTATE_URB_VS", handle_urb
, AUB_DECODE_STAGE_VS
, },
831 { "3DSTATE_URB_GS", handle_urb
, AUB_DECODE_STAGE_GS
, },
832 { "3DSTATE_URB_DS", handle_urb
, AUB_DECODE_STAGE_DS
, },
833 { "3DSTATE_URB_HS", handle_urb
, AUB_DECODE_STAGE_HS
, },
834 { "3DSTATE_VS", handle_urb_read
, AUB_DECODE_STAGE_VS
, },
835 { "3DSTATE_GS", handle_urb_read
, AUB_DECODE_STAGE_GS
, },
836 { "3DSTATE_DS", handle_urb_read
, AUB_DECODE_STAGE_DS
, },
837 { "3DSTATE_HS", handle_urb_read
, AUB_DECODE_STAGE_HS
, },
838 { "3DSTATE_PS", handle_urb_read
, AUB_DECODE_STAGE_PS
, },
839 { "3DSTATE_CONSTANT_VS", handle_urb_constant
, AUB_DECODE_STAGE_VS
, },
840 { "3DSTATE_CONSTANT_GS", handle_urb_constant
, AUB_DECODE_STAGE_GS
, },
841 { "3DSTATE_CONSTANT_DS", handle_urb_constant
, AUB_DECODE_STAGE_DS
, },
842 { "3DSTATE_CONSTANT_HS", handle_urb_constant
, AUB_DECODE_STAGE_HS
, },
843 { "3DSTATE_CONSTANT_PS", handle_urb_constant
, AUB_DECODE_STAGE_PS
, },
846 static inline uint64_t
847 get_address(struct gen_spec
*spec
, const uint32_t *p
)
849 /* Addresses are always guaranteed to be page-aligned and sometimes
850 * hardware packets have extra stuff stuffed in the bottom 12 bits.
852 uint64_t addr
= p
[0] & ~0xfffu
;
854 if (gen_spec_get_gen(spec
) >= gen_make_gen(8,0)) {
855 /* On Broadwell and above, we have 48-bit addresses which consume two
856 * dwords. Some packets require that these get stored in a "canonical
857 * form" which means that bit 47 is sign-extended through the upper
858 * bits. In order to correctly handle those aub dumps, we need to mask
859 * off the top 16 bits.
861 addr
|= ((uint64_t)p
[1] & 0xffff) << 32;
868 aub_viewer_render_batch(struct aub_viewer_decode_ctx
*ctx
,
869 const void *_batch
, uint32_t batch_size
,
872 struct gen_group
*inst
;
873 const uint32_t *p
, *batch
= (const uint32_t *) _batch
, *end
= batch
+ batch_size
;
876 for (p
= batch
; p
< end
; p
+= length
) {
877 inst
= gen_spec_find_instruction(ctx
->spec
, p
);
878 length
= gen_group_get_length(inst
, p
);
879 assert(inst
== NULL
|| length
> 0);
880 length
= MAX2(1, length
);
882 uint64_t offset
= batch_addr
+ ((char *)p
- (char *)batch
);
885 ImGui::TextColored(ctx
->cfg
->error_color
,
886 "x%08" PRIx64
": unknown instruction %08x",
891 const char *inst_name
= gen_group_get_name(inst
);
893 for (unsigned i
= 0; i
< ARRAY_SIZE(info_decoders
); i
++) {
894 if (strcmp(inst_name
, info_decoders
[i
].cmd_name
) == 0) {
895 ctx
->stage
= info_decoders
[i
].stage
;
896 info_decoders
[i
].decode(ctx
, inst
, p
);
901 if (ctx
->decode_cfg
->command_filter
.PassFilter(inst
->name
) &&
903 ImGuiTreeNodeFlags_Framed
,
904 "0x%08" PRIx64
": %s",
905 offset
, inst
->name
)) {
906 aub_viewer_print_group(ctx
, inst
, offset
, p
);
908 for (unsigned i
= 0; i
< ARRAY_SIZE(display_decoders
); i
++) {
909 if (strcmp(inst_name
, display_decoders
[i
].cmd_name
) == 0) {
910 ctx
->stage
= display_decoders
[i
].stage
;
911 display_decoders
[i
].decode(ctx
, inst
, p
);
916 if (ctx
->edit_address
) {
917 if (ImGui::Button("Edit instruction"))
918 ctx
->edit_address(ctx
->user_data
, offset
, length
* 4);
924 if (strcmp(inst_name
, "MI_BATCH_BUFFER_START") == 0) {
925 struct gen_batch_decode_bo next_batch
= {};
927 struct gen_field_iterator iter
;
928 gen_field_iterator_init(&iter
, inst
, p
, 0, false);
929 while (gen_field_iterator_next(&iter
)) {
930 if (strcmp(iter
.name
, "Batch Buffer Start Address") == 0) {
931 next_batch
= ctx_get_bo(ctx
, iter
.raw_value
);
932 } else if (strcmp(iter
.name
, "Second Level Batch Buffer") == 0) {
933 second_level
= iter
.raw_value
;
937 if (next_batch
.map
== NULL
) {
938 ImGui::TextColored(ctx
->cfg
->missing_color
,
939 "Secondary batch at 0x%08" PRIx64
" unavailable",
942 aub_viewer_render_batch(ctx
, next_batch
.map
, next_batch
.size
,
946 /* MI_BATCH_BUFFER_START with "2nd Level Batch Buffer" set acts
947 * like a subroutine call. Commands that come afterwards get
948 * processed once the 2nd level batch buffer returns with
949 * MI_BATCH_BUFFER_END.
953 /* MI_BATCH_BUFFER_START with "2nd Level Batch Buffer" unset acts
954 * like a goto. Nothing after it will ever get processed. In
955 * order to prevent the recursion from growing, we just reset the
960 } else if (strcmp(inst_name
, "MI_BATCH_BUFFER_END") == 0) {