blob: 463a779f90221caf342b96bec0beab475fd8094b [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
Boris Brezillonaa2670c2020-09-05 18:14:17 +020060#define DUMP_UNPACKED(T, var, ...) { \
Boris Brezillon670e8182020-09-09 17:56:53 +020061 pandecode_log(__VA_ARGS__); \
Boris Brezillonaa2670c2020-09-05 18:14:17 +020062 pan_print(pandecode_dump_stream, T, var, (pandecode_indent + 1) * 2); \
63}
64
65#define DUMP_CL(T, cl, ...) {\
Boris Brezillon62c0ef02020-09-05 18:04:43 +020066 pan_unpack(cl, T, temp); \
Boris Brezillonaa2670c2020-09-05 18:14:17 +020067 DUMP_UNPACKED(T, temp, __VA_ARGS__); \
Alyssa Rosenzweigd2ddd4d2020-08-05 19:43:58 -040068}
69
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -040070#define MAP_ADDR(T, addr, cl) \
71 const uint8_t *cl = 0; \
72 { \
73 struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(addr); \
74 cl = pandecode_fetch_gpu_mem(mapped_mem, addr, MALI_ ## T ## _LENGTH); \
75 }
76
Boris Brezillon670e8182020-09-09 17:56:53 +020077#define DUMP_ADDR(T, addr, ...) {\
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -040078 MAP_ADDR(T, addr, cl) \
Boris Brezillon670e8182020-09-09 17:56:53 +020079 DUMP_CL(T, cl, __VA_ARGS__); \
Alyssa Rosenzweigd2ddd4d2020-08-05 19:43:58 -040080}
81
Icecream95be22c072020-01-23 10:14:35 +130082FILE *pandecode_dump_stream;
83
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000084/* Semantic logging type.
85 *
86 * Raw: for raw messages to be printed as is.
87 * Message: for helpful information to be commented out in replays.
88 * Property: for properties of a struct
89 *
90 * Use one of pandecode_log, pandecode_msg, or pandecode_prop as syntax sugar.
91 */
92
93enum pandecode_log_type {
94 PANDECODE_RAW,
95 PANDECODE_MESSAGE,
96 PANDECODE_PROPERTY
97};
98
99#define pandecode_log(...) pandecode_log_typed(PANDECODE_RAW, __VA_ARGS__)
100#define pandecode_msg(...) pandecode_log_typed(PANDECODE_MESSAGE, __VA_ARGS__)
101#define pandecode_prop(...) pandecode_log_typed(PANDECODE_PROPERTY, __VA_ARGS__)
102
103unsigned pandecode_indent = 0;
104
105static void
106pandecode_make_indent(void)
107{
108 for (unsigned i = 0; i < pandecode_indent; ++i)
Boris Brezillon6249ae72020-09-09 17:52:23 +0200109 fprintf(pandecode_dump_stream, " ");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000110}
111
112static void
113pandecode_log_typed(enum pandecode_log_type type, const char *format, ...)
114{
115 va_list ap;
116
117 pandecode_make_indent();
118
119 if (type == PANDECODE_MESSAGE)
Icecream95be22c072020-01-23 10:14:35 +1300120 fprintf(pandecode_dump_stream, "// ");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000121 else if (type == PANDECODE_PROPERTY)
Icecream95be22c072020-01-23 10:14:35 +1300122 fprintf(pandecode_dump_stream, ".");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000123
124 va_start(ap, format);
Icecream95be22c072020-01-23 10:14:35 +1300125 vfprintf(pandecode_dump_stream, format, ap);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000126 va_end(ap);
127
128 if (type == PANDECODE_PROPERTY)
Icecream95be22c072020-01-23 10:14:35 +1300129 fprintf(pandecode_dump_stream, ",\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000130}
131
132static void
133pandecode_log_cont(const char *format, ...)
134{
135 va_list ap;
136
137 va_start(ap, format);
Icecream95be22c072020-01-23 10:14:35 +1300138 vfprintf(pandecode_dump_stream, format, ap);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000139 va_end(ap);
140}
141
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700142/* To check for memory safety issues, validates that the given pointer in GPU
143 * memory is valid, containing at least sz bytes. The goal is to eliminate
144 * GPU-side memory bugs (NULL pointer dereferences, buffer overflows, or buffer
145 * overruns) by statically validating pointers.
146 */
147
148static void
149pandecode_validate_buffer(mali_ptr addr, size_t sz)
150{
151 if (!addr) {
152 pandecode_msg("XXX: null pointer deref");
153 return;
154 }
155
156 /* Find a BO */
157
158 struct pandecode_mapped_memory *bo =
159 pandecode_find_mapped_gpu_mem_containing(addr);
160
161 if (!bo) {
162 pandecode_msg("XXX: invalid memory dereference\n");
163 return;
164 }
165
166 /* Bounds check */
167
168 unsigned offset = addr - bo->gpu_va;
169 unsigned total = offset + sz;
170
171 if (total > bo->length) {
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -0700172 pandecode_msg("XXX: buffer overrun. "
Alyssa Rosenzweigbcfcb7e2019-08-30 17:02:43 -0700173 "Chunk of size %zu at offset %d in buffer of size %zu. "
174 "Overrun by %zu bytes. \n",
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700175 sz, offset, bo->length, total - bo->length);
176 return;
177 }
178}
179
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000180struct pandecode_flag_info {
181 u64 flag;
182 const char *name;
183};
184
185static void
186pandecode_log_decoded_flags(const struct pandecode_flag_info *flag_info,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700187 u64 flags)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000188{
189 bool decodable_flags_found = false;
190
191 for (int i = 0; flag_info[i].name; i++) {
192 if ((flags & flag_info[i].flag) != flag_info[i].flag)
193 continue;
194
195 if (!decodable_flags_found) {
196 decodable_flags_found = true;
197 } else {
198 pandecode_log_cont(" | ");
199 }
200
201 pandecode_log_cont("%s", flag_info[i].name);
202
203 flags &= ~flag_info[i].flag;
204 }
205
206 if (decodable_flags_found) {
207 if (flags)
208 pandecode_log_cont(" | 0x%" PRIx64, flags);
209 } else {
210 pandecode_log_cont("0x%" PRIx64, flags);
211 }
212}
213
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000214#define FLAG_INFO(flag) { MALI_CLEAR_##flag, "MALI_CLEAR_" #flag }
215static const struct pandecode_flag_info clear_flag_info[] = {
216 FLAG_INFO(FAST),
217 FLAG_INFO(SLOW),
218 FLAG_INFO(SLOW_STENCIL),
219 {}
220};
221#undef FLAG_INFO
222
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000223#define FLAG_INFO(flag) { MALI_MFBD_FORMAT_##flag, "MALI_MFBD_FORMAT_" #flag }
224static const struct pandecode_flag_info mfbd_fmt_flag_info[] = {
Alyssa Rosenzweig31a4ef82019-06-17 16:01:24 -0700225 FLAG_INFO(SRGB),
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000226 {}
227};
228#undef FLAG_INFO
229
Icecream959ac106d2020-06-02 14:13:03 +1200230#define FLAG_INFO(flag) { MALI_AFBC_##flag, "MALI_AFBC_" #flag }
231static const struct pandecode_flag_info afbc_fmt_flag_info[] = {
232 FLAG_INFO(YTR),
233 {}
234};
235#undef FLAG_INFO
236
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000237#define FLAG_INFO(flag) { MALI_EXTRA_##flag, "MALI_EXTRA_" #flag }
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500238static const struct pandecode_flag_info mfbd_extra_flag_hi_info[] = {
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000239 FLAG_INFO(PRESENT),
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500240 {}
241};
242#undef FLAG_INFO
243
244#define FLAG_INFO(flag) { MALI_EXTRA_##flag, "MALI_EXTRA_" #flag }
245static const struct pandecode_flag_info mfbd_extra_flag_lo_info[] = {
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000246 FLAG_INFO(ZS),
247 {}
248};
249#undef FLAG_INFO
250
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700251#define FLAG_INFO(flag) { MALI_MFBD_##flag, "MALI_MFBD_" #flag }
252static const struct pandecode_flag_info mfbd_flag_info [] = {
253 FLAG_INFO(DEPTH_WRITE),
254 FLAG_INFO(EXTRA),
255 {}
256};
257#undef FLAG_INFO
258
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100259#define FLAG_INFO(flag) { MALI_SFBD_FORMAT_##flag, "MALI_SFBD_FORMAT_" #flag }
260static const struct pandecode_flag_info sfbd_unk1_info [] = {
261 FLAG_INFO(MSAA_8),
262 FLAG_INFO(MSAA_A),
263 {}
264};
265#undef FLAG_INFO
266
267#define FLAG_INFO(flag) { MALI_SFBD_FORMAT_##flag, "MALI_SFBD_FORMAT_" #flag }
268static const struct pandecode_flag_info sfbd_unk2_info [] = {
269 FLAG_INFO(MSAA_B),
270 FLAG_INFO(SRGB),
271 {}
272};
273#undef FLAG_INFO
274
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700275/* Midgard's tiler descriptor is embedded within the
276 * larger FBD */
277
278static void
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700279pandecode_midgard_tiler_descriptor(
280 const struct midgard_tiler_descriptor *t,
281 unsigned width,
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700282 unsigned height,
Alyssa Rosenzweig9fb09042019-11-27 08:31:16 -0500283 bool is_fragment,
284 bool has_hierarchy)
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700285{
286 pandecode_log(".tiler = {\n");
287 pandecode_indent++;
288
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700289 if (t->hierarchy_mask == MALI_TILER_DISABLED)
290 pandecode_prop("hierarchy_mask = MALI_TILER_DISABLED");
291 else
292 pandecode_prop("hierarchy_mask = 0x%" PRIx16, t->hierarchy_mask);
293
294 /* We know this name from the kernel, but we never see it nonzero */
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700295
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700296 if (t->flags)
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700297 pandecode_msg("XXX: unexpected tiler flags 0x%" PRIx16, t->flags);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700298
299 MEMORY_PROP(t, polygon_list);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700300
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700301 /* The body is offset from the base of the polygon list */
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -0400302 //assert(t->polygon_list_body > t->polygon_list);
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700303 unsigned body_offset = t->polygon_list_body - t->polygon_list;
304
305 /* It needs to fit inside the reported size */
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -0400306 //assert(t->polygon_list_size >= body_offset);
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700307
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700308 /* Now that we've sanity checked, we'll try to calculate the sizes
309 * ourselves for comparison */
310
Alyssa Rosenzweig9fb09042019-11-27 08:31:16 -0500311 unsigned ref_header = panfrost_tiler_header_size(width, height, t->hierarchy_mask, has_hierarchy);
312 unsigned ref_size = panfrost_tiler_full_size(width, height, t->hierarchy_mask, has_hierarchy);
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700313
314 if (!((ref_header == body_offset) && (ref_size == t->polygon_list_size))) {
315 pandecode_msg("XXX: bad polygon list size (expected %d / 0x%x)\n",
316 ref_header, ref_size);
317 pandecode_prop("polygon_list_size = 0x%x", t->polygon_list_size);
318 pandecode_msg("body offset %d\n", body_offset);
319 }
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700320
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700321 /* The tiler heap has a start and end specified -- it should be
322 * identical to what we have in the BO. The exception is if tiling is
323 * disabled. */
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700324
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700325 MEMORY_PROP(t, heap_start);
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700326 assert(t->heap_end >= t->heap_start);
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700327
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700328 unsigned heap_size = t->heap_end - t->heap_start;
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700329
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700330 /* Tiling is enabled with a special flag */
331 unsigned hierarchy_mask = t->hierarchy_mask & MALI_HIERARCHY_MASK;
332 unsigned tiler_flags = t->hierarchy_mask ^ hierarchy_mask;
333
334 bool tiling_enabled = hierarchy_mask;
335
336 if (tiling_enabled) {
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700337 /* We should also have no other flags */
338 if (tiler_flags)
339 pandecode_msg("XXX: unexpected tiler %X\n", tiler_flags);
340 } else {
341 /* When tiling is disabled, we should have that flag and no others */
342
343 if (tiler_flags != MALI_TILER_DISABLED) {
344 pandecode_msg("XXX: unexpected tiler flag %X, expected MALI_TILER_DISABLED\n",
345 tiler_flags);
346 }
347
348 /* We should also have an empty heap */
349 if (heap_size) {
350 pandecode_msg("XXX: tiler heap size %d given, expected empty\n",
351 heap_size);
352 }
353
354 /* Disabled tiling is used only for clear-only jobs, which are
355 * purely FRAGMENT, so we should never see this for
356 * non-FRAGMENT descriptors. */
357
358 if (!is_fragment)
359 pandecode_msg("XXX: tiler disabled for non-FRAGMENT job\n");
360 }
361
362 /* We've never seen weights used in practice, but we know from the
363 * kernel these fields is there */
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700364
365 bool nonzero_weights = false;
366
367 for (unsigned w = 0; w < ARRAY_SIZE(t->weights); ++w) {
368 nonzero_weights |= t->weights[w] != 0x0;
369 }
370
371 if (nonzero_weights) {
Alyssa Rosenzweigacd140c2020-02-28 07:25:07 -0500372 pandecode_log(".weights = { ");
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700373
374 for (unsigned w = 0; w < ARRAY_SIZE(t->weights); ++w) {
Alyssa Rosenzweigacd140c2020-02-28 07:25:07 -0500375 pandecode_log_cont("%d, ", t->weights[w]);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700376 }
377
378 pandecode_log("},");
379 }
380
381 pandecode_indent--;
382 pandecode_log("}\n");
383}
384
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500385/* TODO: The Bifrost tiler is not understood at all yet */
386
387static void
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200388pandecode_bifrost_tiler_descriptor(const struct mali_framebuffer *fb)
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500389{
390 pandecode_log(".tiler = {\n");
391 pandecode_indent++;
392
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200393 MEMORY_PROP(fb, tiler_meta);
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500394
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200395 for (int i = 0; i < 16; i++) {
396 if (fb->zeros[i] != 0) {
397 pandecode_msg("XXX: tiler descriptor zero %d tripped, value %x\n",
398 i, fb->zeros[i]);
399 }
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500400 }
401
402 pandecode_log("},\n");
403
404 pandecode_indent--;
405 pandecode_log("}\n");
406
407}
408
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700409/* Information about the framebuffer passed back for
410 * additional analysis */
411
412struct pandecode_fbd {
413 unsigned width;
414 unsigned height;
415 unsigned rt_count;
416 bool has_extra;
417};
418
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100419static void
420pandecode_sfbd_format(struct mali_sfbd_format format)
421{
422 pandecode_log(".format = {\n");
423 pandecode_indent++;
424
425 pandecode_log(".unk1 = ");
426 pandecode_log_decoded_flags(sfbd_unk1_info, format.unk1);
427 pandecode_log_cont(",\n");
428
429 /* TODO: Map formats so we can check swizzles and print nicely */
430 pandecode_log("swizzle");
431 pandecode_swizzle(format.swizzle, MALI_RGBA8_UNORM);
432 pandecode_log_cont(",\n");
433
434 pandecode_prop("nr_channels = MALI_POSITIVE(%d)",
Alyssa Rosenzweig4ccd42e2019-12-27 12:16:09 -0500435 (format.nr_channels + 1));
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100436
437 pandecode_log(".unk2 = ");
438 pandecode_log_decoded_flags(sfbd_unk2_info, format.unk2);
439 pandecode_log_cont(",\n");
440
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400441 pandecode_prop("block = %s", mali_block_format_as_str(format.block));
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100442
443 pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
444
445 pandecode_indent--;
446 pandecode_log("},\n");
447}
448
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700449static struct pandecode_fbd
Tomeu Vizoso697f02c2019-11-12 12:15:02 +0100450pandecode_sfbd(uint64_t gpu_va, int job_no, bool is_fragment, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000451{
452 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
453 const struct mali_single_framebuffer *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
454
Alyssa Rosenzweigd6d6d632019-08-30 17:00:09 -0700455 struct pandecode_fbd info = {
456 .has_extra = false,
457 .rt_count = 1
458 };
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700459
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +0200460 pandecode_log("struct mali_single_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000461 pandecode_indent++;
Boris Brezillon3a06fc32020-09-03 09:18:09 +0200462 DUMP_CL(LOCAL_STORAGE, &s->shared_memory, "Local Storage:\n");
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100463 pandecode_sfbd_format(s->format);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000464
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700465 info.width = s->width + 1;
466 info.height = s->height + 1;
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700467
468 pandecode_prop("width = MALI_POSITIVE(%" PRId16 ")", info.width);
469 pandecode_prop("height = MALI_POSITIVE(%" PRId16 ")", info.height);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000470
Tomeu Vizoso23fe7cd2019-07-12 12:38:50 +0200471 MEMORY_PROP(s, checksum);
472
473 if (s->checksum_stride)
474 pandecode_prop("checksum_stride = %d", s->checksum_stride);
475
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000476 MEMORY_PROP(s, framebuffer);
477 pandecode_prop("stride = %d", s->stride);
478
479 /* Earlier in the actual commandstream -- right before width -- but we
480 * delay to flow nicer */
481
482 pandecode_log(".clear_flags = ");
483 pandecode_log_decoded_flags(clear_flag_info, s->clear_flags);
484 pandecode_log_cont(",\n");
485
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100486 if (s->depth_buffer) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000487 MEMORY_PROP(s, depth_buffer);
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100488 pandecode_prop("depth_stride = %d", s->depth_stride);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000489 }
490
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100491 if (s->stencil_buffer) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000492 MEMORY_PROP(s, stencil_buffer);
Tomeu Vizoso9447a842019-10-30 12:05:30 +0100493 pandecode_prop("stencil_stride = %d", s->stencil_stride);
494 }
495
496 if (s->depth_stride_zero ||
497 s->stencil_stride_zero ||
498 s->zero7 || s->zero8) {
499 pandecode_msg("XXX: Depth/stencil zeros tripped\n");
500 pandecode_prop("depth_stride_zero = 0x%x",
501 s->depth_stride_zero);
502 pandecode_prop("stencil_stride_zero = 0x%x",
503 s->stencil_stride_zero);
504 pandecode_prop("zero7 = 0x%" PRIx32,
505 s->zero7);
506 pandecode_prop("zero8 = 0x%" PRIx32,
507 s->zero8);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000508 }
509
510 if (s->clear_color_1 | s->clear_color_2 | s->clear_color_3 | s->clear_color_4) {
511 pandecode_prop("clear_color_1 = 0x%" PRIx32, s->clear_color_1);
512 pandecode_prop("clear_color_2 = 0x%" PRIx32, s->clear_color_2);
513 pandecode_prop("clear_color_3 = 0x%" PRIx32, s->clear_color_3);
514 pandecode_prop("clear_color_4 = 0x%" PRIx32, s->clear_color_4);
515 }
516
517 if (s->clear_depth_1 != 0 || s->clear_depth_2 != 0 || s->clear_depth_3 != 0 || s->clear_depth_4 != 0) {
518 pandecode_prop("clear_depth_1 = %f", s->clear_depth_1);
519 pandecode_prop("clear_depth_2 = %f", s->clear_depth_2);
520 pandecode_prop("clear_depth_3 = %f", s->clear_depth_3);
521 pandecode_prop("clear_depth_4 = %f", s->clear_depth_4);
522 }
523
524 if (s->clear_stencil) {
525 pandecode_prop("clear_stencil = 0x%x", s->clear_stencil);
526 }
527
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -0700528 const struct midgard_tiler_descriptor t = s->tiler;
Alyssa Rosenzweig9fb09042019-11-27 08:31:16 -0500529
530 bool has_hierarchy = !(gpu_id == 0x0720 || gpu_id == 0x0820 || gpu_id == 0x0830);
531 pandecode_midgard_tiler_descriptor(&t, s->width + 1, s->height + 1, is_fragment, has_hierarchy);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000532
533 pandecode_indent--;
534 pandecode_log("};\n");
535
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000536 pandecode_prop("zero2 = 0x%" PRIx32, s->zero2);
537 pandecode_prop("zero4 = 0x%" PRIx32, s->zero4);
Tomeu Vizoso94e6d172019-11-06 17:30:54 +0100538 pandecode_prop("zero5 = 0x%" PRIx32, s->zero5);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000539
Icecream95be22c072020-01-23 10:14:35 +1300540 pandecode_log_cont(".zero3 = {");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000541
542 for (int i = 0; i < sizeof(s->zero3) / sizeof(s->zero3[0]); ++i)
Icecream95be22c072020-01-23 10:14:35 +1300543 pandecode_log_cont("%X, ", s->zero3[i]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000544
Icecream95be22c072020-01-23 10:14:35 +1300545 pandecode_log_cont("},\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000546
Icecream95be22c072020-01-23 10:14:35 +1300547 pandecode_log_cont(".zero6 = {");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000548
549 for (int i = 0; i < sizeof(s->zero6) / sizeof(s->zero6[0]); ++i)
Icecream95be22c072020-01-23 10:14:35 +1300550 pandecode_log_cont("%X, ", s->zero6[i]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000551
Icecream95be22c072020-01-23 10:14:35 +1300552 pandecode_log_cont("},\n");
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700553
554 return info;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000555}
556
557static void
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700558pandecode_compute_fbd(uint64_t gpu_va, int job_no)
559{
560 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Boris Brezillon3a06fc32020-09-03 09:18:09 +0200561 const struct mali_local_storage_packed *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
562 DUMP_CL(LOCAL_STORAGE, s, "Local Storage:\n");
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700563}
564
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700565/* Extracts the number of components associated with a Mali format */
566
567static unsigned
568pandecode_format_component_count(enum mali_format fmt)
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000569{
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700570 /* Mask out the format class */
571 unsigned top = fmt & 0b11100000;
572
573 switch (top) {
574 case MALI_FORMAT_SNORM:
575 case MALI_FORMAT_UINT:
576 case MALI_FORMAT_UNORM:
577 case MALI_FORMAT_SINT:
578 return ((fmt >> 3) & 3) + 1;
579 default:
580 /* TODO: Validate */
581 return 4;
582 }
583}
584
585/* Extracts a mask of accessed components from a 12-bit Mali swizzle */
586
587static unsigned
588pandecode_access_mask_from_channel_swizzle(unsigned swizzle)
589{
590 unsigned mask = 0;
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400591 assert(MALI_CHANNEL_R == 0);
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700592
593 for (unsigned c = 0; c < 4; ++c) {
594 enum mali_channel chan = (swizzle >> (3*c)) & 0x7;
595
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400596 if (chan <= MALI_CHANNEL_A)
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700597 mask |= (1 << chan);
598 }
599
600 return mask;
601}
602
603/* Validates that a (format, swizzle) pair is valid, in the sense that the
604 * swizzle doesn't access any components that are undefined in the format.
605 * Returns whether the swizzle is trivial (doesn't do any swizzling) and can be
606 * omitted */
607
608static bool
609pandecode_validate_format_swizzle(enum mali_format fmt, unsigned swizzle)
610{
611 unsigned nr_comp = pandecode_format_component_count(fmt);
612 unsigned access_mask = pandecode_access_mask_from_channel_swizzle(swizzle);
613 unsigned valid_mask = (1 << nr_comp) - 1;
614 unsigned invalid_mask = ~valid_mask;
615
616 if (access_mask & invalid_mask) {
617 pandecode_msg("XXX: invalid components accessed\n");
618 return false;
619 }
620
621 /* Check for the default non-swizzling swizzle so we can suppress
622 * useless printing for the defaults */
623
624 unsigned default_swizzles[4] = {
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400625 MALI_CHANNEL_R | (MALI_CHANNEL_0 << 3) | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9),
626 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9),
627 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_1 << 9),
628 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_A << 9)
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700629 };
630
631 return (swizzle == default_swizzles[nr_comp - 1]);
632}
633
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700634static void
635pandecode_swizzle(unsigned swizzle, enum mali_format format)
636{
637 /* First, do some validation */
638 bool trivial_swizzle = pandecode_validate_format_swizzle(
639 format, swizzle);
640
641 if (trivial_swizzle)
642 return;
643
644 /* Next, print the swizzle */
645 pandecode_log_cont(".");
646
647 static const char components[] = "rgba01";
648
649 for (unsigned c = 0; c < 4; ++c) {
650 enum mali_channel chan = (swizzle >> (3 * c)) & 0x7;
651
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400652 if (chan > MALI_CHANNEL_1) {
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700653 pandecode_log("XXX: invalid swizzle channel %d\n", chan);
654 continue;
655 }
656 pandecode_log_cont("%c", components[chan]);
657 }
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000658}
659
660static void
661pandecode_rt_format(struct mali_rt_format format)
662{
663 pandecode_log(".format = {\n");
664 pandecode_indent++;
665
666 pandecode_prop("unk1 = 0x%" PRIx32, format.unk1);
667 pandecode_prop("unk2 = 0x%" PRIx32, format.unk2);
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700668 pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
Tomeu Vizoso28902ba2020-04-24 11:30:03 +0200669 pandecode_prop("unk4 = 0x%" PRIx32, format.unk4);
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700670
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400671 pandecode_prop("block = %s", mali_block_format_as_str(format.block));
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000672
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700673 /* TODO: Map formats so we can check swizzles and print nicely */
674 pandecode_log("swizzle");
675 pandecode_swizzle(format.swizzle, MALI_RGBA8_UNORM);
676 pandecode_log_cont(",\n");
677
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000678 pandecode_prop("nr_channels = MALI_POSITIVE(%d)",
Alyssa Rosenzweig4ccd42e2019-12-27 12:16:09 -0500679 (format.nr_channels + 1));
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000680
681 pandecode_log(".flags = ");
682 pandecode_log_decoded_flags(mfbd_fmt_flag_info, format.flags);
683 pandecode_log_cont(",\n");
684
Alyssa Rosenzweig99d17fb2020-08-11 21:04:01 -0400685 pandecode_prop("msaa = %s", mali_msaa_as_str(format.msaa));
Alyssa Rosenzweig2c479932020-07-21 18:51:07 -0400686
Alyssa Rosenzweige49204c2019-08-20 11:11:46 -0700687 /* In theory, the no_preload bit can be cleared to enable MFBD preload,
688 * which is a faster hardware-based alternative to the wallpaper method
689 * to preserve framebuffer contents across frames. In practice, MFBD
690 * preload is buggy on Midgard, and so this is a chicken bit. If this
691 * bit isn't set, most likely something broke unrelated to preload */
692
693 if (!format.no_preload) {
694 pandecode_msg("XXX: buggy MFBD preload enabled - chicken bit should be clear\n");
695 pandecode_prop("no_preload = 0x%" PRIx32, format.no_preload);
696 }
Alyssa Rosenzweigb78e04c2019-08-14 16:01:38 -0700697
698 if (format.zero)
699 pandecode_prop("zero = 0x%" PRIx32, format.zero);
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000700
701 pandecode_indent--;
702 pandecode_log("},\n");
703}
704
705static void
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500706pandecode_render_target(uint64_t gpu_va, unsigned job_no, const struct mali_framebuffer *fb)
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700707{
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500708 pandecode_log("struct mali_render_target rts_list_%"PRIx64"_%d[] = {\n", gpu_va, job_no);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700709 pandecode_indent++;
710
Alyssa Rosenzweig4ccd42e2019-12-27 12:16:09 -0500711 for (int i = 0; i < (fb->rt_count_1 + 1); i++) {
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500712 mali_ptr rt_va = gpu_va + i * sizeof(struct mali_render_target);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700713 struct pandecode_mapped_memory *mem =
714 pandecode_find_mapped_gpu_mem_containing(rt_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500715 const struct mali_render_target *PANDECODE_PTR_VAR(rt, mem, (mali_ptr) rt_va);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700716
717 pandecode_log("{\n");
718 pandecode_indent++;
719
720 pandecode_rt_format(rt->format);
721
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400722 if (rt->format.block == MALI_BLOCK_FORMAT_AFBC) {
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700723 pandecode_log(".afbc = {\n");
724 pandecode_indent++;
725
726 char *a = pointer_as_memory_reference(rt->afbc.metadata);
727 pandecode_prop("metadata = %s", a);
728 free(a);
729
730 pandecode_prop("stride = %d", rt->afbc.stride);
Icecream959ac106d2020-06-02 14:13:03 +1200731
732 pandecode_log(".flags = ");
733 pandecode_log_decoded_flags(afbc_fmt_flag_info, rt->afbc.flags);
734 pandecode_log_cont(",\n");
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700735
736 pandecode_indent--;
737 pandecode_log("},\n");
Icecream959ac106d2020-06-02 14:13:03 +1200738 } else if (rt->afbc.metadata || rt->afbc.stride || rt->afbc.flags) {
Alyssa Rosenzweigc9b62332019-08-20 11:06:07 -0700739 pandecode_msg("XXX: AFBC disabled but AFBC field set (0x%lX, 0x%x, 0x%x)\n",
740 rt->afbc.metadata,
741 rt->afbc.stride,
Icecream959ac106d2020-06-02 14:13:03 +1200742 rt->afbc.flags);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700743 }
744
745 MEMORY_PROP(rt, framebuffer);
746 pandecode_prop("framebuffer_stride = %d", rt->framebuffer_stride);
747
Alyssa Rosenzweig37204582020-06-30 16:21:18 -0400748 if (rt->layer_stride)
749 pandecode_prop("layer_stride = %d", rt->layer_stride);
750
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700751 if (rt->clear_color_1 | rt->clear_color_2 | rt->clear_color_3 | rt->clear_color_4) {
752 pandecode_prop("clear_color_1 = 0x%" PRIx32, rt->clear_color_1);
753 pandecode_prop("clear_color_2 = 0x%" PRIx32, rt->clear_color_2);
754 pandecode_prop("clear_color_3 = 0x%" PRIx32, rt->clear_color_3);
755 pandecode_prop("clear_color_4 = 0x%" PRIx32, rt->clear_color_4);
756 }
757
Alyssa Rosenzweig37204582020-06-30 16:21:18 -0400758 if (rt->zero1 || rt->zero2) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700759 pandecode_msg("XXX: render target zeros tripped\n");
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700760 pandecode_prop("zero1 = 0x%" PRIx64, rt->zero1);
761 pandecode_prop("zero2 = 0x%" PRIx32, rt->zero2);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700762 }
763
764 pandecode_indent--;
765 pandecode_log("},\n");
766 }
767
768 pandecode_indent--;
769 pandecode_log("};\n");
770}
771
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700772static struct pandecode_fbd
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500773pandecode_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 +0000774{
775 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500776 const struct mali_framebuffer *PANDECODE_PTR_VAR(fb, mem, (mali_ptr) gpu_va);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000777
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700778 struct pandecode_fbd info;
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500779
780 if (is_bifrost && fb->msaa.sample_locations) {
781 /* The blob stores all possible sample locations in a single buffer
782 * allocated on startup, and just switches the pointer when switching
783 * MSAA state. For now, we just put the data into the cmdstream, but we
784 * should do something like what the blob does with a real driver.
785 *
786 * There seem to be 32 slots for sample locations, followed by another
787 * 16. The second 16 is just the center location followed by 15 zeros
788 * in all the cases I've identified (maybe shader vs. depth/color
789 * samples?).
790 */
791
792 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(fb->msaa.sample_locations);
793
794 const u16 *PANDECODE_PTR_VAR(samples, smem, fb->msaa.sample_locations);
795
796 pandecode_log("uint16_t sample_locations_%d[] = {\n", job_no);
797 pandecode_indent++;
798
799 for (int i = 0; i < 32 + 16; i++) {
800 pandecode_log("%d, %d,\n", samples[2 * i], samples[2 * i + 1]);
801 }
802
803 pandecode_indent--;
804 pandecode_log("};\n");
805 }
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700806
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500807 pandecode_log("struct mali_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000808 pandecode_indent++;
809
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500810 if (is_bifrost) {
811 pandecode_log(".msaa = {\n");
812 pandecode_indent++;
813
814 if (fb->msaa.sample_locations)
815 pandecode_prop("sample_locations = sample_locations_%d", job_no);
816 else
817 pandecode_msg("XXX: sample_locations missing\n");
818
819 if (fb->msaa.zero1 || fb->msaa.zero2 || fb->msaa.zero4) {
820 pandecode_msg("XXX: multisampling zero tripped\n");
821 pandecode_prop("zero1 = %" PRIx64, fb->msaa.zero1);
822 pandecode_prop("zero2 = %" PRIx64, fb->msaa.zero2);
823 pandecode_prop("zero4 = %" PRIx64, fb->msaa.zero4);
824 }
825
826 pandecode_indent--;
827 pandecode_log("},\n");
828 } else {
Boris Brezillon3a06fc32020-09-03 09:18:09 +0200829 struct mali_local_storage_packed ls = fb->shared_memory;
830 DUMP_CL(LOCAL_STORAGE, &ls, "Local Storage:\n");
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500831 }
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700832
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700833 info.width = fb->width1 + 1;
834 info.height = fb->height1 + 1;
835 info.rt_count = fb->rt_count_1 + 1;
836
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000837 pandecode_prop("width1 = MALI_POSITIVE(%d)", fb->width1 + 1);
838 pandecode_prop("height1 = MALI_POSITIVE(%d)", fb->height1 + 1);
839 pandecode_prop("width2 = MALI_POSITIVE(%d)", fb->width2 + 1);
840 pandecode_prop("height2 = MALI_POSITIVE(%d)", fb->height2 + 1);
841
842 pandecode_prop("unk1 = 0x%x", fb->unk1);
843 pandecode_prop("unk2 = 0x%x", fb->unk2);
844 pandecode_prop("rt_count_1 = MALI_POSITIVE(%d)", fb->rt_count_1 + 1);
845 pandecode_prop("rt_count_2 = %d", fb->rt_count_2);
846
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700847 pandecode_log(".mfbd_flags = ");
848 pandecode_log_decoded_flags(mfbd_flag_info, fb->mfbd_flags);
849 pandecode_log_cont(",\n");
850
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700851 if (fb->clear_stencil)
852 pandecode_prop("clear_stencil = 0x%x", fb->clear_stencil);
853
854 if (fb->clear_depth)
855 pandecode_prop("clear_depth = %f", fb->clear_depth);
856
Alyssa Rosenzweig39939692020-01-22 08:51:19 -0500857 if (!is_compute)
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500858 if (is_bifrost)
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200859 pandecode_bifrost_tiler_descriptor(fb);
Alyssa Rosenzweigc2c8b1a2020-05-26 18:10:39 -0400860 else {
861 const struct midgard_tiler_descriptor t = fb->tiler;
862 pandecode_midgard_tiler_descriptor(&t, fb->width1 + 1, fb->height1 + 1, is_fragment, true);
863 }
Alyssa Rosenzweig39939692020-01-22 08:51:19 -0500864 else
865 pandecode_msg("XXX: skipping compute MFBD, fixme\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000866
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700867 if (fb->zero3 || fb->zero4) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700868 pandecode_msg("XXX: framebuffer zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000869 pandecode_prop("zero3 = 0x%" PRIx32, fb->zero3);
870 pandecode_prop("zero4 = 0x%" PRIx32, fb->zero4);
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700871 }
872
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000873 pandecode_indent--;
874 pandecode_log("};\n");
875
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500876 gpu_va += sizeof(struct mali_framebuffer);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000877
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700878 info.has_extra = (fb->mfbd_flags & MALI_MFBD_EXTRA) && is_fragment;
879
880 if (info.has_extra) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000881 mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500882 const struct mali_framebuffer_extra *PANDECODE_PTR_VAR(fbx, mem, (mali_ptr) gpu_va);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000883
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500884 pandecode_log("struct mali_framebuffer_extra fb_extra_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000885 pandecode_indent++;
886
887 MEMORY_PROP(fbx, checksum);
888
889 if (fbx->checksum_stride)
890 pandecode_prop("checksum_stride = %d", fbx->checksum_stride);
891
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500892 pandecode_log(".flags_hi = ");
Alyssa Rosenzweig7e53cce2020-05-04 12:48:34 -0400893 pandecode_log_decoded_flags(mfbd_extra_flag_hi_info, fbx->flags_hi);
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000894 pandecode_log_cont(",\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000895
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500896 pandecode_log(".flags_lo = ");
897 pandecode_log_decoded_flags(mfbd_extra_flag_lo_info, fbx->flags_lo);
898 pandecode_log_cont(",\n");
899
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400900 pandecode_prop("zs_block = %s", mali_block_format_as_str(fbx->zs_block));
Alyssa Rosenzweige061bf02020-07-15 11:57:35 -0400901 pandecode_prop("zs_samples = MALI_POSITIVE(%u)", fbx->zs_samples + 1);
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500902
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400903 if (fbx->zs_block == MALI_BLOCK_FORMAT_AFBC) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000904 pandecode_log(".ds_afbc = {\n");
905 pandecode_indent++;
906
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700907 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil_afbc_metadata);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000908 pandecode_prop("depth_stencil_afbc_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700909 fbx->ds_afbc.depth_stencil_afbc_stride);
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700910 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000911
Icecream959ac106d2020-06-02 14:13:03 +1200912 pandecode_log(".flags = ");
913 pandecode_log_decoded_flags(afbc_fmt_flag_info, fbx->ds_afbc.flags);
914 pandecode_log_cont(",\n");
915
916 if (fbx->ds_afbc.padding) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700917 pandecode_msg("XXX: Depth/stencil AFBC zeros tripped\n");
Icecream959ac106d2020-06-02 14:13:03 +1200918 pandecode_prop("padding = 0x%" PRIx64, fbx->ds_afbc.padding);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000919 }
920
921 pandecode_indent--;
922 pandecode_log("},\n");
923 } else {
924 pandecode_log(".ds_linear = {\n");
925 pandecode_indent++;
926
927 if (fbx->ds_linear.depth) {
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700928 MEMORY_PROP_DIR(fbx->ds_linear, depth);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000929 pandecode_prop("depth_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700930 fbx->ds_linear.depth_stride);
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400931 pandecode_prop("depth_layer_stride = %d",
932 fbx->ds_linear.depth_layer_stride);
933 } else if (fbx->ds_linear.depth_stride || fbx->ds_linear.depth_layer_stride) {
934 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 +0000935 }
936
937 if (fbx->ds_linear.stencil) {
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700938 MEMORY_PROP_DIR(fbx->ds_linear, stencil);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000939 pandecode_prop("stencil_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700940 fbx->ds_linear.stencil_stride);
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400941 pandecode_prop("stencil_layer_stride = %d",
942 fbx->ds_linear.stencil_layer_stride);
943 } else if (fbx->ds_linear.stencil_stride || fbx->ds_linear.stencil_layer_stride) {
944 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 +0000945 }
946
947 if (fbx->ds_linear.depth_stride_zero ||
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400948 fbx->ds_linear.stencil_stride_zero) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700949 pandecode_msg("XXX: Depth/stencil zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000950 pandecode_prop("depth_stride_zero = 0x%x",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700951 fbx->ds_linear.depth_stride_zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000952 pandecode_prop("stencil_stride_zero = 0x%x",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700953 fbx->ds_linear.stencil_stride_zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000954 }
955
956 pandecode_indent--;
957 pandecode_log("},\n");
958 }
959
Alyssa Rosenzweig81a31912020-04-06 19:45:30 -0400960 if (fbx->clear_color_1 | fbx->clear_color_2) {
961 pandecode_prop("clear_color_1 = 0x%" PRIx32, fbx->clear_color_1);
962 pandecode_prop("clear_color_2 = 0x%" PRIx32, fbx->clear_color_2);
963 }
964
965 if (fbx->zero3) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700966 pandecode_msg("XXX: fb_extra zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000967 pandecode_prop("zero3 = 0x%" PRIx64, fbx->zero3);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000968 }
969
970 pandecode_indent--;
971 pandecode_log("};\n");
972
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500973 gpu_va += sizeof(struct mali_framebuffer_extra);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000974 }
975
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700976 if (is_fragment)
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700977 pandecode_render_target(gpu_va, job_no, fb);
Alyssa Rosenzweiga9fc1c82019-06-23 11:29:46 -0700978
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700979 return info;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000980}
981
982static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -0700983pandecode_attributes(const struct pandecode_mapped_memory *mem,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700984 mali_ptr addr, int job_no, char *suffix,
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -0700985 int count, bool varying, enum mali_job_type job_type)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000986{
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -0400987 char *prefix = varying ? "Varying" : "Attribute";
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -0700988 assert(addr);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000989
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -0700990 if (!count) {
991 pandecode_msg("warn: No %s records\n", prefix);
Alyssa Rosenzweig5ad83012019-08-08 09:23:29 -0700992 return;
993 }
994
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -0400995 MAP_ADDR(ATTRIBUTE_BUFFER, addr, cl);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000996
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000997 for (int i = 0; i < count; ++i) {
Boris Brezillon706974c2020-09-15 09:25:18 +0200998 pan_unpack(cl + i * MALI_ATTRIBUTE_BUFFER_LENGTH, ATTRIBUTE_BUFFER, temp);
Boris Brezillonaa2670c2020-09-05 18:14:17 +0200999 DUMP_UNPACKED(ATTRIBUTE_BUFFER, temp, "%s:\n", prefix);
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -07001000
Boris Brezillon706974c2020-09-15 09:25:18 +02001001 if (temp.type != MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR)
1002 continue;
1003
1004 pan_unpack(cl + (i + 1) * MALI_ATTRIBUTE_BUFFER_LENGTH,
1005 ATTRIBUTE_BUFFER_CONTINUATION_NPOT, temp2);
1006 pan_print(pandecode_dump_stream, ATTRIBUTE_BUFFER_CONTINUATION_NPOT,
1007 temp2, (pandecode_indent + 1) * 2);
Alyssa Rosenzweig3b3d9652019-12-19 12:28:42 -05001008 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001009}
1010
1011static mali_ptr
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001012pandecode_shader_address(const char *name, mali_ptr ptr)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001013{
1014 /* TODO: Decode flags */
1015 mali_ptr shader_ptr = ptr & ~15;
1016
1017 char *a = pointer_as_memory_reference(shader_ptr);
1018 pandecode_prop("%s = (%s) | %d", name, a, (int) (ptr & 15));
1019 free(a);
1020
1021 return shader_ptr;
1022}
1023
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001024/* Decodes a Bifrost blend constant. See the notes in bifrost_blend_rt */
1025
1026static unsigned
1027decode_bifrost_constant(u16 constant)
1028{
1029 float lo = (float) (constant & 0xFF);
1030 float hi = (float) (constant >> 8);
1031
1032 return (hi / 255.0) + (lo / 65535.0);
1033}
1034
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001035static mali_ptr
1036pandecode_bifrost_blend(void *descs, int job_no, int rt_no)
1037{
1038 struct bifrost_blend_rt *b =
1039 ((struct bifrost_blend_rt *) descs) + rt_no;
1040
1041 pandecode_log("struct bifrost_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1042 pandecode_indent++;
1043
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001044 pandecode_prop("flags = 0x%" PRIx16, b->flags);
1045 pandecode_prop("constant = 0x%" PRIx8 " /* %f */",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001046 b->constant, decode_bifrost_constant(b->constant));
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001047
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001048 /* TODO figure out blend shader enable bit */
Boris Brezillon670e8182020-09-09 17:56:53 +02001049 DUMP_CL(BLEND_EQUATION, &b->equation, "Equation:\n");
Tomeu Vizoso3c98c452020-04-24 08:40:51 +02001050
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001051 pandecode_prop("unk2 = 0x%" PRIx16, b->unk2);
1052 pandecode_prop("index = 0x%" PRIx16, b->index);
Tomeu Vizoso3c98c452020-04-24 08:40:51 +02001053
Alyssa Rosenzweig0c621dc2020-08-11 21:30:46 -04001054 pandecode_log(".format = %s", mali_format_as_str(b->format));
Tomeu Vizoso3c98c452020-04-24 08:40:51 +02001055 pandecode_swizzle(b->swizzle, b->format);
1056 pandecode_log_cont(",\n");
1057
1058 pandecode_prop("swizzle = 0x%" PRIx32, b->swizzle);
1059 pandecode_prop("format = 0x%" PRIx32, b->format);
1060
1061 if (b->zero1) {
1062 pandecode_msg("XXX: pandecode_bifrost_blend zero1 tripped\n");
1063 pandecode_prop("zero1 = 0x%" PRIx32, b->zero1);
1064 }
1065
1066 pandecode_log(".shader_type = ");
1067 switch(b->shader_type) {
1068 case BIFROST_BLEND_F16:
1069 pandecode_log_cont("BIFROST_BLEND_F16");
1070 break;
1071 case BIFROST_BLEND_F32:
1072 pandecode_log_cont("BIFROST_BLEND_F32");
1073 break;
1074 case BIFROST_BLEND_I32:
1075 pandecode_log_cont("BIFROST_BLEND_I32");
1076 break;
1077 case BIFROST_BLEND_U32:
1078 pandecode_log_cont("BIFROST_BLEND_U32");
1079 break;
1080 case BIFROST_BLEND_I16:
1081 pandecode_log_cont("BIFROST_BLEND_I16");
1082 break;
1083 case BIFROST_BLEND_U16:
1084 pandecode_log_cont("BIFROST_BLEND_U16");
1085 break;
1086 }
1087 pandecode_log_cont(",\n");
1088
1089 if (b->zero2) {
1090 pandecode_msg("XXX: pandecode_bifrost_blend zero2 tripped\n");
1091 pandecode_prop("zero2 = 0x%" PRIx32, b->zero2);
1092 }
1093
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001094 pandecode_prop("shader = 0x%" PRIx32, b->shader);
1095
1096 pandecode_indent--;
1097 pandecode_log("},\n");
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001098
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001099 return 0;
1100}
1101
1102static mali_ptr
1103pandecode_midgard_blend(union midgard_blend *blend, bool is_shader)
1104{
Alyssa Rosenzweig9ce45ac2019-08-21 08:59:57 -07001105 /* constant/equation is in a union */
1106 if (!blend->shader)
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07001107 return 0;
1108
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001109 pandecode_log(".blend = {\n");
1110 pandecode_indent++;
1111
1112 if (is_shader) {
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001113 pandecode_shader_address("shader", blend->shader);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001114 } else {
Boris Brezillon670e8182020-09-09 17:56:53 +02001115 DUMP_CL(BLEND_EQUATION, &blend->equation, "Equation:\n");
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001116 pandecode_prop("constant = %f", blend->constant);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001117 }
1118
1119 pandecode_indent--;
1120 pandecode_log("},\n");
1121
1122 /* Return blend shader to disassemble if present */
1123 return is_shader ? (blend->shader & ~0xF) : 0;
1124}
1125
1126static mali_ptr
1127pandecode_midgard_blend_mrt(void *descs, int job_no, int rt_no)
1128{
1129 struct midgard_blend_rt *b =
1130 ((struct midgard_blend_rt *) descs) + rt_no;
1131
1132 /* Flags determine presence of blend shader */
Alyssa Rosenzweig94c9f872020-08-18 17:06:01 -04001133 bool is_shader = b->flags.opaque[0] & 0x2;
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001134
1135 pandecode_log("struct midgard_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1136 pandecode_indent++;
1137
Boris Brezillon670e8182020-09-09 17:56:53 +02001138 DUMP_CL(BLEND_FLAGS, &b->flags, "Flags:\n");
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001139
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -07001140 union midgard_blend blend = b->blend;
1141 mali_ptr shader = pandecode_midgard_blend(&blend, is_shader);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001142
1143 pandecode_indent--;
1144 pandecode_log("};\n");
1145
1146 return shader;
1147}
1148
Alyssa Rosenzweig2208eb92019-08-20 13:59:26 -07001149/* Attributes and varyings have descriptor records, which contain information
1150 * about their format and ordering with the attribute/varying buffers. We'll
1151 * want to validate that the combinations specified are self-consistent.
1152 */
1153
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001154static int
Alyssa Rosenzweig68552282020-08-26 16:50:16 -04001155pandecode_attribute_meta(int count, mali_ptr attribute, bool varying, char *suffix)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001156{
Alyssa Rosenzweig68552282020-08-26 16:50:16 -04001157 for (int i = 0; i < count; ++i, attribute += MALI_ATTRIBUTE_LENGTH)
Boris Brezillon670e8182020-09-09 17:56:53 +02001158 DUMP_ADDR(ATTRIBUTE, attribute, "%s:\n", varying ? "Varying" : "Attribute");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001159
Alyssa Rosenzweig2c8a7222020-08-13 13:27:16 -04001160 return count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001161}
1162
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001163/* return bits [lo, hi) of word */
1164static u32
1165bits(u32 word, u32 lo, u32 hi)
1166{
1167 if (hi - lo >= 32)
1168 return word; // avoid undefined behavior with the shift
1169
1170 return (word >> lo) & ((1 << (hi - lo)) - 1);
1171}
1172
1173static void
Alyssa Rosenzweig385a4f72019-12-24 22:33:47 -05001174pandecode_vertex_tiler_prefix(struct mali_vertex_tiler_prefix *p, int job_no, bool graphics)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001175{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001176 /* Decode invocation_count. See the comment before the definition of
1177 * invocation_count for an explanation.
1178 */
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001179 struct mali_invocation_packed invocation_packed = p->invocation;
Boris Brezillon706974c2020-09-15 09:25:18 +02001180 pan_unpack(&invocation_packed, INVOCATION, invocation);
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001181
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001182 unsigned size_x = bits(invocation.invocations, 0, invocation.size_y_shift) + 1;
1183 unsigned size_y = bits(invocation.invocations, invocation.size_y_shift, invocation.size_z_shift) + 1;
1184 unsigned size_z = bits(invocation.invocations, invocation.size_z_shift, invocation.workgroups_x_shift) + 1;
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001185
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001186 unsigned groups_x = bits(invocation.invocations, invocation.workgroups_x_shift, invocation.workgroups_y_shift) + 1;
1187 unsigned groups_y = bits(invocation.invocations, invocation.workgroups_y_shift, invocation.workgroups_z_shift) + 1;
1188 unsigned groups_z = bits(invocation.invocations, invocation.workgroups_z_shift, 32) + 1;
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001189
1190 /* Even though we have this decoded, we want to ensure that the
1191 * representation is "unique" so we don't lose anything by printing only
1192 * the final result. More specifically, we need to check that we were
1193 * passed something in canonical form, since the definition per the
1194 * hardware is inherently not unique. How? Well, take the resulting
1195 * decode and pack it ourselves! If it is bit exact with what we
1196 * decoded, we're good to go. */
1197
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001198 struct mali_invocation_packed ref;
Alyssa Rosenzweig385a4f72019-12-24 22:33:47 -05001199 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 -07001200
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001201 if (memcmp(&ref, &invocation_packed, sizeof(ref))) {
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001202 pandecode_msg("XXX: non-canonical workgroups packing\n");
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001203 DUMP_UNPACKED(INVOCATION, invocation, "Invocation:\n")
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001204 }
1205
1206 /* Regardless, print the decode */
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001207 pandecode_log("Invocation (%d, %d, %d) x (%d, %d, %d)\n",
1208 size_x, size_y, size_z,
1209 groups_x, groups_y, groups_z);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001210
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001211 struct mali_primitive_packed prim_packed = p->primitive;
Boris Brezillon706974c2020-09-15 09:25:18 +02001212 pan_unpack(&prim_packed, PRIMITIVE, primitive);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001213 DUMP_UNPACKED(PRIMITIVE, primitive, "Primitive:\n");
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001214
1215 /* Validate an index buffer is present if we need one. TODO: verify
1216 * relationship between invocation_count and index_count */
1217
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001218 if (primitive.indices) {
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001219 /* Grab the size */
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001220 unsigned size = (primitive.index_type == MALI_INDEX_TYPE_UINT32) ?
1221 sizeof(uint32_t) : primitive.index_type;
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001222
1223 /* Ensure we got a size, and if so, validate the index buffer
1224 * is large enough to hold a full set of indices of the given
1225 * size */
1226
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001227 if (!size)
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001228 pandecode_msg("XXX: index size missing\n");
1229 else
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001230 pandecode_validate_buffer(primitive.indices, primitive.index_count * size);
1231 } else if (primitive.index_type)
1232 pandecode_msg("XXX: unexpected index size\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001233}
1234
1235static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001236pandecode_uniform_buffers(mali_ptr pubufs, int ubufs_count, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001237{
1238 struct pandecode_mapped_memory *umem = pandecode_find_mapped_gpu_mem_containing(pubufs);
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001239 uint64_t *PANDECODE_PTR_VAR(ubufs, umem, pubufs);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001240
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001241 for (int i = 0; i < ubufs_count; i++) {
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001242 unsigned size = (ubufs[i] & ((1 << 10) - 1)) * 16;
1243 mali_ptr addr = (ubufs[i] >> 10) << 2;
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001244
1245 pandecode_validate_buffer(addr, size);
1246
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001247 char *ptr = pointer_as_memory_reference(addr);
Alyssa Rosenzweig6ec33b42019-08-21 11:46:06 -07001248 pandecode_log("ubuf_%d[%u] = %s;\n", i, size, ptr);
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001249 free(ptr);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001250 }
1251
Alyssa Rosenzweig6ec33b42019-08-21 11:46:06 -07001252 pandecode_log("\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001253}
1254
1255static void
Alyssa Rosenzweigae84f162019-08-22 11:30:13 -07001256pandecode_uniforms(mali_ptr uniforms, unsigned uniform_count)
1257{
1258 pandecode_validate_buffer(uniforms, uniform_count * 16);
1259
1260 char *ptr = pointer_as_memory_reference(uniforms);
1261 pandecode_log("vec4 uniforms[%u] = %s;\n", uniform_count, ptr);
1262 free(ptr);
1263}
1264
Alyssa Rosenzweig09671c82019-12-23 11:40:40 -05001265static const char *
1266shader_type_for_job(unsigned type)
1267{
1268 switch (type) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001269 case MALI_JOB_TYPE_VERTEX: return "VERTEX";
1270 case MALI_JOB_TYPE_TILER: return "FRAGMENT";
1271 case MALI_JOB_TYPE_COMPUTE: return "COMPUTE";
Alyssa Rosenzweig80049062020-08-26 16:52:53 -04001272 default: return "UNKNOWN";
Alyssa Rosenzweig09671c82019-12-23 11:40:40 -05001273 }
1274}
1275
Alyssa Rosenzweigc4a4f3d2019-08-14 09:19:54 -07001276static unsigned shader_id = 0;
1277
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001278static struct midgard_disasm_stats
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001279pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001280 bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001281{
1282 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(shader_ptr);
1283 uint8_t *PANDECODE_PTR_VAR(code, mem, shader_ptr);
1284
1285 /* Compute maximum possible size */
1286 size_t sz = mem->length - (shader_ptr - mem->gpu_va);
1287
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001288 /* Print some boilerplate to clearly denote the assembly (which doesn't
1289 * obey indentation rules), and actually do the disassembly! */
1290
Icecream95be22c072020-01-23 10:14:35 +13001291 pandecode_log_cont("\n\n");
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001292
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001293 struct midgard_disasm_stats stats;
Alyssa Rosenzweigc4a4f3d2019-08-14 09:19:54 -07001294
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001295 if (is_bifrost) {
Alyssa Rosenzweigc88f8162020-03-27 22:34:15 -04001296 disassemble_bifrost(pandecode_dump_stream, code, sz, true);
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001297
1298 /* TODO: Extend stats to Bifrost */
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001299 stats.texture_count = -128;
1300 stats.sampler_count = -128;
1301 stats.attribute_count = -128;
1302 stats.varying_count = -128;
1303 stats.uniform_count = -128;
1304 stats.uniform_buffer_count = -128;
1305 stats.work_count = -128;
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001306
1307 stats.instruction_count = 0;
1308 stats.bundle_count = 0;
1309 stats.quadword_count = 0;
Alyssa Rosenzweigd6d6d632019-08-30 17:00:09 -07001310 stats.helper_invocations = false;
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001311 } else {
Icecream95be22c072020-01-23 10:14:35 +13001312 stats = disassemble_midgard(pandecode_dump_stream,
1313 code, sz, gpu_id,
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001314 type == MALI_JOB_TYPE_TILER ?
Alyssa Rosenzweigac14fac2019-11-07 09:31:02 -05001315 MESA_SHADER_FRAGMENT : MESA_SHADER_VERTEX);
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001316 }
1317
Alyssa Rosenzweigc088a3b2020-08-26 16:52:23 -04001318 unsigned nr_threads =
1319 (stats.work_count <= 4) ? 4 :
1320 (stats.work_count <= 8) ? 2 :
1321 1;
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001322
Alyssa Rosenzweigc088a3b2020-08-26 16:52:23 -04001323 pandecode_log_cont("shader%d - MESA_SHADER_%s shader: "
1324 "%u inst, %u bundles, %u quadwords, "
1325 "%u registers, %u threads, 0 loops, 0:0 spills:fills\n\n\n",
1326 shader_id++,
1327 shader_type_for_job(type),
1328 stats.instruction_count, stats.bundle_count, stats.quadword_count,
1329 stats.work_count, nr_threads);
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001330
1331 return stats;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001332}
1333
1334static void
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001335pandecode_texture_payload(mali_ptr payload,
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001336 enum mali_texture_dimension dim,
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001337 enum mali_texture_layout layout,
1338 bool manual_stride,
1339 uint8_t levels,
1340 uint16_t depth,
1341 uint16_t array_size,
1342 struct pandecode_mapped_memory *tmem)
1343{
1344 pandecode_log(".payload = {\n");
1345 pandecode_indent++;
1346
1347 /* A bunch of bitmap pointers follow.
1348 * We work out the correct number,
1349 * based on the mipmap/cubemap
1350 * properties, but dump extra
1351 * possibilities to futureproof */
1352
1353 int bitmap_count = levels + 1;
1354
1355 /* Miptree for each face */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001356 if (dim == MALI_TEXTURE_DIMENSION_CUBE)
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001357 bitmap_count *= 6;
Alyssa Rosenzweigeba9bcd2020-06-30 16:21:30 -04001358
1359 /* Array of layers */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001360 bitmap_count *= depth;
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001361
1362 /* Array of textures */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001363 bitmap_count *= array_size;
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001364
1365 /* Stride for each element */
1366 if (manual_stride)
1367 bitmap_count *= 2;
1368
1369 mali_ptr *pointers_and_strides = pandecode_fetch_gpu_mem(tmem,
1370 payload, sizeof(mali_ptr) * bitmap_count);
1371 for (int i = 0; i < bitmap_count; ++i) {
1372 /* How we dump depends if this is a stride or a pointer */
1373
1374 if (manual_stride && (i & 1)) {
1375 /* signed 32-bit snuck in as a 64-bit pointer */
1376 uint64_t stride_set = pointers_and_strides[i];
1377 uint32_t clamped_stride = stride_set;
1378 int32_t stride = clamped_stride;
1379 assert(stride_set == clamped_stride);
1380 pandecode_log("(mali_ptr) %d /* stride */, \n", stride);
1381 } else {
1382 char *a = pointer_as_memory_reference(pointers_and_strides[i]);
1383 pandecode_log("%s, \n", a);
1384 free(a);
1385 }
1386 }
1387
1388 pandecode_indent--;
1389 pandecode_log("},\n");
1390}
1391
1392static void
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001393pandecode_texture(mali_ptr u,
1394 struct pandecode_mapped_memory *tmem,
1395 unsigned job_no, unsigned tex)
1396{
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001397 struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(u);
1398 const uint8_t *cl = pandecode_fetch_gpu_mem(mapped_mem, u, MALI_MIDGARD_TEXTURE_LENGTH);
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001399
Boris Brezillon706974c2020-09-15 09:25:18 +02001400 pan_unpack(cl, MIDGARD_TEXTURE, temp);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001401 DUMP_UNPACKED(MIDGARD_TEXTURE, temp, "Texture:\n")
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001402
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001403 pandecode_indent++;
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001404 pandecode_texture_payload(u + MALI_MIDGARD_TEXTURE_LENGTH,
1405 temp.dimension, temp.texel_ordering, temp.manual_stride,
1406 temp.levels, temp.depth, temp.array_size, mapped_mem);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001407 pandecode_indent--;
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001408}
1409
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001410static void
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001411pandecode_bifrost_texture(
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001412 const void *cl,
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001413 unsigned job_no,
1414 unsigned tex)
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001415{
Boris Brezillon706974c2020-09-15 09:25:18 +02001416 pan_unpack(cl, BIFROST_TEXTURE, temp);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001417 DUMP_UNPACKED(BIFROST_TEXTURE, temp, "Texture:\n")
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001418
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001419 struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(temp.surfaces);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001420 pandecode_indent++;
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001421 pandecode_texture_payload(temp.surfaces, temp.dimension, temp.texel_ordering,
1422 true, temp.levels, 1, 1, tmem);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001423 pandecode_indent--;
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001424}
1425
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001426/* 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 */
1427
1428static void
1429pandecode_shader_prop(const char *name, unsigned claim, signed truth, bool fuzzy)
1430{
1431 /* Nothing to do */
1432 if (claim == truth)
1433 return;
1434
Alyssa Rosenzweig5815f332020-02-25 17:29:55 -05001435 if (fuzzy && (truth < 0))
1436 pandecode_msg("XXX: fuzzy %s, claimed %d, expected %d\n", name, claim, truth);
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001437
1438 if ((truth >= 0) && !fuzzy) {
Alyssa Rosenzweigf48136e2019-08-22 09:02:48 -07001439 pandecode_msg("%s: expected %s = %d, claimed %u\n",
1440 (truth < claim) ? "warn" : "XXX",
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001441 name, truth, claim);
1442 } else if ((claim > -truth) && !fuzzy) {
1443 pandecode_msg("XXX: expected %s <= %u, claimed %u\n",
1444 name, -truth, claim);
1445 } else if (fuzzy && (claim < truth))
1446 pandecode_msg("XXX: expected %s >= %u, claimed %u\n",
1447 name, truth, claim);
1448
1449 pandecode_log(".%s = %" PRId16, name, claim);
1450
1451 if (fuzzy)
1452 pandecode_log_cont(" /* %u used */", truth);
1453
1454 pandecode_log_cont(",\n");
1455}
1456
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001457static void
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001458pandecode_blend_shader_disassemble(mali_ptr shader, int job_no, int job_type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001459 bool is_bifrost, unsigned gpu_id)
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001460{
1461 struct midgard_disasm_stats stats =
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001462 pandecode_shader_disassemble(shader, job_no, job_type, is_bifrost, gpu_id);
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001463
1464 bool has_texture = (stats.texture_count > 0);
1465 bool has_sampler = (stats.sampler_count > 0);
1466 bool has_attribute = (stats.attribute_count > 0);
1467 bool has_varying = (stats.varying_count > 0);
1468 bool has_uniform = (stats.uniform_count > 0);
1469 bool has_ubo = (stats.uniform_buffer_count > 0);
1470
1471 if (has_texture || has_sampler)
1472 pandecode_msg("XXX: blend shader accessing textures\n");
1473
1474 if (has_attribute || has_varying)
1475 pandecode_msg("XXX: blend shader accessing interstage\n");
1476
1477 if (has_uniform || has_ubo)
1478 pandecode_msg("XXX: blend shader accessing uniforms\n");
1479}
1480
1481static void
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001482pandecode_textures(mali_ptr textures, unsigned texture_count, int job_no, bool is_bifrost)
1483{
1484 struct pandecode_mapped_memory *mmem = pandecode_find_mapped_gpu_mem_containing(textures);
1485
1486 if (!mmem)
1487 return;
1488
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001489 pandecode_log("Textures (%"PRIx64"):\n", textures);
1490
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001491 if (is_bifrost) {
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001492 const void *cl = pandecode_fetch_gpu_mem(mmem,
1493 textures, MALI_BIFROST_TEXTURE_LENGTH *
1494 texture_count);
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001495
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001496 for (unsigned tex = 0; tex < texture_count; ++tex) {
1497 pandecode_bifrost_texture(cl +
1498 MALI_BIFROST_TEXTURE_LENGTH * tex,
1499 job_no, tex);
1500 }
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001501 } else {
1502 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures);
1503
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001504 for (int tex = 0; tex < texture_count; ++tex) {
1505 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr));
1506 char *a = pointer_as_memory_reference(*u);
1507 pandecode_log("%s,\n", a);
1508 free(a);
1509 }
1510
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001511 /* Now, finally, descend down into the texture descriptor */
1512 for (unsigned tex = 0; tex < texture_count; ++tex) {
1513 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr));
1514 struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(*u);
1515 if (tmem)
1516 pandecode_texture(*u, tmem, job_no, tex);
1517 }
1518 }
1519}
1520
1521static void
1522pandecode_samplers(mali_ptr samplers, unsigned sampler_count, int job_no, bool is_bifrost)
1523{
Alyssa Rosenzweigb10c3c82020-08-11 18:25:03 -04001524 for (int i = 0; i < sampler_count; ++i) {
1525 if (is_bifrost) {
Boris Brezillon670e8182020-09-09 17:56:53 +02001526 DUMP_ADDR(BIFROST_SAMPLER, samplers + (MALI_BIFROST_SAMPLER_LENGTH * i), "Sampler:\n");
Alyssa Rosenzweigb10c3c82020-08-11 18:25:03 -04001527 } else {
Boris Brezillon670e8182020-09-09 17:56:53 +02001528 DUMP_ADDR(MIDGARD_SAMPLER, samplers + (MALI_MIDGARD_SAMPLER_LENGTH * i), "Sampler:\n");
Alyssa Rosenzweigb10c3c82020-08-11 18:25:03 -04001529 }
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001530 }
1531}
1532
1533static void
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001534pandecode_vertex_tiler_postfix_pre(
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001535 const struct MALI_DRAW *p,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001536 int job_no, enum mali_job_type job_type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001537 char *suffix, bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001538{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001539 struct pandecode_mapped_memory *attr_mem;
1540
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001541 struct pandecode_fbd fbd_info = {
1542 /* Default for Bifrost */
1543 .rt_count = 1
1544 };
1545
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001546 if (is_bifrost)
1547 pandecode_compute_fbd(p->shared & ~1, job_no);
1548 else if (p->shared & MALI_MFBD)
1549 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 -04001550 else if (job_type == MALI_JOB_TYPE_COMPUTE)
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001551 pandecode_compute_fbd((u64) (uintptr_t) p->shared, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001552 else
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001553 fbd_info = pandecode_sfbd((u64) (uintptr_t) p->shared, job_no, false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001554
1555 int varying_count = 0, attribute_count = 0, uniform_count = 0, uniform_buffer_count = 0;
1556 int texture_count = 0, sampler_count = 0;
1557
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001558 if (p->state) {
1559 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(p->state);
1560 uint32_t *cl = pandecode_fetch_gpu_mem(smem, p->state, MALI_STATE_LENGTH);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001561
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001562 /* Disassemble ahead-of-time to get stats. Initialize with
1563 * stats for the missing-shader case so we get validation
1564 * there, too */
1565
1566 struct midgard_disasm_stats info = {
1567 .texture_count = 0,
1568 .sampler_count = 0,
1569 .attribute_count = 0,
1570 .varying_count = 0,
1571 .work_count = 1,
1572
1573 .uniform_count = -128,
1574 .uniform_buffer_count = 0
1575 };
Alyssa Rosenzweig9b067d92019-08-21 14:28:36 -07001576
Boris Brezillon706974c2020-09-15 09:25:18 +02001577 pan_unpack(cl, STATE, state);
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001578
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001579 if (state.shader.shader & ~0xF)
1580 info = pandecode_shader_disassemble(state.shader.shader & ~0xF, job_no, job_type, is_bifrost, gpu_id);
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001581
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001582 DUMP_UNPACKED(STATE, state, "State:\n");
1583 pandecode_indent++;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001584
1585 /* Save for dumps */
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001586 attribute_count = state.shader.attribute_count;
1587 varying_count = state.shader.varying_count;
1588 texture_count = state.shader.texture_count;
1589 sampler_count = state.shader.sampler_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001590
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001591 fprintf(pandecode_dump_stream, " Properties\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001592 if (is_bifrost) {
Boris Brezillon706974c2020-09-15 09:25:18 +02001593 pan_unpack(&state.properties, BIFROST_PROPERTIES, bi_props);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001594 DUMP_UNPACKED(BIFROST_PROPERTIES, bi_props, "Properties:\n");
Alyssa Rosenzweigacf77cb2020-08-20 16:41:41 -04001595
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001596 uniform_count = state.preload.uniform_count;
Alyssa Rosenzweigacf77cb2020-08-20 16:41:41 -04001597 uniform_buffer_count = bi_props.uniform_buffer_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001598 } else {
Boris Brezillon706974c2020-09-15 09:25:18 +02001599 pan_unpack(&state.properties, MIDGARD_PROPERTIES, midg_props);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001600 DUMP_UNPACKED(MIDGARD_PROPERTIES, midg_props, "Properties:\n")
Alyssa Rosenzweig1b7d4f12020-08-20 16:25:14 -04001601
1602 uniform_count = midg_props.uniform_count;
1603 uniform_buffer_count = midg_props.uniform_buffer_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001604 }
1605
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001606 pandecode_shader_prop("texture_count", texture_count, info.texture_count, false);
1607 pandecode_shader_prop("sampler_count", sampler_count, info.sampler_count, false);
1608 pandecode_shader_prop("attribute_count", attribute_count, info.attribute_count, false);
1609 pandecode_shader_prop("varying_count", varying_count, info.varying_count, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001610
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001611 if (is_bifrost) {
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001612 uint32_t opaque = state.preload.uniform_count << 15
1613 | state.preload.untyped;
1614
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001615 switch (job_type) {
1616 case MALI_JOB_TYPE_VERTEX:
Boris Brezillon670e8182020-09-09 17:56:53 +02001617 DUMP_CL(PRELOAD_VERTEX, &opaque, "Preload:\n");
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001618 break;
1619 case MALI_JOB_TYPE_TILER:
Boris Brezillon670e8182020-09-09 17:56:53 +02001620 DUMP_CL(PRELOAD_FRAGMENT, &opaque, "Preload:\n");
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001621 break;
1622 case MALI_JOB_TYPE_COMPUTE:
Boris Brezillon670e8182020-09-09 17:56:53 +02001623 DUMP_CL(PRELOAD_COMPUTE, &opaque, "Preload:\n");
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001624 break;
1625 default:
Boris Brezillon670e8182020-09-09 17:56:53 +02001626 DUMP_CL(PRELOAD, &opaque, "Preload:\n");
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001627 break;
1628 }
1629 }
1630
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001631 if (!is_bifrost) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001632 /* TODO: Blend shaders routing/disasm */
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001633 union midgard_blend blend;
1634 memcpy(&blend, &state.sfbd_blend, sizeof(blend));
1635 mali_ptr shader = pandecode_midgard_blend(&blend, state.multisample_misc.sfbd_blend_shader);
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001636 if (shader & ~0xF)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001637 pandecode_blend_shader_disassemble(shader, job_no, job_type, false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001638 }
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001639 pandecode_indent--;
1640 pandecode_msg("\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001641
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001642 /* MRT blend fields are used whenever MFBD is used, with
1643 * per-RT descriptors */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001644
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001645 if (job_type == MALI_JOB_TYPE_TILER && (is_bifrost || p->shared & MALI_MFBD)) {
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001646 void* blend_base = ((void *) cl) + MALI_STATE_LENGTH;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001647
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001648 for (unsigned i = 0; i < fbd_info.rt_count; i++) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001649 mali_ptr shader = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001650
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001651 if (is_bifrost)
1652 shader = pandecode_bifrost_blend(blend_base, job_no, i);
1653 else
1654 shader = pandecode_midgard_blend_mrt(blend_base, job_no, i);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001655
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001656 if (shader & ~0xF)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001657 pandecode_blend_shader_disassemble(shader, job_no, job_type, false, gpu_id);
Alyssa Rosenzweig139708b2019-08-21 14:04:05 -07001658
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001659 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001660 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001661 } else
Alyssa Rosenzweig5f9a1c72019-08-21 14:16:32 -07001662 pandecode_msg("XXX: missing shader descriptor\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001663
Alyssa Rosenzweig7f487e02020-08-05 19:33:20 -04001664 if (p->viewport)
Boris Brezillon670e8182020-09-09 17:56:53 +02001665 DUMP_ADDR(VIEWPORT, p->viewport, "Viewport:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001666
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001667 unsigned max_attr_index = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001668
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001669 if (p->attributes)
1670 max_attr_index = pandecode_attribute_meta(attribute_count, p->attributes, false, suffix);
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001671
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001672 if (p->attribute_buffers) {
1673 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->attribute_buffers);
1674 pandecode_attributes(attr_mem, p->attribute_buffers, job_no, suffix, max_attr_index, false, job_type);
Alyssa Rosenzweig9e66ff32019-07-31 11:52:52 -07001675 }
1676
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001677 if (p->varyings) {
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001678 varying_count = pandecode_attribute_meta(varying_count, p->varyings, true, suffix);
1679 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001680
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001681 if (p->varying_buffers) {
1682 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->varying_buffers);
1683 pandecode_attributes(attr_mem, p->varying_buffers, job_no, suffix, varying_count, true, job_type);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001684 }
1685
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001686 if (p->uniform_buffers) {
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001687 if (uniform_buffer_count)
1688 pandecode_uniform_buffers(p->uniform_buffers, uniform_buffer_count, job_no);
1689 else
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001690 pandecode_msg("warn: UBOs specified but not referenced\n");
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001691 } else if (uniform_buffer_count)
1692 pandecode_msg("XXX: UBOs referenced but not specified\n");
1693
1694 /* We don't want to actually dump uniforms, but we do need to validate
1695 * that the counts we were given are sane */
1696
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001697 if (p->push_uniforms) {
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001698 if (uniform_count)
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001699 pandecode_uniforms(p->push_uniforms, uniform_count);
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001700 else
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001701 pandecode_msg("warn: Uniforms specified but not referenced\n");
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001702 } else if (uniform_count)
Alyssa Rosenzweigd7473e22019-08-21 14:15:05 -07001703 pandecode_msg("XXX: Uniforms referenced but not specified\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001704
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001705 if (p->textures)
1706 pandecode_textures(p->textures, texture_count, job_no, is_bifrost);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001707
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001708 if (p->samplers)
1709 pandecode_samplers(p->samplers, sampler_count, job_no, is_bifrost);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001710}
1711
1712static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001713pandecode_tiler_heap_meta(mali_ptr gpu_va, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001714{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001715 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
1716 const struct bifrost_tiler_heap_meta *PANDECODE_PTR_VAR(h, mem, gpu_va);
1717
Tomeu Vizoso46e42462020-04-08 15:58:42 +02001718 pandecode_log("struct bifrost_tiler_heap_meta tiler_heap_meta_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001719 pandecode_indent++;
1720
1721 if (h->zero) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001722 pandecode_msg("XXX: tiler heap zero tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001723 pandecode_prop("zero = 0x%x", h->zero);
1724 }
1725
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001726 pandecode_prop("heap_size = 0x%x", h->heap_size);
1727 MEMORY_PROP(h, tiler_heap_start);
1728 MEMORY_PROP(h, tiler_heap_free);
1729
1730 /* this might point to the beginning of another buffer, when it's
1731 * really the end of the tiler heap buffer, so we have to be careful
Alyssa Rosenzweig17752ba2019-07-18 12:28:56 -07001732 * here. but for zero length, we need the same pointer.
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001733 */
Alyssa Rosenzweig17752ba2019-07-18 12:28:56 -07001734
1735 if (h->tiler_heap_end == h->tiler_heap_start) {
1736 MEMORY_PROP(h, tiler_heap_start);
1737 } else {
1738 char *a = pointer_as_memory_reference(h->tiler_heap_end - 1);
1739 pandecode_prop("tiler_heap_end = %s + 1", a);
1740 free(a);
1741 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001742
Tomeu Vizoso0a0b6702020-04-09 09:39:17 +02001743 for (int i = 0; i < 10; i++) {
1744 if (h->zeros[i] != 0) {
1745 pandecode_msg("XXX: tiler heap zero %d tripped, value %x\n",
1746 i, h->zeros[i]);
1747 }
1748 }
1749
1750 if (h->unk1 != 0x1) {
1751 pandecode_msg("XXX: tiler heap unk1 tripped\n");
1752 pandecode_prop("unk1 = 0x%x", h->unk1);
1753 }
1754
1755 if (h->unk7e007e != 0x7e007e) {
1756 pandecode_msg("XXX: tiler heap unk7e007e tripped\n");
1757 pandecode_prop("unk7e007e = 0x%x", h->unk7e007e);
1758 }
1759
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001760 pandecode_indent--;
1761 pandecode_log("};\n");
1762}
1763
1764static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001765pandecode_tiler_meta(mali_ptr gpu_va, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001766{
1767 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
1768 const struct bifrost_tiler_meta *PANDECODE_PTR_VAR(t, mem, gpu_va);
1769
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001770 pandecode_tiler_heap_meta(t->tiler_heap_meta, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001771
Tomeu Vizoso46e42462020-04-08 15:58:42 +02001772 pandecode_log("struct bifrost_tiler_meta tiler_meta_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001773 pandecode_indent++;
1774
Tomeu Vizoso7104e282020-04-27 17:09:39 +02001775 pandecode_prop("tiler_heap_next_start = 0x%" PRIx32, t->tiler_heap_next_start);
1776 pandecode_prop("used_hierarchy_mask = 0x%" PRIx32, t->used_hierarchy_mask);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001777
Tomeu Vizoso0a0b6702020-04-09 09:39:17 +02001778 if (t->hierarchy_mask != 0xa &&
1779 t->hierarchy_mask != 0x14 &&
1780 t->hierarchy_mask != 0x28 &&
1781 t->hierarchy_mask != 0x50 &&
1782 t->hierarchy_mask != 0xa0)
1783 pandecode_prop("XXX: Unexpected hierarchy_mask (not 0xa, 0x14, 0x28, 0x50 or 0xa0)!");
1784
Alyssa Rosenzweig7f26bb32019-06-13 10:25:32 -07001785 pandecode_prop("hierarchy_mask = 0x%" PRIx16, t->hierarchy_mask);
Tomeu Vizoso0a0b6702020-04-09 09:39:17 +02001786
Alyssa Rosenzweig7f26bb32019-06-13 10:25:32 -07001787 pandecode_prop("flags = 0x%" PRIx16, t->flags);
1788
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001789 pandecode_prop("width = MALI_POSITIVE(%d)", t->width + 1);
1790 pandecode_prop("height = MALI_POSITIVE(%d)", t->height + 1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001791
Tomeu Vizoso7104e282020-04-27 17:09:39 +02001792 if (t->zero0) {
1793 pandecode_msg("XXX: tiler meta zero tripped\n");
1794 pandecode_prop("zero0 = 0x%" PRIx64, t->zero0);
1795 }
1796
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001797 for (int i = 0; i < 12; i++) {
1798 if (t->zeros[i] != 0) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001799 pandecode_msg("XXX: tiler heap zero %d tripped, value %" PRIx64 "\n",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001800 i, t->zeros[i]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001801 }
1802 }
1803
1804 pandecode_indent--;
1805 pandecode_log("};\n");
1806}
1807
1808static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001809pandecode_primitive_size(union midgard_primitive_size u, bool constant)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001810{
Alyssa Rosenzweig2608da12019-06-19 09:35:57 -07001811 if (u.pointer == 0x0)
1812 return;
1813
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001814 pandecode_log(".primitive_size = {\n");
1815 pandecode_indent++;
1816
Alyssa Rosenzweigb517e362019-03-15 03:21:27 +00001817 if (constant) {
1818 pandecode_prop("constant = %f", u.constant);
1819 } else {
1820 MEMORY_PROP((&u), pointer);
1821 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001822
1823 pandecode_indent--;
1824 pandecode_log("},\n");
1825}
1826
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001827static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001828pandecode_vertex_job_bfr(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001829 const struct pandecode_mapped_memory *mem,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001830 mali_ptr payload, int job_no, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001831{
1832 struct bifrost_payload_vertex *PANDECODE_PTR_VAR(v, mem, payload);
1833
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001834 struct mali_draw_packed draw_packed;
1835 memcpy(&draw_packed, &v->postfix, sizeof(draw_packed));
Boris Brezillon706974c2020-09-15 09:25:18 +02001836 pan_unpack(&draw_packed, DRAW, draw);
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001837 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", true, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001838
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001839 pandecode_vertex_tiler_prefix(&v->prefix, job_no, false);
Boris Brezillon670e8182020-09-09 17:56:53 +02001840 DUMP_CL(DRAW, &draw_packed, "Draw:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001841
1842 return sizeof(*v);
1843}
1844
1845static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001846pandecode_tiler_job_bfr(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001847 const struct pandecode_mapped_memory *mem,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001848 mali_ptr payload, int job_no, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001849{
1850 struct bifrost_payload_tiler *PANDECODE_PTR_VAR(t, mem, payload);
1851
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001852 struct mali_draw_packed draw_packed;
1853 memcpy(&draw_packed, &t->postfix, sizeof(draw_packed));
Boris Brezillon706974c2020-09-15 09:25:18 +02001854 pan_unpack(&draw_packed, DRAW, draw);
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001855 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", true, gpu_id);
Alyssa Rosenzweig4467e792020-08-26 13:21:06 -04001856 pandecode_tiler_meta(t->tiler_meta, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001857
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001858 pandecode_vertex_tiler_prefix(&t->prefix, job_no, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001859
Alyssa Rosenzweig4467e792020-08-26 13:21:06 -04001860 /* TODO: gl_PointSize on Bifrost */
1861 pandecode_primitive_size(t->primitive_size, true);
1862
1863 if (t->zero1 || t->zero2 || t->zero3 || t->zero4 || t->zero5
1864 || t->zero6) {
1865 pandecode_msg("XXX: tiler only zero tripped\n");
1866 pandecode_prop("zero1 = 0x%" PRIx64, t->zero1);
1867 pandecode_prop("zero2 = 0x%" PRIx64, t->zero2);
1868 pandecode_prop("zero3 = 0x%" PRIx64, t->zero3);
1869 pandecode_prop("zero4 = 0x%" PRIx64, t->zero4);
1870 pandecode_prop("zero5 = 0x%" PRIx64, t->zero5);
1871 pandecode_prop("zero6 = 0x%" PRIx64, t->zero6);
1872 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001873
Boris Brezillon670e8182020-09-09 17:56:53 +02001874 DUMP_CL(DRAW, &draw_packed, "Draw:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001875
1876 return sizeof(*t);
1877}
1878
1879static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001880pandecode_vertex_or_tiler_job_mdg(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 midgard_payload_vertex_tiler *PANDECODE_PTR_VAR(v, mem, payload);
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001885 bool is_graphics = (h->job_type == MALI_JOB_TYPE_VERTEX) || (h->job_type == MALI_JOB_TYPE_TILER);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001886
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001887 struct mali_draw_packed draw_packed;
1888 memcpy(&draw_packed, &v->postfix, sizeof(draw_packed));
Boris Brezillon706974c2020-09-15 09:25:18 +02001889 pan_unpack(&draw_packed, DRAW, draw);
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001890 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001891
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -04001892 pandecode_vertex_tiler_prefix(&v->prefix, job_no, is_graphics);
Boris Brezillon670e8182020-09-09 17:56:53 +02001893 DUMP_CL(DRAW, &draw_packed, "Draw:\n");
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -04001894
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001895 struct mali_primitive_packed prim_packed = v->prefix.primitive;
Boris Brezillon706974c2020-09-15 09:25:18 +02001896 pan_unpack(&prim_packed, PRIMITIVE, primitive);
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001897
1898 pandecode_primitive_size(v->primitive_size, primitive.point_size_array == 0);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001899
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001900 return sizeof(*v);
1901}
1902
1903static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001904pandecode_fragment_job(const struct pandecode_mapped_memory *mem,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001905 mali_ptr payload, int job_no,
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01001906 bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001907{
1908 const struct mali_payload_fragment *PANDECODE_PTR_VAR(s, mem, payload);
1909
Alyssa Rosenzweig89593642019-12-16 12:05:45 -05001910 bool is_mfbd = s->framebuffer & MALI_MFBD;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001911
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001912 if (!is_mfbd && is_bifrost)
1913 pandecode_msg("XXX: Bifrost fragment must use MFBD\n");
1914
1915 struct pandecode_fbd info;
1916
1917 if (is_mfbd)
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -05001918 info = pandecode_mfbd_bfr(s->framebuffer & FBD_MASK, job_no, true, false, is_bifrost);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001919 else
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01001920 info = pandecode_sfbd(s->framebuffer & FBD_MASK, job_no, true, gpu_id);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001921
1922 /* Compute the tag for the tagged pointer. This contains the type of
1923 * FBD (MFBD/SFBD), and in the case of an MFBD, information about which
1924 * additional structures follow the MFBD header (an extra payload or
1925 * not, as well as a count of render targets) */
1926
Alyssa Rosenzweig89593642019-12-16 12:05:45 -05001927 unsigned expected_tag = is_mfbd ? MALI_MFBD : 0;
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001928
1929 if (is_mfbd) {
1930 if (info.has_extra)
1931 expected_tag |= MALI_MFBD_TAG_EXTRA;
1932
1933 expected_tag |= (MALI_POSITIVE(info.rt_count) << 2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001934 }
1935
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001936 if ((s->min_tile_coord | s->max_tile_coord) & ~(MALI_X_COORD_MASK | MALI_Y_COORD_MASK)) {
1937 pandecode_msg("XXX: unexpected tile coordinate bits\n");
1938 pandecode_prop("min_tile_coord = 0x%X\n", s->min_tile_coord);
Alyssa Rosenzweig52d6b4d2020-05-11 18:54:05 -04001939 pandecode_prop("max_tile_coord = 0x%X\n", s->max_tile_coord);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001940 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001941
Alyssa Rosenzweigded9a682019-08-21 12:29:47 -07001942 /* Extract tile coordinates */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001943
Alyssa Rosenzweigded9a682019-08-21 12:29:47 -07001944 unsigned min_x = MALI_TILE_COORD_X(s->min_tile_coord) << MALI_TILE_SHIFT;
1945 unsigned min_y = MALI_TILE_COORD_Y(s->min_tile_coord) << MALI_TILE_SHIFT;
1946
1947 unsigned max_x = (MALI_TILE_COORD_X(s->max_tile_coord) + 1) << MALI_TILE_SHIFT;
1948 unsigned max_y = (MALI_TILE_COORD_Y(s->max_tile_coord) + 1) << MALI_TILE_SHIFT;
1949
1950 /* For the max, we also want the floored (rather than ceiled) version for checking */
1951
1952 unsigned max_x_f = (MALI_TILE_COORD_X(s->max_tile_coord)) << MALI_TILE_SHIFT;
1953 unsigned max_y_f = (MALI_TILE_COORD_Y(s->max_tile_coord)) << MALI_TILE_SHIFT;
1954
1955 /* Validate the coordinates are well-ordered */
1956
1957 if (min_x == max_x)
1958 pandecode_msg("XXX: empty X coordinates (%u = %u)\n", min_x, max_x);
1959 else if (min_x > max_x)
1960 pandecode_msg("XXX: misordered X coordinates (%u > %u)\n", min_x, max_x);
1961
1962 if (min_y == max_y)
1963 pandecode_msg("XXX: empty X coordinates (%u = %u)\n", min_x, max_x);
1964 else if (min_y > max_y)
1965 pandecode_msg("XXX: misordered X coordinates (%u > %u)\n", min_x, max_x);
1966
1967 /* Validate the coordinates fit inside the framebuffer. We use floor,
1968 * rather than ceil, for the max coordinates, since the tile
1969 * coordinates for something like an 800x600 framebuffer will actually
1970 * resolve to 800x608, which would otherwise trigger a Y-overflow */
1971
1972 if ((min_x > info.width) || (max_x_f > info.width))
1973 pandecode_msg("XXX: tile coordinates overflow in X direction\n");
1974
1975 if ((min_y > info.height) || (max_y_f > info.height))
1976 pandecode_msg("XXX: tile coordinates overflow in Y direction\n");
1977
1978 /* After validation, we print */
1979
1980 pandecode_log("fragment (%u, %u) ... (%u, %u)\n\n", min_x, min_y, max_x, max_y);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001981
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001982 /* The FBD is a tagged pointer */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001983
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001984 unsigned tag = (s->framebuffer & ~FBD_MASK);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001985
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001986 if (tag != expected_tag)
1987 pandecode_msg("XXX: expected FBD tag %X but got %X\n", expected_tag, tag);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001988
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001989 return sizeof(*s);
1990}
1991
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05001992/* Entrypoint to start tracing. jc_gpu_va is the GPU address for the first job
1993 * in the chain; later jobs are found by walking the chain. Bifrost is, well,
1994 * if it's bifrost or not. GPU ID is the more finegrained ID (at some point, we
1995 * might wish to combine this with the bifrost parameter) because some details
1996 * are model-specific even within a particular architecture. Minimal traces
1997 * *only* examine the job descriptors, skipping printing entirely if there is
1998 * no faults, and only descends into the payload if there are faults. This is
1999 * useful for looking for faults without the overhead of invasive traces. */
2000
Alyssa Rosenzweig59986462020-02-18 07:46:03 -05002001void
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05002002pandecode_jc(mali_ptr jc_gpu_va, bool bifrost, unsigned gpu_id, bool minimal)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002003{
Icecream9501d60d32020-07-16 16:12:13 +12002004 pandecode_dump_file_open();
2005
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002006 struct mali_job_descriptor_header *h;
Alyssa Rosenzweig59986462020-02-18 07:46:03 -05002007 unsigned job_descriptor_number = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002008
2009 do {
2010 struct pandecode_mapped_memory *mem =
2011 pandecode_find_mapped_gpu_mem_containing(jc_gpu_va);
2012
2013 void *payload;
2014
2015 h = PANDECODE_PTR(mem, jc_gpu_va, struct mali_job_descriptor_header);
2016
Alyssa Rosenzweigaac5a552020-08-21 09:31:43 -04002017 mali_ptr payload_ptr = jc_gpu_va + sizeof(*h);
Alyssa Rosenzweigd353b152020-08-21 09:36:14 -04002018 payload = pandecode_fetch_gpu_mem(mem, payload_ptr, 64);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002019
2020 int job_no = job_descriptor_number++;
2021
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05002022 /* If the job is good to go, skip it in minimal mode */
2023 if (minimal && (h->exception_status == 0x0 || h->exception_status == 0x1))
2024 continue;
2025
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02002026 pandecode_log("struct mali_job_descriptor_header job_%"PRIx64"_%d = {\n", jc_gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002027 pandecode_indent++;
2028
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002029 pandecode_prop("job_type = %s", mali_job_type_as_str(h->job_type));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002030
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002031 if (h->job_descriptor_size)
2032 pandecode_prop("job_descriptor_size = %d", h->job_descriptor_size);
2033
Alyssa Rosenzweige918dd82019-08-16 16:36:39 -07002034 if (h->exception_status && h->exception_status != 0x1)
Alyssa Rosenzweig358372b2019-08-09 16:04:24 -07002035 pandecode_prop("exception_status = %x (source ID: 0x%x access: %s exception: 0x%x)",
Tomeu Vizosofa36c192019-06-25 08:22:30 +02002036 h->exception_status,
2037 (h->exception_status >> 16) & 0xFFFF,
Alyssa Rosenzweig78445ce2020-08-11 21:19:52 -04002038 mali_exception_access_as_str((h->exception_status >> 8) & 0x3),
Tomeu Vizosofa36c192019-06-25 08:22:30 +02002039 h->exception_status & 0xFF);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002040
2041 if (h->first_incomplete_task)
2042 pandecode_prop("first_incomplete_task = %d", h->first_incomplete_task);
2043
2044 if (h->fault_pointer)
2045 pandecode_prop("fault_pointer = 0x%" PRIx64, h->fault_pointer);
2046
2047 if (h->job_barrier)
2048 pandecode_prop("job_barrier = %d", h->job_barrier);
2049
2050 pandecode_prop("job_index = %d", h->job_index);
2051
2052 if (h->unknown_flags)
2053 pandecode_prop("unknown_flags = %d", h->unknown_flags);
2054
2055 if (h->job_dependency_index_1)
2056 pandecode_prop("job_dependency_index_1 = %d", h->job_dependency_index_1);
2057
2058 if (h->job_dependency_index_2)
2059 pandecode_prop("job_dependency_index_2 = %d", h->job_dependency_index_2);
2060
2061 pandecode_indent--;
2062 pandecode_log("};\n");
2063
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002064 switch (h->job_type) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002065 case MALI_JOB_TYPE_WRITE_VALUE: {
Alyssa Rosenzweigadf716d2019-12-05 09:06:53 -05002066 struct mali_payload_write_value *s = payload;
2067 pandecode_log("struct mali_payload_write_value payload_%"PRIx64"_%d = {\n", payload_ptr, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002068 pandecode_indent++;
Alyssa Rosenzweig9eae9502019-12-04 08:59:29 -05002069 MEMORY_PROP(s, address);
2070
Alyssa Rosenzweigadf716d2019-12-05 09:06:53 -05002071 if (s->value_descriptor != MALI_WRITE_VALUE_ZERO) {
Alyssa Rosenzweig9eae9502019-12-04 08:59:29 -05002072 pandecode_msg("XXX: unknown value descriptor\n");
2073 pandecode_prop("value_descriptor = 0x%" PRIX32, s->value_descriptor);
2074 }
2075
2076 if (s->reserved) {
2077 pandecode_msg("XXX: set value tripped\n");
2078 pandecode_prop("reserved = 0x%" PRIX32, s->reserved);
2079 }
2080
2081 pandecode_prop("immediate = 0x%" PRIX64, s->immediate);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002082 pandecode_indent--;
2083 pandecode_log("};\n");
2084
2085 break;
2086 }
2087
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002088 case MALI_JOB_TYPE_TILER:
2089 case MALI_JOB_TYPE_VERTEX:
2090 case MALI_JOB_TYPE_COMPUTE:
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002091 if (bifrost) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002092 if (h->job_type == MALI_JOB_TYPE_TILER)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01002093 pandecode_tiler_job_bfr(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002094 else
Tomeu Vizoso072207b2019-11-07 08:27:53 +01002095 pandecode_vertex_job_bfr(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002096 } else
Tomeu Vizoso072207b2019-11-07 08:27:53 +01002097 pandecode_vertex_or_tiler_job_mdg(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002098
2099 break;
2100
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04002101 case MALI_JOB_TYPE_FRAGMENT:
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01002102 pandecode_fragment_job(mem, payload_ptr, job_no, bifrost, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002103 break;
2104
2105 default:
2106 break;
2107 }
Alyssa Rosenzweig65e5c192019-12-27 13:03:22 -05002108 } while ((jc_gpu_va = h->next_job));
Icecream95ef672182020-06-22 22:49:53 +12002109
2110 pandecode_map_read_write();
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002111}