panfrost/decode: Preserve empty tiler heap symmetry
[mesa.git] / src / panfrost / pandecode / decode.c
1 /*
2 * Copyright (C) 2017-2019 Alyssa Rosenzweig
3 * Copyright (C) 2017-2019 Connor Abbott
4 * Copyright (C) 2019 Collabora, Ltd.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #include <panfrost-job.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <memory.h>
30 #include <stdbool.h>
31 #include <stdarg.h>
32 #include "decode.h"
33 #include "util/u_math.h"
34
35 #include "pan_pretty_print.h"
36 #include "midgard/disassemble.h"
37 #include "bifrost/disassemble.h"
38
39 int pandecode_jc(mali_ptr jc_gpu_va, bool bifrost);
40
41 #define MEMORY_PROP(obj, p) {\
42 if (obj->p) { \
43 char *a = pointer_as_memory_reference(obj->p); \
44 pandecode_prop("%s = %s", #p, a); \
45 free(a); \
46 } \
47 }
48
49 #define MEMORY_PROP_DIR(obj, p) {\
50 if (obj.p) { \
51 char *a = pointer_as_memory_reference(obj.p); \
52 pandecode_prop("%s = %s", #p, a); \
53 free(a); \
54 } \
55 }
56
57 #define DYN_MEMORY_PROP(obj, no, p) { \
58 if (obj->p) \
59 pandecode_prop("%s = %s_%d_p", #p, #p, no); \
60 }
61
62 /* Semantic logging type.
63 *
64 * Raw: for raw messages to be printed as is.
65 * Message: for helpful information to be commented out in replays.
66 * Property: for properties of a struct
67 *
68 * Use one of pandecode_log, pandecode_msg, or pandecode_prop as syntax sugar.
69 */
70
71 enum pandecode_log_type {
72 PANDECODE_RAW,
73 PANDECODE_MESSAGE,
74 PANDECODE_PROPERTY
75 };
76
77 #define pandecode_log(...) pandecode_log_typed(PANDECODE_RAW, __VA_ARGS__)
78 #define pandecode_msg(...) pandecode_log_typed(PANDECODE_MESSAGE, __VA_ARGS__)
79 #define pandecode_prop(...) pandecode_log_typed(PANDECODE_PROPERTY, __VA_ARGS__)
80
81 unsigned pandecode_indent = 0;
82
83 static void
84 pandecode_make_indent(void)
85 {
86 for (unsigned i = 0; i < pandecode_indent; ++i)
87 printf(" ");
88 }
89
90 static void
91 pandecode_log_typed(enum pandecode_log_type type, const char *format, ...)
92 {
93 va_list ap;
94
95 pandecode_make_indent();
96
97 if (type == PANDECODE_MESSAGE)
98 printf("// ");
99 else if (type == PANDECODE_PROPERTY)
100 printf(".");
101
102 va_start(ap, format);
103 vprintf(format, ap);
104 va_end(ap);
105
106 if (type == PANDECODE_PROPERTY)
107 printf(",\n");
108 }
109
110 static void
111 pandecode_log_cont(const char *format, ...)
112 {
113 va_list ap;
114
115 va_start(ap, format);
116 vprintf(format, ap);
117 va_end(ap);
118 }
119
120 struct pandecode_flag_info {
121 u64 flag;
122 const char *name;
123 };
124
125 static void
126 pandecode_log_decoded_flags(const struct pandecode_flag_info *flag_info,
127 u64 flags)
128 {
129 bool decodable_flags_found = false;
130
131 for (int i = 0; flag_info[i].name; i++) {
132 if ((flags & flag_info[i].flag) != flag_info[i].flag)
133 continue;
134
135 if (!decodable_flags_found) {
136 decodable_flags_found = true;
137 } else {
138 pandecode_log_cont(" | ");
139 }
140
141 pandecode_log_cont("%s", flag_info[i].name);
142
143 flags &= ~flag_info[i].flag;
144 }
145
146 if (decodable_flags_found) {
147 if (flags)
148 pandecode_log_cont(" | 0x%" PRIx64, flags);
149 } else {
150 pandecode_log_cont("0x%" PRIx64, flags);
151 }
152 }
153
154 #define FLAG_INFO(flag) { MALI_##flag, "MALI_" #flag }
155 static const struct pandecode_flag_info gl_enable_flag_info[] = {
156 FLAG_INFO(OCCLUSION_QUERY),
157 FLAG_INFO(OCCLUSION_PRECISE),
158 FLAG_INFO(FRONT_CCW_TOP),
159 FLAG_INFO(CULL_FACE_FRONT),
160 FLAG_INFO(CULL_FACE_BACK),
161 {}
162 };
163 #undef FLAG_INFO
164
165 #define FLAG_INFO(flag) { MALI_CLEAR_##flag, "MALI_CLEAR_" #flag }
166 static const struct pandecode_flag_info clear_flag_info[] = {
167 FLAG_INFO(FAST),
168 FLAG_INFO(SLOW),
169 FLAG_INFO(SLOW_STENCIL),
170 {}
171 };
172 #undef FLAG_INFO
173
174 #define FLAG_INFO(flag) { MALI_MASK_##flag, "MALI_MASK_" #flag }
175 static const struct pandecode_flag_info mask_flag_info[] = {
176 FLAG_INFO(R),
177 FLAG_INFO(G),
178 FLAG_INFO(B),
179 FLAG_INFO(A),
180 {}
181 };
182 #undef FLAG_INFO
183
184 #define FLAG_INFO(flag) { MALI_##flag, "MALI_" #flag }
185 static const struct pandecode_flag_info u3_flag_info[] = {
186 FLAG_INFO(HAS_MSAA),
187 FLAG_INFO(CAN_DISCARD),
188 FLAG_INFO(HAS_BLEND_SHADER),
189 FLAG_INFO(DEPTH_TEST),
190 {}
191 };
192
193 static const struct pandecode_flag_info u4_flag_info[] = {
194 FLAG_INFO(NO_MSAA),
195 FLAG_INFO(NO_DITHER),
196 FLAG_INFO(DEPTH_RANGE_A),
197 FLAG_INFO(DEPTH_RANGE_B),
198 FLAG_INFO(STENCIL_TEST),
199 FLAG_INFO(SAMPLE_ALPHA_TO_COVERAGE_NO_BLEND_SHADER),
200 {}
201 };
202 #undef FLAG_INFO
203
204 #define FLAG_INFO(flag) { MALI_FRAMEBUFFER_##flag, "MALI_FRAMEBUFFER_" #flag }
205 static const struct pandecode_flag_info fb_fmt_flag_info[] = {
206 FLAG_INFO(MSAA_A),
207 FLAG_INFO(MSAA_B),
208 FLAG_INFO(MSAA_8),
209 {}
210 };
211 #undef FLAG_INFO
212
213 #define FLAG_INFO(flag) { MALI_MFBD_FORMAT_##flag, "MALI_MFBD_FORMAT_" #flag }
214 static const struct pandecode_flag_info mfbd_fmt_flag_info[] = {
215 FLAG_INFO(MSAA),
216 FLAG_INFO(SRGB),
217 {}
218 };
219 #undef FLAG_INFO
220
221 #define FLAG_INFO(flag) { MALI_EXTRA_##flag, "MALI_EXTRA_" #flag }
222 static const struct pandecode_flag_info mfbd_extra_flag_info[] = {
223 FLAG_INFO(PRESENT),
224 FLAG_INFO(AFBC),
225 FLAG_INFO(ZS),
226 {}
227 };
228 #undef FLAG_INFO
229
230 #define FLAG_INFO(flag) { MALI_##flag, "MALI_" #flag }
231 static const struct pandecode_flag_info shader_midgard1_flag_info [] = {
232 FLAG_INFO(EARLY_Z),
233 FLAG_INFO(HELPER_INVOCATIONS),
234 FLAG_INFO(READS_TILEBUFFER),
235 FLAG_INFO(READS_ZS),
236 {}
237 };
238 #undef FLAG_INFO
239
240 #define FLAG_INFO(flag) { MALI_MFBD_##flag, "MALI_MFBD_" #flag }
241 static const struct pandecode_flag_info mfbd_flag_info [] = {
242 FLAG_INFO(DEPTH_WRITE),
243 FLAG_INFO(EXTRA),
244 {}
245 };
246 #undef FLAG_INFO
247
248
249 extern char *replace_fragment;
250 extern char *replace_vertex;
251
252 static char *
253 pandecode_job_type(enum mali_job_type type)
254 {
255 #define DEFINE_CASE(name) case JOB_TYPE_ ## name: return "JOB_TYPE_" #name
256
257 switch (type) {
258 DEFINE_CASE(NULL);
259 DEFINE_CASE(SET_VALUE);
260 DEFINE_CASE(CACHE_FLUSH);
261 DEFINE_CASE(COMPUTE);
262 DEFINE_CASE(VERTEX);
263 DEFINE_CASE(TILER);
264 DEFINE_CASE(FUSED);
265 DEFINE_CASE(FRAGMENT);
266
267 case JOB_NOT_STARTED:
268 return "NOT_STARTED";
269
270 default:
271 pandecode_log("Warning! Unknown job type %x\n", type);
272 return "!?!?!?";
273 }
274
275 #undef DEFINE_CASE
276 }
277
278 static char *
279 pandecode_draw_mode(enum mali_draw_mode mode)
280 {
281 #define DEFINE_CASE(name) case MALI_ ## name: return "MALI_" #name
282
283 switch (mode) {
284 DEFINE_CASE(DRAW_NONE);
285 DEFINE_CASE(POINTS);
286 DEFINE_CASE(LINES);
287 DEFINE_CASE(TRIANGLES);
288 DEFINE_CASE(TRIANGLE_STRIP);
289 DEFINE_CASE(TRIANGLE_FAN);
290 DEFINE_CASE(LINE_STRIP);
291 DEFINE_CASE(LINE_LOOP);
292 DEFINE_CASE(POLYGON);
293 DEFINE_CASE(QUADS);
294 DEFINE_CASE(QUAD_STRIP);
295
296 default:
297 return "MALI_TRIANGLES /* XXX: Unknown GL mode, check dump */";
298 }
299
300 #undef DEFINE_CASE
301 }
302
303 #define DEFINE_CASE(name) case MALI_FUNC_ ## name: return "MALI_FUNC_" #name
304 static char *
305 pandecode_func(enum mali_func mode)
306 {
307 switch (mode) {
308 DEFINE_CASE(NEVER);
309 DEFINE_CASE(LESS);
310 DEFINE_CASE(EQUAL);
311 DEFINE_CASE(LEQUAL);
312 DEFINE_CASE(GREATER);
313 DEFINE_CASE(NOTEQUAL);
314 DEFINE_CASE(GEQUAL);
315 DEFINE_CASE(ALWAYS);
316
317 default:
318 return "MALI_FUNC_NEVER /* XXX: Unknown function, check dump */";
319 }
320 }
321 #undef DEFINE_CASE
322
323 /* Why is this duplicated? Who knows... */
324 #define DEFINE_CASE(name) case MALI_ALT_FUNC_ ## name: return "MALI_ALT_FUNC_" #name
325 static char *
326 pandecode_alt_func(enum mali_alt_func mode)
327 {
328 switch (mode) {
329 DEFINE_CASE(NEVER);
330 DEFINE_CASE(LESS);
331 DEFINE_CASE(EQUAL);
332 DEFINE_CASE(LEQUAL);
333 DEFINE_CASE(GREATER);
334 DEFINE_CASE(NOTEQUAL);
335 DEFINE_CASE(GEQUAL);
336 DEFINE_CASE(ALWAYS);
337
338 default:
339 return "MALI_FUNC_NEVER /* XXX: Unknown function, check dump */";
340 }
341 }
342 #undef DEFINE_CASE
343
344 #define DEFINE_CASE(name) case MALI_STENCIL_ ## name: return "MALI_STENCIL_" #name
345 static char *
346 pandecode_stencil_op(enum mali_stencil_op op)
347 {
348 switch (op) {
349 DEFINE_CASE(KEEP);
350 DEFINE_CASE(REPLACE);
351 DEFINE_CASE(ZERO);
352 DEFINE_CASE(INVERT);
353 DEFINE_CASE(INCR_WRAP);
354 DEFINE_CASE(DECR_WRAP);
355 DEFINE_CASE(INCR);
356 DEFINE_CASE(DECR);
357
358 default:
359 return "MALI_STENCIL_KEEP /* XXX: Unknown stencil op, check dump */";
360 }
361 }
362
363 #undef DEFINE_CASE
364
365 #define DEFINE_CASE(name) case MALI_ATTR_ ## name: return "MALI_ATTR_" #name
366 static char *pandecode_attr_mode(enum mali_attr_mode mode)
367 {
368 switch(mode) {
369 DEFINE_CASE(UNUSED);
370 DEFINE_CASE(LINEAR);
371 DEFINE_CASE(POT_DIVIDE);
372 DEFINE_CASE(MODULO);
373 DEFINE_CASE(NPOT_DIVIDE);
374 default:
375 return "MALI_ATTR_UNUSED /* XXX: Unknown stencil op, check dump */";
376 }
377 }
378
379 #undef DEFINE_CASE
380
381 #define DEFINE_CASE(name) case MALI_CHANNEL_## name: return "MALI_CHANNEL_" #name
382 static char *
383 pandecode_channel(enum mali_channel channel)
384 {
385 switch (channel) {
386 DEFINE_CASE(RED);
387 DEFINE_CASE(GREEN);
388 DEFINE_CASE(BLUE);
389 DEFINE_CASE(ALPHA);
390 DEFINE_CASE(ZERO);
391 DEFINE_CASE(ONE);
392 DEFINE_CASE(RESERVED_0);
393 DEFINE_CASE(RESERVED_1);
394
395 default:
396 return "MALI_CHANNEL_ZERO /* XXX: Unknown channel, check dump */";
397 }
398 }
399 #undef DEFINE_CASE
400
401 #define DEFINE_CASE(name) case MALI_WRAP_## name: return "MALI_WRAP_" #name
402 static char *
403 pandecode_wrap_mode(enum mali_wrap_mode op)
404 {
405 switch (op) {
406 DEFINE_CASE(REPEAT);
407 DEFINE_CASE(CLAMP_TO_EDGE);
408 DEFINE_CASE(CLAMP_TO_BORDER);
409 DEFINE_CASE(MIRRORED_REPEAT);
410
411 default:
412 return "MALI_WRAP_REPEAT /* XXX: Unknown wrap mode, check dump */";
413 }
414 }
415 #undef DEFINE_CASE
416
417 #define DEFINE_CASE(name) case MALI_TEX_## name: return "MALI_TEX_" #name
418 static char *
419 pandecode_texture_type(enum mali_texture_type type)
420 {
421 switch (type) {
422 DEFINE_CASE(1D);
423 DEFINE_CASE(2D);
424 DEFINE_CASE(3D);
425 DEFINE_CASE(CUBE);
426
427 default:
428 unreachable("Unknown case");
429 }
430 }
431 #undef DEFINE_CASE
432
433 #define DEFINE_CASE(name) case MALI_MFBD_BLOCK_## name: return "MALI_MFBD_BLOCK_" #name
434 static char *
435 pandecode_mfbd_block_format(enum mali_mfbd_block_format fmt)
436 {
437 switch (fmt) {
438 DEFINE_CASE(TILED);
439 DEFINE_CASE(UNKNOWN);
440 DEFINE_CASE(LINEAR);
441 DEFINE_CASE(AFBC);
442
443 default:
444 unreachable("Invalid case");
445 }
446 }
447 #undef DEFINE_CASE
448
449 /* Midgard's tiler descriptor is embedded within the
450 * larger FBD */
451
452 static void
453 pandecode_midgard_tiler_descriptor(const struct midgard_tiler_descriptor *t)
454 {
455 pandecode_log(".tiler = {\n");
456 pandecode_indent++;
457
458 pandecode_prop("hierarchy_mask = 0x%" PRIx16, t->hierarchy_mask);
459 pandecode_prop("flags = 0x%" PRIx16, t->flags);
460 pandecode_prop("polygon_list_size = 0x%x", t->polygon_list_size);
461
462 MEMORY_PROP(t, polygon_list);
463 MEMORY_PROP(t, polygon_list_body);
464
465 MEMORY_PROP(t, heap_start);
466
467 if (t->heap_start == t->heap_end) {
468 /* Print identically to show symmetry for empty tiler heaps */
469 MEMORY_PROP(t, heap_start);
470 } else {
471 /* Points to the end of a buffer */
472 char *a = pointer_as_memory_reference(t->heap_end - 1);
473 pandecode_prop("heap_end = %s + 1", a);
474 free(a);
475 }
476
477 bool nonzero_weights = false;
478
479 for (unsigned w = 0; w < ARRAY_SIZE(t->weights); ++w) {
480 nonzero_weights |= t->weights[w] != 0x0;
481 }
482
483 if (nonzero_weights) {
484 pandecode_log(".weights = {");
485
486 for (unsigned w = 0; w < ARRAY_SIZE(t->weights); ++w) {
487 pandecode_log("%d, ", t->weights[w]);
488 }
489
490 pandecode_log("},");
491 }
492
493 pandecode_indent--;
494 pandecode_log("}\n");
495 }
496
497 static void
498 pandecode_sfbd(uint64_t gpu_va, int job_no)
499 {
500 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
501 const struct mali_single_framebuffer *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
502
503 pandecode_log("struct mali_single_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
504 pandecode_indent++;
505
506 pandecode_prop("unknown1 = 0x%" PRIx32, s->unknown1);
507 pandecode_prop("unknown2 = 0x%" PRIx32, s->unknown2);
508
509 pandecode_log(".format = ");
510 pandecode_log_decoded_flags(fb_fmt_flag_info, s->format);
511 pandecode_log_cont(",\n");
512
513 pandecode_prop("width = MALI_POSITIVE(%" PRId16 ")", s->width + 1);
514 pandecode_prop("height = MALI_POSITIVE(%" PRId16 ")", s->height + 1);
515
516 MEMORY_PROP(s, framebuffer);
517 pandecode_prop("stride = %d", s->stride);
518
519 /* Earlier in the actual commandstream -- right before width -- but we
520 * delay to flow nicer */
521
522 pandecode_log(".clear_flags = ");
523 pandecode_log_decoded_flags(clear_flag_info, s->clear_flags);
524 pandecode_log_cont(",\n");
525
526 if (s->depth_buffer | s->depth_buffer_enable) {
527 MEMORY_PROP(s, depth_buffer);
528 pandecode_prop("depth_buffer_enable = %s", DS_ENABLE(s->depth_buffer_enable));
529 }
530
531 if (s->stencil_buffer | s->stencil_buffer_enable) {
532 MEMORY_PROP(s, stencil_buffer);
533 pandecode_prop("stencil_buffer_enable = %s", DS_ENABLE(s->stencil_buffer_enable));
534 }
535
536 if (s->clear_color_1 | s->clear_color_2 | s->clear_color_3 | s->clear_color_4) {
537 pandecode_prop("clear_color_1 = 0x%" PRIx32, s->clear_color_1);
538 pandecode_prop("clear_color_2 = 0x%" PRIx32, s->clear_color_2);
539 pandecode_prop("clear_color_3 = 0x%" PRIx32, s->clear_color_3);
540 pandecode_prop("clear_color_4 = 0x%" PRIx32, s->clear_color_4);
541 }
542
543 if (s->clear_depth_1 != 0 || s->clear_depth_2 != 0 || s->clear_depth_3 != 0 || s->clear_depth_4 != 0) {
544 pandecode_prop("clear_depth_1 = %f", s->clear_depth_1);
545 pandecode_prop("clear_depth_2 = %f", s->clear_depth_2);
546 pandecode_prop("clear_depth_3 = %f", s->clear_depth_3);
547 pandecode_prop("clear_depth_4 = %f", s->clear_depth_4);
548 }
549
550 if (s->clear_stencil) {
551 pandecode_prop("clear_stencil = 0x%x", s->clear_stencil);
552 }
553
554 MEMORY_PROP(s, unknown_address_0);
555 const struct midgard_tiler_descriptor t = s->tiler;
556 pandecode_midgard_tiler_descriptor(&t);
557
558 pandecode_indent--;
559 pandecode_log("};\n");
560
561 pandecode_prop("zero0 = 0x%" PRIx64, s->zero0);
562 pandecode_prop("zero1 = 0x%" PRIx64, s->zero1);
563 pandecode_prop("zero2 = 0x%" PRIx32, s->zero2);
564 pandecode_prop("zero4 = 0x%" PRIx32, s->zero4);
565
566 printf(".zero3 = {");
567
568 for (int i = 0; i < sizeof(s->zero3) / sizeof(s->zero3[0]); ++i)
569 printf("%X, ", s->zero3[i]);
570
571 printf("},\n");
572
573 printf(".zero6 = {");
574
575 for (int i = 0; i < sizeof(s->zero6) / sizeof(s->zero6[0]); ++i)
576 printf("%X, ", s->zero6[i]);
577
578 printf("},\n");
579 }
580
581 static void
582 pandecode_u32_slide(unsigned name, const u32 *slide, unsigned count)
583 {
584 pandecode_log(".unknown%d = {", name);
585
586 for (int i = 0; i < count; ++i)
587 printf("%X, ", slide[i]);
588
589 pandecode_log("},\n");
590 }
591
592 #define SHORT_SLIDE(num) \
593 pandecode_u32_slide(num, s->unknown ## num, ARRAY_SIZE(s->unknown ## num))
594
595 static void
596 pandecode_compute_fbd(uint64_t gpu_va, int job_no)
597 {
598 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
599 const struct mali_compute_fbd *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
600
601 pandecode_log("struct mali_compute_fbd framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
602 pandecode_indent++;
603
604 SHORT_SLIDE(1);
605
606 pandecode_indent--;
607 printf("},\n");
608 }
609
610 static void
611 pandecode_swizzle(unsigned swizzle)
612 {
613 pandecode_prop("swizzle = %s | (%s << 3) | (%s << 6) | (%s << 9)",
614 pandecode_channel((swizzle >> 0) & 0x7),
615 pandecode_channel((swizzle >> 3) & 0x7),
616 pandecode_channel((swizzle >> 6) & 0x7),
617 pandecode_channel((swizzle >> 9) & 0x7));
618 }
619
620 static void
621 pandecode_rt_format(struct mali_rt_format format)
622 {
623 pandecode_log(".format = {\n");
624 pandecode_indent++;
625
626 pandecode_prop("unk1 = 0x%" PRIx32, format.unk1);
627 pandecode_prop("unk2 = 0x%" PRIx32, format.unk2);
628 pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
629
630 pandecode_prop("block = %s",
631 pandecode_mfbd_block_format(format.block));
632
633 pandecode_prop("nr_channels = MALI_POSITIVE(%d)",
634 MALI_NEGATIVE(format.nr_channels));
635
636 pandecode_log(".flags = ");
637 pandecode_log_decoded_flags(mfbd_fmt_flag_info, format.flags);
638 pandecode_log_cont(",\n");
639
640 pandecode_swizzle(format.swizzle);
641
642 pandecode_prop("unk4 = 0x%" PRIx32, format.unk4);
643
644 pandecode_indent--;
645 pandecode_log("},\n");
646 }
647
648 static void
649 pandecode_render_target(uint64_t gpu_va, unsigned job_no, const struct bifrost_framebuffer *fb)
650 {
651 pandecode_log("struct bifrost_render_target rts_list_%"PRIx64"_%d[] = {\n", gpu_va, job_no);
652 pandecode_indent++;
653
654 for (int i = 0; i < MALI_NEGATIVE(fb->rt_count_1); i++) {
655 mali_ptr rt_va = gpu_va + i * sizeof(struct bifrost_render_target);
656 struct pandecode_mapped_memory *mem =
657 pandecode_find_mapped_gpu_mem_containing(rt_va);
658 const struct bifrost_render_target *PANDECODE_PTR_VAR(rt, mem, (mali_ptr) rt_va);
659
660 pandecode_log("{\n");
661 pandecode_indent++;
662
663 pandecode_rt_format(rt->format);
664
665 if (rt->format.block == MALI_MFBD_BLOCK_AFBC) {
666 pandecode_log(".afbc = {\n");
667 pandecode_indent++;
668
669 char *a = pointer_as_memory_reference(rt->afbc.metadata);
670 pandecode_prop("metadata = %s", a);
671 free(a);
672
673 pandecode_prop("stride = %d", rt->afbc.stride);
674 pandecode_prop("unk = 0x%" PRIx32, rt->afbc.unk);
675
676 pandecode_indent--;
677 pandecode_log("},\n");
678 } else {
679 pandecode_log(".chunknown = {\n");
680 pandecode_indent++;
681
682 pandecode_prop("unk = 0x%" PRIx64, rt->chunknown.unk);
683
684 char *a = pointer_as_memory_reference(rt->chunknown.pointer);
685 pandecode_prop("pointer = %s", a);
686 free(a);
687
688 pandecode_indent--;
689 pandecode_log("},\n");
690 }
691
692 MEMORY_PROP(rt, framebuffer);
693 pandecode_prop("framebuffer_stride = %d", rt->framebuffer_stride);
694
695 if (rt->clear_color_1 | rt->clear_color_2 | rt->clear_color_3 | rt->clear_color_4) {
696 pandecode_prop("clear_color_1 = 0x%" PRIx32, rt->clear_color_1);
697 pandecode_prop("clear_color_2 = 0x%" PRIx32, rt->clear_color_2);
698 pandecode_prop("clear_color_3 = 0x%" PRIx32, rt->clear_color_3);
699 pandecode_prop("clear_color_4 = 0x%" PRIx32, rt->clear_color_4);
700 }
701
702 if (rt->zero1 || rt->zero2 || rt->zero3) {
703 pandecode_msg("render target zeros tripped\n");
704 pandecode_prop("zero1 = 0x%" PRIx64, rt->zero1);
705 pandecode_prop("zero2 = 0x%" PRIx32, rt->zero2);
706 pandecode_prop("zero3 = 0x%" PRIx32, rt->zero3);
707 }
708
709 pandecode_indent--;
710 pandecode_log("},\n");
711 }
712
713 pandecode_indent--;
714 pandecode_log("};\n");
715 }
716
717 static unsigned
718 pandecode_mfbd_bfr(uint64_t gpu_va, int job_no, bool with_render_targets)
719 {
720 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
721 const struct bifrost_framebuffer *PANDECODE_PTR_VAR(fb, mem, (mali_ptr) gpu_va);
722
723 if (fb->sample_locations) {
724 /* The blob stores all possible sample locations in a single buffer
725 * allocated on startup, and just switches the pointer when switching
726 * MSAA state. For now, we just put the data into the cmdstream, but we
727 * should do something like what the blob does with a real driver.
728 *
729 * There seem to be 32 slots for sample locations, followed by another
730 * 16. The second 16 is just the center location followed by 15 zeros
731 * in all the cases I've identified (maybe shader vs. depth/color
732 * samples?).
733 */
734
735 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(fb->sample_locations);
736
737 const u16 *PANDECODE_PTR_VAR(samples, smem, fb->sample_locations);
738
739 pandecode_log("uint16_t sample_locations_%d[] = {\n", job_no);
740 pandecode_indent++;
741
742 for (int i = 0; i < 32 + 16; i++) {
743 pandecode_log("%d, %d,\n", samples[2 * i], samples[2 * i + 1]);
744 }
745
746 pandecode_indent--;
747 pandecode_log("};\n");
748 }
749
750 pandecode_log("struct bifrost_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
751 pandecode_indent++;
752
753 pandecode_prop("unk0 = 0x%x", fb->unk0);
754
755 if (fb->sample_locations)
756 pandecode_prop("sample_locations = sample_locations_%d", job_no);
757
758 /* Assume that unknown1 was emitted in the last job for
759 * now */
760 MEMORY_PROP(fb, unknown1);
761
762 pandecode_prop("width1 = MALI_POSITIVE(%d)", fb->width1 + 1);
763 pandecode_prop("height1 = MALI_POSITIVE(%d)", fb->height1 + 1);
764 pandecode_prop("width2 = MALI_POSITIVE(%d)", fb->width2 + 1);
765 pandecode_prop("height2 = MALI_POSITIVE(%d)", fb->height2 + 1);
766
767 pandecode_prop("unk1 = 0x%x", fb->unk1);
768 pandecode_prop("unk2 = 0x%x", fb->unk2);
769 pandecode_prop("rt_count_1 = MALI_POSITIVE(%d)", fb->rt_count_1 + 1);
770 pandecode_prop("rt_count_2 = %d", fb->rt_count_2);
771
772 pandecode_log(".mfbd_flags = ");
773 pandecode_log_decoded_flags(mfbd_flag_info, fb->mfbd_flags);
774 pandecode_log_cont(",\n");
775
776 pandecode_prop("clear_stencil = 0x%x", fb->clear_stencil);
777 pandecode_prop("clear_depth = %f", fb->clear_depth);
778
779 pandecode_prop("unknown2 = 0x%x", fb->unknown2);
780 MEMORY_PROP(fb, scratchpad);
781 const struct midgard_tiler_descriptor t = fb->tiler;
782 pandecode_midgard_tiler_descriptor(&t);
783
784 if (fb->zero3 || fb->zero4) {
785 pandecode_msg("framebuffer zeros tripped\n");
786 pandecode_prop("zero3 = 0x%" PRIx32, fb->zero3);
787 pandecode_prop("zero4 = 0x%" PRIx32, fb->zero4);
788 }
789
790 pandecode_indent--;
791 pandecode_log("};\n");
792
793 gpu_va += sizeof(struct bifrost_framebuffer);
794
795 if ((fb->mfbd_flags & MALI_MFBD_EXTRA) && with_render_targets) {
796 mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
797 const struct bifrost_fb_extra *PANDECODE_PTR_VAR(fbx, mem, (mali_ptr) gpu_va);
798
799 pandecode_log("struct bifrost_fb_extra fb_extra_%"PRIx64"_%d = {\n", gpu_va, job_no);
800 pandecode_indent++;
801
802 MEMORY_PROP(fbx, checksum);
803
804 if (fbx->checksum_stride)
805 pandecode_prop("checksum_stride = %d", fbx->checksum_stride);
806
807 pandecode_log(".flags = ");
808 pandecode_log_decoded_flags(mfbd_extra_flag_info, fbx->flags);
809 pandecode_log_cont(",\n");
810
811 if (fbx->flags & MALI_EXTRA_AFBC_ZS) {
812 pandecode_log(".ds_afbc = {\n");
813 pandecode_indent++;
814
815 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil_afbc_metadata);
816 pandecode_prop("depth_stencil_afbc_stride = %d",
817 fbx->ds_afbc.depth_stencil_afbc_stride);
818 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil);
819
820 if (fbx->ds_afbc.zero1 || fbx->ds_afbc.padding) {
821 pandecode_msg("Depth/stencil AFBC zeros tripped\n");
822 pandecode_prop("zero1 = 0x%" PRIx32,
823 fbx->ds_afbc.zero1);
824 pandecode_prop("padding = 0x%" PRIx64,
825 fbx->ds_afbc.padding);
826 }
827
828 pandecode_indent--;
829 pandecode_log("},\n");
830 } else {
831 pandecode_log(".ds_linear = {\n");
832 pandecode_indent++;
833
834 if (fbx->ds_linear.depth) {
835 MEMORY_PROP_DIR(fbx->ds_linear, depth);
836 pandecode_prop("depth_stride = %d",
837 fbx->ds_linear.depth_stride);
838 }
839
840 if (fbx->ds_linear.stencil) {
841 MEMORY_PROP_DIR(fbx->ds_linear, stencil);
842 pandecode_prop("stencil_stride = %d",
843 fbx->ds_linear.stencil_stride);
844 }
845
846 if (fbx->ds_linear.depth_stride_zero ||
847 fbx->ds_linear.stencil_stride_zero ||
848 fbx->ds_linear.zero1 || fbx->ds_linear.zero2) {
849 pandecode_msg("Depth/stencil zeros tripped\n");
850 pandecode_prop("depth_stride_zero = 0x%x",
851 fbx->ds_linear.depth_stride_zero);
852 pandecode_prop("stencil_stride_zero = 0x%x",
853 fbx->ds_linear.stencil_stride_zero);
854 pandecode_prop("zero1 = 0x%" PRIx32,
855 fbx->ds_linear.zero1);
856 pandecode_prop("zero2 = 0x%" PRIx32,
857 fbx->ds_linear.zero2);
858 }
859
860 pandecode_indent--;
861 pandecode_log("},\n");
862 }
863
864 if (fbx->zero3 || fbx->zero4) {
865 pandecode_msg("fb_extra zeros tripped\n");
866 pandecode_prop("zero3 = 0x%" PRIx64, fbx->zero3);
867 pandecode_prop("zero4 = 0x%" PRIx64, fbx->zero4);
868 }
869
870 pandecode_indent--;
871 pandecode_log("};\n");
872
873 gpu_va += sizeof(struct bifrost_fb_extra);
874 }
875
876 if (with_render_targets)
877 pandecode_render_target(gpu_va, job_no, fb);
878
879 /* Passback the render target count */
880 return MALI_NEGATIVE(fb->rt_count_1);
881 }
882
883 /* Just add a comment decoding the shift/odd fields forming the padded vertices
884 * count */
885
886 static void
887 pandecode_padded_vertices(unsigned shift, unsigned k)
888 {
889 unsigned odd = 2*k + 1;
890 unsigned pot = 1 << shift;
891 pandecode_msg("padded_num_vertices = %d\n", odd * pot);
892 }
893
894 /* Given a magic divisor, recover what we were trying to divide by.
895 *
896 * Let m represent the magic divisor. By definition, m is an element on Z, whre
897 * 0 <= m < 2^N, for N bits in m.
898 *
899 * Let q represent the number we would like to divide by.
900 *
901 * By definition of a magic divisor for N-bit unsigned integers (a number you
902 * multiply by to magically get division), m is a number such that:
903 *
904 * (m * x) & (2^N - 1) = floor(x/q).
905 * for all x on Z where 0 <= x < 2^N
906 *
907 * Ignore the case where any of the above values equals zero; it is irrelevant
908 * for our purposes (instanced arrays).
909 *
910 * Choose x = q. Then:
911 *
912 * (m * x) & (2^N - 1) = floor(x/q).
913 * (m * q) & (2^N - 1) = floor(q/q).
914 *
915 * floor(q/q) = floor(1) = 1, therefore:
916 *
917 * (m * q) & (2^N - 1) = 1
918 *
919 * Recall the identity that the bitwise AND of one less than a power-of-two
920 * equals the modulo with that power of two, i.e. for all x:
921 *
922 * x & (2^N - 1) = x % N
923 *
924 * Therefore:
925 *
926 * mq % (2^N) = 1
927 *
928 * By definition, a modular multiplicative inverse of a number m is the number
929 * q such that with respect to a modulos M:
930 *
931 * mq % M = 1
932 *
933 * Therefore, q is the modular multiplicative inverse of m with modulus 2^N.
934 *
935 */
936
937 static void
938 pandecode_magic_divisor(uint32_t magic, unsigned shift, unsigned orig_divisor, unsigned extra)
939 {
940 /* Compute the modular inverse of `magic` with respect to 2^(32 -
941 * shift) the most lame way possible... just repeatedly add.
942 * Asymptoptically slow but nobody cares in practice, unless you have
943 * massive numbers of vertices or high divisors. */
944
945 unsigned inverse = 0;
946
947 /* Magic implicitly has the highest bit set */
948 magic |= (1 << 31);
949
950 /* Depending on rounding direction */
951 if (extra)
952 magic++;
953
954 for (;;) {
955 uint32_t product = magic * inverse;
956
957 if (shift) {
958 product >>= shift;
959 }
960
961 if (product == 1)
962 break;
963
964 ++inverse;
965 }
966
967 pandecode_msg("dividing by %d (maybe off by two)\n", inverse);
968
969 /* Recall we're supposed to divide by (gl_level_divisor *
970 * padded_num_vertices) */
971
972 unsigned padded_num_vertices = inverse / orig_divisor;
973
974 pandecode_msg("padded_num_vertices = %d\n", padded_num_vertices);
975 }
976
977 static void
978 pandecode_attributes(const struct pandecode_mapped_memory *mem,
979 mali_ptr addr, int job_no, char *suffix,
980 int count, bool varying)
981 {
982 char *prefix = varying ? "varyings" : "attributes";
983
984 union mali_attr *attr = pandecode_fetch_gpu_mem(mem, addr, sizeof(union mali_attr) * count);
985
986 char base[128];
987 snprintf(base, sizeof(base), "%s_data_%d%s", prefix, job_no, suffix);
988
989 for (int i = 0; i < count; ++i) {
990 enum mali_attr_mode mode = attr[i].elements & 7;
991
992 if (mode == MALI_ATTR_UNUSED)
993 continue;
994
995 mali_ptr raw_elements = attr[i].elements & ~7;
996
997 /* TODO: Do we maybe want to dump the attribute values
998 * themselves given the specified format? Or is that too hard?
999 * */
1000
1001 char *a = pointer_as_memory_reference(raw_elements);
1002 pandecode_log("mali_ptr %s_%d_p = %s;\n", base, i, a);
1003 free(a);
1004 }
1005
1006 pandecode_log("union mali_attr %s_%d[] = {\n", prefix, job_no);
1007 pandecode_indent++;
1008
1009 for (int i = 0; i < count; ++i) {
1010 pandecode_log("{\n");
1011 pandecode_indent++;
1012
1013 unsigned mode = attr[i].elements & 7;
1014 pandecode_prop("elements = (%s_%d_p) | %s", base, i, pandecode_attr_mode(mode));
1015 pandecode_prop("shift = %d", attr[i].shift);
1016 pandecode_prop("extra_flags = %d", attr[i].extra_flags);
1017 pandecode_prop("stride = 0x%" PRIx32, attr[i].stride);
1018 pandecode_prop("size = 0x%" PRIx32, attr[i].size);
1019
1020 /* Decode further where possible */
1021
1022 if (mode == MALI_ATTR_MODULO) {
1023 pandecode_padded_vertices(
1024 attr[i].shift,
1025 attr[i].extra_flags);
1026 }
1027
1028 pandecode_indent--;
1029 pandecode_log("}, \n");
1030
1031 if (mode == MALI_ATTR_NPOT_DIVIDE) {
1032 i++;
1033 pandecode_log("{\n");
1034 pandecode_indent++;
1035 pandecode_prop("unk = 0x%x", attr[i].unk);
1036 pandecode_prop("magic_divisor = 0x%08x", attr[i].magic_divisor);
1037 if (attr[i].zero != 0)
1038 pandecode_prop("zero = 0x%x /* XXX zero tripped */", attr[i].zero);
1039 pandecode_prop("divisor = %d", attr[i].divisor);
1040 pandecode_magic_divisor(attr[i].magic_divisor, attr[i - 1].shift, attr[i].divisor, attr[i - 1].extra_flags);
1041 pandecode_indent--;
1042 pandecode_log("}, \n");
1043 }
1044
1045 }
1046
1047 pandecode_indent--;
1048 pandecode_log("};\n");
1049 }
1050
1051 static mali_ptr
1052 pandecode_shader_address(const char *name, mali_ptr ptr)
1053 {
1054 /* TODO: Decode flags */
1055 mali_ptr shader_ptr = ptr & ~15;
1056
1057 char *a = pointer_as_memory_reference(shader_ptr);
1058 pandecode_prop("%s = (%s) | %d", name, a, (int) (ptr & 15));
1059 free(a);
1060
1061 return shader_ptr;
1062 }
1063
1064 static bool
1065 all_zero(unsigned *buffer, unsigned count)
1066 {
1067 for (unsigned i = 0; i < count; ++i) {
1068 if (buffer[i])
1069 return false;
1070 }
1071
1072 return true;
1073 }
1074
1075 static void
1076 pandecode_stencil(const char *name, const struct mali_stencil_test *stencil)
1077 {
1078 if (all_zero((unsigned *) stencil, sizeof(stencil) / sizeof(unsigned)))
1079 return;
1080
1081 const char *func = pandecode_func(stencil->func);
1082 const char *sfail = pandecode_stencil_op(stencil->sfail);
1083 const char *dpfail = pandecode_stencil_op(stencil->dpfail);
1084 const char *dppass = pandecode_stencil_op(stencil->dppass);
1085
1086 if (stencil->zero)
1087 pandecode_msg("Stencil zero tripped: %X\n", stencil->zero);
1088
1089 pandecode_log(".stencil_%s = {\n", name);
1090 pandecode_indent++;
1091 pandecode_prop("ref = %d", stencil->ref);
1092 pandecode_prop("mask = 0x%02X", stencil->mask);
1093 pandecode_prop("func = %s", func);
1094 pandecode_prop("sfail = %s", sfail);
1095 pandecode_prop("dpfail = %s", dpfail);
1096 pandecode_prop("dppass = %s", dppass);
1097 pandecode_indent--;
1098 pandecode_log("},\n");
1099 }
1100
1101 static void
1102 pandecode_blend_equation(const struct mali_blend_equation *blend)
1103 {
1104 if (blend->zero1)
1105 pandecode_msg("Blend zero tripped: %X\n", blend->zero1);
1106
1107 pandecode_log(".equation = {\n");
1108 pandecode_indent++;
1109
1110 pandecode_prop("rgb_mode = 0x%X", blend->rgb_mode);
1111 pandecode_prop("alpha_mode = 0x%X", blend->alpha_mode);
1112
1113 pandecode_log(".color_mask = ");
1114 pandecode_log_decoded_flags(mask_flag_info, blend->color_mask);
1115 pandecode_log_cont(",\n");
1116
1117 pandecode_indent--;
1118 pandecode_log("},\n");
1119 }
1120
1121 /* Decodes a Bifrost blend constant. See the notes in bifrost_blend_rt */
1122
1123 static unsigned
1124 decode_bifrost_constant(u16 constant)
1125 {
1126 float lo = (float) (constant & 0xFF);
1127 float hi = (float) (constant >> 8);
1128
1129 return (hi / 255.0) + (lo / 65535.0);
1130 }
1131
1132 static mali_ptr
1133 pandecode_bifrost_blend(void *descs, int job_no, int rt_no)
1134 {
1135 struct bifrost_blend_rt *b =
1136 ((struct bifrost_blend_rt *) descs) + rt_no;
1137
1138 pandecode_log("struct bifrost_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1139 pandecode_indent++;
1140
1141 pandecode_prop("flags = 0x%" PRIx16, b->flags);
1142 pandecode_prop("constant = 0x%" PRIx8 " /* %f */",
1143 b->constant, decode_bifrost_constant(b->constant));
1144
1145 /* TODO figure out blend shader enable bit */
1146 pandecode_blend_equation(&b->equation);
1147 pandecode_prop("unk2 = 0x%" PRIx16, b->unk2);
1148 pandecode_prop("index = 0x%" PRIx16, b->index);
1149 pandecode_prop("shader = 0x%" PRIx32, b->shader);
1150
1151 pandecode_indent--;
1152 pandecode_log("},\n");
1153
1154 return 0;
1155 }
1156
1157 static mali_ptr
1158 pandecode_midgard_blend(union midgard_blend *blend, bool is_shader)
1159 {
1160 if (all_zero((unsigned *) blend, sizeof(blend) / sizeof(unsigned)))
1161 return 0;
1162
1163 pandecode_log(".blend = {\n");
1164 pandecode_indent++;
1165
1166 if (is_shader) {
1167 pandecode_shader_address("shader", blend->shader);
1168 } else {
1169 pandecode_blend_equation(&blend->equation);
1170 pandecode_prop("constant = %f", blend->constant);
1171 }
1172
1173 pandecode_indent--;
1174 pandecode_log("},\n");
1175
1176 /* Return blend shader to disassemble if present */
1177 return is_shader ? (blend->shader & ~0xF) : 0;
1178 }
1179
1180 static mali_ptr
1181 pandecode_midgard_blend_mrt(void *descs, int job_no, int rt_no)
1182 {
1183 struct midgard_blend_rt *b =
1184 ((struct midgard_blend_rt *) descs) + rt_no;
1185
1186 /* Flags determine presence of blend shader */
1187 bool is_shader = (b->flags & 0xF) >= 0x2;
1188
1189 pandecode_log("struct midgard_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1190 pandecode_indent++;
1191
1192 pandecode_prop("flags = 0x%" PRIx64, b->flags);
1193
1194 union midgard_blend blend = b->blend;
1195 mali_ptr shader = pandecode_midgard_blend(&blend, is_shader);
1196
1197 pandecode_indent--;
1198 pandecode_log("};\n");
1199
1200 return shader;
1201 }
1202
1203 static int
1204 pandecode_attribute_meta(int job_no, int count, const struct mali_vertex_tiler_postfix *v, bool varying, char *suffix)
1205 {
1206 char base[128];
1207 char *prefix = varying ? "varying" : "attribute";
1208 unsigned max_index = 0;
1209 snprintf(base, sizeof(base), "%s_meta", prefix);
1210
1211 pandecode_log("struct mali_attr_meta %s_%d%s[] = {\n", base, job_no, suffix);
1212 pandecode_indent++;
1213
1214 struct mali_attr_meta *attr_meta;
1215 mali_ptr p = varying ? (v->varying_meta & ~0xF) : v->attribute_meta;
1216
1217 struct pandecode_mapped_memory *attr_mem = pandecode_find_mapped_gpu_mem_containing(p);
1218
1219 for (int i = 0; i < count; ++i, p += sizeof(struct mali_attr_meta)) {
1220 attr_meta = pandecode_fetch_gpu_mem(attr_mem, p,
1221 sizeof(*attr_mem));
1222
1223 pandecode_log("{\n");
1224 pandecode_indent++;
1225 pandecode_prop("index = %d", attr_meta->index);
1226
1227 if (attr_meta->index > max_index)
1228 max_index = attr_meta->index;
1229 pandecode_swizzle(attr_meta->swizzle);
1230 pandecode_prop("format = %s", pandecode_format(attr_meta->format));
1231
1232 pandecode_prop("unknown1 = 0x%" PRIx64, (u64) attr_meta->unknown1);
1233 pandecode_prop("unknown3 = 0x%" PRIx64, (u64) attr_meta->unknown3);
1234 pandecode_prop("src_offset = %d", attr_meta->src_offset);
1235 pandecode_indent--;
1236 pandecode_log("},\n");
1237
1238 }
1239
1240 pandecode_indent--;
1241 pandecode_log("};\n");
1242
1243 return max_index;
1244 }
1245
1246 static void
1247 pandecode_indices(uintptr_t pindices, uint32_t index_count, int job_no)
1248 {
1249 struct pandecode_mapped_memory *imem = pandecode_find_mapped_gpu_mem_containing(pindices);
1250
1251 if (imem) {
1252 /* Indices are literally just a u32 array :) */
1253
1254 uint32_t *PANDECODE_PTR_VAR(indices, imem, pindices);
1255
1256 pandecode_log("uint32_t indices_%d[] = {\n", job_no);
1257 pandecode_indent++;
1258
1259 for (unsigned i = 0; i < (index_count + 1); i += 3)
1260 pandecode_log("%d, %d, %d,\n",
1261 indices[i],
1262 indices[i + 1],
1263 indices[i + 2]);
1264
1265 pandecode_indent--;
1266 pandecode_log("};\n");
1267 }
1268 }
1269
1270 /* return bits [lo, hi) of word */
1271 static u32
1272 bits(u32 word, u32 lo, u32 hi)
1273 {
1274 if (hi - lo >= 32)
1275 return word; // avoid undefined behavior with the shift
1276
1277 return (word >> lo) & ((1 << (hi - lo)) - 1);
1278 }
1279
1280 static void
1281 pandecode_vertex_tiler_prefix(struct mali_vertex_tiler_prefix *p, int job_no)
1282 {
1283 pandecode_log_cont("{\n");
1284 pandecode_indent++;
1285
1286 pandecode_prop("invocation_count = 0x%" PRIx32, p->invocation_count);
1287 pandecode_prop("size_y_shift = %d", p->size_y_shift);
1288 pandecode_prop("size_z_shift = %d", p->size_z_shift);
1289 pandecode_prop("workgroups_x_shift = %d", p->workgroups_x_shift);
1290 pandecode_prop("workgroups_y_shift = %d", p->workgroups_y_shift);
1291 pandecode_prop("workgroups_z_shift = %d", p->workgroups_z_shift);
1292 pandecode_prop("workgroups_x_shift_2 = 0x%" PRIx32, p->workgroups_x_shift_2);
1293
1294 /* Decode invocation_count. See the comment before the definition of
1295 * invocation_count for an explanation.
1296 */
1297 pandecode_msg("size: (%d, %d, %d)\n",
1298 bits(p->invocation_count, 0, p->size_y_shift) + 1,
1299 bits(p->invocation_count, p->size_y_shift, p->size_z_shift) + 1,
1300 bits(p->invocation_count, p->size_z_shift,
1301 p->workgroups_x_shift) + 1);
1302 pandecode_msg("workgroups: (%d, %d, %d)\n",
1303 bits(p->invocation_count, p->workgroups_x_shift,
1304 p->workgroups_y_shift) + 1,
1305 bits(p->invocation_count, p->workgroups_y_shift,
1306 p->workgroups_z_shift) + 1,
1307 bits(p->invocation_count, p->workgroups_z_shift,
1308 32) + 1);
1309
1310 /* TODO: Decode */
1311 if (p->unknown_draw)
1312 pandecode_prop("unknown_draw = 0x%" PRIx32, p->unknown_draw);
1313
1314 pandecode_prop("workgroups_x_shift_3 = 0x%" PRIx32, p->workgroups_x_shift_3);
1315
1316 pandecode_prop("draw_mode = %s", pandecode_draw_mode(p->draw_mode));
1317
1318 /* Index count only exists for tiler jobs anyway */
1319
1320 if (p->index_count)
1321 pandecode_prop("index_count = MALI_POSITIVE(%" PRId32 ")", p->index_count + 1);
1322
1323 if (p->negative_start)
1324 pandecode_prop("negative_start = %d", p->negative_start);
1325
1326 DYN_MEMORY_PROP(p, job_no, indices);
1327
1328 if (p->zero1) {
1329 pandecode_msg("Zero tripped\n");
1330 pandecode_prop("zero1 = 0x%" PRIx32, p->zero1);
1331 }
1332
1333 pandecode_indent--;
1334 pandecode_log("},\n");
1335 }
1336
1337 static void
1338 pandecode_uniform_buffers(mali_ptr pubufs, int ubufs_count, int job_no)
1339 {
1340 struct pandecode_mapped_memory *umem = pandecode_find_mapped_gpu_mem_containing(pubufs);
1341
1342 struct mali_uniform_buffer_meta *PANDECODE_PTR_VAR(ubufs, umem, pubufs);
1343
1344 for (int i = 0; i < ubufs_count; i++) {
1345 mali_ptr ptr = ubufs[i].ptr << 2;
1346 struct pandecode_mapped_memory *umem2 = pandecode_find_mapped_gpu_mem_containing(ptr);
1347 uint32_t *PANDECODE_PTR_VAR(ubuf, umem2, ptr);
1348 char name[50];
1349 snprintf(name, sizeof(name), "ubuf_%d", i);
1350 /* The blob uses ubuf 0 to upload internal stuff and
1351 * uniforms that won't fit/are accessed indirectly, so
1352 * it puts it in the batchbuffer.
1353 */
1354 pandecode_log("uint32_t %s_%d[] = {\n", name, job_no);
1355 pandecode_indent++;
1356
1357 for (int j = 0; j <= ubufs[i].size; j++) {
1358 for (int k = 0; k < 4; k++) {
1359 if (k == 0)
1360 pandecode_log("0x%"PRIx32", ", ubuf[4 * j + k]);
1361 else
1362 pandecode_log_cont("0x%"PRIx32", ", ubuf[4 * j + k]);
1363
1364 }
1365
1366 pandecode_log_cont("\n");
1367 }
1368
1369 pandecode_indent--;
1370 pandecode_log("};\n");
1371 }
1372
1373 pandecode_log("struct mali_uniform_buffer_meta uniform_buffers_%"PRIx64"_%d[] = {\n",
1374 pubufs, job_no);
1375 pandecode_indent++;
1376
1377 for (int i = 0; i < ubufs_count; i++) {
1378 pandecode_log("{\n");
1379 pandecode_indent++;
1380 pandecode_prop("size = MALI_POSITIVE(%d)", ubufs[i].size + 1);
1381 pandecode_prop("ptr = ubuf_%d_%d_p >> 2", i, job_no);
1382 pandecode_indent--;
1383 pandecode_log("},\n");
1384 }
1385
1386 pandecode_indent--;
1387 pandecode_log("};\n");
1388 }
1389
1390 static void
1391 pandecode_scratchpad(uintptr_t pscratchpad, int job_no, char *suffix)
1392 {
1393
1394 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(pscratchpad);
1395
1396 struct bifrost_scratchpad *PANDECODE_PTR_VAR(scratchpad, mem, pscratchpad);
1397
1398 if (scratchpad->zero)
1399 pandecode_msg("XXX scratchpad zero tripped");
1400
1401 pandecode_log("struct bifrost_scratchpad scratchpad_%"PRIx64"_%d%s = {\n", pscratchpad, job_no, suffix);
1402 pandecode_indent++;
1403
1404 pandecode_prop("flags = 0x%x", scratchpad->flags);
1405 MEMORY_PROP(scratchpad, gpu_scratchpad);
1406
1407 pandecode_indent--;
1408 pandecode_log("};\n");
1409 }
1410
1411 static void
1412 pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
1413 bool is_bifrost)
1414 {
1415 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(shader_ptr);
1416 uint8_t *PANDECODE_PTR_VAR(code, mem, shader_ptr);
1417
1418 /* Compute maximum possible size */
1419 size_t sz = mem->length - (shader_ptr - mem->gpu_va);
1420
1421 /* Print some boilerplate to clearly denote the assembly (which doesn't
1422 * obey indentation rules), and actually do the disassembly! */
1423
1424 printf("\n\n");
1425
1426 if (is_bifrost) {
1427 disassemble_bifrost(code, sz, false);
1428 } else {
1429 disassemble_midgard(code, sz);
1430 }
1431
1432 printf("\n\n");
1433 }
1434
1435 static void
1436 pandecode_vertex_tiler_postfix_pre(const struct mali_vertex_tiler_postfix *p,
1437 int job_no, enum mali_job_type job_type,
1438 char *suffix, bool is_bifrost)
1439 {
1440 mali_ptr shader_meta_ptr = (u64) (uintptr_t) (p->_shader_upper << 4);
1441 struct pandecode_mapped_memory *attr_mem;
1442
1443 unsigned rt_count = 1;
1444
1445 /* On Bifrost, since the tiler heap (for tiler jobs) and the scratchpad
1446 * are the only things actually needed from the FBD, vertex/tiler jobs
1447 * no longer reference the FBD -- instead, this field points to some
1448 * info about the scratchpad.
1449 */
1450 if (is_bifrost)
1451 pandecode_scratchpad(p->framebuffer & ~FBD_TYPE, job_no, suffix);
1452 else if (p->framebuffer & MALI_MFBD)
1453 rt_count = pandecode_mfbd_bfr((u64) ((uintptr_t) p->framebuffer) & FBD_MASK, job_no, false);
1454 else if (job_type == JOB_TYPE_COMPUTE)
1455 pandecode_compute_fbd((u64) (uintptr_t) p->framebuffer, job_no);
1456 else
1457 pandecode_sfbd((u64) (uintptr_t) p->framebuffer, job_no);
1458
1459 int varying_count = 0, attribute_count = 0, uniform_count = 0, uniform_buffer_count = 0;
1460 int texture_count = 0, sampler_count = 0;
1461
1462 if (shader_meta_ptr) {
1463 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(shader_meta_ptr);
1464 struct mali_shader_meta *PANDECODE_PTR_VAR(s, smem, shader_meta_ptr);
1465
1466 pandecode_log("struct mali_shader_meta shader_meta_%"PRIx64"_%d%s = {\n", shader_meta_ptr, job_no, suffix);
1467 pandecode_indent++;
1468
1469 /* Save for dumps */
1470 attribute_count = s->attribute_count;
1471 varying_count = s->varying_count;
1472 texture_count = s->texture_count;
1473 sampler_count = s->sampler_count;
1474
1475 if (is_bifrost) {
1476 uniform_count = s->bifrost2.uniform_count;
1477 uniform_buffer_count = s->bifrost1.uniform_buffer_count;
1478 } else {
1479 uniform_count = s->midgard1.uniform_count;
1480 uniform_buffer_count = s->midgard1.uniform_buffer_count;
1481 }
1482
1483 mali_ptr shader_ptr = pandecode_shader_address("shader", s->shader);
1484
1485 pandecode_prop("texture_count = %" PRId16, s->texture_count);
1486 pandecode_prop("sampler_count = %" PRId16, s->sampler_count);
1487 pandecode_prop("attribute_count = %" PRId16, s->attribute_count);
1488 pandecode_prop("varying_count = %" PRId16, s->varying_count);
1489
1490 if (is_bifrost) {
1491 pandecode_log(".bifrost1 = {\n");
1492 pandecode_indent++;
1493
1494 pandecode_prop("uniform_buffer_count = %" PRId32, s->bifrost1.uniform_buffer_count);
1495 pandecode_prop("unk1 = 0x%" PRIx32, s->bifrost1.unk1);
1496
1497 pandecode_indent--;
1498 pandecode_log("},\n");
1499 } else {
1500 pandecode_log(".midgard1 = {\n");
1501 pandecode_indent++;
1502
1503 pandecode_prop("uniform_count = %" PRId16, s->midgard1.uniform_count);
1504 pandecode_prop("uniform_buffer_count = %" PRId16, s->midgard1.uniform_buffer_count);
1505 pandecode_prop("work_count = %" PRId16, s->midgard1.work_count);
1506
1507 pandecode_log(".flags = ");
1508 pandecode_log_decoded_flags(shader_midgard1_flag_info, s->midgard1.flags);
1509 pandecode_log_cont(",\n");
1510
1511 pandecode_prop("unknown2 = 0x%" PRIx32, s->midgard1.unknown2);
1512
1513 pandecode_indent--;
1514 pandecode_log("},\n");
1515 }
1516
1517 if (s->depth_units || s->depth_factor) {
1518 pandecode_prop("depth_factor = %f", s->depth_factor);
1519 pandecode_prop("depth_units = %f", s->depth_units);
1520 }
1521
1522 if (s->alpha_coverage) {
1523 bool invert_alpha_coverage = s->alpha_coverage & 0xFFF0;
1524 uint16_t inverted_coverage = invert_alpha_coverage ? ~s->alpha_coverage : s->alpha_coverage;
1525
1526 pandecode_prop("alpha_coverage = %sMALI_ALPHA_COVERAGE(%f)",
1527 invert_alpha_coverage ? "~" : "",
1528 MALI_GET_ALPHA_COVERAGE(inverted_coverage));
1529 }
1530
1531 if (s->unknown2_3 || s->unknown2_4) {
1532 pandecode_log(".unknown2_3 = ");
1533
1534 int unknown2_3 = s->unknown2_3;
1535 int unknown2_4 = s->unknown2_4;
1536
1537 /* We're not quite sure what these flags mean without the depth test, if anything */
1538
1539 if (unknown2_3 & (MALI_DEPTH_TEST | MALI_DEPTH_FUNC_MASK)) {
1540 const char *func = pandecode_func(MALI_GET_DEPTH_FUNC(unknown2_3));
1541 unknown2_3 &= ~MALI_DEPTH_FUNC_MASK;
1542
1543 pandecode_log_cont("MALI_DEPTH_FUNC(%s) | ", func);
1544 }
1545
1546 pandecode_log_decoded_flags(u3_flag_info, unknown2_3);
1547 pandecode_log_cont(",\n");
1548
1549 pandecode_log(".unknown2_4 = ");
1550 pandecode_log_decoded_flags(u4_flag_info, unknown2_4);
1551 pandecode_log_cont(",\n");
1552 }
1553
1554 if (s->stencil_mask_front || s->stencil_mask_back) {
1555 pandecode_prop("stencil_mask_front = 0x%02X", s->stencil_mask_front);
1556 pandecode_prop("stencil_mask_back = 0x%02X", s->stencil_mask_back);
1557 }
1558
1559 pandecode_stencil("front", &s->stencil_front);
1560 pandecode_stencil("back", &s->stencil_back);
1561
1562 if (is_bifrost) {
1563 pandecode_log(".bifrost2 = {\n");
1564 pandecode_indent++;
1565
1566 pandecode_prop("unk3 = 0x%" PRIx32, s->bifrost2.unk3);
1567 pandecode_prop("preload_regs = 0x%" PRIx32, s->bifrost2.preload_regs);
1568 pandecode_prop("uniform_count = %" PRId32, s->bifrost2.uniform_count);
1569 pandecode_prop("unk4 = 0x%" PRIx32, s->bifrost2.unk4);
1570
1571 pandecode_indent--;
1572 pandecode_log("},\n");
1573 } else if (s->midgard2.unknown2_7) {
1574 pandecode_log(".midgard2 = {\n");
1575 pandecode_indent++;
1576
1577 pandecode_prop("unknown2_7 = 0x%" PRIx32, s->midgard2.unknown2_7);
1578 pandecode_indent--;
1579 pandecode_log("},\n");
1580 }
1581
1582 if (s->unknown2_8)
1583 pandecode_prop("unknown2_8 = 0x%" PRIx32, s->unknown2_8);
1584
1585 if (!is_bifrost) {
1586 /* TODO: Blend shaders routing/disasm */
1587
1588 union midgard_blend blend = s->blend;
1589 pandecode_midgard_blend(&blend, false);
1590 }
1591
1592 pandecode_indent--;
1593 pandecode_log("};\n");
1594
1595 /* MRT blend fields are used whenever MFBD is used, with
1596 * per-RT descriptors */
1597
1598 if (job_type == JOB_TYPE_TILER) {
1599 void* blend_base = (void *) (s + 1);
1600
1601 for (unsigned i = 0; i < rt_count; i++) {
1602 mali_ptr shader = 0;
1603
1604 if (is_bifrost)
1605 shader = pandecode_bifrost_blend(blend_base, job_no, i);
1606 else
1607 shader = pandecode_midgard_blend_mrt(blend_base, job_no, i);
1608
1609 if (shader & ~0xF)
1610 pandecode_shader_disassemble(shader, job_no, job_type, false);
1611 }
1612 }
1613
1614 if (shader_ptr & ~0xF)
1615 pandecode_shader_disassemble(shader_ptr, job_no, job_type, is_bifrost);
1616 } else
1617 pandecode_msg("<no shader>\n");
1618
1619 if (p->viewport) {
1620 struct pandecode_mapped_memory *fmem = pandecode_find_mapped_gpu_mem_containing(p->viewport);
1621 struct mali_viewport *PANDECODE_PTR_VAR(f, fmem, p->viewport);
1622
1623 pandecode_log("struct mali_viewport viewport_%"PRIx64"_%d%s = {\n", p->viewport, job_no, suffix);
1624 pandecode_indent++;
1625
1626 pandecode_prop("clip_minx = %f", f->clip_minx);
1627 pandecode_prop("clip_miny = %f", f->clip_miny);
1628 pandecode_prop("clip_minz = %f", f->clip_minz);
1629 pandecode_prop("clip_maxx = %f", f->clip_maxx);
1630 pandecode_prop("clip_maxy = %f", f->clip_maxy);
1631 pandecode_prop("clip_maxz = %f", f->clip_maxz);
1632
1633 /* Only the higher coordinates are MALI_POSITIVE scaled */
1634
1635 pandecode_prop("viewport0 = { %d, %d }",
1636 f->viewport0[0], f->viewport0[1]);
1637
1638 pandecode_prop("viewport1 = { MALI_POSITIVE(%d), MALI_POSITIVE(%d) }",
1639 f->viewport1[0] + 1, f->viewport1[1] + 1);
1640
1641 pandecode_indent--;
1642 pandecode_log("};\n");
1643 }
1644
1645 if (p->attribute_meta) {
1646 unsigned max_attr_index = pandecode_attribute_meta(job_no, attribute_count, p, false, suffix);
1647
1648 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->attributes);
1649 pandecode_attributes(attr_mem, p->attributes, job_no, suffix, max_attr_index + 1, false);
1650 }
1651
1652 /* Varyings are encoded like attributes but not actually sent; we just
1653 * pass a zero buffer with the right stride/size set, (or whatever)
1654 * since the GPU will write to it itself */
1655
1656 if (p->varyings) {
1657 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->varyings);
1658
1659 /* Number of descriptors depends on whether there are
1660 * non-internal varyings */
1661
1662 pandecode_attributes(attr_mem, p->varyings, job_no, suffix, varying_count > 1 ? 4 : 1, true);
1663 }
1664
1665 if (p->varying_meta) {
1666 pandecode_attribute_meta(job_no, varying_count, p, true, suffix);
1667 }
1668
1669 bool is_compute = job_type == JOB_TYPE_COMPUTE;
1670
1671 if (p->uniforms && !is_compute) {
1672 int rows = uniform_count, width = 4;
1673 size_t sz = rows * width * sizeof(float);
1674
1675 struct pandecode_mapped_memory *uniform_mem = pandecode_find_mapped_gpu_mem_containing(p->uniforms);
1676 pandecode_fetch_gpu_mem(uniform_mem, p->uniforms, sz);
1677 u32 *PANDECODE_PTR_VAR(uniforms, uniform_mem, p->uniforms);
1678
1679 pandecode_log("u32 uniforms_%d%s[] = {\n", job_no, suffix);
1680
1681 pandecode_indent++;
1682
1683 for (int row = 0; row < rows; row++) {
1684 for (int i = 0; i < width; i++) {
1685 u32 v = uniforms[i];
1686 float f;
1687 memcpy(&f, &v, sizeof(v));
1688 pandecode_log_cont("%X /* %f */, ", v, f);
1689 }
1690
1691 pandecode_log_cont("\n");
1692
1693 uniforms += width;
1694 }
1695
1696 pandecode_indent--;
1697 pandecode_log("};\n");
1698 } else if (p->uniforms) {
1699 int rows = uniform_count * 2;
1700 size_t sz = rows * sizeof(mali_ptr);
1701
1702 struct pandecode_mapped_memory *uniform_mem = pandecode_find_mapped_gpu_mem_containing(p->uniforms);
1703 pandecode_fetch_gpu_mem(uniform_mem, p->uniforms, sz);
1704 mali_ptr *PANDECODE_PTR_VAR(uniforms, uniform_mem, p->uniforms);
1705
1706 pandecode_log("mali_ptr uniforms_%d%s[] = {\n", job_no, suffix);
1707
1708 pandecode_indent++;
1709
1710 for (int row = 0; row < rows; row++) {
1711 char *a = pointer_as_memory_reference(uniforms[row]);
1712 pandecode_log("%s,\n", a);
1713 free(a);
1714 }
1715
1716 pandecode_indent--;
1717 pandecode_log("};\n");
1718
1719 }
1720
1721 if (p->uniform_buffers) {
1722 pandecode_uniform_buffers(p->uniform_buffers, uniform_buffer_count, job_no);
1723 }
1724
1725 if (p->texture_trampoline) {
1726 struct pandecode_mapped_memory *mmem = pandecode_find_mapped_gpu_mem_containing(p->texture_trampoline);
1727
1728 if (mmem) {
1729 mali_ptr *PANDECODE_PTR_VAR(u, mmem, p->texture_trampoline);
1730
1731 pandecode_log("uint64_t texture_trampoline_%"PRIx64"_%d[] = {\n", p->texture_trampoline, job_no);
1732 pandecode_indent++;
1733
1734 for (int tex = 0; tex < texture_count; ++tex) {
1735 mali_ptr *PANDECODE_PTR_VAR(u, mmem, p->texture_trampoline + tex * sizeof(mali_ptr));
1736 char *a = pointer_as_memory_reference(*u);
1737 pandecode_log("%s,\n", a);
1738 free(a);
1739 }
1740
1741 pandecode_indent--;
1742 pandecode_log("};\n");
1743
1744 /* Now, finally, descend down into the texture descriptor */
1745 for (int tex = 0; tex < texture_count; ++tex) {
1746 mali_ptr *PANDECODE_PTR_VAR(u, mmem, p->texture_trampoline + tex * sizeof(mali_ptr));
1747 struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(*u);
1748
1749 if (tmem) {
1750 struct mali_texture_descriptor *PANDECODE_PTR_VAR(t, tmem, *u);
1751
1752 pandecode_log("struct mali_texture_descriptor texture_descriptor_%"PRIx64"_%d_%d = {\n", *u, job_no, tex);
1753 pandecode_indent++;
1754
1755 pandecode_prop("width = MALI_POSITIVE(%" PRId16 ")", t->width + 1);
1756 pandecode_prop("height = MALI_POSITIVE(%" PRId16 ")", t->height + 1);
1757 pandecode_prop("depth = MALI_POSITIVE(%" PRId16 ")", t->depth + 1);
1758 pandecode_prop("array_size = MALI_POSITIVE(%" PRId16 ")", t->array_size + 1);
1759 pandecode_prop("unknown3 = %" PRId16, t->unknown3);
1760 pandecode_prop("unknown3A = %" PRId8, t->unknown3A);
1761 pandecode_prop("nr_mipmap_levels = %" PRId8, t->nr_mipmap_levels);
1762
1763 struct mali_texture_format f = t->format;
1764
1765 pandecode_log(".format = {\n");
1766 pandecode_indent++;
1767
1768 pandecode_swizzle(f.swizzle);
1769 pandecode_prop("format = %s", pandecode_format(f.format));
1770 pandecode_prop("type = %s", pandecode_texture_type(f.type));
1771 pandecode_prop("srgb = %" PRId32, f.srgb);
1772 pandecode_prop("unknown1 = %" PRId32, f.unknown1);
1773 pandecode_prop("usage2 = 0x%" PRIx32, f.usage2);
1774
1775 pandecode_indent--;
1776 pandecode_log("},\n");
1777
1778 pandecode_swizzle(t->swizzle);
1779
1780 if (t->swizzle_zero) {
1781 /* Shouldn't happen */
1782 pandecode_msg("Swizzle zero tripped but replay will be fine anyway");
1783 pandecode_prop("swizzle_zero = %d", t->swizzle_zero);
1784 }
1785
1786 pandecode_prop("unknown3 = 0x%" PRIx32, t->unknown3);
1787
1788 pandecode_prop("unknown5 = 0x%" PRIx32, t->unknown5);
1789 pandecode_prop("unknown6 = 0x%" PRIx32, t->unknown6);
1790 pandecode_prop("unknown7 = 0x%" PRIx32, t->unknown7);
1791
1792 pandecode_log(".payload = {\n");
1793 pandecode_indent++;
1794
1795 /* A bunch of bitmap pointers follow.
1796 * We work out the correct number,
1797 * based on the mipmap/cubemap
1798 * properties, but dump extra
1799 * possibilities to futureproof */
1800
1801 int bitmap_count = MALI_NEGATIVE(t->nr_mipmap_levels);
1802 bool manual_stride = f.usage2 & MALI_TEX_MANUAL_STRIDE;
1803
1804 /* Miptree for each face */
1805 if (f.type == MALI_TEX_CUBE)
1806 bitmap_count *= 6;
1807
1808 /* Array of textures */
1809 bitmap_count *= MALI_NEGATIVE(t->array_size);
1810
1811 /* Stride for each element */
1812 if (manual_stride)
1813 bitmap_count *= 2;
1814
1815 /* Sanity check the size */
1816 int max_count = sizeof(t->payload) / sizeof(t->payload[0]);
1817 assert (bitmap_count <= max_count);
1818
1819 /* Dump more to be safe, but not _that_ much more */
1820 int safe_count = MIN2(bitmap_count * 2, max_count);
1821
1822 for (int i = 0; i < safe_count; ++i) {
1823 char *prefix = (i >= bitmap_count) ? "// " : "";
1824
1825 /* How we dump depends if this is a stride or a pointer */
1826
1827 if ((f.usage2 & MALI_TEX_MANUAL_STRIDE) && (i & 1)) {
1828 /* signed 32-bit snuck in as a 64-bit pointer */
1829 uint64_t stride_set = t->payload[i];
1830 uint32_t clamped_stride = stride_set;
1831 int32_t stride = clamped_stride;
1832 assert(stride_set == clamped_stride);
1833 pandecode_log("%s(mali_ptr) %d /* stride */, \n", prefix, stride);
1834 } else {
1835 char *a = pointer_as_memory_reference(t->payload[i]);
1836 pandecode_log("%s%s, \n", prefix, a);
1837 free(a);
1838 }
1839 }
1840
1841 pandecode_indent--;
1842 pandecode_log("},\n");
1843
1844 pandecode_indent--;
1845 pandecode_log("};\n");
1846 }
1847 }
1848 }
1849 }
1850
1851 if (p->sampler_descriptor) {
1852 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(p->sampler_descriptor);
1853
1854 if (smem) {
1855 struct mali_sampler_descriptor *s;
1856
1857 mali_ptr d = p->sampler_descriptor;
1858
1859 for (int i = 0; i < sampler_count; ++i) {
1860 s = pandecode_fetch_gpu_mem(smem, d + sizeof(*s) * i, sizeof(*s));
1861
1862 pandecode_log("struct mali_sampler_descriptor sampler_descriptor_%"PRIx64"_%d_%d = {\n", d + sizeof(*s) * i, job_no, i);
1863 pandecode_indent++;
1864
1865 /* Only the lower two bits are understood right now; the rest we display as hex */
1866 pandecode_log(".filter_mode = MALI_TEX_MIN(%s) | MALI_TEX_MAG(%s) | 0x%" PRIx32",\n",
1867 MALI_FILTER_NAME(s->filter_mode & MALI_TEX_MIN_MASK),
1868 MALI_FILTER_NAME(s->filter_mode & MALI_TEX_MAG_MASK),
1869 s->filter_mode & ~3);
1870
1871 pandecode_prop("min_lod = FIXED_16(%f)", DECODE_FIXED_16(s->min_lod));
1872 pandecode_prop("max_lod = FIXED_16(%f)", DECODE_FIXED_16(s->max_lod));
1873
1874 pandecode_prop("wrap_s = %s", pandecode_wrap_mode(s->wrap_s));
1875 pandecode_prop("wrap_t = %s", pandecode_wrap_mode(s->wrap_t));
1876 pandecode_prop("wrap_r = %s", pandecode_wrap_mode(s->wrap_r));
1877
1878 pandecode_prop("compare_func = %s", pandecode_alt_func(s->compare_func));
1879
1880 if (s->zero || s->zero2) {
1881 pandecode_msg("Zero tripped\n");
1882 pandecode_prop("zero = 0x%X, 0x%X\n", s->zero, s->zero2);
1883 }
1884
1885 pandecode_prop("seamless_cube_map = %d", s->seamless_cube_map);
1886
1887 pandecode_prop("border_color = { %f, %f, %f, %f }",
1888 s->border_color[0],
1889 s->border_color[1],
1890 s->border_color[2],
1891 s->border_color[3]);
1892
1893 pandecode_indent--;
1894 pandecode_log("};\n");
1895 }
1896 }
1897 }
1898 }
1899
1900 static void
1901 pandecode_vertex_tiler_postfix(const struct mali_vertex_tiler_postfix *p, int job_no, bool is_bifrost)
1902 {
1903 pandecode_log_cont("{\n");
1904 pandecode_indent++;
1905
1906 MEMORY_PROP(p, position_varying);
1907 DYN_MEMORY_PROP(p, job_no, uniform_buffers);
1908 DYN_MEMORY_PROP(p, job_no, texture_trampoline);
1909 DYN_MEMORY_PROP(p, job_no, sampler_descriptor);
1910 DYN_MEMORY_PROP(p, job_no, uniforms);
1911 DYN_MEMORY_PROP(p, job_no, attributes);
1912 DYN_MEMORY_PROP(p, job_no, attribute_meta);
1913 DYN_MEMORY_PROP(p, job_no, varyings);
1914 DYN_MEMORY_PROP(p, job_no, varying_meta);
1915 DYN_MEMORY_PROP(p, job_no, viewport);
1916 DYN_MEMORY_PROP(p, job_no, occlusion_counter);
1917
1918 if (is_bifrost)
1919 pandecode_prop("framebuffer = scratchpad_%d_p", job_no);
1920 else
1921 pandecode_prop("framebuffer = framebuffer_%d_p | %s", job_no, p->framebuffer & MALI_MFBD ? "MALI_MFBD" : "0");
1922
1923 pandecode_prop("_shader_upper = (shader_meta_%d_p) >> 4", job_no);
1924 pandecode_prop("flags = %d", p->flags);
1925
1926 pandecode_indent--;
1927 pandecode_log("},\n");
1928 }
1929
1930 static void
1931 pandecode_vertex_only_bfr(struct bifrost_vertex_only *v)
1932 {
1933 pandecode_log_cont("{\n");
1934 pandecode_indent++;
1935
1936 pandecode_prop("unk2 = 0x%x", v->unk2);
1937
1938 if (v->zero0 || v->zero1) {
1939 pandecode_msg("vertex only zero tripped");
1940 pandecode_prop("zero0 = 0x%" PRIx32, v->zero0);
1941 pandecode_prop("zero1 = 0x%" PRIx64, v->zero1);
1942 }
1943
1944 pandecode_indent--;
1945 pandecode_log("}\n");
1946 }
1947
1948 static void
1949 pandecode_tiler_heap_meta(mali_ptr gpu_va, int job_no)
1950 {
1951
1952 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
1953 const struct bifrost_tiler_heap_meta *PANDECODE_PTR_VAR(h, mem, gpu_va);
1954
1955 pandecode_log("struct mali_tiler_heap_meta tiler_heap_meta_%d = {\n", job_no);
1956 pandecode_indent++;
1957
1958 if (h->zero) {
1959 pandecode_msg("tiler heap zero tripped\n");
1960 pandecode_prop("zero = 0x%x", h->zero);
1961 }
1962
1963 for (int i = 0; i < 12; i++) {
1964 if (h->zeros[i] != 0) {
1965 pandecode_msg("tiler heap zero %d tripped, value %x\n",
1966 i, h->zeros[i]);
1967 }
1968 }
1969
1970 pandecode_prop("heap_size = 0x%x", h->heap_size);
1971 MEMORY_PROP(h, tiler_heap_start);
1972 MEMORY_PROP(h, tiler_heap_free);
1973
1974 /* this might point to the beginning of another buffer, when it's
1975 * really the end of the tiler heap buffer, so we have to be careful
1976 * here. but for zero length, we need the same pointer.
1977 */
1978
1979 if (h->tiler_heap_end == h->tiler_heap_start) {
1980 MEMORY_PROP(h, tiler_heap_start);
1981 } else {
1982 char *a = pointer_as_memory_reference(h->tiler_heap_end - 1);
1983 pandecode_prop("tiler_heap_end = %s + 1", a);
1984 free(a);
1985 }
1986
1987 pandecode_indent--;
1988 pandecode_log("};\n");
1989 }
1990
1991 static void
1992 pandecode_tiler_meta(mali_ptr gpu_va, int job_no)
1993 {
1994 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
1995 const struct bifrost_tiler_meta *PANDECODE_PTR_VAR(t, mem, gpu_va);
1996
1997 pandecode_tiler_heap_meta(t->tiler_heap_meta, job_no);
1998
1999 pandecode_log("struct bifrost_tiler_meta tiler_meta_%d = {\n", job_no);
2000 pandecode_indent++;
2001
2002 if (t->zero0 || t->zero1) {
2003 pandecode_msg("tiler meta zero tripped");
2004 pandecode_prop("zero0 = 0x%" PRIx64, t->zero0);
2005 pandecode_prop("zero1 = 0x%" PRIx64, t->zero1);
2006 }
2007
2008 pandecode_prop("hierarchy_mask = 0x%" PRIx16, t->hierarchy_mask);
2009 pandecode_prop("flags = 0x%" PRIx16, t->flags);
2010
2011 pandecode_prop("width = MALI_POSITIVE(%d)", t->width + 1);
2012 pandecode_prop("height = MALI_POSITIVE(%d)", t->height + 1);
2013 DYN_MEMORY_PROP(t, job_no, tiler_heap_meta);
2014
2015 for (int i = 0; i < 12; i++) {
2016 if (t->zeros[i] != 0) {
2017 pandecode_msg("tiler heap zero %d tripped, value %" PRIx64 "\n",
2018 i, t->zeros[i]);
2019 }
2020 }
2021
2022 pandecode_indent--;
2023 pandecode_log("};\n");
2024 }
2025
2026 static void
2027 pandecode_gl_enables(uint32_t gl_enables, int job_type)
2028 {
2029 pandecode_log(".gl_enables = ");
2030
2031 pandecode_log_decoded_flags(gl_enable_flag_info, gl_enables);
2032
2033 pandecode_log_cont(",\n");
2034 }
2035
2036 static void
2037 pandecode_primitive_size(union midgard_primitive_size u, bool constant)
2038 {
2039 if (u.pointer == 0x0)
2040 return;
2041
2042 pandecode_log(".primitive_size = {\n");
2043 pandecode_indent++;
2044
2045 if (constant) {
2046 pandecode_prop("constant = %f", u.constant);
2047 } else {
2048 MEMORY_PROP((&u), pointer);
2049 }
2050
2051 pandecode_indent--;
2052 pandecode_log("},\n");
2053 }
2054
2055 static void
2056 pandecode_tiler_only_bfr(const struct bifrost_tiler_only *t, int job_no)
2057 {
2058 pandecode_log_cont("{\n");
2059 pandecode_indent++;
2060
2061 /* TODO: gl_PointSize on Bifrost */
2062 pandecode_primitive_size(t->primitive_size, true);
2063
2064 DYN_MEMORY_PROP(t, job_no, tiler_meta);
2065 pandecode_gl_enables(t->gl_enables, JOB_TYPE_TILER);
2066
2067 if (t->zero1 || t->zero2 || t->zero3 || t->zero4 || t->zero5
2068 || t->zero6 || t->zero7 || t->zero8) {
2069 pandecode_msg("tiler only zero tripped");
2070 pandecode_prop("zero1 = 0x%" PRIx64, t->zero1);
2071 pandecode_prop("zero2 = 0x%" PRIx64, t->zero2);
2072 pandecode_prop("zero3 = 0x%" PRIx64, t->zero3);
2073 pandecode_prop("zero4 = 0x%" PRIx64, t->zero4);
2074 pandecode_prop("zero5 = 0x%" PRIx64, t->zero5);
2075 pandecode_prop("zero6 = 0x%" PRIx64, t->zero6);
2076 pandecode_prop("zero7 = 0x%" PRIx32, t->zero7);
2077 pandecode_prop("zero8 = 0x%" PRIx64, t->zero8);
2078 }
2079
2080 pandecode_indent--;
2081 pandecode_log("},\n");
2082 }
2083
2084 static int
2085 pandecode_vertex_job_bfr(const struct mali_job_descriptor_header *h,
2086 const struct pandecode_mapped_memory *mem,
2087 mali_ptr payload, int job_no)
2088 {
2089 struct bifrost_payload_vertex *PANDECODE_PTR_VAR(v, mem, payload);
2090
2091 pandecode_vertex_tiler_postfix_pre(&v->postfix, job_no, h->job_type, "", true);
2092
2093 pandecode_log("struct bifrost_payload_vertex payload_%d = {\n", job_no);
2094 pandecode_indent++;
2095
2096 pandecode_log(".prefix = ");
2097 pandecode_vertex_tiler_prefix(&v->prefix, job_no);
2098
2099 pandecode_log(".vertex = ");
2100 pandecode_vertex_only_bfr(&v->vertex);
2101
2102 pandecode_log(".postfix = ");
2103 pandecode_vertex_tiler_postfix(&v->postfix, job_no, true);
2104
2105 pandecode_indent--;
2106 pandecode_log("};\n");
2107
2108 return sizeof(*v);
2109 }
2110
2111 static int
2112 pandecode_tiler_job_bfr(const struct mali_job_descriptor_header *h,
2113 const struct pandecode_mapped_memory *mem,
2114 mali_ptr payload, int job_no)
2115 {
2116 struct bifrost_payload_tiler *PANDECODE_PTR_VAR(t, mem, payload);
2117
2118 pandecode_vertex_tiler_postfix_pre(&t->postfix, job_no, h->job_type, "", true);
2119
2120 pandecode_indices(t->prefix.indices, t->prefix.index_count, job_no);
2121 pandecode_tiler_meta(t->tiler.tiler_meta, job_no);
2122
2123 pandecode_log("struct bifrost_payload_tiler payload_%d = {\n", job_no);
2124 pandecode_indent++;
2125
2126 pandecode_log(".prefix = ");
2127 pandecode_vertex_tiler_prefix(&t->prefix, job_no);
2128
2129 pandecode_log(".tiler = ");
2130 pandecode_tiler_only_bfr(&t->tiler, job_no);
2131
2132 pandecode_log(".postfix = ");
2133 pandecode_vertex_tiler_postfix(&t->postfix, job_no, true);
2134
2135 pandecode_indent--;
2136 pandecode_log("};\n");
2137
2138 return sizeof(*t);
2139 }
2140
2141 static int
2142 pandecode_vertex_or_tiler_job_mdg(const struct mali_job_descriptor_header *h,
2143 const struct pandecode_mapped_memory *mem,
2144 mali_ptr payload, int job_no)
2145 {
2146 struct midgard_payload_vertex_tiler *PANDECODE_PTR_VAR(v, mem, payload);
2147
2148 pandecode_vertex_tiler_postfix_pre(&v->postfix, job_no, h->job_type, "", false);
2149
2150 pandecode_indices(v->prefix.indices, v->prefix.index_count, job_no);
2151
2152 pandecode_log("struct midgard_payload_vertex_tiler payload_%d = {\n", job_no);
2153 pandecode_indent++;
2154
2155 bool has_primitive_pointer = v->prefix.unknown_draw & MALI_DRAW_VARYING_SIZE;
2156 pandecode_primitive_size(v->primitive_size, !has_primitive_pointer);
2157
2158 pandecode_log(".prefix = ");
2159 pandecode_vertex_tiler_prefix(&v->prefix, job_no);
2160
2161 pandecode_gl_enables(v->gl_enables, h->job_type);
2162
2163 if (v->instance_shift || v->instance_odd) {
2164 pandecode_prop("instance_shift = 0x%d /* %d */",
2165 v->instance_shift, 1 << v->instance_shift);
2166 pandecode_prop("instance_odd = 0x%X /* %d */",
2167 v->instance_odd, (2 * v->instance_odd) + 1);
2168
2169 pandecode_padded_vertices(v->instance_shift, v->instance_odd);
2170 }
2171
2172 if (v->draw_start)
2173 pandecode_prop("draw_start = %d", v->draw_start);
2174
2175 if (v->zero5) {
2176 pandecode_msg("Zero tripped\n");
2177 pandecode_prop("zero5 = 0x%" PRIx64, v->zero5);
2178 }
2179
2180 pandecode_log(".postfix = ");
2181 pandecode_vertex_tiler_postfix(&v->postfix, job_no, false);
2182
2183 pandecode_indent--;
2184 pandecode_log("};\n");
2185
2186 return sizeof(*v);
2187 }
2188
2189 static int
2190 pandecode_fragment_job(const struct pandecode_mapped_memory *mem,
2191 mali_ptr payload, int job_no,
2192 bool is_bifrost)
2193 {
2194 const struct mali_payload_fragment *PANDECODE_PTR_VAR(s, mem, payload);
2195
2196 bool fbd_dumped = false;
2197
2198 if (!is_bifrost && (s->framebuffer & FBD_TYPE) == MALI_SFBD) {
2199 /* Only SFBDs are understood, not MFBDs. We're speculating,
2200 * based on the versioning, kernel code, etc, that the
2201 * difference is between Single FrameBuffer Descriptor and
2202 * Multiple FrmaeBuffer Descriptor; the change apparently lines
2203 * up with multi-framebuffer support being added (T7xx onwards,
2204 * including Gxx). In any event, there's some field shuffling
2205 * that we haven't looked into yet. */
2206
2207 pandecode_sfbd(s->framebuffer & FBD_MASK, job_no);
2208 fbd_dumped = true;
2209 } else if ((s->framebuffer & FBD_TYPE) == MALI_MFBD) {
2210 /* We don't know if Bifrost supports SFBD's at all, since the
2211 * driver never uses them. And the format is different from
2212 * Midgard anyways, due to the tiler heap and scratchpad being
2213 * moved out into separate structures, so it's not clear what a
2214 * Bifrost SFBD would even look like without getting an actual
2215 * trace, which appears impossible.
2216 */
2217
2218 pandecode_mfbd_bfr(s->framebuffer & FBD_MASK, job_no, true);
2219 fbd_dumped = true;
2220 }
2221
2222 uintptr_t p = (uintptr_t) s->framebuffer & FBD_MASK;
2223 pandecode_log("struct mali_payload_fragment payload_%"PRIx64"_%d = {\n", payload, job_no);
2224 pandecode_indent++;
2225
2226 /* See the comments by the macro definitions for mathematical context
2227 * on why this is so weird */
2228
2229 if (MALI_TILE_COORD_FLAGS(s->max_tile_coord) || MALI_TILE_COORD_FLAGS(s->min_tile_coord))
2230 pandecode_msg("Tile coordinate flag missed, replay wrong\n");
2231
2232 pandecode_prop("min_tile_coord = MALI_COORDINATE_TO_TILE_MIN(%d, %d)",
2233 MALI_TILE_COORD_X(s->min_tile_coord) << MALI_TILE_SHIFT,
2234 MALI_TILE_COORD_Y(s->min_tile_coord) << MALI_TILE_SHIFT);
2235
2236 pandecode_prop("max_tile_coord = MALI_COORDINATE_TO_TILE_MAX(%d, %d)",
2237 (MALI_TILE_COORD_X(s->max_tile_coord) + 1) << MALI_TILE_SHIFT,
2238 (MALI_TILE_COORD_Y(s->max_tile_coord) + 1) << MALI_TILE_SHIFT);
2239
2240 /* If the FBD was just decoded, we can refer to it by pointer. If not,
2241 * we have to fallback on offsets. */
2242
2243 const char *fbd_type = s->framebuffer & MALI_MFBD ? "MALI_MFBD" : "MALI_SFBD";
2244
2245 if (fbd_dumped)
2246 pandecode_prop("framebuffer = framebuffer_%d_p | %s", job_no, fbd_type);
2247 else
2248 pandecode_prop("framebuffer = %s | %s", pointer_as_memory_reference(p), fbd_type);
2249
2250 pandecode_indent--;
2251 pandecode_log("};\n");
2252
2253 return sizeof(*s);
2254 }
2255
2256 static int job_descriptor_number = 0;
2257
2258 int
2259 pandecode_jc(mali_ptr jc_gpu_va, bool bifrost)
2260 {
2261 struct mali_job_descriptor_header *h;
2262
2263 int start_number = 0;
2264
2265 bool first = true;
2266 bool last_size;
2267
2268 do {
2269 struct pandecode_mapped_memory *mem =
2270 pandecode_find_mapped_gpu_mem_containing(jc_gpu_va);
2271
2272 void *payload;
2273
2274 h = PANDECODE_PTR(mem, jc_gpu_va, struct mali_job_descriptor_header);
2275
2276 /* On Midgard, for 32-bit jobs except for fragment jobs, the
2277 * high 32-bits of the 64-bit pointer are reused to store
2278 * something else.
2279 */
2280 int offset = h->job_descriptor_size == MALI_JOB_32 &&
2281 h->job_type != JOB_TYPE_FRAGMENT ? 4 : 0;
2282 mali_ptr payload_ptr = jc_gpu_va + sizeof(*h) - offset;
2283
2284 payload = pandecode_fetch_gpu_mem(mem, payload_ptr,
2285 MALI_PAYLOAD_SIZE);
2286
2287 int job_no = job_descriptor_number++;
2288
2289 if (first)
2290 start_number = job_no;
2291
2292 pandecode_log("struct mali_job_descriptor_header job_%"PRIx64"_%d = {\n", jc_gpu_va, job_no);
2293 pandecode_indent++;
2294
2295 pandecode_prop("job_type = %s", pandecode_job_type(h->job_type));
2296
2297 /* Save for next job fixing */
2298 last_size = h->job_descriptor_size;
2299
2300 if (h->job_descriptor_size)
2301 pandecode_prop("job_descriptor_size = %d", h->job_descriptor_size);
2302
2303 if (h->exception_status != 0x1)
2304 pandecode_prop("exception_status = %x (source ID: 0x%x access: 0x%x exception: 0x%x)",
2305 h->exception_status,
2306 (h->exception_status >> 16) & 0xFFFF,
2307 (h->exception_status >> 8) & 0x3,
2308 h->exception_status & 0xFF);
2309
2310 if (h->first_incomplete_task)
2311 pandecode_prop("first_incomplete_task = %d", h->first_incomplete_task);
2312
2313 if (h->fault_pointer)
2314 pandecode_prop("fault_pointer = 0x%" PRIx64, h->fault_pointer);
2315
2316 if (h->job_barrier)
2317 pandecode_prop("job_barrier = %d", h->job_barrier);
2318
2319 pandecode_prop("job_index = %d", h->job_index);
2320
2321 if (h->unknown_flags)
2322 pandecode_prop("unknown_flags = %d", h->unknown_flags);
2323
2324 if (h->job_dependency_index_1)
2325 pandecode_prop("job_dependency_index_1 = %d", h->job_dependency_index_1);
2326
2327 if (h->job_dependency_index_2)
2328 pandecode_prop("job_dependency_index_2 = %d", h->job_dependency_index_2);
2329
2330 pandecode_indent--;
2331 pandecode_log("};\n");
2332
2333 /* Do not touch the field yet -- decode the payload first, and
2334 * don't touch that either. This is essential for the uploads
2335 * to occur in sequence and therefore be dynamically allocated
2336 * correctly. Do note the size, however, for that related
2337 * reason. */
2338
2339 switch (h->job_type) {
2340 case JOB_TYPE_SET_VALUE: {
2341 struct mali_payload_set_value *s = payload;
2342 pandecode_log("struct mali_payload_set_value payload_%"PRIx64"_%d = {\n", payload_ptr, job_no);
2343 pandecode_indent++;
2344 MEMORY_PROP(s, out);
2345 pandecode_prop("unknown = 0x%" PRIX64, s->unknown);
2346 pandecode_indent--;
2347 pandecode_log("};\n");
2348
2349 break;
2350 }
2351
2352 case JOB_TYPE_TILER:
2353 case JOB_TYPE_VERTEX:
2354 case JOB_TYPE_COMPUTE:
2355 if (bifrost) {
2356 if (h->job_type == JOB_TYPE_TILER)
2357 pandecode_tiler_job_bfr(h, mem, payload_ptr, job_no);
2358 else
2359 pandecode_vertex_job_bfr(h, mem, payload_ptr, job_no);
2360 } else
2361 pandecode_vertex_or_tiler_job_mdg(h, mem, payload_ptr, job_no);
2362
2363 break;
2364
2365 case JOB_TYPE_FRAGMENT:
2366 pandecode_fragment_job(mem, payload_ptr, job_no, bifrost);
2367 break;
2368
2369 default:
2370 break;
2371 }
2372
2373 /* Handle linkage */
2374
2375 if (!first) {
2376 pandecode_log("((struct mali_job_descriptor_header *) (uintptr_t) job_%d_p)->", job_no - 1);
2377
2378 if (last_size)
2379 pandecode_log_cont("next_job_64 = job_%d_p;\n\n", job_no);
2380 else
2381 pandecode_log_cont("next_job_32 = (u32) (uintptr_t) job_%d_p;\n\n", job_no);
2382 }
2383
2384 first = false;
2385
2386 } while ((jc_gpu_va = h->job_descriptor_size ? h->next_job_64 : h->next_job_32));
2387
2388 return start_number;
2389 }