blob: 710a4022d912323494fb2343fbdcaf6e670de4df [file] [log] [blame]
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001/*
2 * Copyright (C) 2017-2019 Alyssa Rosenzweig
3 * Copyright (C) 2017-2019 Connor Abbott
Alyssa Rosenzweigd4575c32019-06-25 13:30:17 -07004 * Copyright (C) 2019 Collabora, Ltd.
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00005 *
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
Alyssa Rosenzweig88dc4c22020-08-05 18:13:11 -040026#include <midgard_pack.h>
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000027#include <stdio.h>
28#include <stdlib.h>
29#include <memory.h>
30#include <stdbool.h>
31#include <stdarg.h>
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -070032#include <ctype.h>
Alyssa Rosenzweigfc7bcee2019-06-11 12:25:35 -070033#include "decode.h"
Lionel Landwerlin66373952019-08-09 16:39:58 +030034#include "util/macros.h"
Alyssa Rosenzweigd699ffb2019-05-14 22:21:39 +000035#include "util/u_math.h"
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000036
Alyssa Rosenzweigec2a59c2019-07-10 10:33:24 -070037#include "midgard/disassemble.h"
38#include "bifrost/disassemble.h"
39
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -070040#include "pan_encoder.h"
41
Tomeu Vizoso9447a842019-10-30 12:05:30 +010042static void pandecode_swizzle(unsigned swizzle, enum mali_format format);
43
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000044#define MEMORY_PROP(obj, p) {\
Alyssa Rosenzweig2608da12019-06-19 09:35:57 -070045 if (obj->p) { \
46 char *a = pointer_as_memory_reference(obj->p); \
47 pandecode_prop("%s = %s", #p, a); \
48 free(a); \
49 } \
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000050}
51
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -070052#define MEMORY_PROP_DIR(obj, p) {\
53 if (obj.p) { \
54 char *a = pointer_as_memory_reference(obj.p); \
55 pandecode_prop("%s = %s", #p, a); \
56 free(a); \
57 } \
58}
59
Alyssa Rosenzweigd2ddd4d2020-08-05 19:43:58 -040060#define DUMP_CL(title, T, cl, indent) {\
61 fprintf(pandecode_dump_stream, "%s\n", title); \
Boris Brezillon62c0ef02020-09-05 18:04:43 +020062 pan_unpack(cl, T, temp); \
63 pan_print(pandecode_dump_stream, T, temp, indent * 2); \
Alyssa Rosenzweigd2ddd4d2020-08-05 19:43:58 -040064}
65
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -040066#define MAP_ADDR(T, addr, cl) \
67 const uint8_t *cl = 0; \
68 { \
69 struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(addr); \
70 cl = pandecode_fetch_gpu_mem(mapped_mem, addr, MALI_ ## T ## _LENGTH); \
71 }
72
Alyssa Rosenzweigd2ddd4d2020-08-05 19:43:58 -040073#define DUMP_ADDR(title, T, addr, indent) {\
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -040074 MAP_ADDR(T, addr, cl) \
Alyssa Rosenzweigd2ddd4d2020-08-05 19:43:58 -040075 DUMP_CL(title, T, cl, indent); \
76}
77
Icecream95be22c072020-01-23 10:14:35 +130078FILE *pandecode_dump_stream;
79
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000080/* Semantic logging type.
81 *
82 * Raw: for raw messages to be printed as is.
83 * Message: for helpful information to be commented out in replays.
84 * Property: for properties of a struct
85 *
86 * Use one of pandecode_log, pandecode_msg, or pandecode_prop as syntax sugar.
87 */
88
89enum pandecode_log_type {
90 PANDECODE_RAW,
91 PANDECODE_MESSAGE,
92 PANDECODE_PROPERTY
93};
94
95#define pandecode_log(...) pandecode_log_typed(PANDECODE_RAW, __VA_ARGS__)
96#define pandecode_msg(...) pandecode_log_typed(PANDECODE_MESSAGE, __VA_ARGS__)
97#define pandecode_prop(...) pandecode_log_typed(PANDECODE_PROPERTY, __VA_ARGS__)
98
99unsigned pandecode_indent = 0;
100
101static void
102pandecode_make_indent(void)
103{
104 for (unsigned i = 0; i < pandecode_indent; ++i)
Boris Brezillon6249ae72020-09-09 17:52:23 +0200105 fprintf(pandecode_dump_stream, " ");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000106}
107
108static void
109pandecode_log_typed(enum pandecode_log_type type, const char *format, ...)
110{
111 va_list ap;
112
113 pandecode_make_indent();
114
115 if (type == PANDECODE_MESSAGE)
Icecream95be22c072020-01-23 10:14:35 +1300116 fprintf(pandecode_dump_stream, "// ");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000117 else if (type == PANDECODE_PROPERTY)
Icecream95be22c072020-01-23 10:14:35 +1300118 fprintf(pandecode_dump_stream, ".");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000119
120 va_start(ap, format);
Icecream95be22c072020-01-23 10:14:35 +1300121 vfprintf(pandecode_dump_stream, format, ap);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000122 va_end(ap);
123
124 if (type == PANDECODE_PROPERTY)
Icecream95be22c072020-01-23 10:14:35 +1300125 fprintf(pandecode_dump_stream, ",\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000126}
127
128static void
129pandecode_log_cont(const char *format, ...)
130{
131 va_list ap;
132
133 va_start(ap, format);
Icecream95be22c072020-01-23 10:14:35 +1300134 vfprintf(pandecode_dump_stream, format, ap);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000135 va_end(ap);
136}
137
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700138/* To check for memory safety issues, validates that the given pointer in GPU
139 * memory is valid, containing at least sz bytes. The goal is to eliminate
140 * GPU-side memory bugs (NULL pointer dereferences, buffer overflows, or buffer
141 * overruns) by statically validating pointers.
142 */
143
144static void
145pandecode_validate_buffer(mali_ptr addr, size_t sz)
146{
147 if (!addr) {
148 pandecode_msg("XXX: null pointer deref");
149 return;
150 }
151
152 /* Find a BO */
153
154 struct pandecode_mapped_memory *bo =
155 pandecode_find_mapped_gpu_mem_containing(addr);
156
157 if (!bo) {
158 pandecode_msg("XXX: invalid memory dereference\n");
159 return;
160 }
161
162 /* Bounds check */
163
164 unsigned offset = addr - bo->gpu_va;
165 unsigned total = offset + sz;
166
167 if (total > bo->length) {
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -0700168 pandecode_msg("XXX: buffer overrun. "
Alyssa Rosenzweigbcfcb7e2019-08-30 17:02:43 -0700169 "Chunk of size %zu at offset %d in buffer of size %zu. "
170 "Overrun by %zu bytes. \n",
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700171 sz, offset, bo->length, total - bo->length);
172 return;
173 }
174}
175
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000176struct pandecode_flag_info {
177 u64 flag;
178 const char *name;
179};
180
181static void
182pandecode_log_decoded_flags(const struct pandecode_flag_info *flag_info,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700183 u64 flags)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000184{
185 bool decodable_flags_found = false;
186
187 for (int i = 0; flag_info[i].name; i++) {
188 if ((flags & flag_info[i].flag) != flag_info[i].flag)
189 continue;
190
191 if (!decodable_flags_found) {
192 decodable_flags_found = true;
193 } else {
194 pandecode_log_cont(" | ");
195 }
196
197 pandecode_log_cont("%s", flag_info[i].name);
198
199 flags &= ~flag_info[i].flag;
200 }
201
202 if (decodable_flags_found) {
203 if (flags)
204 pandecode_log_cont(" | 0x%" PRIx64, flags);
205 } else {
206 pandecode_log_cont("0x%" PRIx64, flags);
207 }
208}
209
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000210#define FLAG_INFO(flag) { MALI_CLEAR_##flag, "MALI_CLEAR_" #flag }
211static const struct pandecode_flag_info clear_flag_info[] = {
212 FLAG_INFO(FAST),
213 FLAG_INFO(SLOW),
214 FLAG_INFO(SLOW_STENCIL),
215 {}
216};
217#undef FLAG_INFO
218
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000219#define FLAG_INFO(flag) { MALI_MFBD_FORMAT_##flag, "MALI_MFBD_FORMAT_" #flag }
220static const struct pandecode_flag_info mfbd_fmt_flag_info[] = {
Alyssa Rosenzweig31a4ef82019-06-17 16:01:24 -0700221 FLAG_INFO(SRGB),
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000222 {}
223};
224#undef FLAG_INFO
225
Icecream959ac106d2020-06-02 14:13:03 +1200226#define FLAG_INFO(flag) { MALI_AFBC_##flag, "MALI_AFBC_" #flag }
227static const struct pandecode_flag_info afbc_fmt_flag_info[] = {
228 FLAG_INFO(YTR),
229 {}
230};
231#undef FLAG_INFO
232
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000233#define FLAG_INFO(flag) { MALI_EXTRA_##flag, "MALI_EXTRA_" #flag }
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500234static const struct pandecode_flag_info mfbd_extra_flag_hi_info[] = {
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000235 FLAG_INFO(PRESENT),
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500236 {}
237};
238#undef FLAG_INFO
239
240#define FLAG_INFO(flag) { MALI_EXTRA_##flag, "MALI_EXTRA_" #flag }
241static const struct pandecode_flag_info mfbd_extra_flag_lo_info[] = {
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000242 FLAG_INFO(ZS),
243 {}
244};
245#undef FLAG_INFO
246
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700247#define FLAG_INFO(flag) { MALI_MFBD_##flag, "MALI_MFBD_" #flag }
248static const struct pandecode_flag_info mfbd_flag_info [] = {
249 FLAG_INFO(DEPTH_WRITE),
250 FLAG_INFO(EXTRA),
251 {}
252};
253#undef FLAG_INFO
254
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100255#define FLAG_INFO(flag) { MALI_SFBD_FORMAT_##flag, "MALI_SFBD_FORMAT_" #flag }
256static const struct pandecode_flag_info sfbd_unk1_info [] = {
257 FLAG_INFO(MSAA_8),
258 FLAG_INFO(MSAA_A),
259 {}
260};
261#undef FLAG_INFO
262
263#define FLAG_INFO(flag) { MALI_SFBD_FORMAT_##flag, "MALI_SFBD_FORMAT_" #flag }
264static const struct pandecode_flag_info sfbd_unk2_info [] = {
265 FLAG_INFO(MSAA_B),
266 FLAG_INFO(SRGB),
267 {}
268};
269#undef FLAG_INFO
270
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700271/* Midgard's tiler descriptor is embedded within the
272 * larger FBD */
273
274static void
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700275pandecode_midgard_tiler_descriptor(
276 const struct midgard_tiler_descriptor *t,
277 unsigned width,
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700278 unsigned height,
Alyssa Rosenzweig9fb09042019-11-27 08:31:16 -0500279 bool is_fragment,
280 bool has_hierarchy)
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700281{
282 pandecode_log(".tiler = {\n");
283 pandecode_indent++;
284
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700285 if (t->hierarchy_mask == MALI_TILER_DISABLED)
286 pandecode_prop("hierarchy_mask = MALI_TILER_DISABLED");
287 else
288 pandecode_prop("hierarchy_mask = 0x%" PRIx16, t->hierarchy_mask);
289
290 /* We know this name from the kernel, but we never see it nonzero */
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700291
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700292 if (t->flags)
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700293 pandecode_msg("XXX: unexpected tiler flags 0x%" PRIx16, t->flags);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700294
295 MEMORY_PROP(t, polygon_list);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700296
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700297 /* The body is offset from the base of the polygon list */
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -0400298 //assert(t->polygon_list_body > t->polygon_list);
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700299 unsigned body_offset = t->polygon_list_body - t->polygon_list;
300
301 /* It needs to fit inside the reported size */
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -0400302 //assert(t->polygon_list_size >= body_offset);
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700303
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700304 /* Now that we've sanity checked, we'll try to calculate the sizes
305 * ourselves for comparison */
306
Alyssa Rosenzweig9fb09042019-11-27 08:31:16 -0500307 unsigned ref_header = panfrost_tiler_header_size(width, height, t->hierarchy_mask, has_hierarchy);
308 unsigned ref_size = panfrost_tiler_full_size(width, height, t->hierarchy_mask, has_hierarchy);
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700309
310 if (!((ref_header == body_offset) && (ref_size == t->polygon_list_size))) {
311 pandecode_msg("XXX: bad polygon list size (expected %d / 0x%x)\n",
312 ref_header, ref_size);
313 pandecode_prop("polygon_list_size = 0x%x", t->polygon_list_size);
314 pandecode_msg("body offset %d\n", body_offset);
315 }
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700316
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700317 /* The tiler heap has a start and end specified -- it should be
318 * identical to what we have in the BO. The exception is if tiling is
319 * disabled. */
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700320
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700321 MEMORY_PROP(t, heap_start);
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700322 assert(t->heap_end >= t->heap_start);
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700323
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700324 unsigned heap_size = t->heap_end - t->heap_start;
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700325
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700326 /* Tiling is enabled with a special flag */
327 unsigned hierarchy_mask = t->hierarchy_mask & MALI_HIERARCHY_MASK;
328 unsigned tiler_flags = t->hierarchy_mask ^ hierarchy_mask;
329
330 bool tiling_enabled = hierarchy_mask;
331
332 if (tiling_enabled) {
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700333 /* We should also have no other flags */
334 if (tiler_flags)
335 pandecode_msg("XXX: unexpected tiler %X\n", tiler_flags);
336 } else {
337 /* When tiling is disabled, we should have that flag and no others */
338
339 if (tiler_flags != MALI_TILER_DISABLED) {
340 pandecode_msg("XXX: unexpected tiler flag %X, expected MALI_TILER_DISABLED\n",
341 tiler_flags);
342 }
343
344 /* We should also have an empty heap */
345 if (heap_size) {
346 pandecode_msg("XXX: tiler heap size %d given, expected empty\n",
347 heap_size);
348 }
349
350 /* Disabled tiling is used only for clear-only jobs, which are
351 * purely FRAGMENT, so we should never see this for
352 * non-FRAGMENT descriptors. */
353
354 if (!is_fragment)
355 pandecode_msg("XXX: tiler disabled for non-FRAGMENT job\n");
356 }
357
358 /* We've never seen weights used in practice, but we know from the
359 * kernel these fields is there */
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700360
361 bool nonzero_weights = false;
362
363 for (unsigned w = 0; w < ARRAY_SIZE(t->weights); ++w) {
364 nonzero_weights |= t->weights[w] != 0x0;
365 }
366
367 if (nonzero_weights) {
Alyssa Rosenzweigacd140c2020-02-28 07:25:07 -0500368 pandecode_log(".weights = { ");
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700369
370 for (unsigned w = 0; w < ARRAY_SIZE(t->weights); ++w) {
Alyssa Rosenzweigacd140c2020-02-28 07:25:07 -0500371 pandecode_log_cont("%d, ", t->weights[w]);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700372 }
373
374 pandecode_log("},");
375 }
376
377 pandecode_indent--;
378 pandecode_log("}\n");
379}
380
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500381/* TODO: The Bifrost tiler is not understood at all yet */
382
383static void
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200384pandecode_bifrost_tiler_descriptor(const struct mali_framebuffer *fb)
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500385{
386 pandecode_log(".tiler = {\n");
387 pandecode_indent++;
388
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200389 MEMORY_PROP(fb, tiler_meta);
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500390
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200391 for (int i = 0; i < 16; i++) {
392 if (fb->zeros[i] != 0) {
393 pandecode_msg("XXX: tiler descriptor zero %d tripped, value %x\n",
394 i, fb->zeros[i]);
395 }
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500396 }
397
398 pandecode_log("},\n");
399
400 pandecode_indent--;
401 pandecode_log("}\n");
402
403}
404
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700405/* Information about the framebuffer passed back for
406 * additional analysis */
407
408struct pandecode_fbd {
409 unsigned width;
410 unsigned height;
411 unsigned rt_count;
412 bool has_extra;
413};
414
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100415static void
416pandecode_sfbd_format(struct mali_sfbd_format format)
417{
418 pandecode_log(".format = {\n");
419 pandecode_indent++;
420
421 pandecode_log(".unk1 = ");
422 pandecode_log_decoded_flags(sfbd_unk1_info, format.unk1);
423 pandecode_log_cont(",\n");
424
425 /* TODO: Map formats so we can check swizzles and print nicely */
426 pandecode_log("swizzle");
427 pandecode_swizzle(format.swizzle, MALI_RGBA8_UNORM);
428 pandecode_log_cont(",\n");
429
430 pandecode_prop("nr_channels = MALI_POSITIVE(%d)",
Alyssa Rosenzweig4ccd42e2019-12-27 12:16:09 -0500431 (format.nr_channels + 1));
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100432
433 pandecode_log(".unk2 = ");
434 pandecode_log_decoded_flags(sfbd_unk2_info, format.unk2);
435 pandecode_log_cont(",\n");
436
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400437 pandecode_prop("block = %s", mali_block_format_as_str(format.block));
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100438
439 pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
440
441 pandecode_indent--;
442 pandecode_log("},\n");
443}
444
Alyssa Rosenzweig254f40f2020-02-05 15:58:28 -0500445static void
446pandecode_shared_memory(const struct mali_shared_memory *desc, bool is_compute)
447{
448 pandecode_prop("stack_shift = 0x%x", desc->stack_shift);
449
450 if (desc->unk0)
451 pandecode_prop("unk0 = 0x%x", desc->unk0);
452
453 if (desc->shared_workgroup_count != 0x1F) {
454 pandecode_prop("shared_workgroup_count = %d", desc->shared_workgroup_count);
455 if (!is_compute)
456 pandecode_msg("XXX: wrong workgroup count for noncompute\n");
457 }
458
459 if (desc->shared_unk1 || desc->shared_shift) {
460 pandecode_prop("shared_unk1 = %X", desc->shared_unk1);
461 pandecode_prop("shared_shift = %X", desc->shared_shift);
462
463 if (!is_compute)
464 pandecode_msg("XXX: shared memory configured in noncompute shader");
465 }
466
467 if (desc->shared_zero) {
468 pandecode_msg("XXX: shared memory zero tripped\n");
469 pandecode_prop("shared_zero = 0x%" PRIx32, desc->shared_zero);
470 }
471
472 if (desc->shared_memory && !is_compute)
473 pandecode_msg("XXX: shared memory used in noncompute shader\n");
474
475 MEMORY_PROP(desc, scratchpad);
476 MEMORY_PROP(desc, shared_memory);
477 MEMORY_PROP(desc, unknown1);
478}
479
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700480static struct pandecode_fbd
Tomeu Vizoso697f02c2019-11-12 12:15:02 +0100481pandecode_sfbd(uint64_t gpu_va, int job_no, bool is_fragment, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000482{
483 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
484 const struct mali_single_framebuffer *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
485
Alyssa Rosenzweigd6d6d632019-08-30 17:00:09 -0700486 struct pandecode_fbd info = {
487 .has_extra = false,
488 .rt_count = 1
489 };
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700490
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +0200491 pandecode_log("struct mali_single_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000492 pandecode_indent++;
493
Alyssa Rosenzweig254f40f2020-02-05 15:58:28 -0500494 pandecode_log(".shared_memory = {\n");
495 pandecode_indent++;
496 pandecode_shared_memory(&s->shared_memory, false);
497 pandecode_indent--;
498 pandecode_log("},\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000499
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100500 pandecode_sfbd_format(s->format);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000501
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700502 info.width = s->width + 1;
503 info.height = s->height + 1;
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700504
505 pandecode_prop("width = MALI_POSITIVE(%" PRId16 ")", info.width);
506 pandecode_prop("height = MALI_POSITIVE(%" PRId16 ")", info.height);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000507
Tomeu Vizoso23fe7cd2019-07-12 12:38:50 +0200508 MEMORY_PROP(s, checksum);
509
510 if (s->checksum_stride)
511 pandecode_prop("checksum_stride = %d", s->checksum_stride);
512
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000513 MEMORY_PROP(s, framebuffer);
514 pandecode_prop("stride = %d", s->stride);
515
516 /* Earlier in the actual commandstream -- right before width -- but we
517 * delay to flow nicer */
518
519 pandecode_log(".clear_flags = ");
520 pandecode_log_decoded_flags(clear_flag_info, s->clear_flags);
521 pandecode_log_cont(",\n");
522
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100523 if (s->depth_buffer) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000524 MEMORY_PROP(s, depth_buffer);
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100525 pandecode_prop("depth_stride = %d", s->depth_stride);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000526 }
527
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100528 if (s->stencil_buffer) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000529 MEMORY_PROP(s, stencil_buffer);
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100530 pandecode_prop("stencil_stride = %d", s->stencil_stride);
531 }
532
533 if (s->depth_stride_zero ||
534 s->stencil_stride_zero ||
535 s->zero7 || s->zero8) {
536 pandecode_msg("XXX: Depth/stencil zeros tripped\n");
537 pandecode_prop("depth_stride_zero = 0x%x",
538 s->depth_stride_zero);
539 pandecode_prop("stencil_stride_zero = 0x%x",
540 s->stencil_stride_zero);
541 pandecode_prop("zero7 = 0x%" PRIx32,
542 s->zero7);
543 pandecode_prop("zero8 = 0x%" PRIx32,
544 s->zero8);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000545 }
546
547 if (s->clear_color_1 | s->clear_color_2 | s->clear_color_3 | s->clear_color_4) {
548 pandecode_prop("clear_color_1 = 0x%" PRIx32, s->clear_color_1);
549 pandecode_prop("clear_color_2 = 0x%" PRIx32, s->clear_color_2);
550 pandecode_prop("clear_color_3 = 0x%" PRIx32, s->clear_color_3);
551 pandecode_prop("clear_color_4 = 0x%" PRIx32, s->clear_color_4);
552 }
553
554 if (s->clear_depth_1 != 0 || s->clear_depth_2 != 0 || s->clear_depth_3 != 0 || s->clear_depth_4 != 0) {
555 pandecode_prop("clear_depth_1 = %f", s->clear_depth_1);
556 pandecode_prop("clear_depth_2 = %f", s->clear_depth_2);
557 pandecode_prop("clear_depth_3 = %f", s->clear_depth_3);
558 pandecode_prop("clear_depth_4 = %f", s->clear_depth_4);
559 }
560
561 if (s->clear_stencil) {
562 pandecode_prop("clear_stencil = 0x%x", s->clear_stencil);
563 }
564
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -0700565 const struct midgard_tiler_descriptor t = s->tiler;
Alyssa Rosenzweig9fb09042019-11-27 08:31:16 -0500566
567 bool has_hierarchy = !(gpu_id == 0x0720 || gpu_id == 0x0820 || gpu_id == 0x0830);
568 pandecode_midgard_tiler_descriptor(&t, s->width + 1, s->height + 1, is_fragment, has_hierarchy);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000569
570 pandecode_indent--;
571 pandecode_log("};\n");
572
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000573 pandecode_prop("zero2 = 0x%" PRIx32, s->zero2);
574 pandecode_prop("zero4 = 0x%" PRIx32, s->zero4);
Tomeu Vizoso94e6d172019-11-06 17:30:54 +0100575 pandecode_prop("zero5 = 0x%" PRIx32, s->zero5);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000576
Icecream95be22c072020-01-23 10:14:35 +1300577 pandecode_log_cont(".zero3 = {");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000578
579 for (int i = 0; i < sizeof(s->zero3) / sizeof(s->zero3[0]); ++i)
Icecream95be22c072020-01-23 10:14:35 +1300580 pandecode_log_cont("%X, ", s->zero3[i]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000581
Icecream95be22c072020-01-23 10:14:35 +1300582 pandecode_log_cont("},\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000583
Icecream95be22c072020-01-23 10:14:35 +1300584 pandecode_log_cont(".zero6 = {");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000585
586 for (int i = 0; i < sizeof(s->zero6) / sizeof(s->zero6[0]); ++i)
Icecream95be22c072020-01-23 10:14:35 +1300587 pandecode_log_cont("%X, ", s->zero6[i]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000588
Icecream95be22c072020-01-23 10:14:35 +1300589 pandecode_log_cont("},\n");
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700590
591 return info;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000592}
593
594static void
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700595pandecode_compute_fbd(uint64_t gpu_va, int job_no)
596{
597 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Alyssa Rosenzweig254f40f2020-02-05 15:58:28 -0500598 const struct mali_shared_memory *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700599
Alyssa Rosenzweig254f40f2020-02-05 15:58:28 -0500600 pandecode_log("struct mali_shared_memory shared_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700601 pandecode_indent++;
Alyssa Rosenzweig254f40f2020-02-05 15:58:28 -0500602 pandecode_shared_memory(s, true);
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700603 pandecode_indent--;
Alyssa Rosenzweig254f40f2020-02-05 15:58:28 -0500604 pandecode_log("},\n");
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700605}
606
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700607/* Extracts the number of components associated with a Mali format */
608
609static unsigned
610pandecode_format_component_count(enum mali_format fmt)
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000611{
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700612 /* Mask out the format class */
613 unsigned top = fmt & 0b11100000;
614
615 switch (top) {
616 case MALI_FORMAT_SNORM:
617 case MALI_FORMAT_UINT:
618 case MALI_FORMAT_UNORM:
619 case MALI_FORMAT_SINT:
620 return ((fmt >> 3) & 3) + 1;
621 default:
622 /* TODO: Validate */
623 return 4;
624 }
625}
626
627/* Extracts a mask of accessed components from a 12-bit Mali swizzle */
628
629static unsigned
630pandecode_access_mask_from_channel_swizzle(unsigned swizzle)
631{
632 unsigned mask = 0;
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400633 assert(MALI_CHANNEL_R == 0);
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700634
635 for (unsigned c = 0; c < 4; ++c) {
636 enum mali_channel chan = (swizzle >> (3*c)) & 0x7;
637
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400638 if (chan <= MALI_CHANNEL_A)
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700639 mask |= (1 << chan);
640 }
641
642 return mask;
643}
644
645/* Validates that a (format, swizzle) pair is valid, in the sense that the
646 * swizzle doesn't access any components that are undefined in the format.
647 * Returns whether the swizzle is trivial (doesn't do any swizzling) and can be
648 * omitted */
649
650static bool
651pandecode_validate_format_swizzle(enum mali_format fmt, unsigned swizzle)
652{
653 unsigned nr_comp = pandecode_format_component_count(fmt);
654 unsigned access_mask = pandecode_access_mask_from_channel_swizzle(swizzle);
655 unsigned valid_mask = (1 << nr_comp) - 1;
656 unsigned invalid_mask = ~valid_mask;
657
658 if (access_mask & invalid_mask) {
659 pandecode_msg("XXX: invalid components accessed\n");
660 return false;
661 }
662
663 /* Check for the default non-swizzling swizzle so we can suppress
664 * useless printing for the defaults */
665
666 unsigned default_swizzles[4] = {
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400667 MALI_CHANNEL_R | (MALI_CHANNEL_0 << 3) | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9),
668 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9),
669 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_1 << 9),
670 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_A << 9)
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700671 };
672
673 return (swizzle == default_swizzles[nr_comp - 1]);
674}
675
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700676static void
677pandecode_swizzle(unsigned swizzle, enum mali_format format)
678{
679 /* First, do some validation */
680 bool trivial_swizzle = pandecode_validate_format_swizzle(
681 format, swizzle);
682
683 if (trivial_swizzle)
684 return;
685
686 /* Next, print the swizzle */
687 pandecode_log_cont(".");
688
689 static const char components[] = "rgba01";
690
691 for (unsigned c = 0; c < 4; ++c) {
692 enum mali_channel chan = (swizzle >> (3 * c)) & 0x7;
693
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400694 if (chan > MALI_CHANNEL_1) {
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700695 pandecode_log("XXX: invalid swizzle channel %d\n", chan);
696 continue;
697 }
698 pandecode_log_cont("%c", components[chan]);
699 }
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000700}
701
702static void
703pandecode_rt_format(struct mali_rt_format format)
704{
705 pandecode_log(".format = {\n");
706 pandecode_indent++;
707
708 pandecode_prop("unk1 = 0x%" PRIx32, format.unk1);
709 pandecode_prop("unk2 = 0x%" PRIx32, format.unk2);
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700710 pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
Tomeu Vizoso28902ba2020-04-24 11:30:03 +0200711 pandecode_prop("unk4 = 0x%" PRIx32, format.unk4);
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700712
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400713 pandecode_prop("block = %s", mali_block_format_as_str(format.block));
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000714
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700715 /* TODO: Map formats so we can check swizzles and print nicely */
716 pandecode_log("swizzle");
717 pandecode_swizzle(format.swizzle, MALI_RGBA8_UNORM);
718 pandecode_log_cont(",\n");
719
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000720 pandecode_prop("nr_channels = MALI_POSITIVE(%d)",
Alyssa Rosenzweig4ccd42e2019-12-27 12:16:09 -0500721 (format.nr_channels + 1));
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000722
723 pandecode_log(".flags = ");
724 pandecode_log_decoded_flags(mfbd_fmt_flag_info, format.flags);
725 pandecode_log_cont(",\n");
726
Alyssa Rosenzweig99d17fb2020-08-11 21:04:01 -0400727 pandecode_prop("msaa = %s", mali_msaa_as_str(format.msaa));
Alyssa Rosenzweig2c479932020-07-21 18:51:07 -0400728
Alyssa Rosenzweige49204c2019-08-20 11:11:46 -0700729 /* In theory, the no_preload bit can be cleared to enable MFBD preload,
730 * which is a faster hardware-based alternative to the wallpaper method
731 * to preserve framebuffer contents across frames. In practice, MFBD
732 * preload is buggy on Midgard, and so this is a chicken bit. If this
733 * bit isn't set, most likely something broke unrelated to preload */
734
735 if (!format.no_preload) {
736 pandecode_msg("XXX: buggy MFBD preload enabled - chicken bit should be clear\n");
737 pandecode_prop("no_preload = 0x%" PRIx32, format.no_preload);
738 }
Alyssa Rosenzweigb78e04c2019-08-14 16:01:38 -0700739
740 if (format.zero)
741 pandecode_prop("zero = 0x%" PRIx32, format.zero);
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000742
743 pandecode_indent--;
744 pandecode_log("},\n");
745}
746
747static void
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500748pandecode_render_target(uint64_t gpu_va, unsigned job_no, const struct mali_framebuffer *fb)
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700749{
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500750 pandecode_log("struct mali_render_target rts_list_%"PRIx64"_%d[] = {\n", gpu_va, job_no);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700751 pandecode_indent++;
752
Alyssa Rosenzweig4ccd42e2019-12-27 12:16:09 -0500753 for (int i = 0; i < (fb->rt_count_1 + 1); i++) {
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500754 mali_ptr rt_va = gpu_va + i * sizeof(struct mali_render_target);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700755 struct pandecode_mapped_memory *mem =
756 pandecode_find_mapped_gpu_mem_containing(rt_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500757 const struct mali_render_target *PANDECODE_PTR_VAR(rt, mem, (mali_ptr) rt_va);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700758
759 pandecode_log("{\n");
760 pandecode_indent++;
761
762 pandecode_rt_format(rt->format);
763
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400764 if (rt->format.block == MALI_BLOCK_FORMAT_AFBC) {
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700765 pandecode_log(".afbc = {\n");
766 pandecode_indent++;
767
768 char *a = pointer_as_memory_reference(rt->afbc.metadata);
769 pandecode_prop("metadata = %s", a);
770 free(a);
771
772 pandecode_prop("stride = %d", rt->afbc.stride);
Icecream959ac106d2020-06-02 14:13:03 +1200773
774 pandecode_log(".flags = ");
775 pandecode_log_decoded_flags(afbc_fmt_flag_info, rt->afbc.flags);
776 pandecode_log_cont(",\n");
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700777
778 pandecode_indent--;
779 pandecode_log("},\n");
Icecream959ac106d2020-06-02 14:13:03 +1200780 } else if (rt->afbc.metadata || rt->afbc.stride || rt->afbc.flags) {
Alyssa Rosenzweigc9b62332019-08-20 11:06:07 -0700781 pandecode_msg("XXX: AFBC disabled but AFBC field set (0x%lX, 0x%x, 0x%x)\n",
782 rt->afbc.metadata,
783 rt->afbc.stride,
Icecream959ac106d2020-06-02 14:13:03 +1200784 rt->afbc.flags);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700785 }
786
787 MEMORY_PROP(rt, framebuffer);
788 pandecode_prop("framebuffer_stride = %d", rt->framebuffer_stride);
789
Alyssa Rosenzweig37204582020-06-30 16:21:18 -0400790 if (rt->layer_stride)
791 pandecode_prop("layer_stride = %d", rt->layer_stride);
792
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700793 if (rt->clear_color_1 | rt->clear_color_2 | rt->clear_color_3 | rt->clear_color_4) {
794 pandecode_prop("clear_color_1 = 0x%" PRIx32, rt->clear_color_1);
795 pandecode_prop("clear_color_2 = 0x%" PRIx32, rt->clear_color_2);
796 pandecode_prop("clear_color_3 = 0x%" PRIx32, rt->clear_color_3);
797 pandecode_prop("clear_color_4 = 0x%" PRIx32, rt->clear_color_4);
798 }
799
Alyssa Rosenzweig37204582020-06-30 16:21:18 -0400800 if (rt->zero1 || rt->zero2) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700801 pandecode_msg("XXX: render target zeros tripped\n");
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700802 pandecode_prop("zero1 = 0x%" PRIx64, rt->zero1);
803 pandecode_prop("zero2 = 0x%" PRIx32, rt->zero2);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700804 }
805
806 pandecode_indent--;
807 pandecode_log("},\n");
808 }
809
810 pandecode_indent--;
811 pandecode_log("};\n");
812}
813
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700814static struct pandecode_fbd
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500815pandecode_mfbd_bfr(uint64_t gpu_va, int job_no, bool is_fragment, bool is_compute, bool is_bifrost)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000816{
817 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500818 const struct mali_framebuffer *PANDECODE_PTR_VAR(fb, mem, (mali_ptr) gpu_va);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000819
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700820 struct pandecode_fbd info;
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500821
822 if (is_bifrost && fb->msaa.sample_locations) {
823 /* The blob stores all possible sample locations in a single buffer
824 * allocated on startup, and just switches the pointer when switching
825 * MSAA state. For now, we just put the data into the cmdstream, but we
826 * should do something like what the blob does with a real driver.
827 *
828 * There seem to be 32 slots for sample locations, followed by another
829 * 16. The second 16 is just the center location followed by 15 zeros
830 * in all the cases I've identified (maybe shader vs. depth/color
831 * samples?).
832 */
833
834 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(fb->msaa.sample_locations);
835
836 const u16 *PANDECODE_PTR_VAR(samples, smem, fb->msaa.sample_locations);
837
838 pandecode_log("uint16_t sample_locations_%d[] = {\n", job_no);
839 pandecode_indent++;
840
841 for (int i = 0; i < 32 + 16; i++) {
842 pandecode_log("%d, %d,\n", samples[2 * i], samples[2 * i + 1]);
843 }
844
845 pandecode_indent--;
846 pandecode_log("};\n");
847 }
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700848
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500849 pandecode_log("struct mali_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000850 pandecode_indent++;
851
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500852 if (is_bifrost) {
853 pandecode_log(".msaa = {\n");
854 pandecode_indent++;
855
856 if (fb->msaa.sample_locations)
857 pandecode_prop("sample_locations = sample_locations_%d", job_no);
858 else
859 pandecode_msg("XXX: sample_locations missing\n");
860
861 if (fb->msaa.zero1 || fb->msaa.zero2 || fb->msaa.zero4) {
862 pandecode_msg("XXX: multisampling zero tripped\n");
863 pandecode_prop("zero1 = %" PRIx64, fb->msaa.zero1);
864 pandecode_prop("zero2 = %" PRIx64, fb->msaa.zero2);
865 pandecode_prop("zero4 = %" PRIx64, fb->msaa.zero4);
866 }
867
868 pandecode_indent--;
869 pandecode_log("},\n");
870 } else {
871 pandecode_log(".shared_memory = {\n");
872 pandecode_indent++;
873 pandecode_shared_memory(&fb->shared_memory, is_compute);
874 pandecode_indent--;
875 pandecode_log("},\n");
876 }
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700877
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700878 info.width = fb->width1 + 1;
879 info.height = fb->height1 + 1;
880 info.rt_count = fb->rt_count_1 + 1;
881
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000882 pandecode_prop("width1 = MALI_POSITIVE(%d)", fb->width1 + 1);
883 pandecode_prop("height1 = MALI_POSITIVE(%d)", fb->height1 + 1);
884 pandecode_prop("width2 = MALI_POSITIVE(%d)", fb->width2 + 1);
885 pandecode_prop("height2 = MALI_POSITIVE(%d)", fb->height2 + 1);
886
887 pandecode_prop("unk1 = 0x%x", fb->unk1);
888 pandecode_prop("unk2 = 0x%x", fb->unk2);
889 pandecode_prop("rt_count_1 = MALI_POSITIVE(%d)", fb->rt_count_1 + 1);
890 pandecode_prop("rt_count_2 = %d", fb->rt_count_2);
891
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700892 pandecode_log(".mfbd_flags = ");
893 pandecode_log_decoded_flags(mfbd_flag_info, fb->mfbd_flags);
894 pandecode_log_cont(",\n");
895
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700896 if (fb->clear_stencil)
897 pandecode_prop("clear_stencil = 0x%x", fb->clear_stencil);
898
899 if (fb->clear_depth)
900 pandecode_prop("clear_depth = %f", fb->clear_depth);
901
Alyssa Rosenzweig39939692020-01-22 08:51:19 -0500902 if (!is_compute)
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500903 if (is_bifrost)
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200904 pandecode_bifrost_tiler_descriptor(fb);
Alyssa Rosenzweigc2c8b1a2020-05-26 18:10:39 -0400905 else {
906 const struct midgard_tiler_descriptor t = fb->tiler;
907 pandecode_midgard_tiler_descriptor(&t, fb->width1 + 1, fb->height1 + 1, is_fragment, true);
908 }
Alyssa Rosenzweig39939692020-01-22 08:51:19 -0500909 else
910 pandecode_msg("XXX: skipping compute MFBD, fixme\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000911
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700912 if (fb->zero3 || fb->zero4) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700913 pandecode_msg("XXX: framebuffer zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000914 pandecode_prop("zero3 = 0x%" PRIx32, fb->zero3);
915 pandecode_prop("zero4 = 0x%" PRIx32, fb->zero4);
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700916 }
917
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000918 pandecode_indent--;
919 pandecode_log("};\n");
920
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500921 gpu_va += sizeof(struct mali_framebuffer);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000922
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700923 info.has_extra = (fb->mfbd_flags & MALI_MFBD_EXTRA) && is_fragment;
924
925 if (info.has_extra) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000926 mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500927 const struct mali_framebuffer_extra *PANDECODE_PTR_VAR(fbx, mem, (mali_ptr) gpu_va);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000928
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500929 pandecode_log("struct mali_framebuffer_extra fb_extra_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000930 pandecode_indent++;
931
932 MEMORY_PROP(fbx, checksum);
933
934 if (fbx->checksum_stride)
935 pandecode_prop("checksum_stride = %d", fbx->checksum_stride);
936
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500937 pandecode_log(".flags_hi = ");
Alyssa Rosenzweig7e53cce2020-05-04 12:48:34 -0400938 pandecode_log_decoded_flags(mfbd_extra_flag_hi_info, fbx->flags_hi);
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000939 pandecode_log_cont(",\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000940
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500941 pandecode_log(".flags_lo = ");
942 pandecode_log_decoded_flags(mfbd_extra_flag_lo_info, fbx->flags_lo);
943 pandecode_log_cont(",\n");
944
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400945 pandecode_prop("zs_block = %s", mali_block_format_as_str(fbx->zs_block));
Alyssa Rosenzweige061bf02020-07-15 11:57:35 -0400946 pandecode_prop("zs_samples = MALI_POSITIVE(%u)", fbx->zs_samples + 1);
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500947
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400948 if (fbx->zs_block == MALI_BLOCK_FORMAT_AFBC) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000949 pandecode_log(".ds_afbc = {\n");
950 pandecode_indent++;
951
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700952 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil_afbc_metadata);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000953 pandecode_prop("depth_stencil_afbc_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700954 fbx->ds_afbc.depth_stencil_afbc_stride);
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700955 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000956
Icecream959ac106d2020-06-02 14:13:03 +1200957 pandecode_log(".flags = ");
958 pandecode_log_decoded_flags(afbc_fmt_flag_info, fbx->ds_afbc.flags);
959 pandecode_log_cont(",\n");
960
961 if (fbx->ds_afbc.padding) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700962 pandecode_msg("XXX: Depth/stencil AFBC zeros tripped\n");
Icecream959ac106d2020-06-02 14:13:03 +1200963 pandecode_prop("padding = 0x%" PRIx64, fbx->ds_afbc.padding);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000964 }
965
966 pandecode_indent--;
967 pandecode_log("},\n");
968 } else {
969 pandecode_log(".ds_linear = {\n");
970 pandecode_indent++;
971
972 if (fbx->ds_linear.depth) {
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700973 MEMORY_PROP_DIR(fbx->ds_linear, depth);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000974 pandecode_prop("depth_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700975 fbx->ds_linear.depth_stride);
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400976 pandecode_prop("depth_layer_stride = %d",
977 fbx->ds_linear.depth_layer_stride);
978 } else if (fbx->ds_linear.depth_stride || fbx->ds_linear.depth_layer_stride) {
979 pandecode_msg("XXX: depth stride zero tripped %d %d\n", fbx->ds_linear.depth_stride, fbx->ds_linear.depth_layer_stride);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000980 }
981
982 if (fbx->ds_linear.stencil) {
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700983 MEMORY_PROP_DIR(fbx->ds_linear, stencil);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000984 pandecode_prop("stencil_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700985 fbx->ds_linear.stencil_stride);
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400986 pandecode_prop("stencil_layer_stride = %d",
987 fbx->ds_linear.stencil_layer_stride);
988 } else if (fbx->ds_linear.stencil_stride || fbx->ds_linear.stencil_layer_stride) {
989 pandecode_msg("XXX: stencil stride zero tripped %d %d\n", fbx->ds_linear.stencil_stride, fbx->ds_linear.stencil_layer_stride);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000990 }
991
992 if (fbx->ds_linear.depth_stride_zero ||
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400993 fbx->ds_linear.stencil_stride_zero) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700994 pandecode_msg("XXX: Depth/stencil zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000995 pandecode_prop("depth_stride_zero = 0x%x",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700996 fbx->ds_linear.depth_stride_zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000997 pandecode_prop("stencil_stride_zero = 0x%x",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700998 fbx->ds_linear.stencil_stride_zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000999 }
1000
1001 pandecode_indent--;
1002 pandecode_log("},\n");
1003 }
1004
Alyssa Rosenzweig81a31912020-04-06 19:45:30 -04001005 if (fbx->clear_color_1 | fbx->clear_color_2) {
1006 pandecode_prop("clear_color_1 = 0x%" PRIx32, fbx->clear_color_1);
1007 pandecode_prop("clear_color_2 = 0x%" PRIx32, fbx->clear_color_2);
1008 }
1009
1010 if (fbx->zero3) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001011 pandecode_msg("XXX: fb_extra zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001012 pandecode_prop("zero3 = 0x%" PRIx64, fbx->zero3);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001013 }
1014
1015 pandecode_indent--;
1016 pandecode_log("};\n");
1017
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -05001018 gpu_va += sizeof(struct mali_framebuffer_extra);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001019 }
1020
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -07001021 if (is_fragment)
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -07001022 pandecode_render_target(gpu_va, job_no, fb);
Alyssa Rosenzweiga9fc1c82019-06-23 11:29:46 -07001023
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001024 return info;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001025}
1026
1027static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001028pandecode_attributes(const struct pandecode_mapped_memory *mem,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001029 mali_ptr addr, int job_no, char *suffix,
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -07001030 int count, bool varying, enum mali_job_type job_type)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001031{
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -04001032 char *prefix = varying ? "Varying" : "Attribute";
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001033 assert(addr);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001034
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001035 if (!count) {
1036 pandecode_msg("warn: No %s records\n", prefix);
Alyssa Rosenzweig5ad83012019-08-08 09:23:29 -07001037 return;
1038 }
1039
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -04001040 MAP_ADDR(ATTRIBUTE_BUFFER, addr, cl);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001041
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001042 for (int i = 0; i < count; ++i) {
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -04001043 fprintf(pandecode_dump_stream, "%s\n", prefix);
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -07001044
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -04001045 struct MALI_ATTRIBUTE_BUFFER temp;
1046 MALI_ATTRIBUTE_BUFFER_unpack(cl + i * MALI_ATTRIBUTE_BUFFER_LENGTH, &temp);
1047 MALI_ATTRIBUTE_BUFFER_print(pandecode_dump_stream, &temp, 2);
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -07001048
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -04001049 if (temp.type == MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR) {
1050 struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT temp2;
1051 MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_unpack(cl + (i + 1) * MALI_ATTRIBUTE_BUFFER_LENGTH, &temp2);
1052 MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_print(pandecode_dump_stream, &temp2, 2);
1053 }
Alyssa Rosenzweig3b3d9652019-12-19 12:28:42 -05001054 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001055}
1056
1057static mali_ptr
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001058pandecode_shader_address(const char *name, mali_ptr ptr)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001059{
1060 /* TODO: Decode flags */
1061 mali_ptr shader_ptr = ptr & ~15;
1062
1063 char *a = pointer_as_memory_reference(shader_ptr);
1064 pandecode_prop("%s = (%s) | %d", name, a, (int) (ptr & 15));
1065 free(a);
1066
1067 return shader_ptr;
1068}
1069
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001070/* Decodes a Bifrost blend constant. See the notes in bifrost_blend_rt */
1071
1072static unsigned
1073decode_bifrost_constant(u16 constant)
1074{
1075 float lo = (float) (constant & 0xFF);
1076 float hi = (float) (constant >> 8);
1077
1078 return (hi / 255.0) + (lo / 65535.0);
1079}
1080
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001081static mali_ptr
1082pandecode_bifrost_blend(void *descs, int job_no, int rt_no)
1083{
1084 struct bifrost_blend_rt *b =
1085 ((struct bifrost_blend_rt *) descs) + rt_no;
1086
1087 pandecode_log("struct bifrost_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1088 pandecode_indent++;
1089
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001090 pandecode_prop("flags = 0x%" PRIx16, b->flags);
1091 pandecode_prop("constant = 0x%" PRIx8 " /* %f */",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001092 b->constant, decode_bifrost_constant(b->constant));
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001093
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001094 /* TODO figure out blend shader enable bit */
Alyssa Rosenzweigbf6d5482020-08-18 18:15:45 -04001095 DUMP_CL("Equation", BLEND_EQUATION, &b->equation, 2);
Tomeu Vizoso3c98c452020-04-24 08:40:51 +02001096
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001097 pandecode_prop("unk2 = 0x%" PRIx16, b->unk2);
1098 pandecode_prop("index = 0x%" PRIx16, b->index);
Tomeu Vizoso3c98c452020-04-24 08:40:51 +02001099
Alyssa Rosenzweig0c621dc2020-08-11 21:30:46 -04001100 pandecode_log(".format = %s", mali_format_as_str(b->format));
Tomeu Vizoso3c98c452020-04-24 08:40:51 +02001101 pandecode_swizzle(b->swizzle, b->format);
1102 pandecode_log_cont(",\n");
1103
1104 pandecode_prop("swizzle = 0x%" PRIx32, b->swizzle);
1105 pandecode_prop("format = 0x%" PRIx32, b->format);
1106
1107 if (b->zero1) {
1108 pandecode_msg("XXX: pandecode_bifrost_blend zero1 tripped\n");
1109 pandecode_prop("zero1 = 0x%" PRIx32, b->zero1);
1110 }
1111
1112 pandecode_log(".shader_type = ");
1113 switch(b->shader_type) {
1114 case BIFROST_BLEND_F16:
1115 pandecode_log_cont("BIFROST_BLEND_F16");
1116 break;
1117 case BIFROST_BLEND_F32:
1118 pandecode_log_cont("BIFROST_BLEND_F32");
1119 break;
1120 case BIFROST_BLEND_I32:
1121 pandecode_log_cont("BIFROST_BLEND_I32");
1122 break;
1123 case BIFROST_BLEND_U32:
1124 pandecode_log_cont("BIFROST_BLEND_U32");
1125 break;
1126 case BIFROST_BLEND_I16:
1127 pandecode_log_cont("BIFROST_BLEND_I16");
1128 break;
1129 case BIFROST_BLEND_U16:
1130 pandecode_log_cont("BIFROST_BLEND_U16");
1131 break;
1132 }
1133 pandecode_log_cont(",\n");
1134
1135 if (b->zero2) {
1136 pandecode_msg("XXX: pandecode_bifrost_blend zero2 tripped\n");
1137 pandecode_prop("zero2 = 0x%" PRIx32, b->zero2);
1138 }
1139
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001140 pandecode_prop("shader = 0x%" PRIx32, b->shader);
1141
1142 pandecode_indent--;
1143 pandecode_log("},\n");
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001144
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001145 return 0;
1146}
1147
1148static mali_ptr
1149pandecode_midgard_blend(union midgard_blend *blend, bool is_shader)
1150{
Alyssa Rosenzweig9ce45ac2019-08-21 08:59:57 -07001151 /* constant/equation is in a union */
1152 if (!blend->shader)
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07001153 return 0;
1154
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001155 pandecode_log(".blend = {\n");
1156 pandecode_indent++;
1157
1158 if (is_shader) {
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001159 pandecode_shader_address("shader", blend->shader);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001160 } else {
Alyssa Rosenzweigbf6d5482020-08-18 18:15:45 -04001161 DUMP_CL("Equation", BLEND_EQUATION, &blend->equation, 2);
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001162 pandecode_prop("constant = %f", blend->constant);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001163 }
1164
1165 pandecode_indent--;
1166 pandecode_log("},\n");
1167
1168 /* Return blend shader to disassemble if present */
1169 return is_shader ? (blend->shader & ~0xF) : 0;
1170}
1171
1172static mali_ptr
1173pandecode_midgard_blend_mrt(void *descs, int job_no, int rt_no)
1174{
1175 struct midgard_blend_rt *b =
1176 ((struct midgard_blend_rt *) descs) + rt_no;
1177
1178 /* Flags determine presence of blend shader */
Alyssa Rosenzweig94c9f872020-08-18 17:06:01 -04001179 bool is_shader = b->flags.opaque[0] & 0x2;
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001180
1181 pandecode_log("struct midgard_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1182 pandecode_indent++;
1183
Alyssa Rosenzweig94c9f872020-08-18 17:06:01 -04001184 DUMP_CL("Flags", BLEND_FLAGS, &b->flags, 2);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001185
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -07001186 union midgard_blend blend = b->blend;
1187 mali_ptr shader = pandecode_midgard_blend(&blend, is_shader);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001188
1189 pandecode_indent--;
1190 pandecode_log("};\n");
1191
1192 return shader;
1193}
1194
Alyssa Rosenzweig2208eb92019-08-20 13:59:26 -07001195/* Attributes and varyings have descriptor records, which contain information
1196 * about their format and ordering with the attribute/varying buffers. We'll
1197 * want to validate that the combinations specified are self-consistent.
1198 */
1199
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001200static int
Alyssa Rosenzweig68552282020-08-26 16:50:16 -04001201pandecode_attribute_meta(int count, mali_ptr attribute, bool varying, char *suffix)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001202{
Alyssa Rosenzweig2c8a7222020-08-13 13:27:16 -04001203 const char *prefix = varying ? "Varying" : "Attribute";
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001204
Alyssa Rosenzweig68552282020-08-26 16:50:16 -04001205 for (int i = 0; i < count; ++i, attribute += MALI_ATTRIBUTE_LENGTH)
1206 DUMP_ADDR(prefix, ATTRIBUTE, attribute, 1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001207
Alyssa Rosenzweig2c8a7222020-08-13 13:27:16 -04001208 return count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001209}
1210
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001211/* return bits [lo, hi) of word */
1212static u32
1213bits(u32 word, u32 lo, u32 hi)
1214{
1215 if (hi - lo >= 32)
1216 return word; // avoid undefined behavior with the shift
1217
1218 return (word >> lo) & ((1 << (hi - lo)) - 1);
1219}
1220
1221static void
Alyssa Rosenzweig385a4f72019-12-24 22:33:47 -05001222pandecode_vertex_tiler_prefix(struct mali_vertex_tiler_prefix *p, int job_no, bool graphics)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001223{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001224 /* Decode invocation_count. See the comment before the definition of
1225 * invocation_count for an explanation.
1226 */
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001227 struct MALI_INVOCATION invocation;
1228 struct mali_invocation_packed invocation_packed = p->invocation;
1229 MALI_INVOCATION_unpack((const uint8_t *) &invocation_packed, &invocation);
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001230
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001231 unsigned size_x = bits(invocation.invocations, 0, invocation.size_y_shift) + 1;
1232 unsigned size_y = bits(invocation.invocations, invocation.size_y_shift, invocation.size_z_shift) + 1;
1233 unsigned size_z = bits(invocation.invocations, invocation.size_z_shift, invocation.workgroups_x_shift) + 1;
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001234
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001235 unsigned groups_x = bits(invocation.invocations, invocation.workgroups_x_shift, invocation.workgroups_y_shift) + 1;
1236 unsigned groups_y = bits(invocation.invocations, invocation.workgroups_y_shift, invocation.workgroups_z_shift) + 1;
1237 unsigned groups_z = bits(invocation.invocations, invocation.workgroups_z_shift, 32) + 1;
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001238
1239 /* Even though we have this decoded, we want to ensure that the
1240 * representation is "unique" so we don't lose anything by printing only
1241 * the final result. More specifically, we need to check that we were
1242 * passed something in canonical form, since the definition per the
1243 * hardware is inherently not unique. How? Well, take the resulting
1244 * decode and pack it ourselves! If it is bit exact with what we
1245 * decoded, we're good to go. */
1246
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001247 struct mali_invocation_packed ref;
Alyssa Rosenzweig385a4f72019-12-24 22:33:47 -05001248 panfrost_pack_work_groups_compute(&ref, groups_x, groups_y, groups_z, size_x, size_y, size_z, graphics);
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001249
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001250 if (memcmp(&ref, &invocation_packed, sizeof(ref))) {
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001251 pandecode_msg("XXX: non-canonical workgroups packing\n");
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001252 MALI_INVOCATION_print(pandecode_dump_stream, &invocation, 1 * 2);
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001253 }
1254
1255 /* Regardless, print the decode */
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001256 fprintf(pandecode_dump_stream,
1257 "Invocation (%d, %d, %d) x (%d, %d, %d)\n",
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001258 size_x, size_y, size_z,
1259 groups_x, groups_y, groups_z);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001260
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001261 fprintf(pandecode_dump_stream, "Primitive\n");
1262 struct MALI_PRIMITIVE primitive;
1263 struct mali_primitive_packed prim_packed = p->primitive;
1264 MALI_PRIMITIVE_unpack((const uint8_t *) &prim_packed, &primitive);
1265 MALI_PRIMITIVE_print(pandecode_dump_stream, &primitive, 1 * 2);
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001266
1267 /* Validate an index buffer is present if we need one. TODO: verify
1268 * relationship between invocation_count and index_count */
1269
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001270 if (primitive.indices) {
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001271 /* Grab the size */
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001272 unsigned size = (primitive.index_type == MALI_INDEX_TYPE_UINT32) ?
1273 sizeof(uint32_t) : primitive.index_type;
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001274
1275 /* Ensure we got a size, and if so, validate the index buffer
1276 * is large enough to hold a full set of indices of the given
1277 * size */
1278
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001279 if (!size)
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001280 pandecode_msg("XXX: index size missing\n");
1281 else
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001282 pandecode_validate_buffer(primitive.indices, primitive.index_count * size);
1283 } else if (primitive.index_type)
1284 pandecode_msg("XXX: unexpected index size\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001285}
1286
1287static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001288pandecode_uniform_buffers(mali_ptr pubufs, int ubufs_count, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001289{
1290 struct pandecode_mapped_memory *umem = pandecode_find_mapped_gpu_mem_containing(pubufs);
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001291 uint64_t *PANDECODE_PTR_VAR(ubufs, umem, pubufs);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001292
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001293 for (int i = 0; i < ubufs_count; i++) {
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001294 unsigned size = (ubufs[i] & ((1 << 10) - 1)) * 16;
1295 mali_ptr addr = (ubufs[i] >> 10) << 2;
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001296
1297 pandecode_validate_buffer(addr, size);
1298
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001299 char *ptr = pointer_as_memory_reference(addr);
Alyssa Rosenzweig6ec33b42019-08-21 11:46:06 -07001300 pandecode_log("ubuf_%d[%u] = %s;\n", i, size, ptr);
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001301 free(ptr);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001302 }
1303
Alyssa Rosenzweig6ec33b42019-08-21 11:46:06 -07001304 pandecode_log("\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001305}
1306
1307static void
Alyssa Rosenzweigae84f162019-08-22 11:30:13 -07001308pandecode_uniforms(mali_ptr uniforms, unsigned uniform_count)
1309{
1310 pandecode_validate_buffer(uniforms, uniform_count * 16);
1311
1312 char *ptr = pointer_as_memory_reference(uniforms);
1313 pandecode_log("vec4 uniforms[%u] = %s;\n", uniform_count, ptr);
1314 free(ptr);
1315}
1316
Alyssa Rosenzweig09671c82019-12-23 11:40:40 -05001317static const char *
1318shader_type_for_job(unsigned type)
1319{
1320 switch (type) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001321 case MALI_JOB_TYPE_VERTEX: return "VERTEX";
1322 case MALI_JOB_TYPE_TILER: return "FRAGMENT";
1323 case MALI_JOB_TYPE_COMPUTE: return "COMPUTE";
Alyssa Rosenzweig80049062020-08-26 16:52:53 -04001324 default: return "UNKNOWN";
Alyssa Rosenzweig09671c82019-12-23 11:40:40 -05001325 }
1326}
1327
Alyssa Rosenzweigc4a4f3d2019-08-14 09:19:54 -07001328static unsigned shader_id = 0;
1329
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001330static struct midgard_disasm_stats
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001331pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001332 bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001333{
1334 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(shader_ptr);
1335 uint8_t *PANDECODE_PTR_VAR(code, mem, shader_ptr);
1336
1337 /* Compute maximum possible size */
1338 size_t sz = mem->length - (shader_ptr - mem->gpu_va);
1339
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001340 /* Print some boilerplate to clearly denote the assembly (which doesn't
1341 * obey indentation rules), and actually do the disassembly! */
1342
Icecream95be22c072020-01-23 10:14:35 +13001343 pandecode_log_cont("\n\n");
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001344
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001345 struct midgard_disasm_stats stats;
Alyssa Rosenzweigc4a4f3d2019-08-14 09:19:54 -07001346
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001347 if (is_bifrost) {
Alyssa Rosenzweigc88f8162020-03-27 22:34:15 -04001348 disassemble_bifrost(pandecode_dump_stream, code, sz, true);
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001349
1350 /* TODO: Extend stats to Bifrost */
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001351 stats.texture_count = -128;
1352 stats.sampler_count = -128;
1353 stats.attribute_count = -128;
1354 stats.varying_count = -128;
1355 stats.uniform_count = -128;
1356 stats.uniform_buffer_count = -128;
1357 stats.work_count = -128;
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001358
1359 stats.instruction_count = 0;
1360 stats.bundle_count = 0;
1361 stats.quadword_count = 0;
Alyssa Rosenzweigd6d6d632019-08-30 17:00:09 -07001362 stats.helper_invocations = false;
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001363 } else {
Icecream95be22c072020-01-23 10:14:35 +13001364 stats = disassemble_midgard(pandecode_dump_stream,
1365 code, sz, gpu_id,
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001366 type == MALI_JOB_TYPE_TILER ?
Alyssa Rosenzweigac14fac2019-11-07 09:31:02 -05001367 MESA_SHADER_FRAGMENT : MESA_SHADER_VERTEX);
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001368 }
1369
Alyssa Rosenzweigc088a3b2020-08-26 16:52:23 -04001370 unsigned nr_threads =
1371 (stats.work_count <= 4) ? 4 :
1372 (stats.work_count <= 8) ? 2 :
1373 1;
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001374
Alyssa Rosenzweigc088a3b2020-08-26 16:52:23 -04001375 pandecode_log_cont("shader%d - MESA_SHADER_%s shader: "
1376 "%u inst, %u bundles, %u quadwords, "
1377 "%u registers, %u threads, 0 loops, 0:0 spills:fills\n\n\n",
1378 shader_id++,
1379 shader_type_for_job(type),
1380 stats.instruction_count, stats.bundle_count, stats.quadword_count,
1381 stats.work_count, nr_threads);
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001382
1383 return stats;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001384}
1385
1386static void
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001387pandecode_texture_payload(mali_ptr payload,
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001388 enum mali_texture_dimension dim,
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001389 enum mali_texture_layout layout,
1390 bool manual_stride,
1391 uint8_t levels,
1392 uint16_t depth,
1393 uint16_t array_size,
1394 struct pandecode_mapped_memory *tmem)
1395{
1396 pandecode_log(".payload = {\n");
1397 pandecode_indent++;
1398
1399 /* A bunch of bitmap pointers follow.
1400 * We work out the correct number,
1401 * based on the mipmap/cubemap
1402 * properties, but dump extra
1403 * possibilities to futureproof */
1404
1405 int bitmap_count = levels + 1;
1406
1407 /* Miptree for each face */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001408 if (dim == MALI_TEXTURE_DIMENSION_CUBE)
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001409 bitmap_count *= 6;
Alyssa Rosenzweigeba9bcd2020-06-30 16:21:30 -04001410
1411 /* Array of layers */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001412 bitmap_count *= depth;
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001413
1414 /* Array of textures */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001415 bitmap_count *= array_size;
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001416
1417 /* Stride for each element */
1418 if (manual_stride)
1419 bitmap_count *= 2;
1420
1421 mali_ptr *pointers_and_strides = pandecode_fetch_gpu_mem(tmem,
1422 payload, sizeof(mali_ptr) * bitmap_count);
1423 for (int i = 0; i < bitmap_count; ++i) {
1424 /* How we dump depends if this is a stride or a pointer */
1425
1426 if (manual_stride && (i & 1)) {
1427 /* signed 32-bit snuck in as a 64-bit pointer */
1428 uint64_t stride_set = pointers_and_strides[i];
1429 uint32_t clamped_stride = stride_set;
1430 int32_t stride = clamped_stride;
1431 assert(stride_set == clamped_stride);
1432 pandecode_log("(mali_ptr) %d /* stride */, \n", stride);
1433 } else {
1434 char *a = pointer_as_memory_reference(pointers_and_strides[i]);
1435 pandecode_log("%s, \n", a);
1436 free(a);
1437 }
1438 }
1439
1440 pandecode_indent--;
1441 pandecode_log("},\n");
1442}
1443
1444static void
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001445pandecode_texture(mali_ptr u,
1446 struct pandecode_mapped_memory *tmem,
1447 unsigned job_no, unsigned tex)
1448{
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001449 struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(u);
1450 const uint8_t *cl = pandecode_fetch_gpu_mem(mapped_mem, u, MALI_MIDGARD_TEXTURE_LENGTH);
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001451
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001452 struct MALI_MIDGARD_TEXTURE temp;
1453 MALI_MIDGARD_TEXTURE_unpack(cl, &temp);
1454 MALI_MIDGARD_TEXTURE_print(pandecode_dump_stream, &temp, 2);
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001455
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001456 pandecode_texture_payload(u + MALI_MIDGARD_TEXTURE_LENGTH,
1457 temp.dimension, temp.texel_ordering, temp.manual_stride,
1458 temp.levels, temp.depth, temp.array_size, mapped_mem);
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001459}
1460
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001461static void
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001462pandecode_bifrost_texture(
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001463 const void *cl,
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001464 unsigned job_no,
1465 unsigned tex)
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001466{
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001467 struct MALI_BIFROST_TEXTURE temp;
1468 MALI_BIFROST_TEXTURE_unpack(cl, &temp);
1469 MALI_BIFROST_TEXTURE_print(pandecode_dump_stream, &temp, 2);
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001470
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001471 struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(temp.surfaces);
1472 pandecode_texture_payload(temp.surfaces, temp.dimension, temp.texel_ordering,
1473 true, temp.levels, 1, 1, tmem);
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001474}
1475
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001476/* For shader properties like texture_count, we have a claimed property in the shader_meta, and the actual Truth from static analysis (this may just be an upper limit). We validate accordingly */
1477
1478static void
1479pandecode_shader_prop(const char *name, unsigned claim, signed truth, bool fuzzy)
1480{
1481 /* Nothing to do */
1482 if (claim == truth)
1483 return;
1484
Alyssa Rosenzweig5815f332020-02-25 17:29:55 -05001485 if (fuzzy && (truth < 0))
1486 pandecode_msg("XXX: fuzzy %s, claimed %d, expected %d\n", name, claim, truth);
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001487
1488 if ((truth >= 0) && !fuzzy) {
Alyssa Rosenzweigf48136e2019-08-22 09:02:48 -07001489 pandecode_msg("%s: expected %s = %d, claimed %u\n",
1490 (truth < claim) ? "warn" : "XXX",
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001491 name, truth, claim);
1492 } else if ((claim > -truth) && !fuzzy) {
1493 pandecode_msg("XXX: expected %s <= %u, claimed %u\n",
1494 name, -truth, claim);
1495 } else if (fuzzy && (claim < truth))
1496 pandecode_msg("XXX: expected %s >= %u, claimed %u\n",
1497 name, truth, claim);
1498
1499 pandecode_log(".%s = %" PRId16, name, claim);
1500
1501 if (fuzzy)
1502 pandecode_log_cont(" /* %u used */", truth);
1503
1504 pandecode_log_cont(",\n");
1505}
1506
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001507static void
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001508pandecode_blend_shader_disassemble(mali_ptr shader, int job_no, int job_type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001509 bool is_bifrost, unsigned gpu_id)
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001510{
1511 struct midgard_disasm_stats stats =
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001512 pandecode_shader_disassemble(shader, job_no, job_type, is_bifrost, gpu_id);
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001513
1514 bool has_texture = (stats.texture_count > 0);
1515 bool has_sampler = (stats.sampler_count > 0);
1516 bool has_attribute = (stats.attribute_count > 0);
1517 bool has_varying = (stats.varying_count > 0);
1518 bool has_uniform = (stats.uniform_count > 0);
1519 bool has_ubo = (stats.uniform_buffer_count > 0);
1520
1521 if (has_texture || has_sampler)
1522 pandecode_msg("XXX: blend shader accessing textures\n");
1523
1524 if (has_attribute || has_varying)
1525 pandecode_msg("XXX: blend shader accessing interstage\n");
1526
1527 if (has_uniform || has_ubo)
1528 pandecode_msg("XXX: blend shader accessing uniforms\n");
1529}
1530
1531static void
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001532pandecode_textures(mali_ptr textures, unsigned texture_count, int job_no, bool is_bifrost)
1533{
1534 struct pandecode_mapped_memory *mmem = pandecode_find_mapped_gpu_mem_containing(textures);
1535
1536 if (!mmem)
1537 return;
1538
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001539 pandecode_log("Textures (%"PRIx64"):\n", textures);
1540
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001541 if (is_bifrost) {
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001542 const void *cl = pandecode_fetch_gpu_mem(mmem,
1543 textures, MALI_BIFROST_TEXTURE_LENGTH *
1544 texture_count);
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001545
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001546 for (unsigned tex = 0; tex < texture_count; ++tex) {
1547 pandecode_bifrost_texture(cl +
1548 MALI_BIFROST_TEXTURE_LENGTH * tex,
1549 job_no, tex);
1550 }
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001551 } else {
1552 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures);
1553
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001554 for (int tex = 0; tex < texture_count; ++tex) {
1555 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr));
1556 char *a = pointer_as_memory_reference(*u);
1557 pandecode_log("%s,\n", a);
1558 free(a);
1559 }
1560
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001561 /* Now, finally, descend down into the texture descriptor */
1562 for (unsigned tex = 0; tex < texture_count; ++tex) {
1563 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr));
1564 struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(*u);
1565 if (tmem)
1566 pandecode_texture(*u, tmem, job_no, tex);
1567 }
1568 }
1569}
1570
1571static void
1572pandecode_samplers(mali_ptr samplers, unsigned sampler_count, int job_no, bool is_bifrost)
1573{
Alyssa Rosenzweigb10c3c82020-08-11 18:25:03 -04001574 for (int i = 0; i < sampler_count; ++i) {
1575 if (is_bifrost) {
1576 DUMP_ADDR("Sampler", BIFROST_SAMPLER, samplers + (MALI_BIFROST_SAMPLER_LENGTH * i), 1);
1577 } else {
Alyssa Rosenzweigf74186b2020-08-11 18:23:12 -04001578 DUMP_ADDR("Sampler", MIDGARD_SAMPLER, samplers + (MALI_MIDGARD_SAMPLER_LENGTH * i), 1);
Alyssa Rosenzweigb10c3c82020-08-11 18:25:03 -04001579 }
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001580 }
1581}
1582
1583static void
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001584pandecode_vertex_tiler_postfix_pre(
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001585 const struct MALI_DRAW *p,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001586 int job_no, enum mali_job_type job_type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001587 char *suffix, bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001588{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001589 struct pandecode_mapped_memory *attr_mem;
1590
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001591 struct pandecode_fbd fbd_info = {
1592 /* Default for Bifrost */
1593 .rt_count = 1
1594 };
1595
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001596 if (is_bifrost)
1597 pandecode_compute_fbd(p->shared & ~1, job_no);
1598 else if (p->shared & MALI_MFBD)
1599 fbd_info = pandecode_mfbd_bfr((u64) ((uintptr_t) p->shared) & FBD_MASK, job_no, false, job_type == MALI_JOB_TYPE_COMPUTE, false);
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001600 else if (job_type == MALI_JOB_TYPE_COMPUTE)
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001601 pandecode_compute_fbd((u64) (uintptr_t) p->shared, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001602 else
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001603 fbd_info = pandecode_sfbd((u64) (uintptr_t) p->shared, job_no, false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001604
1605 int varying_count = 0, attribute_count = 0, uniform_count = 0, uniform_buffer_count = 0;
1606 int texture_count = 0, sampler_count = 0;
1607
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001608 if (p->state) {
1609 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(p->state);
1610 uint32_t *cl = pandecode_fetch_gpu_mem(smem, p->state, MALI_STATE_LENGTH);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001611
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001612 /* Disassemble ahead-of-time to get stats. Initialize with
1613 * stats for the missing-shader case so we get validation
1614 * there, too */
1615
1616 struct midgard_disasm_stats info = {
1617 .texture_count = 0,
1618 .sampler_count = 0,
1619 .attribute_count = 0,
1620 .varying_count = 0,
1621 .work_count = 1,
1622
1623 .uniform_count = -128,
1624 .uniform_buffer_count = 0
1625 };
Alyssa Rosenzweig9b067d92019-08-21 14:28:36 -07001626
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001627 struct MALI_STATE state;
Alyssa Rosenzweig1b7d4f12020-08-20 16:25:14 -04001628 struct MALI_MIDGARD_PROPERTIES midg_props;
Alyssa Rosenzweigacf77cb2020-08-20 16:41:41 -04001629 struct MALI_BIFROST_PROPERTIES bi_props;
Alyssa Rosenzweig1b7d4f12020-08-20 16:25:14 -04001630
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001631 MALI_STATE_unpack((const uint8_t *) cl, &state);
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001632
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001633 if (state.shader.shader & ~0xF)
1634 info = pandecode_shader_disassemble(state.shader.shader & ~0xF, job_no, job_type, is_bifrost, gpu_id);
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001635
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001636 fprintf(pandecode_dump_stream, "State");
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001637 MALI_STATE_print(pandecode_dump_stream, &state, 1 * 2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001638
1639 /* Save for dumps */
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001640 attribute_count = state.shader.attribute_count;
1641 varying_count = state.shader.varying_count;
1642 texture_count = state.shader.texture_count;
1643 sampler_count = state.shader.sampler_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001644
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001645 fprintf(pandecode_dump_stream, " Properties\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001646 if (is_bifrost) {
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001647 MALI_BIFROST_PROPERTIES_unpack((const uint8_t *) &state.properties, &bi_props);
1648 MALI_BIFROST_PROPERTIES_print(pandecode_dump_stream, &bi_props, 2 * 2);
Alyssa Rosenzweigacf77cb2020-08-20 16:41:41 -04001649
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001650 uniform_count = state.preload.uniform_count;
Alyssa Rosenzweigacf77cb2020-08-20 16:41:41 -04001651 uniform_buffer_count = bi_props.uniform_buffer_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001652 } else {
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001653 MALI_MIDGARD_PROPERTIES_unpack((const uint8_t *) &state.properties, &midg_props);
1654 MALI_MIDGARD_PROPERTIES_print(pandecode_dump_stream, &midg_props, 2 * 2);
Alyssa Rosenzweig1b7d4f12020-08-20 16:25:14 -04001655
1656 uniform_count = midg_props.uniform_count;
1657 uniform_buffer_count = midg_props.uniform_buffer_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001658 }
1659
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001660 pandecode_shader_prop("texture_count", texture_count, info.texture_count, false);
1661 pandecode_shader_prop("sampler_count", sampler_count, info.sampler_count, false);
1662 pandecode_shader_prop("attribute_count", attribute_count, info.attribute_count, false);
1663 pandecode_shader_prop("varying_count", varying_count, info.varying_count, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001664
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001665 if (is_bifrost) {
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001666 uint32_t opaque = state.preload.uniform_count << 15
1667 | state.preload.untyped;
1668
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001669 switch (job_type) {
1670 case MALI_JOB_TYPE_VERTEX:
1671 DUMP_CL("Preload", PRELOAD_VERTEX, &opaque, 2);
1672 break;
1673 case MALI_JOB_TYPE_TILER:
1674 DUMP_CL("Preload", PRELOAD_FRAGMENT, &opaque, 2);
1675 break;
1676 case MALI_JOB_TYPE_COMPUTE:
1677 DUMP_CL("Preload", PRELOAD_COMPUTE, &opaque, 2);
1678 break;
1679 default:
1680 DUMP_CL("Preload", PRELOAD, &opaque, 2);
1681 break;
1682 }
1683 }
1684
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001685 if (!is_bifrost) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001686 /* TODO: Blend shaders routing/disasm */
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001687 union midgard_blend blend;
1688 memcpy(&blend, &state.sfbd_blend, sizeof(blend));
1689 mali_ptr shader = pandecode_midgard_blend(&blend, state.multisample_misc.sfbd_blend_shader);
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001690 if (shader & ~0xF)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001691 pandecode_blend_shader_disassemble(shader, job_no, job_type, false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001692 }
1693
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001694 /* MRT blend fields are used whenever MFBD is used, with
1695 * per-RT descriptors */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001696
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001697 if (job_type == MALI_JOB_TYPE_TILER && (is_bifrost || p->shared & MALI_MFBD)) {
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001698 void* blend_base = ((void *) cl) + MALI_STATE_LENGTH;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001699
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001700 for (unsigned i = 0; i < fbd_info.rt_count; i++) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001701 mali_ptr shader = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001702
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001703 if (is_bifrost)
1704 shader = pandecode_bifrost_blend(blend_base, job_no, i);
1705 else
1706 shader = pandecode_midgard_blend_mrt(blend_base, job_no, i);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001707
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001708 if (shader & ~0xF)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001709 pandecode_blend_shader_disassemble(shader, job_no, job_type, false, gpu_id);
Alyssa Rosenzweig139708b2019-08-21 14:04:05 -07001710
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001711 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001712 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001713 } else
Alyssa Rosenzweig5f9a1c72019-08-21 14:16:32 -07001714 pandecode_msg("XXX: missing shader descriptor\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001715
Alyssa Rosenzweig7f487e02020-08-05 19:33:20 -04001716 if (p->viewport)
1717 DUMP_ADDR("Viewport", VIEWPORT, p->viewport, 1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001718
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001719 unsigned max_attr_index = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001720
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001721 if (p->attributes)
1722 max_attr_index = pandecode_attribute_meta(attribute_count, p->attributes, false, suffix);
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001723
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001724 if (p->attribute_buffers) {
1725 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->attribute_buffers);
1726 pandecode_attributes(attr_mem, p->attribute_buffers, job_no, suffix, max_attr_index, false, job_type);
Alyssa Rosenzweig9e66ff32019-07-31 11:52:52 -07001727 }
1728
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001729 if (p->varyings) {
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001730 varying_count = pandecode_attribute_meta(varying_count, p->varyings, true, suffix);
1731 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001732
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001733 if (p->varying_buffers) {
1734 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->varying_buffers);
1735 pandecode_attributes(attr_mem, p->varying_buffers, job_no, suffix, varying_count, true, job_type);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001736 }
1737
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001738 if (p->uniform_buffers) {
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001739 if (uniform_buffer_count)
1740 pandecode_uniform_buffers(p->uniform_buffers, uniform_buffer_count, job_no);
1741 else
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001742 pandecode_msg("warn: UBOs specified but not referenced\n");
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001743 } else if (uniform_buffer_count)
1744 pandecode_msg("XXX: UBOs referenced but not specified\n");
1745
1746 /* We don't want to actually dump uniforms, but we do need to validate
1747 * that the counts we were given are sane */
1748
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001749 if (p->push_uniforms) {
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001750 if (uniform_count)
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001751 pandecode_uniforms(p->push_uniforms, uniform_count);
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001752 else
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001753 pandecode_msg("warn: Uniforms specified but not referenced\n");
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001754 } else if (uniform_count)
Alyssa Rosenzweigd7473e22019-08-21 14:15:05 -07001755 pandecode_msg("XXX: Uniforms referenced but not specified\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001756
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001757 if (p->textures)
1758 pandecode_textures(p->textures, texture_count, job_no, is_bifrost);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001759
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001760 if (p->samplers)
1761 pandecode_samplers(p->samplers, sampler_count, job_no, is_bifrost);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001762}
1763
1764static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001765pandecode_tiler_heap_meta(mali_ptr gpu_va, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001766{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001767 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
1768 const struct bifrost_tiler_heap_meta *PANDECODE_PTR_VAR(h, mem, gpu_va);
1769
Tomeu Vizoso46e42462020-04-08 15:58:42 +02001770 pandecode_log("struct bifrost_tiler_heap_meta tiler_heap_meta_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001771 pandecode_indent++;
1772
1773 if (h->zero) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001774 pandecode_msg("XXX: tiler heap zero tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001775 pandecode_prop("zero = 0x%x", h->zero);
1776 }
1777
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001778 pandecode_prop("heap_size = 0x%x", h->heap_size);
1779 MEMORY_PROP(h, tiler_heap_start);
1780 MEMORY_PROP(h, tiler_heap_free);
1781
1782 /* this might point to the beginning of another buffer, when it's
1783 * really the end of the tiler heap buffer, so we have to be careful
Alyssa Rosenzweig17752ba2019-07-18 12:28:56 -07001784 * here. but for zero length, we need the same pointer.
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001785 */
Alyssa Rosenzweig17752ba2019-07-18 12:28:56 -07001786
1787 if (h->tiler_heap_end == h->tiler_heap_start) {
1788 MEMORY_PROP(h, tiler_heap_start);
1789 } else {
1790 char *a = pointer_as_memory_reference(h->tiler_heap_end - 1);
1791 pandecode_prop("tiler_heap_end = %s + 1", a);
1792 free(a);
1793 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001794
Tomeu Vizoso0a0b6702020-04-09 09:39:17 +02001795 for (int i = 0; i < 10; i++) {
1796 if (h->zeros[i] != 0) {
1797 pandecode_msg("XXX: tiler heap zero %d tripped, value %x\n",
1798 i, h->zeros[i]);
1799 }
1800 }
1801
1802 if (h->unk1 != 0x1) {
1803 pandecode_msg("XXX: tiler heap unk1 tripped\n");
1804 pandecode_prop("unk1 = 0x%x", h->unk1);
1805 }
1806
1807 if (h->unk7e007e != 0x7e007e) {
1808 pandecode_msg("XXX: tiler heap unk7e007e tripped\n");
1809 pandecode_prop("unk7e007e = 0x%x", h->unk7e007e);
1810 }
1811
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001812 pandecode_indent--;
1813 pandecode_log("};\n");
1814}
1815
1816static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001817pandecode_tiler_meta(mali_ptr gpu_va, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001818{
1819 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
1820 const struct bifrost_tiler_meta *PANDECODE_PTR_VAR(t, mem, gpu_va);
1821
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001822 pandecode_tiler_heap_meta(t->tiler_heap_meta, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001823
Tomeu Vizoso46e42462020-04-08 15:58:42 +02001824 pandecode_log("struct bifrost_tiler_meta tiler_meta_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001825 pandecode_indent++;
1826
Tomeu Vizoso7104e282020-04-27 17:09:39 +02001827 pandecode_prop("tiler_heap_next_start = 0x%" PRIx32, t->tiler_heap_next_start);
1828 pandecode_prop("used_hierarchy_mask = 0x%" PRIx32, t->used_hierarchy_mask);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001829
Tomeu Vizoso0a0b6702020-04-09 09:39:17 +02001830 if (t->hierarchy_mask != 0xa &&
1831 t->hierarchy_mask != 0x14 &&
1832 t->hierarchy_mask != 0x28 &&
1833 t->hierarchy_mask != 0x50 &&
1834 t->hierarchy_mask != 0xa0)
1835 pandecode_prop("XXX: Unexpected hierarchy_mask (not 0xa, 0x14, 0x28, 0x50 or 0xa0)!");
1836
Alyssa Rosenzweig7f26bb32019-06-13 10:25:32 -07001837 pandecode_prop("hierarchy_mask = 0x%" PRIx16, t->hierarchy_mask);
Tomeu Vizoso0a0b6702020-04-09 09:39:17 +02001838
Alyssa Rosenzweig7f26bb32019-06-13 10:25:32 -07001839 pandecode_prop("flags = 0x%" PRIx16, t->flags);
1840
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001841 pandecode_prop("width = MALI_POSITIVE(%d)", t->width + 1);
1842 pandecode_prop("height = MALI_POSITIVE(%d)", t->height + 1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001843
Tomeu Vizoso7104e282020-04-27 17:09:39 +02001844 if (t->zero0) {
1845 pandecode_msg("XXX: tiler meta zero tripped\n");
1846 pandecode_prop("zero0 = 0x%" PRIx64, t->zero0);
1847 }
1848
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001849 for (int i = 0; i < 12; i++) {
1850 if (t->zeros[i] != 0) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001851 pandecode_msg("XXX: tiler heap zero %d tripped, value %" PRIx64 "\n",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001852 i, t->zeros[i]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001853 }
1854 }
1855
1856 pandecode_indent--;
1857 pandecode_log("};\n");
1858}
1859
1860static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001861pandecode_primitive_size(union midgard_primitive_size u, bool constant)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001862{
Alyssa Rosenzweig2608da12019-06-19 09:35:57 -07001863 if (u.pointer == 0x0)
1864 return;
1865
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001866 pandecode_log(".primitive_size = {\n");
1867 pandecode_indent++;
1868
Alyssa Rosenzweigb517e362019-03-15 03:21:27 +00001869 if (constant) {
1870 pandecode_prop("constant = %f", u.constant);
1871 } else {
1872 MEMORY_PROP((&u), pointer);
1873 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001874
1875 pandecode_indent--;
1876 pandecode_log("},\n");
1877}
1878
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001879static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001880pandecode_vertex_job_bfr(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001881 const struct pandecode_mapped_memory *mem,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001882 mali_ptr payload, int job_no, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001883{
1884 struct bifrost_payload_vertex *PANDECODE_PTR_VAR(v, mem, payload);
1885
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001886 struct MALI_DRAW draw;
1887 struct mali_draw_packed draw_packed;
1888 memcpy(&draw_packed, &v->postfix, sizeof(draw_packed));
1889 MALI_DRAW_unpack((const uint8_t *) &draw_packed, &draw); \
1890 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", true, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001891
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001892 pandecode_vertex_tiler_prefix(&v->prefix, job_no, false);
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001893 DUMP_CL("Draw", DRAW, &draw_packed, 2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001894
1895 return sizeof(*v);
1896}
1897
1898static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001899pandecode_tiler_job_bfr(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001900 const struct pandecode_mapped_memory *mem,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001901 mali_ptr payload, int job_no, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001902{
1903 struct bifrost_payload_tiler *PANDECODE_PTR_VAR(t, mem, payload);
1904
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001905 struct MALI_DRAW draw;
1906 struct mali_draw_packed draw_packed;
1907 memcpy(&draw_packed, &t->postfix, sizeof(draw_packed));
1908 MALI_DRAW_unpack((const uint8_t *) &draw_packed, &draw); \
1909 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", true, gpu_id);
Alyssa Rosenzweig4467e792020-08-26 13:21:06 -04001910 pandecode_tiler_meta(t->tiler_meta, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001911
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001912 pandecode_vertex_tiler_prefix(&t->prefix, job_no, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001913
Alyssa Rosenzweig4467e792020-08-26 13:21:06 -04001914 /* TODO: gl_PointSize on Bifrost */
1915 pandecode_primitive_size(t->primitive_size, true);
1916
1917 if (t->zero1 || t->zero2 || t->zero3 || t->zero4 || t->zero5
1918 || t->zero6) {
1919 pandecode_msg("XXX: tiler only zero tripped\n");
1920 pandecode_prop("zero1 = 0x%" PRIx64, t->zero1);
1921 pandecode_prop("zero2 = 0x%" PRIx64, t->zero2);
1922 pandecode_prop("zero3 = 0x%" PRIx64, t->zero3);
1923 pandecode_prop("zero4 = 0x%" PRIx64, t->zero4);
1924 pandecode_prop("zero5 = 0x%" PRIx64, t->zero5);
1925 pandecode_prop("zero6 = 0x%" PRIx64, t->zero6);
1926 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001927
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001928 DUMP_CL("Draw", DRAW, &draw_packed, 2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001929
1930 return sizeof(*t);
1931}
1932
1933static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001934pandecode_vertex_or_tiler_job_mdg(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001935 const struct pandecode_mapped_memory *mem,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001936 mali_ptr payload, int job_no, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001937{
1938 struct midgard_payload_vertex_tiler *PANDECODE_PTR_VAR(v, mem, payload);
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001939 bool is_graphics = (h->job_type == MALI_JOB_TYPE_VERTEX) || (h->job_type == MALI_JOB_TYPE_TILER);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001940
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001941 struct MALI_DRAW draw;
1942 struct mali_draw_packed draw_packed;
1943 memcpy(&draw_packed, &v->postfix, sizeof(draw_packed));
1944 MALI_DRAW_unpack((const uint8_t *) &draw_packed, &draw); \
1945 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001946
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -04001947 pandecode_vertex_tiler_prefix(&v->prefix, job_no, is_graphics);
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001948 DUMP_CL("Draw", DRAW, &draw_packed, 2);
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -04001949
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001950 struct MALI_PRIMITIVE primitive;
1951 struct mali_primitive_packed prim_packed = v->prefix.primitive;
1952 MALI_PRIMITIVE_unpack((const uint8_t *) &prim_packed, &primitive);
1953
1954 pandecode_primitive_size(v->primitive_size, primitive.point_size_array == 0);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001955
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001956 return sizeof(*v);
1957}
1958
1959static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001960pandecode_fragment_job(const struct pandecode_mapped_memory *mem,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001961 mali_ptr payload, int job_no,
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01001962 bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001963{
1964 const struct mali_payload_fragment *PANDECODE_PTR_VAR(s, mem, payload);
1965
Alyssa Rosenzweig89593642019-12-16 12:05:45 -05001966 bool is_mfbd = s->framebuffer & MALI_MFBD;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001967
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001968 if (!is_mfbd && is_bifrost)
1969 pandecode_msg("XXX: Bifrost fragment must use MFBD\n");
1970
1971 struct pandecode_fbd info;
1972
1973 if (is_mfbd)
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -05001974 info = pandecode_mfbd_bfr(s->framebuffer & FBD_MASK, job_no, true, false, is_bifrost);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001975 else
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01001976 info = pandecode_sfbd(s->framebuffer & FBD_MASK, job_no, true, gpu_id);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001977
1978 /* Compute the tag for the tagged pointer. This contains the type of
1979 * FBD (MFBD/SFBD), and in the case of an MFBD, information about which
1980 * additional structures follow the MFBD header (an extra payload or
1981 * not, as well as a count of render targets) */
1982
Alyssa Rosenzweig89593642019-12-16 12:05:45 -05001983 unsigned expected_tag = is_mfbd ? MALI_MFBD : 0;
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001984
1985 if (is_mfbd) {
1986 if (info.has_extra)
1987 expected_tag |= MALI_MFBD_TAG_EXTRA;
1988
1989 expected_tag |= (MALI_POSITIVE(info.rt_count) << 2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001990 }
1991
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001992 if ((s->min_tile_coord | s->max_tile_coord) & ~(MALI_X_COORD_MASK | MALI_Y_COORD_MASK)) {
1993 pandecode_msg("XXX: unexpected tile coordinate bits\n");
1994 pandecode_prop("min_tile_coord = 0x%X\n", s->min_tile_coord);
Alyssa Rosenzweig52d6b4d2020-05-11 18:54:05 -04001995 pandecode_prop("max_tile_coord = 0x%X\n", s->max_tile_coord);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001996 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001997
Alyssa Rosenzweigded9a682019-08-21 12:29:47 -07001998 /* Extract tile coordinates */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001999
Alyssa Rosenzweigded9a682019-08-21 12:29:47 -07002000 unsigned min_x = MALI_TILE_COORD_X(s->min_tile_coord) << MALI_TILE_SHIFT;
2001 unsigned min_y = MALI_TILE_COORD_Y(s->min_tile_coord) << MALI_TILE_SHIFT;
2002
2003 unsigned max_x = (MALI_TILE_COORD_X(s->max_tile_coord) + 1) << MALI_TILE_SHIFT;
2004 unsigned max_y = (MALI_TILE_COORD_Y(s->max_tile_coord) + 1) << MALI_TILE_SHIFT;
2005
2006 /* For the max, we also want the floored (rather than ceiled) version for checking */
2007
2008 unsigned max_x_f = (MALI_TILE_COORD_X(s->max_tile_coord)) << MALI_TILE_SHIFT;
2009 unsigned max_y_f = (MALI_TILE_COORD_Y(s->max_tile_coord)) << MALI_TILE_SHIFT;
2010
2011 /* Validate the coordinates are well-ordered */
2012
2013 if (min_x == max_x)
2014 pandecode_msg("XXX: empty X coordinates (%u = %u)\n", min_x, max_x);
2015 else if (min_x > max_x)
2016 pandecode_msg("XXX: misordered X coordinates (%u > %u)\n", min_x, max_x);
2017
2018 if (min_y == max_y)
2019 pandecode_msg("XXX: empty X coordinates (%u = %u)\n", min_x, max_x);
2020 else if (min_y > max_y)
2021 pandecode_msg("XXX: misordered X coordinates (%u > %u)\n", min_x, max_x);
2022
2023 /* Validate the coordinates fit inside the framebuffer. We use floor,
2024 * rather than ceil, for the max coordinates, since the tile
2025 * coordinates for something like an 800x600 framebuffer will actually
2026 * resolve to 800x608, which would otherwise trigger a Y-overflow */
2027
2028 if ((min_x > info.width) || (max_x_f > info.width))
2029 pandecode_msg("XXX: tile coordinates overflow in X direction\n");
2030
2031 if ((min_y > info.height) || (max_y_f > info.height))
2032 pandecode_msg("XXX: tile coordinates overflow in Y direction\n");
2033
2034 /* After validation, we print */
2035
2036 pandecode_log("fragment (%u, %u) ... (%u, %u)\n\n", min_x, min_y, max_x, max_y);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002037
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002038 /* The FBD is a tagged pointer */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002039
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002040 unsigned tag = (s->framebuffer & ~FBD_MASK);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002041
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002042 if (tag != expected_tag)
2043 pandecode_msg("XXX: expected FBD tag %X but got %X\n", expected_tag, tag);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002044
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002045 return sizeof(*s);
2046}
2047
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05002048/* Entrypoint to start tracing. jc_gpu_va is the GPU address for the first job
2049 * in the chain; later jobs are found by walking the chain. Bifrost is, well,
2050 * if it's bifrost or not. GPU ID is the more finegrained ID (at some point, we
2051 * might wish to combine this with the bifrost parameter) because some details
2052 * are model-specific even within a particular architecture. Minimal traces
2053 * *only* examine the job descriptors, skipping printing entirely if there is
2054 * no faults, and only descends into the payload if there are faults. This is
2055 * useful for looking for faults without the overhead of invasive traces. */
2056
Alyssa Rosenzweig59986462020-02-18 07:46:03 -05002057void
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05002058pandecode_jc(mali_ptr jc_gpu_va, bool bifrost, unsigned gpu_id, bool minimal)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002059{
Icecream9501d60d32020-07-16 16:12:13 +12002060 pandecode_dump_file_open();
2061
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002062 struct mali_job_descriptor_header *h;
Alyssa Rosenzweig59986462020-02-18 07:46:03 -05002063 unsigned job_descriptor_number = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002064
2065 do {
2066 struct pandecode_mapped_memory *mem =
2067 pandecode_find_mapped_gpu_mem_containing(jc_gpu_va);
2068
2069 void *payload;
2070
2071 h = PANDECODE_PTR(mem, jc_gpu_va, struct mali_job_descriptor_header);
2072
Alyssa Rosenzweigaac5a552020-08-21 09:31:43 -04002073 mali_ptr payload_ptr = jc_gpu_va + sizeof(*h);
Alyssa Rosenzweigd353b152020-08-21 09:36:14 -04002074 payload = pandecode_fetch_gpu_mem(mem, payload_ptr, 64);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002075
2076 int job_no = job_descriptor_number++;
2077
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05002078 /* If the job is good to go, skip it in minimal mode */
2079 if (minimal && (h->exception_status == 0x0 || h->exception_status == 0x1))
2080 continue;
2081
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02002082 pandecode_log("struct mali_job_descriptor_header job_%"PRIx64"_%d = {\n", jc_gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002083 pandecode_indent++;
2084
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002085 pandecode_prop("job_type = %s", mali_job_type_as_str(h->job_type));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002086
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002087 if (h->job_descriptor_size)
2088 pandecode_prop("job_descriptor_size = %d", h->job_descriptor_size);
2089
Alyssa Rosenzweige918dd82019-08-16 16:36:39 -07002090 if (h->exception_status && h->exception_status != 0x1)
Alyssa Rosenzweig358372b2019-08-09 16:04:24 -07002091 pandecode_prop("exception_status = %x (source ID: 0x%x access: %s exception: 0x%x)",
Tomeu Vizosofa36c192019-06-25 08:22:30 +02002092 h->exception_status,
2093 (h->exception_status >> 16) & 0xFFFF,
Alyssa Rosenzweig78445ce2020-08-11 21:19:52 -04002094 mali_exception_access_as_str((h->exception_status >> 8) & 0x3),
Tomeu Vizosofa36c192019-06-25 08:22:30 +02002095 h->exception_status & 0xFF);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002096
2097 if (h->first_incomplete_task)
2098 pandecode_prop("first_incomplete_task = %d", h->first_incomplete_task);
2099
2100 if (h->fault_pointer)
2101 pandecode_prop("fault_pointer = 0x%" PRIx64, h->fault_pointer);
2102
2103 if (h->job_barrier)
2104 pandecode_prop("job_barrier = %d", h->job_barrier);
2105
2106 pandecode_prop("job_index = %d", h->job_index);
2107
2108 if (h->unknown_flags)
2109 pandecode_prop("unknown_flags = %d", h->unknown_flags);
2110
2111 if (h->job_dependency_index_1)
2112 pandecode_prop("job_dependency_index_1 = %d", h->job_dependency_index_1);
2113
2114 if (h->job_dependency_index_2)
2115 pandecode_prop("job_dependency_index_2 = %d", h->job_dependency_index_2);
2116
2117 pandecode_indent--;
2118 pandecode_log("};\n");
2119
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002120 switch (h->job_type) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002121 case MALI_JOB_TYPE_WRITE_VALUE: {
Alyssa Rosenzweigadf716d2019-12-05 09:06:53 -05002122 struct mali_payload_write_value *s = payload;
2123 pandecode_log("struct mali_payload_write_value payload_%"PRIx64"_%d = {\n", payload_ptr, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002124 pandecode_indent++;
Alyssa Rosenzweig9eae9502019-12-04 08:59:29 -05002125 MEMORY_PROP(s, address);
2126
Alyssa Rosenzweigadf716d2019-12-05 09:06:53 -05002127 if (s->value_descriptor != MALI_WRITE_VALUE_ZERO) {
Alyssa Rosenzweig9eae9502019-12-04 08:59:29 -05002128 pandecode_msg("XXX: unknown value descriptor\n");
2129 pandecode_prop("value_descriptor = 0x%" PRIX32, s->value_descriptor);
2130 }
2131
2132 if (s->reserved) {
2133 pandecode_msg("XXX: set value tripped\n");
2134 pandecode_prop("reserved = 0x%" PRIX32, s->reserved);
2135 }
2136
2137 pandecode_prop("immediate = 0x%" PRIX64, s->immediate);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002138 pandecode_indent--;
2139 pandecode_log("};\n");
2140
2141 break;
2142 }
2143
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002144 case MALI_JOB_TYPE_TILER:
2145 case MALI_JOB_TYPE_VERTEX:
2146 case MALI_JOB_TYPE_COMPUTE:
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002147 if (bifrost) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002148 if (h->job_type == MALI_JOB_TYPE_TILER)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01002149 pandecode_tiler_job_bfr(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002150 else
Tomeu Vizoso072207b2019-11-07 08:27:53 +01002151 pandecode_vertex_job_bfr(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002152 } else
Tomeu Vizoso072207b2019-11-07 08:27:53 +01002153 pandecode_vertex_or_tiler_job_mdg(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002154
2155 break;
2156
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002157 case MALI_JOB_TYPE_FRAGMENT:
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01002158 pandecode_fragment_job(mem, payload_ptr, job_no, bifrost, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002159 break;
2160
2161 default:
2162 break;
2163 }
Alyssa Rosenzweig65e5c192019-12-27 13:03:22 -05002164 } while ((jc_gpu_va = h->next_job));
Icecream95ef672182020-06-22 22:49:53 +12002165
2166 pandecode_map_read_write();
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002167}