blob: 544b0d1ebd41076d0e3c8323dd1b4fef1074a78f [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
Boris Brezillon95eb7d92020-09-06 11:01:09 +020070#define DUMP_SECTION(A, S, cl, ...) { \
71 pan_section_unpack(cl, A, S, temp); \
72 pandecode_log(__VA_ARGS__); \
73 pan_section_print(pandecode_dump_stream, A, S, temp, (pandecode_indent + 1) * 2); \
74}
75
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -040076#define MAP_ADDR(T, addr, cl) \
77 const uint8_t *cl = 0; \
78 { \
79 struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(addr); \
80 cl = pandecode_fetch_gpu_mem(mapped_mem, addr, MALI_ ## T ## _LENGTH); \
81 }
82
Boris Brezillon670e8182020-09-09 17:56:53 +020083#define DUMP_ADDR(T, addr, ...) {\
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -040084 MAP_ADDR(T, addr, cl) \
Boris Brezillon670e8182020-09-09 17:56:53 +020085 DUMP_CL(T, cl, __VA_ARGS__); \
Alyssa Rosenzweigd2ddd4d2020-08-05 19:43:58 -040086}
87
Icecream95be22c072020-01-23 10:14:35 +130088FILE *pandecode_dump_stream;
89
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000090/* Semantic logging type.
91 *
92 * Raw: for raw messages to be printed as is.
93 * Message: for helpful information to be commented out in replays.
94 * Property: for properties of a struct
95 *
96 * Use one of pandecode_log, pandecode_msg, or pandecode_prop as syntax sugar.
97 */
98
99enum pandecode_log_type {
100 PANDECODE_RAW,
101 PANDECODE_MESSAGE,
102 PANDECODE_PROPERTY
103};
104
105#define pandecode_log(...) pandecode_log_typed(PANDECODE_RAW, __VA_ARGS__)
106#define pandecode_msg(...) pandecode_log_typed(PANDECODE_MESSAGE, __VA_ARGS__)
107#define pandecode_prop(...) pandecode_log_typed(PANDECODE_PROPERTY, __VA_ARGS__)
108
109unsigned pandecode_indent = 0;
110
111static void
112pandecode_make_indent(void)
113{
114 for (unsigned i = 0; i < pandecode_indent; ++i)
Boris Brezillon6249ae72020-09-09 17:52:23 +0200115 fprintf(pandecode_dump_stream, " ");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000116}
117
118static void
119pandecode_log_typed(enum pandecode_log_type type, const char *format, ...)
120{
121 va_list ap;
122
123 pandecode_make_indent();
124
125 if (type == PANDECODE_MESSAGE)
Icecream95be22c072020-01-23 10:14:35 +1300126 fprintf(pandecode_dump_stream, "// ");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000127 else if (type == PANDECODE_PROPERTY)
Icecream95be22c072020-01-23 10:14:35 +1300128 fprintf(pandecode_dump_stream, ".");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000129
130 va_start(ap, format);
Icecream95be22c072020-01-23 10:14:35 +1300131 vfprintf(pandecode_dump_stream, format, ap);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000132 va_end(ap);
133
134 if (type == PANDECODE_PROPERTY)
Icecream95be22c072020-01-23 10:14:35 +1300135 fprintf(pandecode_dump_stream, ",\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000136}
137
138static void
139pandecode_log_cont(const char *format, ...)
140{
141 va_list ap;
142
143 va_start(ap, format);
Icecream95be22c072020-01-23 10:14:35 +1300144 vfprintf(pandecode_dump_stream, format, ap);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000145 va_end(ap);
146}
147
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700148/* To check for memory safety issues, validates that the given pointer in GPU
149 * memory is valid, containing at least sz bytes. The goal is to eliminate
150 * GPU-side memory bugs (NULL pointer dereferences, buffer overflows, or buffer
151 * overruns) by statically validating pointers.
152 */
153
154static void
155pandecode_validate_buffer(mali_ptr addr, size_t sz)
156{
157 if (!addr) {
158 pandecode_msg("XXX: null pointer deref");
159 return;
160 }
161
162 /* Find a BO */
163
164 struct pandecode_mapped_memory *bo =
165 pandecode_find_mapped_gpu_mem_containing(addr);
166
167 if (!bo) {
168 pandecode_msg("XXX: invalid memory dereference\n");
169 return;
170 }
171
172 /* Bounds check */
173
174 unsigned offset = addr - bo->gpu_va;
175 unsigned total = offset + sz;
176
177 if (total > bo->length) {
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -0700178 pandecode_msg("XXX: buffer overrun. "
Alyssa Rosenzweigbcfcb7e2019-08-30 17:02:43 -0700179 "Chunk of size %zu at offset %d in buffer of size %zu. "
180 "Overrun by %zu bytes. \n",
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700181 sz, offset, bo->length, total - bo->length);
182 return;
183 }
184}
185
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000186struct pandecode_flag_info {
187 u64 flag;
188 const char *name;
189};
190
191static void
192pandecode_log_decoded_flags(const struct pandecode_flag_info *flag_info,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700193 u64 flags)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000194{
195 bool decodable_flags_found = false;
196
197 for (int i = 0; flag_info[i].name; i++) {
198 if ((flags & flag_info[i].flag) != flag_info[i].flag)
199 continue;
200
201 if (!decodable_flags_found) {
202 decodable_flags_found = true;
203 } else {
204 pandecode_log_cont(" | ");
205 }
206
207 pandecode_log_cont("%s", flag_info[i].name);
208
209 flags &= ~flag_info[i].flag;
210 }
211
212 if (decodable_flags_found) {
213 if (flags)
214 pandecode_log_cont(" | 0x%" PRIx64, flags);
215 } else {
216 pandecode_log_cont("0x%" PRIx64, flags);
217 }
218}
219
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000220#define FLAG_INFO(flag) { MALI_MFBD_FORMAT_##flag, "MALI_MFBD_FORMAT_" #flag }
221static const struct pandecode_flag_info mfbd_fmt_flag_info[] = {
Alyssa Rosenzweig31a4ef82019-06-17 16:01:24 -0700222 FLAG_INFO(SRGB),
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000223 {}
224};
225#undef FLAG_INFO
226
Icecream959ac106d2020-06-02 14:13:03 +1200227#define FLAG_INFO(flag) { MALI_AFBC_##flag, "MALI_AFBC_" #flag }
228static const struct pandecode_flag_info afbc_fmt_flag_info[] = {
229 FLAG_INFO(YTR),
230 {}
231};
232#undef FLAG_INFO
233
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000234#define FLAG_INFO(flag) { MALI_EXTRA_##flag, "MALI_EXTRA_" #flag }
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500235static const struct pandecode_flag_info mfbd_extra_flag_hi_info[] = {
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000236 FLAG_INFO(PRESENT),
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500237 {}
238};
239#undef FLAG_INFO
240
241#define FLAG_INFO(flag) { MALI_EXTRA_##flag, "MALI_EXTRA_" #flag }
242static const struct pandecode_flag_info mfbd_extra_flag_lo_info[] = {
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000243 FLAG_INFO(ZS),
244 {}
245};
246#undef FLAG_INFO
247
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700248#define FLAG_INFO(flag) { MALI_MFBD_##flag, "MALI_MFBD_" #flag }
249static const struct pandecode_flag_info mfbd_flag_info [] = {
250 FLAG_INFO(DEPTH_WRITE),
251 FLAG_INFO(EXTRA),
252 {}
253};
254#undef FLAG_INFO
255
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700256/* Midgard's tiler descriptor is embedded within the
257 * larger FBD */
258
259static void
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700260pandecode_midgard_tiler_descriptor(
Boris Brezillone8556982020-09-05 18:16:37 +0200261 const struct mali_midgard_tiler_packed *tp,
262 const struct mali_midgard_tiler_weights_packed *wp,
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700263 unsigned width,
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700264 unsigned height,
Alyssa Rosenzweig9fb09042019-11-27 08:31:16 -0500265 bool is_fragment,
266 bool has_hierarchy)
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700267{
Boris Brezillone8556982020-09-05 18:16:37 +0200268 pan_unpack(tp, MIDGARD_TILER, t);
269 DUMP_UNPACKED(MIDGARD_TILER, t, "Tiler:\n");
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700270
Boris Brezillone8556982020-09-05 18:16:37 +0200271 MEMORY_PROP_DIR(t, polygon_list);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700272
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700273 /* The body is offset from the base of the polygon list */
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -0400274 //assert(t->polygon_list_body > t->polygon_list);
Boris Brezillone8556982020-09-05 18:16:37 +0200275 unsigned body_offset = t.polygon_list_body - t.polygon_list;
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700276
277 /* It needs to fit inside the reported size */
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -0400278 //assert(t->polygon_list_size >= body_offset);
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700279
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700280 /* Now that we've sanity checked, we'll try to calculate the sizes
281 * ourselves for comparison */
282
Boris Brezillone8556982020-09-05 18:16:37 +0200283 unsigned ref_header = panfrost_tiler_header_size(width, height, t.hierarchy_mask, has_hierarchy);
284 unsigned ref_size = panfrost_tiler_full_size(width, height, t.hierarchy_mask, has_hierarchy);
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700285
Boris Brezillone8556982020-09-05 18:16:37 +0200286 if (!((ref_header == body_offset) && (ref_size == t.polygon_list_size))) {
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700287 pandecode_msg("XXX: bad polygon list size (expected %d / 0x%x)\n",
288 ref_header, ref_size);
Boris Brezillone8556982020-09-05 18:16:37 +0200289 pandecode_prop("polygon_list_size = 0x%x", t.polygon_list_size);
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700290 pandecode_msg("body offset %d\n", body_offset);
291 }
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700292
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700293 /* The tiler heap has a start and end specified -- it should be
294 * identical to what we have in the BO. The exception is if tiling is
295 * disabled. */
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700296
Boris Brezillone8556982020-09-05 18:16:37 +0200297 MEMORY_PROP_DIR(t, heap_start);
298 assert(t.heap_end >= t.heap_start);
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700299
Boris Brezillone8556982020-09-05 18:16:37 +0200300 unsigned heap_size = t.heap_end - t.heap_start;
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700301
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700302 /* Tiling is enabled with a special flag */
Boris Brezillone8556982020-09-05 18:16:37 +0200303 unsigned hierarchy_mask = t.hierarchy_mask & MALI_MIDGARD_TILER_HIERARCHY_MASK;
304 unsigned tiler_flags = t.hierarchy_mask ^ hierarchy_mask;
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700305
306 bool tiling_enabled = hierarchy_mask;
307
308 if (tiling_enabled) {
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700309 /* We should also have no other flags */
310 if (tiler_flags)
311 pandecode_msg("XXX: unexpected tiler %X\n", tiler_flags);
312 } else {
313 /* When tiling is disabled, we should have that flag and no others */
314
Boris Brezillone8556982020-09-05 18:16:37 +0200315 if (tiler_flags != MALI_MIDGARD_TILER_DISABLED) {
316 pandecode_msg("XXX: unexpected tiler flag %X, expected MALI_MIDGARD_TILER_DISABLED\n",
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700317 tiler_flags);
318 }
319
320 /* We should also have an empty heap */
321 if (heap_size) {
322 pandecode_msg("XXX: tiler heap size %d given, expected empty\n",
323 heap_size);
324 }
325
326 /* Disabled tiling is used only for clear-only jobs, which are
327 * purely FRAGMENT, so we should never see this for
328 * non-FRAGMENT descriptors. */
329
330 if (!is_fragment)
331 pandecode_msg("XXX: tiler disabled for non-FRAGMENT job\n");
332 }
333
334 /* We've never seen weights used in practice, but we know from the
335 * kernel these fields is there */
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700336
Boris Brezillone8556982020-09-05 18:16:37 +0200337 pan_unpack(wp, MIDGARD_TILER_WEIGHTS, w);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700338 bool nonzero_weights = false;
339
Boris Brezillone8556982020-09-05 18:16:37 +0200340 nonzero_weights |= w.weight0 != 0x0;
341 nonzero_weights |= w.weight1 != 0x0;
342 nonzero_weights |= w.weight2 != 0x0;
343 nonzero_weights |= w.weight3 != 0x0;
344 nonzero_weights |= w.weight4 != 0x0;
345 nonzero_weights |= w.weight5 != 0x0;
346 nonzero_weights |= w.weight6 != 0x0;
347 nonzero_weights |= w.weight7 != 0x0;
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700348
Boris Brezillone8556982020-09-05 18:16:37 +0200349 if (nonzero_weights)
350 DUMP_UNPACKED(MIDGARD_TILER_WEIGHTS, w, "Tiler Weights:\n");
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700351}
352
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500353/* TODO: The Bifrost tiler is not understood at all yet */
354
355static void
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200356pandecode_bifrost_tiler_descriptor(const struct mali_framebuffer *fb)
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500357{
358 pandecode_log(".tiler = {\n");
359 pandecode_indent++;
360
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200361 MEMORY_PROP(fb, tiler_meta);
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500362
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200363 for (int i = 0; i < 16; i++) {
364 if (fb->zeros[i] != 0) {
365 pandecode_msg("XXX: tiler descriptor zero %d tripped, value %x\n",
366 i, fb->zeros[i]);
367 }
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500368 }
369
370 pandecode_log("},\n");
371
372 pandecode_indent--;
373 pandecode_log("}\n");
374
375}
376
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700377/* Information about the framebuffer passed back for
378 * additional analysis */
379
380struct pandecode_fbd {
381 unsigned width;
382 unsigned height;
383 unsigned rt_count;
384 bool has_extra;
385};
386
387static struct pandecode_fbd
Tomeu Vizoso697f02c2019-11-12 12:15:02 +0100388pandecode_sfbd(uint64_t gpu_va, int job_no, bool is_fragment, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000389{
390 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Boris Brezillon95eb7d92020-09-06 11:01:09 +0200391 const void *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000392
Alyssa Rosenzweigd6d6d632019-08-30 17:00:09 -0700393 struct pandecode_fbd info = {
394 .has_extra = false,
395 .rt_count = 1
396 };
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700397
Boris Brezillon95eb7d92020-09-06 11:01:09 +0200398 pandecode_log("Single-Target Framebuffer:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000399 pandecode_indent++;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000400
Boris Brezillon95eb7d92020-09-06 11:01:09 +0200401 DUMP_SECTION(SINGLE_TARGET_FRAMEBUFFER, LOCAL_STORAGE, s, "Local Storage:\n");
402 pan_section_unpack(s, SINGLE_TARGET_FRAMEBUFFER, PARAMETERS, p);
403 DUMP_UNPACKED(SINGLE_TARGET_FRAMEBUFFER_PARAMETERS, p, "Parameters:\n");
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700404
Boris Brezillon95eb7d92020-09-06 11:01:09 +0200405 const void *t = pan_section_ptr(s, SINGLE_TARGET_FRAMEBUFFER, TILER);
406 const void *w = pan_section_ptr(s, SINGLE_TARGET_FRAMEBUFFER, TILER_WEIGHTS);
Alyssa Rosenzweig9fb09042019-11-27 08:31:16 -0500407
408 bool has_hierarchy = !(gpu_id == 0x0720 || gpu_id == 0x0820 || gpu_id == 0x0830);
Boris Brezillon95eb7d92020-09-06 11:01:09 +0200409 pandecode_midgard_tiler_descriptor(t, w, p.bound_max_x + 1, p.bound_max_y + 1, is_fragment, has_hierarchy);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000410
411 pandecode_indent--;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000412
Boris Brezillon95eb7d92020-09-06 11:01:09 +0200413 /* Dummy unpack of the padding section to make sure all words are 0.
414 * No need to call print here since the section is supposed to be empty.
415 */
416 pan_section_unpack(s, SINGLE_TARGET_FRAMEBUFFER, PADDING_1, padding1);
417 pan_section_unpack(s, SINGLE_TARGET_FRAMEBUFFER, PADDING_2, padding2);
418 pandecode_log("\n");
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700419
420 return info;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000421}
422
423static void
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700424pandecode_compute_fbd(uint64_t gpu_va, int job_no)
425{
426 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Boris Brezillon3a06fc32020-09-03 09:18:09 +0200427 const struct mali_local_storage_packed *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
428 DUMP_CL(LOCAL_STORAGE, s, "Local Storage:\n");
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700429}
430
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700431/* Extracts the number of components associated with a Mali format */
432
433static unsigned
434pandecode_format_component_count(enum mali_format fmt)
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000435{
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700436 /* Mask out the format class */
437 unsigned top = fmt & 0b11100000;
438
439 switch (top) {
440 case MALI_FORMAT_SNORM:
441 case MALI_FORMAT_UINT:
442 case MALI_FORMAT_UNORM:
443 case MALI_FORMAT_SINT:
444 return ((fmt >> 3) & 3) + 1;
445 default:
446 /* TODO: Validate */
447 return 4;
448 }
449}
450
451/* Extracts a mask of accessed components from a 12-bit Mali swizzle */
452
453static unsigned
454pandecode_access_mask_from_channel_swizzle(unsigned swizzle)
455{
456 unsigned mask = 0;
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400457 assert(MALI_CHANNEL_R == 0);
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700458
459 for (unsigned c = 0; c < 4; ++c) {
460 enum mali_channel chan = (swizzle >> (3*c)) & 0x7;
461
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400462 if (chan <= MALI_CHANNEL_A)
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700463 mask |= (1 << chan);
464 }
465
466 return mask;
467}
468
469/* Validates that a (format, swizzle) pair is valid, in the sense that the
470 * swizzle doesn't access any components that are undefined in the format.
471 * Returns whether the swizzle is trivial (doesn't do any swizzling) and can be
472 * omitted */
473
474static bool
475pandecode_validate_format_swizzle(enum mali_format fmt, unsigned swizzle)
476{
477 unsigned nr_comp = pandecode_format_component_count(fmt);
478 unsigned access_mask = pandecode_access_mask_from_channel_swizzle(swizzle);
479 unsigned valid_mask = (1 << nr_comp) - 1;
480 unsigned invalid_mask = ~valid_mask;
481
482 if (access_mask & invalid_mask) {
483 pandecode_msg("XXX: invalid components accessed\n");
484 return false;
485 }
486
487 /* Check for the default non-swizzling swizzle so we can suppress
488 * useless printing for the defaults */
489
490 unsigned default_swizzles[4] = {
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400491 MALI_CHANNEL_R | (MALI_CHANNEL_0 << 3) | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9),
492 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9),
493 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_1 << 9),
494 MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_A << 9)
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700495 };
496
497 return (swizzle == default_swizzles[nr_comp - 1]);
498}
499
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700500static void
501pandecode_swizzle(unsigned swizzle, enum mali_format format)
502{
503 /* First, do some validation */
504 bool trivial_swizzle = pandecode_validate_format_swizzle(
505 format, swizzle);
506
507 if (trivial_swizzle)
508 return;
509
510 /* Next, print the swizzle */
511 pandecode_log_cont(".");
512
513 static const char components[] = "rgba01";
514
515 for (unsigned c = 0; c < 4; ++c) {
516 enum mali_channel chan = (swizzle >> (3 * c)) & 0x7;
517
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400518 if (chan > MALI_CHANNEL_1) {
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700519 pandecode_log("XXX: invalid swizzle channel %d\n", chan);
520 continue;
521 }
522 pandecode_log_cont("%c", components[chan]);
523 }
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000524}
525
526static void
527pandecode_rt_format(struct mali_rt_format format)
528{
529 pandecode_log(".format = {\n");
530 pandecode_indent++;
531
532 pandecode_prop("unk1 = 0x%" PRIx32, format.unk1);
533 pandecode_prop("unk2 = 0x%" PRIx32, format.unk2);
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700534 pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
Tomeu Vizoso28902ba2020-04-24 11:30:03 +0200535 pandecode_prop("unk4 = 0x%" PRIx32, format.unk4);
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700536
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400537 pandecode_prop("block = %s", mali_block_format_as_str(format.block));
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000538
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700539 /* TODO: Map formats so we can check swizzles and print nicely */
540 pandecode_log("swizzle");
541 pandecode_swizzle(format.swizzle, MALI_RGBA8_UNORM);
542 pandecode_log_cont(",\n");
543
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000544 pandecode_prop("nr_channels = MALI_POSITIVE(%d)",
Alyssa Rosenzweig4ccd42e2019-12-27 12:16:09 -0500545 (format.nr_channels + 1));
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000546
547 pandecode_log(".flags = ");
548 pandecode_log_decoded_flags(mfbd_fmt_flag_info, format.flags);
549 pandecode_log_cont(",\n");
550
Alyssa Rosenzweig99d17fb2020-08-11 21:04:01 -0400551 pandecode_prop("msaa = %s", mali_msaa_as_str(format.msaa));
Alyssa Rosenzweig2c479932020-07-21 18:51:07 -0400552
Alyssa Rosenzweige49204c2019-08-20 11:11:46 -0700553 /* In theory, the no_preload bit can be cleared to enable MFBD preload,
554 * which is a faster hardware-based alternative to the wallpaper method
555 * to preserve framebuffer contents across frames. In practice, MFBD
556 * preload is buggy on Midgard, and so this is a chicken bit. If this
557 * bit isn't set, most likely something broke unrelated to preload */
558
559 if (!format.no_preload) {
560 pandecode_msg("XXX: buggy MFBD preload enabled - chicken bit should be clear\n");
561 pandecode_prop("no_preload = 0x%" PRIx32, format.no_preload);
562 }
Alyssa Rosenzweigb78e04c2019-08-14 16:01:38 -0700563
564 if (format.zero)
565 pandecode_prop("zero = 0x%" PRIx32, format.zero);
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000566
567 pandecode_indent--;
568 pandecode_log("},\n");
569}
570
571static void
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500572pandecode_render_target(uint64_t gpu_va, unsigned job_no, const struct mali_framebuffer *fb)
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700573{
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500574 pandecode_log("struct mali_render_target rts_list_%"PRIx64"_%d[] = {\n", gpu_va, job_no);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700575 pandecode_indent++;
576
Alyssa Rosenzweig4ccd42e2019-12-27 12:16:09 -0500577 for (int i = 0; i < (fb->rt_count_1 + 1); i++) {
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500578 mali_ptr rt_va = gpu_va + i * sizeof(struct mali_render_target);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700579 struct pandecode_mapped_memory *mem =
580 pandecode_find_mapped_gpu_mem_containing(rt_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500581 const struct mali_render_target *PANDECODE_PTR_VAR(rt, mem, (mali_ptr) rt_va);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700582
583 pandecode_log("{\n");
584 pandecode_indent++;
585
586 pandecode_rt_format(rt->format);
587
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400588 if (rt->format.block == MALI_BLOCK_FORMAT_AFBC) {
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700589 pandecode_log(".afbc = {\n");
590 pandecode_indent++;
591
592 char *a = pointer_as_memory_reference(rt->afbc.metadata);
593 pandecode_prop("metadata = %s", a);
594 free(a);
595
596 pandecode_prop("stride = %d", rt->afbc.stride);
Icecream959ac106d2020-06-02 14:13:03 +1200597
598 pandecode_log(".flags = ");
599 pandecode_log_decoded_flags(afbc_fmt_flag_info, rt->afbc.flags);
600 pandecode_log_cont(",\n");
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700601
602 pandecode_indent--;
603 pandecode_log("},\n");
Icecream959ac106d2020-06-02 14:13:03 +1200604 } else if (rt->afbc.metadata || rt->afbc.stride || rt->afbc.flags) {
Alyssa Rosenzweigc9b62332019-08-20 11:06:07 -0700605 pandecode_msg("XXX: AFBC disabled but AFBC field set (0x%lX, 0x%x, 0x%x)\n",
606 rt->afbc.metadata,
607 rt->afbc.stride,
Icecream959ac106d2020-06-02 14:13:03 +1200608 rt->afbc.flags);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700609 }
610
611 MEMORY_PROP(rt, framebuffer);
612 pandecode_prop("framebuffer_stride = %d", rt->framebuffer_stride);
613
Alyssa Rosenzweig37204582020-06-30 16:21:18 -0400614 if (rt->layer_stride)
615 pandecode_prop("layer_stride = %d", rt->layer_stride);
616
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700617 if (rt->clear_color_1 | rt->clear_color_2 | rt->clear_color_3 | rt->clear_color_4) {
618 pandecode_prop("clear_color_1 = 0x%" PRIx32, rt->clear_color_1);
619 pandecode_prop("clear_color_2 = 0x%" PRIx32, rt->clear_color_2);
620 pandecode_prop("clear_color_3 = 0x%" PRIx32, rt->clear_color_3);
621 pandecode_prop("clear_color_4 = 0x%" PRIx32, rt->clear_color_4);
622 }
623
Alyssa Rosenzweig37204582020-06-30 16:21:18 -0400624 if (rt->zero1 || rt->zero2) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700625 pandecode_msg("XXX: render target zeros tripped\n");
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700626 pandecode_prop("zero1 = 0x%" PRIx64, rt->zero1);
627 pandecode_prop("zero2 = 0x%" PRIx32, rt->zero2);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700628 }
629
630 pandecode_indent--;
631 pandecode_log("},\n");
632 }
633
634 pandecode_indent--;
635 pandecode_log("};\n");
636}
637
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700638static struct pandecode_fbd
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500639pandecode_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 +0000640{
641 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500642 const struct mali_framebuffer *PANDECODE_PTR_VAR(fb, mem, (mali_ptr) gpu_va);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000643
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700644 struct pandecode_fbd info;
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500645
646 if (is_bifrost && fb->msaa.sample_locations) {
647 /* The blob stores all possible sample locations in a single buffer
648 * allocated on startup, and just switches the pointer when switching
649 * MSAA state. For now, we just put the data into the cmdstream, but we
650 * should do something like what the blob does with a real driver.
651 *
652 * There seem to be 32 slots for sample locations, followed by another
653 * 16. The second 16 is just the center location followed by 15 zeros
654 * in all the cases I've identified (maybe shader vs. depth/color
655 * samples?).
656 */
657
658 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(fb->msaa.sample_locations);
659
660 const u16 *PANDECODE_PTR_VAR(samples, smem, fb->msaa.sample_locations);
661
662 pandecode_log("uint16_t sample_locations_%d[] = {\n", job_no);
663 pandecode_indent++;
664
665 for (int i = 0; i < 32 + 16; i++) {
666 pandecode_log("%d, %d,\n", samples[2 * i], samples[2 * i + 1]);
667 }
668
669 pandecode_indent--;
670 pandecode_log("};\n");
671 }
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700672
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500673 pandecode_log("struct mali_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000674 pandecode_indent++;
675
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500676 if (is_bifrost) {
677 pandecode_log(".msaa = {\n");
678 pandecode_indent++;
679
680 if (fb->msaa.sample_locations)
681 pandecode_prop("sample_locations = sample_locations_%d", job_no);
682 else
683 pandecode_msg("XXX: sample_locations missing\n");
684
685 if (fb->msaa.zero1 || fb->msaa.zero2 || fb->msaa.zero4) {
686 pandecode_msg("XXX: multisampling zero tripped\n");
687 pandecode_prop("zero1 = %" PRIx64, fb->msaa.zero1);
688 pandecode_prop("zero2 = %" PRIx64, fb->msaa.zero2);
689 pandecode_prop("zero4 = %" PRIx64, fb->msaa.zero4);
690 }
691
692 pandecode_indent--;
693 pandecode_log("},\n");
694 } else {
Boris Brezillon3a06fc32020-09-03 09:18:09 +0200695 struct mali_local_storage_packed ls = fb->shared_memory;
696 DUMP_CL(LOCAL_STORAGE, &ls, "Local Storage:\n");
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -0500697 }
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700698
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700699 info.width = fb->width1 + 1;
700 info.height = fb->height1 + 1;
701 info.rt_count = fb->rt_count_1 + 1;
702
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000703 pandecode_prop("width1 = MALI_POSITIVE(%d)", fb->width1 + 1);
704 pandecode_prop("height1 = MALI_POSITIVE(%d)", fb->height1 + 1);
705 pandecode_prop("width2 = MALI_POSITIVE(%d)", fb->width2 + 1);
706 pandecode_prop("height2 = MALI_POSITIVE(%d)", fb->height2 + 1);
707
708 pandecode_prop("unk1 = 0x%x", fb->unk1);
709 pandecode_prop("unk2 = 0x%x", fb->unk2);
710 pandecode_prop("rt_count_1 = MALI_POSITIVE(%d)", fb->rt_count_1 + 1);
711 pandecode_prop("rt_count_2 = %d", fb->rt_count_2);
712
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700713 pandecode_log(".mfbd_flags = ");
714 pandecode_log_decoded_flags(mfbd_flag_info, fb->mfbd_flags);
715 pandecode_log_cont(",\n");
716
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700717 if (fb->clear_stencil)
718 pandecode_prop("clear_stencil = 0x%x", fb->clear_stencil);
719
720 if (fb->clear_depth)
721 pandecode_prop("clear_depth = %f", fb->clear_depth);
722
Alyssa Rosenzweig39939692020-01-22 08:51:19 -0500723 if (!is_compute)
Alyssa Rosenzweig3044a372020-02-28 07:25:25 -0500724 if (is_bifrost)
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200725 pandecode_bifrost_tiler_descriptor(fb);
Alyssa Rosenzweigc2c8b1a2020-05-26 18:10:39 -0400726 else {
Boris Brezillone8556982020-09-05 18:16:37 +0200727 const struct mali_midgard_tiler_packed t = fb->tiler;
728 const struct mali_midgard_tiler_weights_packed w = fb->tiler_weights;
729 pandecode_midgard_tiler_descriptor(&t, &w, fb->width1 + 1, fb->height1 + 1, is_fragment, true);
Alyssa Rosenzweigc2c8b1a2020-05-26 18:10:39 -0400730 }
Alyssa Rosenzweig39939692020-01-22 08:51:19 -0500731 else
732 pandecode_msg("XXX: skipping compute MFBD, fixme\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000733
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700734 if (fb->zero3 || fb->zero4) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700735 pandecode_msg("XXX: framebuffer zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000736 pandecode_prop("zero3 = 0x%" PRIx32, fb->zero3);
737 pandecode_prop("zero4 = 0x%" PRIx32, fb->zero4);
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -0700738 }
739
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000740 pandecode_indent--;
741 pandecode_log("};\n");
742
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500743 gpu_va += sizeof(struct mali_framebuffer);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000744
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700745 info.has_extra = (fb->mfbd_flags & MALI_MFBD_EXTRA) && is_fragment;
746
747 if (info.has_extra) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000748 mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500749 const struct mali_framebuffer_extra *PANDECODE_PTR_VAR(fbx, mem, (mali_ptr) gpu_va);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000750
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500751 pandecode_log("struct mali_framebuffer_extra fb_extra_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000752 pandecode_indent++;
753
754 MEMORY_PROP(fbx, checksum);
755
756 if (fbx->checksum_stride)
757 pandecode_prop("checksum_stride = %d", fbx->checksum_stride);
758
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500759 pandecode_log(".flags_hi = ");
Alyssa Rosenzweig7e53cce2020-05-04 12:48:34 -0400760 pandecode_log_decoded_flags(mfbd_extra_flag_hi_info, fbx->flags_hi);
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000761 pandecode_log_cont(",\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000762
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500763 pandecode_log(".flags_lo = ");
764 pandecode_log_decoded_flags(mfbd_extra_flag_lo_info, fbx->flags_lo);
765 pandecode_log_cont(",\n");
766
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400767 pandecode_prop("zs_block = %s", mali_block_format_as_str(fbx->zs_block));
Alyssa Rosenzweige061bf02020-07-15 11:57:35 -0400768 pandecode_prop("zs_samples = MALI_POSITIVE(%u)", fbx->zs_samples + 1);
Alyssa Rosenzweig6bd9c4d2020-01-10 13:12:35 -0500769
Alyssa Rosenzweigc9bdba22020-08-11 21:00:47 -0400770 if (fbx->zs_block == MALI_BLOCK_FORMAT_AFBC) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000771 pandecode_log(".ds_afbc = {\n");
772 pandecode_indent++;
773
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700774 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil_afbc_metadata);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000775 pandecode_prop("depth_stencil_afbc_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700776 fbx->ds_afbc.depth_stencil_afbc_stride);
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700777 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000778
Icecream959ac106d2020-06-02 14:13:03 +1200779 pandecode_log(".flags = ");
780 pandecode_log_decoded_flags(afbc_fmt_flag_info, fbx->ds_afbc.flags);
781 pandecode_log_cont(",\n");
782
783 if (fbx->ds_afbc.padding) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700784 pandecode_msg("XXX: Depth/stencil AFBC zeros tripped\n");
Icecream959ac106d2020-06-02 14:13:03 +1200785 pandecode_prop("padding = 0x%" PRIx64, fbx->ds_afbc.padding);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000786 }
787
788 pandecode_indent--;
789 pandecode_log("},\n");
790 } else {
791 pandecode_log(".ds_linear = {\n");
792 pandecode_indent++;
793
794 if (fbx->ds_linear.depth) {
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700795 MEMORY_PROP_DIR(fbx->ds_linear, depth);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000796 pandecode_prop("depth_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700797 fbx->ds_linear.depth_stride);
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400798 pandecode_prop("depth_layer_stride = %d",
799 fbx->ds_linear.depth_layer_stride);
800 } else if (fbx->ds_linear.depth_stride || fbx->ds_linear.depth_layer_stride) {
801 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 +0000802 }
803
804 if (fbx->ds_linear.stencil) {
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -0700805 MEMORY_PROP_DIR(fbx->ds_linear, stencil);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000806 pandecode_prop("stencil_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700807 fbx->ds_linear.stencil_stride);
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400808 pandecode_prop("stencil_layer_stride = %d",
809 fbx->ds_linear.stencil_layer_stride);
810 } else if (fbx->ds_linear.stencil_stride || fbx->ds_linear.stencil_layer_stride) {
811 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 +0000812 }
813
814 if (fbx->ds_linear.depth_stride_zero ||
Alyssa Rosenzweig5e38d952020-07-03 11:27:48 -0400815 fbx->ds_linear.stencil_stride_zero) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700816 pandecode_msg("XXX: Depth/stencil zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000817 pandecode_prop("depth_stride_zero = 0x%x",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700818 fbx->ds_linear.depth_stride_zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000819 pandecode_prop("stencil_stride_zero = 0x%x",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700820 fbx->ds_linear.stencil_stride_zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000821 }
822
823 pandecode_indent--;
824 pandecode_log("},\n");
825 }
826
Alyssa Rosenzweig81a31912020-04-06 19:45:30 -0400827 if (fbx->clear_color_1 | fbx->clear_color_2) {
828 pandecode_prop("clear_color_1 = 0x%" PRIx32, fbx->clear_color_1);
829 pandecode_prop("clear_color_2 = 0x%" PRIx32, fbx->clear_color_2);
830 }
831
832 if (fbx->zero3) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700833 pandecode_msg("XXX: fb_extra zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000834 pandecode_prop("zero3 = 0x%" PRIx64, fbx->zero3);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000835 }
836
837 pandecode_indent--;
838 pandecode_log("};\n");
839
Alyssa Rosenzweig6d9ee3e2020-02-10 08:51:37 -0500840 gpu_va += sizeof(struct mali_framebuffer_extra);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000841 }
842
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700843 if (is_fragment)
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700844 pandecode_render_target(gpu_va, job_no, fb);
Alyssa Rosenzweiga9fc1c82019-06-23 11:29:46 -0700845
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700846 return info;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000847}
848
849static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -0700850pandecode_attributes(const struct pandecode_mapped_memory *mem,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700851 mali_ptr addr, int job_no, char *suffix,
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -0700852 int count, bool varying, enum mali_job_type job_type)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000853{
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -0400854 char *prefix = varying ? "Varying" : "Attribute";
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -0700855 assert(addr);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000856
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -0700857 if (!count) {
858 pandecode_msg("warn: No %s records\n", prefix);
Alyssa Rosenzweig5ad83012019-08-08 09:23:29 -0700859 return;
860 }
861
Alyssa Rosenzweig4e3fe542020-08-14 16:03:12 -0400862 MAP_ADDR(ATTRIBUTE_BUFFER, addr, cl);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000863
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000864 for (int i = 0; i < count; ++i) {
Boris Brezillon706974c2020-09-15 09:25:18 +0200865 pan_unpack(cl + i * MALI_ATTRIBUTE_BUFFER_LENGTH, ATTRIBUTE_BUFFER, temp);
Boris Brezillonaa2670c2020-09-05 18:14:17 +0200866 DUMP_UNPACKED(ATTRIBUTE_BUFFER, temp, "%s:\n", prefix);
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -0700867
Boris Brezillon706974c2020-09-15 09:25:18 +0200868 if (temp.type != MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR)
869 continue;
870
871 pan_unpack(cl + (i + 1) * MALI_ATTRIBUTE_BUFFER_LENGTH,
872 ATTRIBUTE_BUFFER_CONTINUATION_NPOT, temp2);
873 pan_print(pandecode_dump_stream, ATTRIBUTE_BUFFER_CONTINUATION_NPOT,
874 temp2, (pandecode_indent + 1) * 2);
Alyssa Rosenzweig3b3d9652019-12-19 12:28:42 -0500875 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000876}
877
878static mali_ptr
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -0700879pandecode_shader_address(const char *name, mali_ptr ptr)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000880{
881 /* TODO: Decode flags */
882 mali_ptr shader_ptr = ptr & ~15;
883
884 char *a = pointer_as_memory_reference(shader_ptr);
885 pandecode_prop("%s = (%s) | %d", name, a, (int) (ptr & 15));
886 free(a);
887
888 return shader_ptr;
889}
890
Alyssa Rosenzweigae705382019-05-18 20:48:43 +0000891/* Decodes a Bifrost blend constant. See the notes in bifrost_blend_rt */
892
893static unsigned
894decode_bifrost_constant(u16 constant)
895{
896 float lo = (float) (constant & 0xFF);
897 float hi = (float) (constant >> 8);
898
899 return (hi / 255.0) + (lo / 65535.0);
900}
901
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +0000902static mali_ptr
903pandecode_bifrost_blend(void *descs, int job_no, int rt_no)
904{
905 struct bifrost_blend_rt *b =
906 ((struct bifrost_blend_rt *) descs) + rt_no;
907
908 pandecode_log("struct bifrost_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
909 pandecode_indent++;
910
Alyssa Rosenzweigae705382019-05-18 20:48:43 +0000911 pandecode_prop("flags = 0x%" PRIx16, b->flags);
912 pandecode_prop("constant = 0x%" PRIx8 " /* %f */",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700913 b->constant, decode_bifrost_constant(b->constant));
Alyssa Rosenzweigae705382019-05-18 20:48:43 +0000914
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +0000915 /* TODO figure out blend shader enable bit */
Boris Brezillon670e8182020-09-09 17:56:53 +0200916 DUMP_CL(BLEND_EQUATION, &b->equation, "Equation:\n");
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200917
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +0000918 pandecode_prop("unk2 = 0x%" PRIx16, b->unk2);
919 pandecode_prop("index = 0x%" PRIx16, b->index);
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200920
Alyssa Rosenzweig0c621dc2020-08-11 21:30:46 -0400921 pandecode_log(".format = %s", mali_format_as_str(b->format));
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200922 pandecode_swizzle(b->swizzle, b->format);
923 pandecode_log_cont(",\n");
924
925 pandecode_prop("swizzle = 0x%" PRIx32, b->swizzle);
926 pandecode_prop("format = 0x%" PRIx32, b->format);
927
928 if (b->zero1) {
929 pandecode_msg("XXX: pandecode_bifrost_blend zero1 tripped\n");
930 pandecode_prop("zero1 = 0x%" PRIx32, b->zero1);
931 }
932
933 pandecode_log(".shader_type = ");
934 switch(b->shader_type) {
935 case BIFROST_BLEND_F16:
936 pandecode_log_cont("BIFROST_BLEND_F16");
937 break;
938 case BIFROST_BLEND_F32:
939 pandecode_log_cont("BIFROST_BLEND_F32");
940 break;
941 case BIFROST_BLEND_I32:
942 pandecode_log_cont("BIFROST_BLEND_I32");
943 break;
944 case BIFROST_BLEND_U32:
945 pandecode_log_cont("BIFROST_BLEND_U32");
946 break;
947 case BIFROST_BLEND_I16:
948 pandecode_log_cont("BIFROST_BLEND_I16");
949 break;
950 case BIFROST_BLEND_U16:
951 pandecode_log_cont("BIFROST_BLEND_U16");
952 break;
953 }
954 pandecode_log_cont(",\n");
955
956 if (b->zero2) {
957 pandecode_msg("XXX: pandecode_bifrost_blend zero2 tripped\n");
958 pandecode_prop("zero2 = 0x%" PRIx32, b->zero2);
959 }
960
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +0000961 pandecode_prop("shader = 0x%" PRIx32, b->shader);
962
963 pandecode_indent--;
964 pandecode_log("},\n");
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700965
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +0000966 return 0;
967}
968
969static mali_ptr
970pandecode_midgard_blend(union midgard_blend *blend, bool is_shader)
971{
Alyssa Rosenzweig9ce45ac2019-08-21 08:59:57 -0700972 /* constant/equation is in a union */
973 if (!blend->shader)
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -0700974 return 0;
975
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +0000976 pandecode_log(".blend = {\n");
977 pandecode_indent++;
978
979 if (is_shader) {
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -0700980 pandecode_shader_address("shader", blend->shader);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +0000981 } else {
Boris Brezillon670e8182020-09-09 17:56:53 +0200982 DUMP_CL(BLEND_EQUATION, &blend->equation, "Equation:\n");
Alyssa Rosenzweigae705382019-05-18 20:48:43 +0000983 pandecode_prop("constant = %f", blend->constant);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +0000984 }
985
986 pandecode_indent--;
987 pandecode_log("},\n");
988
989 /* Return blend shader to disassemble if present */
990 return is_shader ? (blend->shader & ~0xF) : 0;
991}
992
993static mali_ptr
994pandecode_midgard_blend_mrt(void *descs, int job_no, int rt_no)
995{
996 struct midgard_blend_rt *b =
997 ((struct midgard_blend_rt *) descs) + rt_no;
998
999 /* Flags determine presence of blend shader */
Alyssa Rosenzweig94c9f872020-08-18 17:06:01 -04001000 bool is_shader = b->flags.opaque[0] & 0x2;
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001001
1002 pandecode_log("struct midgard_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1003 pandecode_indent++;
1004
Boris Brezillon670e8182020-09-09 17:56:53 +02001005 DUMP_CL(BLEND_FLAGS, &b->flags, "Flags:\n");
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001006
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -07001007 union midgard_blend blend = b->blend;
1008 mali_ptr shader = pandecode_midgard_blend(&blend, is_shader);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001009
1010 pandecode_indent--;
1011 pandecode_log("};\n");
1012
1013 return shader;
1014}
1015
Alyssa Rosenzweig2208eb92019-08-20 13:59:26 -07001016/* Attributes and varyings have descriptor records, which contain information
1017 * about their format and ordering with the attribute/varying buffers. We'll
1018 * want to validate that the combinations specified are self-consistent.
1019 */
1020
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001021static int
Alyssa Rosenzweig68552282020-08-26 16:50:16 -04001022pandecode_attribute_meta(int count, mali_ptr attribute, bool varying, char *suffix)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001023{
Alyssa Rosenzweig68552282020-08-26 16:50:16 -04001024 for (int i = 0; i < count; ++i, attribute += MALI_ATTRIBUTE_LENGTH)
Boris Brezillon670e8182020-09-09 17:56:53 +02001025 DUMP_ADDR(ATTRIBUTE, attribute, "%s:\n", varying ? "Varying" : "Attribute");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001026
Alyssa Rosenzweig2c8a7222020-08-13 13:27:16 -04001027 return count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001028}
1029
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001030/* return bits [lo, hi) of word */
1031static u32
1032bits(u32 word, u32 lo, u32 hi)
1033{
1034 if (hi - lo >= 32)
1035 return word; // avoid undefined behavior with the shift
1036
1037 return (word >> lo) & ((1 << (hi - lo)) - 1);
1038}
1039
1040static void
Alyssa Rosenzweig385a4f72019-12-24 22:33:47 -05001041pandecode_vertex_tiler_prefix(struct mali_vertex_tiler_prefix *p, int job_no, bool graphics)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001042{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001043 /* Decode invocation_count. See the comment before the definition of
1044 * invocation_count for an explanation.
1045 */
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001046 struct mali_invocation_packed invocation_packed = p->invocation;
Boris Brezillon706974c2020-09-15 09:25:18 +02001047 pan_unpack(&invocation_packed, INVOCATION, invocation);
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001048
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001049 unsigned size_x = bits(invocation.invocations, 0, invocation.size_y_shift) + 1;
1050 unsigned size_y = bits(invocation.invocations, invocation.size_y_shift, invocation.size_z_shift) + 1;
1051 unsigned size_z = bits(invocation.invocations, invocation.size_z_shift, invocation.workgroups_x_shift) + 1;
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001052
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001053 unsigned groups_x = bits(invocation.invocations, invocation.workgroups_x_shift, invocation.workgroups_y_shift) + 1;
1054 unsigned groups_y = bits(invocation.invocations, invocation.workgroups_y_shift, invocation.workgroups_z_shift) + 1;
1055 unsigned groups_z = bits(invocation.invocations, invocation.workgroups_z_shift, 32) + 1;
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001056
1057 /* Even though we have this decoded, we want to ensure that the
1058 * representation is "unique" so we don't lose anything by printing only
1059 * the final result. More specifically, we need to check that we were
1060 * passed something in canonical form, since the definition per the
1061 * hardware is inherently not unique. How? Well, take the resulting
1062 * decode and pack it ourselves! If it is bit exact with what we
1063 * decoded, we're good to go. */
1064
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001065 struct mali_invocation_packed ref;
Alyssa Rosenzweig385a4f72019-12-24 22:33:47 -05001066 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 -07001067
Alyssa Rosenzweig02e768e2020-08-26 13:04:17 -04001068 if (memcmp(&ref, &invocation_packed, sizeof(ref))) {
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001069 pandecode_msg("XXX: non-canonical workgroups packing\n");
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001070 DUMP_UNPACKED(INVOCATION, invocation, "Invocation:\n")
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001071 }
1072
1073 /* Regardless, print the decode */
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001074 pandecode_log("Invocation (%d, %d, %d) x (%d, %d, %d)\n",
1075 size_x, size_y, size_z,
1076 groups_x, groups_y, groups_z);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001077
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001078 struct mali_primitive_packed prim_packed = p->primitive;
Boris Brezillon706974c2020-09-15 09:25:18 +02001079 pan_unpack(&prim_packed, PRIMITIVE, primitive);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001080 DUMP_UNPACKED(PRIMITIVE, primitive, "Primitive:\n");
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001081
1082 /* Validate an index buffer is present if we need one. TODO: verify
1083 * relationship between invocation_count and index_count */
1084
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001085 if (primitive.indices) {
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001086 /* Grab the size */
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001087 unsigned size = (primitive.index_type == MALI_INDEX_TYPE_UINT32) ?
1088 sizeof(uint32_t) : primitive.index_type;
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001089
1090 /* Ensure we got a size, and if so, validate the index buffer
1091 * is large enough to hold a full set of indices of the given
1092 * size */
1093
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001094 if (!size)
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001095 pandecode_msg("XXX: index size missing\n");
1096 else
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001097 pandecode_validate_buffer(primitive.indices, primitive.index_count * size);
1098 } else if (primitive.index_type)
1099 pandecode_msg("XXX: unexpected index size\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001100}
1101
1102static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001103pandecode_uniform_buffers(mali_ptr pubufs, int ubufs_count, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001104{
1105 struct pandecode_mapped_memory *umem = pandecode_find_mapped_gpu_mem_containing(pubufs);
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001106 uint64_t *PANDECODE_PTR_VAR(ubufs, umem, pubufs);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001107
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001108 for (int i = 0; i < ubufs_count; i++) {
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001109 unsigned size = (ubufs[i] & ((1 << 10) - 1)) * 16;
1110 mali_ptr addr = (ubufs[i] >> 10) << 2;
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001111
1112 pandecode_validate_buffer(addr, size);
1113
Alyssa Rosenzweig7d3c48f2020-02-16 17:01:02 -05001114 char *ptr = pointer_as_memory_reference(addr);
Alyssa Rosenzweig6ec33b42019-08-21 11:46:06 -07001115 pandecode_log("ubuf_%d[%u] = %s;\n", i, size, ptr);
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001116 free(ptr);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001117 }
1118
Alyssa Rosenzweig6ec33b42019-08-21 11:46:06 -07001119 pandecode_log("\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001120}
1121
1122static void
Alyssa Rosenzweigae84f162019-08-22 11:30:13 -07001123pandecode_uniforms(mali_ptr uniforms, unsigned uniform_count)
1124{
1125 pandecode_validate_buffer(uniforms, uniform_count * 16);
1126
1127 char *ptr = pointer_as_memory_reference(uniforms);
1128 pandecode_log("vec4 uniforms[%u] = %s;\n", uniform_count, ptr);
1129 free(ptr);
1130}
1131
Alyssa Rosenzweig09671c82019-12-23 11:40:40 -05001132static const char *
1133shader_type_for_job(unsigned type)
1134{
1135 switch (type) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001136 case MALI_JOB_TYPE_VERTEX: return "VERTEX";
1137 case MALI_JOB_TYPE_TILER: return "FRAGMENT";
1138 case MALI_JOB_TYPE_COMPUTE: return "COMPUTE";
Alyssa Rosenzweig80049062020-08-26 16:52:53 -04001139 default: return "UNKNOWN";
Alyssa Rosenzweig09671c82019-12-23 11:40:40 -05001140 }
1141}
1142
Alyssa Rosenzweigc4a4f3d2019-08-14 09:19:54 -07001143static unsigned shader_id = 0;
1144
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001145static struct midgard_disasm_stats
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001146pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001147 bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001148{
1149 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(shader_ptr);
1150 uint8_t *PANDECODE_PTR_VAR(code, mem, shader_ptr);
1151
1152 /* Compute maximum possible size */
1153 size_t sz = mem->length - (shader_ptr - mem->gpu_va);
1154
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001155 /* Print some boilerplate to clearly denote the assembly (which doesn't
1156 * obey indentation rules), and actually do the disassembly! */
1157
Icecream95be22c072020-01-23 10:14:35 +13001158 pandecode_log_cont("\n\n");
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001159
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001160 struct midgard_disasm_stats stats;
Alyssa Rosenzweigc4a4f3d2019-08-14 09:19:54 -07001161
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001162 if (is_bifrost) {
Alyssa Rosenzweigc88f8162020-03-27 22:34:15 -04001163 disassemble_bifrost(pandecode_dump_stream, code, sz, true);
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001164
1165 /* TODO: Extend stats to Bifrost */
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001166 stats.texture_count = -128;
1167 stats.sampler_count = -128;
1168 stats.attribute_count = -128;
1169 stats.varying_count = -128;
1170 stats.uniform_count = -128;
1171 stats.uniform_buffer_count = -128;
1172 stats.work_count = -128;
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001173
1174 stats.instruction_count = 0;
1175 stats.bundle_count = 0;
1176 stats.quadword_count = 0;
Alyssa Rosenzweigd6d6d632019-08-30 17:00:09 -07001177 stats.helper_invocations = false;
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001178 } else {
Icecream95be22c072020-01-23 10:14:35 +13001179 stats = disassemble_midgard(pandecode_dump_stream,
1180 code, sz, gpu_id,
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001181 type == MALI_JOB_TYPE_TILER ?
Alyssa Rosenzweigac14fac2019-11-07 09:31:02 -05001182 MESA_SHADER_FRAGMENT : MESA_SHADER_VERTEX);
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001183 }
1184
Alyssa Rosenzweigc088a3b2020-08-26 16:52:23 -04001185 unsigned nr_threads =
1186 (stats.work_count <= 4) ? 4 :
1187 (stats.work_count <= 8) ? 2 :
1188 1;
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001189
Alyssa Rosenzweigc088a3b2020-08-26 16:52:23 -04001190 pandecode_log_cont("shader%d - MESA_SHADER_%s shader: "
1191 "%u inst, %u bundles, %u quadwords, "
1192 "%u registers, %u threads, 0 loops, 0:0 spills:fills\n\n\n",
1193 shader_id++,
1194 shader_type_for_job(type),
1195 stats.instruction_count, stats.bundle_count, stats.quadword_count,
1196 stats.work_count, nr_threads);
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001197
1198 return stats;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001199}
1200
1201static void
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001202pandecode_texture_payload(mali_ptr payload,
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001203 enum mali_texture_dimension dim,
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001204 enum mali_texture_layout layout,
1205 bool manual_stride,
1206 uint8_t levels,
1207 uint16_t depth,
1208 uint16_t array_size,
1209 struct pandecode_mapped_memory *tmem)
1210{
1211 pandecode_log(".payload = {\n");
1212 pandecode_indent++;
1213
1214 /* A bunch of bitmap pointers follow.
1215 * We work out the correct number,
1216 * based on the mipmap/cubemap
1217 * properties, but dump extra
1218 * possibilities to futureproof */
1219
1220 int bitmap_count = levels + 1;
1221
1222 /* Miptree for each face */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001223 if (dim == MALI_TEXTURE_DIMENSION_CUBE)
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001224 bitmap_count *= 6;
Alyssa Rosenzweigeba9bcd2020-06-30 16:21:30 -04001225
1226 /* Array of layers */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001227 bitmap_count *= depth;
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001228
1229 /* Array of textures */
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001230 bitmap_count *= array_size;
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001231
1232 /* Stride for each element */
1233 if (manual_stride)
1234 bitmap_count *= 2;
1235
1236 mali_ptr *pointers_and_strides = pandecode_fetch_gpu_mem(tmem,
1237 payload, sizeof(mali_ptr) * bitmap_count);
1238 for (int i = 0; i < bitmap_count; ++i) {
1239 /* How we dump depends if this is a stride or a pointer */
1240
1241 if (manual_stride && (i & 1)) {
1242 /* signed 32-bit snuck in as a 64-bit pointer */
1243 uint64_t stride_set = pointers_and_strides[i];
1244 uint32_t clamped_stride = stride_set;
1245 int32_t stride = clamped_stride;
1246 assert(stride_set == clamped_stride);
1247 pandecode_log("(mali_ptr) %d /* stride */, \n", stride);
1248 } else {
1249 char *a = pointer_as_memory_reference(pointers_and_strides[i]);
1250 pandecode_log("%s, \n", a);
1251 free(a);
1252 }
1253 }
1254
1255 pandecode_indent--;
1256 pandecode_log("},\n");
1257}
1258
1259static void
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001260pandecode_texture(mali_ptr u,
1261 struct pandecode_mapped_memory *tmem,
1262 unsigned job_no, unsigned tex)
1263{
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001264 struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(u);
1265 const uint8_t *cl = pandecode_fetch_gpu_mem(mapped_mem, u, MALI_MIDGARD_TEXTURE_LENGTH);
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001266
Boris Brezillon706974c2020-09-15 09:25:18 +02001267 pan_unpack(cl, MIDGARD_TEXTURE, temp);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001268 DUMP_UNPACKED(MIDGARD_TEXTURE, temp, "Texture:\n")
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001269
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001270 pandecode_indent++;
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -04001271 pandecode_texture_payload(u + MALI_MIDGARD_TEXTURE_LENGTH,
1272 temp.dimension, temp.texel_ordering, temp.manual_stride,
1273 temp.levels, temp.depth, temp.array_size, mapped_mem);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001274 pandecode_indent--;
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001275}
1276
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001277static void
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001278pandecode_bifrost_texture(
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001279 const void *cl,
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -04001280 unsigned job_no,
1281 unsigned tex)
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001282{
Boris Brezillon706974c2020-09-15 09:25:18 +02001283 pan_unpack(cl, BIFROST_TEXTURE, temp);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001284 DUMP_UNPACKED(BIFROST_TEXTURE, temp, "Texture:\n")
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001285
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001286 struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(temp.surfaces);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001287 pandecode_indent++;
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001288 pandecode_texture_payload(temp.surfaces, temp.dimension, temp.texel_ordering,
1289 true, temp.levels, 1, 1, tmem);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001290 pandecode_indent--;
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001291}
1292
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001293/* 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 */
1294
1295static void
1296pandecode_shader_prop(const char *name, unsigned claim, signed truth, bool fuzzy)
1297{
1298 /* Nothing to do */
1299 if (claim == truth)
1300 return;
1301
Alyssa Rosenzweig5815f332020-02-25 17:29:55 -05001302 if (fuzzy && (truth < 0))
1303 pandecode_msg("XXX: fuzzy %s, claimed %d, expected %d\n", name, claim, truth);
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001304
1305 if ((truth >= 0) && !fuzzy) {
Alyssa Rosenzweigf48136e2019-08-22 09:02:48 -07001306 pandecode_msg("%s: expected %s = %d, claimed %u\n",
1307 (truth < claim) ? "warn" : "XXX",
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001308 name, truth, claim);
1309 } else if ((claim > -truth) && !fuzzy) {
1310 pandecode_msg("XXX: expected %s <= %u, claimed %u\n",
1311 name, -truth, claim);
1312 } else if (fuzzy && (claim < truth))
1313 pandecode_msg("XXX: expected %s >= %u, claimed %u\n",
1314 name, truth, claim);
1315
1316 pandecode_log(".%s = %" PRId16, name, claim);
1317
1318 if (fuzzy)
1319 pandecode_log_cont(" /* %u used */", truth);
1320
1321 pandecode_log_cont(",\n");
1322}
1323
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001324static void
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001325pandecode_blend_shader_disassemble(mali_ptr shader, int job_no, int job_type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001326 bool is_bifrost, unsigned gpu_id)
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001327{
1328 struct midgard_disasm_stats stats =
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001329 pandecode_shader_disassemble(shader, job_no, job_type, is_bifrost, gpu_id);
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001330
1331 bool has_texture = (stats.texture_count > 0);
1332 bool has_sampler = (stats.sampler_count > 0);
1333 bool has_attribute = (stats.attribute_count > 0);
1334 bool has_varying = (stats.varying_count > 0);
1335 bool has_uniform = (stats.uniform_count > 0);
1336 bool has_ubo = (stats.uniform_buffer_count > 0);
1337
1338 if (has_texture || has_sampler)
1339 pandecode_msg("XXX: blend shader accessing textures\n");
1340
1341 if (has_attribute || has_varying)
1342 pandecode_msg("XXX: blend shader accessing interstage\n");
1343
1344 if (has_uniform || has_ubo)
1345 pandecode_msg("XXX: blend shader accessing uniforms\n");
1346}
1347
1348static void
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001349pandecode_textures(mali_ptr textures, unsigned texture_count, int job_no, bool is_bifrost)
1350{
1351 struct pandecode_mapped_memory *mmem = pandecode_find_mapped_gpu_mem_containing(textures);
1352
1353 if (!mmem)
1354 return;
1355
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001356 pandecode_log("Textures (%"PRIx64"):\n", textures);
1357
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001358 if (is_bifrost) {
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001359 const void *cl = pandecode_fetch_gpu_mem(mmem,
1360 textures, MALI_BIFROST_TEXTURE_LENGTH *
1361 texture_count);
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001362
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -04001363 for (unsigned tex = 0; tex < texture_count; ++tex) {
1364 pandecode_bifrost_texture(cl +
1365 MALI_BIFROST_TEXTURE_LENGTH * tex,
1366 job_no, tex);
1367 }
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001368 } else {
1369 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures);
1370
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001371 for (int tex = 0; tex < texture_count; ++tex) {
1372 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr));
1373 char *a = pointer_as_memory_reference(*u);
1374 pandecode_log("%s,\n", a);
1375 free(a);
1376 }
1377
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001378 /* Now, finally, descend down into the texture descriptor */
1379 for (unsigned tex = 0; tex < texture_count; ++tex) {
1380 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr));
1381 struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(*u);
1382 if (tmem)
1383 pandecode_texture(*u, tmem, job_no, tex);
1384 }
1385 }
1386}
1387
1388static void
1389pandecode_samplers(mali_ptr samplers, unsigned sampler_count, int job_no, bool is_bifrost)
1390{
Alyssa Rosenzweigb10c3c82020-08-11 18:25:03 -04001391 for (int i = 0; i < sampler_count; ++i) {
1392 if (is_bifrost) {
Boris Brezillon670e8182020-09-09 17:56:53 +02001393 DUMP_ADDR(BIFROST_SAMPLER, samplers + (MALI_BIFROST_SAMPLER_LENGTH * i), "Sampler:\n");
Alyssa Rosenzweigb10c3c82020-08-11 18:25:03 -04001394 } else {
Boris Brezillon670e8182020-09-09 17:56:53 +02001395 DUMP_ADDR(MIDGARD_SAMPLER, samplers + (MALI_MIDGARD_SAMPLER_LENGTH * i), "Sampler:\n");
Alyssa Rosenzweigb10c3c82020-08-11 18:25:03 -04001396 }
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001397 }
1398}
1399
1400static void
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001401pandecode_vertex_tiler_postfix_pre(
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001402 const struct MALI_DRAW *p,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001403 int job_no, enum mali_job_type job_type,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001404 char *suffix, bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001405{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001406 struct pandecode_mapped_memory *attr_mem;
1407
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001408 struct pandecode_fbd fbd_info = {
1409 /* Default for Bifrost */
1410 .rt_count = 1
1411 };
1412
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001413 if (is_bifrost)
1414 pandecode_compute_fbd(p->shared & ~1, job_no);
1415 else if (p->shared & MALI_MFBD)
1416 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 -04001417 else if (job_type == MALI_JOB_TYPE_COMPUTE)
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001418 pandecode_compute_fbd((u64) (uintptr_t) p->shared, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001419 else
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001420 fbd_info = pandecode_sfbd((u64) (uintptr_t) p->shared, job_no, false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001421
1422 int varying_count = 0, attribute_count = 0, uniform_count = 0, uniform_buffer_count = 0;
1423 int texture_count = 0, sampler_count = 0;
1424
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001425 if (p->state) {
1426 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(p->state);
1427 uint32_t *cl = pandecode_fetch_gpu_mem(smem, p->state, MALI_STATE_LENGTH);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001428
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001429 /* Disassemble ahead-of-time to get stats. Initialize with
1430 * stats for the missing-shader case so we get validation
1431 * there, too */
1432
1433 struct midgard_disasm_stats info = {
1434 .texture_count = 0,
1435 .sampler_count = 0,
1436 .attribute_count = 0,
1437 .varying_count = 0,
1438 .work_count = 1,
1439
1440 .uniform_count = -128,
1441 .uniform_buffer_count = 0
1442 };
Alyssa Rosenzweig9b067d92019-08-21 14:28:36 -07001443
Boris Brezillon706974c2020-09-15 09:25:18 +02001444 pan_unpack(cl, STATE, state);
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001445
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001446 if (state.shader.shader & ~0xF)
1447 info = pandecode_shader_disassemble(state.shader.shader & ~0xF, job_no, job_type, is_bifrost, gpu_id);
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001448
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001449 DUMP_UNPACKED(STATE, state, "State:\n");
1450 pandecode_indent++;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001451
1452 /* Save for dumps */
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001453 attribute_count = state.shader.attribute_count;
1454 varying_count = state.shader.varying_count;
1455 texture_count = state.shader.texture_count;
1456 sampler_count = state.shader.sampler_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001457
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001458 fprintf(pandecode_dump_stream, " Properties\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001459 if (is_bifrost) {
Boris Brezillon706974c2020-09-15 09:25:18 +02001460 pan_unpack(&state.properties, BIFROST_PROPERTIES, bi_props);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001461 DUMP_UNPACKED(BIFROST_PROPERTIES, bi_props, "Properties:\n");
Alyssa Rosenzweigacf77cb2020-08-20 16:41:41 -04001462
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001463 uniform_count = state.preload.uniform_count;
Alyssa Rosenzweigacf77cb2020-08-20 16:41:41 -04001464 uniform_buffer_count = bi_props.uniform_buffer_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001465 } else {
Boris Brezillon706974c2020-09-15 09:25:18 +02001466 pan_unpack(&state.properties, MIDGARD_PROPERTIES, midg_props);
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001467 DUMP_UNPACKED(MIDGARD_PROPERTIES, midg_props, "Properties:\n")
Alyssa Rosenzweig1b7d4f12020-08-20 16:25:14 -04001468
1469 uniform_count = midg_props.uniform_count;
1470 uniform_buffer_count = midg_props.uniform_buffer_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001471 }
1472
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -04001473 pandecode_shader_prop("texture_count", texture_count, info.texture_count, false);
1474 pandecode_shader_prop("sampler_count", sampler_count, info.sampler_count, false);
1475 pandecode_shader_prop("attribute_count", attribute_count, info.attribute_count, false);
1476 pandecode_shader_prop("varying_count", varying_count, info.varying_count, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001477
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001478 if (is_bifrost) {
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001479 uint32_t opaque = state.preload.uniform_count << 15
1480 | state.preload.untyped;
1481
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001482 switch (job_type) {
1483 case MALI_JOB_TYPE_VERTEX:
Boris Brezillon670e8182020-09-09 17:56:53 +02001484 DUMP_CL(PRELOAD_VERTEX, &opaque, "Preload:\n");
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001485 break;
1486 case MALI_JOB_TYPE_TILER:
Boris Brezillon670e8182020-09-09 17:56:53 +02001487 DUMP_CL(PRELOAD_FRAGMENT, &opaque, "Preload:\n");
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001488 break;
1489 case MALI_JOB_TYPE_COMPUTE:
Boris Brezillon670e8182020-09-09 17:56:53 +02001490 DUMP_CL(PRELOAD_COMPUTE, &opaque, "Preload:\n");
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001491 break;
1492 default:
Boris Brezillon670e8182020-09-09 17:56:53 +02001493 DUMP_CL(PRELOAD, &opaque, "Preload:\n");
Alyssa Rosenzweig7a95ed22020-08-20 20:42:32 -04001494 break;
1495 }
1496 }
1497
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001498 if (!is_bifrost) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001499 /* TODO: Blend shaders routing/disasm */
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001500 union midgard_blend blend;
1501 memcpy(&blend, &state.sfbd_blend, sizeof(blend));
1502 mali_ptr shader = pandecode_midgard_blend(&blend, state.multisample_misc.sfbd_blend_shader);
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001503 if (shader & ~0xF)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001504 pandecode_blend_shader_disassemble(shader, job_no, job_type, false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001505 }
Boris Brezillonaa2670c2020-09-05 18:14:17 +02001506 pandecode_indent--;
1507 pandecode_msg("\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001508
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001509 /* MRT blend fields are used whenever MFBD is used, with
1510 * per-RT descriptors */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001511
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001512 if (job_type == MALI_JOB_TYPE_TILER && (is_bifrost || p->shared & MALI_MFBD)) {
Alyssa Rosenzweig3d7ce132020-08-21 19:59:22 -04001513 void* blend_base = ((void *) cl) + MALI_STATE_LENGTH;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001514
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001515 for (unsigned i = 0; i < fbd_info.rt_count; i++) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001516 mali_ptr shader = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001517
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001518 if (is_bifrost)
1519 shader = pandecode_bifrost_blend(blend_base, job_no, i);
1520 else
1521 shader = pandecode_midgard_blend_mrt(blend_base, job_no, i);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001522
Tomeu Vizoso8e1ae5f2019-11-05 15:31:42 +01001523 if (shader & ~0xF)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001524 pandecode_blend_shader_disassemble(shader, job_no, job_type, false, gpu_id);
Alyssa Rosenzweig139708b2019-08-21 14:04:05 -07001525
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001526 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001527 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001528 } else
Alyssa Rosenzweig5f9a1c72019-08-21 14:16:32 -07001529 pandecode_msg("XXX: missing shader descriptor\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001530
Alyssa Rosenzweig7f487e02020-08-05 19:33:20 -04001531 if (p->viewport)
Boris Brezillon670e8182020-09-09 17:56:53 +02001532 DUMP_ADDR(VIEWPORT, p->viewport, "Viewport:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001533
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001534 unsigned max_attr_index = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001535
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001536 if (p->attributes)
1537 max_attr_index = pandecode_attribute_meta(attribute_count, p->attributes, false, suffix);
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001538
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001539 if (p->attribute_buffers) {
1540 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->attribute_buffers);
1541 pandecode_attributes(attr_mem, p->attribute_buffers, job_no, suffix, max_attr_index, false, job_type);
Alyssa Rosenzweig9e66ff32019-07-31 11:52:52 -07001542 }
1543
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001544 if (p->varyings) {
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001545 varying_count = pandecode_attribute_meta(varying_count, p->varyings, true, suffix);
1546 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001547
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001548 if (p->varying_buffers) {
1549 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->varying_buffers);
1550 pandecode_attributes(attr_mem, p->varying_buffers, job_no, suffix, varying_count, true, job_type);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001551 }
1552
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001553 if (p->uniform_buffers) {
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001554 if (uniform_buffer_count)
1555 pandecode_uniform_buffers(p->uniform_buffers, uniform_buffer_count, job_no);
1556 else
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001557 pandecode_msg("warn: UBOs specified but not referenced\n");
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001558 } else if (uniform_buffer_count)
1559 pandecode_msg("XXX: UBOs referenced but not specified\n");
1560
1561 /* We don't want to actually dump uniforms, but we do need to validate
1562 * that the counts we were given are sane */
1563
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001564 if (p->push_uniforms) {
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001565 if (uniform_count)
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001566 pandecode_uniforms(p->push_uniforms, uniform_count);
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001567 else
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001568 pandecode_msg("warn: Uniforms specified but not referenced\n");
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001569 } else if (uniform_count)
Alyssa Rosenzweigd7473e22019-08-21 14:15:05 -07001570 pandecode_msg("XXX: Uniforms referenced but not specified\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001571
Alyssa Rosenzweig497977b2020-03-09 13:51:39 -04001572 if (p->textures)
1573 pandecode_textures(p->textures, texture_count, job_no, is_bifrost);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001574
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001575 if (p->samplers)
1576 pandecode_samplers(p->samplers, sampler_count, job_no, is_bifrost);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001577}
1578
1579static void
Boris Brezillonefce73d2020-09-08 10:11:26 +02001580pandecode_bifrost_tiler_heap(mali_ptr gpu_va, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001581{
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001582 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Boris Brezillonefce73d2020-09-08 10:11:26 +02001583 pan_unpack(PANDECODE_PTR(mem, gpu_va, void), BIFROST_TILER_HEAP, h);
1584 DUMP_UNPACKED(BIFROST_TILER_HEAP, h, "Bifrost Tiler Heap:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001585}
1586
1587static void
Boris Brezillonefce73d2020-09-08 10:11:26 +02001588pandecode_bifrost_tiler(mali_ptr gpu_va, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001589{
1590 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
Boris Brezillonefce73d2020-09-08 10:11:26 +02001591 pan_unpack(PANDECODE_PTR(mem, gpu_va, void), BIFROST_TILER, t);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001592
Boris Brezillonefce73d2020-09-08 10:11:26 +02001593 pandecode_bifrost_tiler_heap(t.heap, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001594
Boris Brezillonefce73d2020-09-08 10:11:26 +02001595 DUMP_UNPACKED(BIFROST_TILER, t, "Bifrost Tiler:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001596 pandecode_indent++;
Boris Brezillonefce73d2020-09-08 10:11:26 +02001597 if (t.hierarchy_mask != 0xa &&
1598 t.hierarchy_mask != 0x14 &&
1599 t.hierarchy_mask != 0x28 &&
1600 t.hierarchy_mask != 0x50 &&
1601 t.hierarchy_mask != 0xa0)
Tomeu Vizoso0a0b6702020-04-09 09:39:17 +02001602 pandecode_prop("XXX: Unexpected hierarchy_mask (not 0xa, 0x14, 0x28, 0x50 or 0xa0)!");
1603
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001604 pandecode_indent--;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001605}
1606
1607static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001608pandecode_primitive_size(union midgard_primitive_size u, bool constant)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001609{
Alyssa Rosenzweig2608da12019-06-19 09:35:57 -07001610 if (u.pointer == 0x0)
1611 return;
1612
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001613 pandecode_log(".primitive_size = {\n");
1614 pandecode_indent++;
1615
Alyssa Rosenzweigb517e362019-03-15 03:21:27 +00001616 if (constant) {
1617 pandecode_prop("constant = %f", u.constant);
1618 } else {
1619 MEMORY_PROP((&u), pointer);
1620 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001621
1622 pandecode_indent--;
1623 pandecode_log("},\n");
1624}
1625
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001626static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001627pandecode_vertex_job_bfr(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001628 const struct pandecode_mapped_memory *mem,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001629 mali_ptr payload, int job_no, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001630{
1631 struct bifrost_payload_vertex *PANDECODE_PTR_VAR(v, mem, payload);
1632
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001633 struct mali_draw_packed draw_packed;
1634 memcpy(&draw_packed, &v->postfix, sizeof(draw_packed));
Boris Brezillon706974c2020-09-15 09:25:18 +02001635 pan_unpack(&draw_packed, DRAW, draw);
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001636 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", true, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001637
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001638 pandecode_vertex_tiler_prefix(&v->prefix, job_no, false);
Boris Brezillon670e8182020-09-09 17:56:53 +02001639 DUMP_CL(DRAW, &draw_packed, "Draw:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001640
1641 return sizeof(*v);
1642}
1643
1644static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001645pandecode_tiler_job_bfr(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001646 const struct pandecode_mapped_memory *mem,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001647 mali_ptr payload, int job_no, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001648{
1649 struct bifrost_payload_tiler *PANDECODE_PTR_VAR(t, mem, payload);
1650
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001651 struct mali_draw_packed draw_packed;
1652 memcpy(&draw_packed, &t->postfix, sizeof(draw_packed));
Boris Brezillon706974c2020-09-15 09:25:18 +02001653 pan_unpack(&draw_packed, DRAW, draw);
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001654 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", true, gpu_id);
Boris Brezillonefce73d2020-09-08 10:11:26 +02001655 pandecode_bifrost_tiler(t->tiler_meta, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001656
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001657 pandecode_vertex_tiler_prefix(&t->prefix, job_no, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001658
Alyssa Rosenzweig4467e792020-08-26 13:21:06 -04001659 /* TODO: gl_PointSize on Bifrost */
1660 pandecode_primitive_size(t->primitive_size, true);
1661
1662 if (t->zero1 || t->zero2 || t->zero3 || t->zero4 || t->zero5
1663 || t->zero6) {
1664 pandecode_msg("XXX: tiler only zero tripped\n");
1665 pandecode_prop("zero1 = 0x%" PRIx64, t->zero1);
1666 pandecode_prop("zero2 = 0x%" PRIx64, t->zero2);
1667 pandecode_prop("zero3 = 0x%" PRIx64, t->zero3);
1668 pandecode_prop("zero4 = 0x%" PRIx64, t->zero4);
1669 pandecode_prop("zero5 = 0x%" PRIx64, t->zero5);
1670 pandecode_prop("zero6 = 0x%" PRIx64, t->zero6);
1671 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001672
Boris Brezillon670e8182020-09-09 17:56:53 +02001673 DUMP_CL(DRAW, &draw_packed, "Draw:\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001674
1675 return sizeof(*t);
1676}
1677
1678static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001679pandecode_vertex_or_tiler_job_mdg(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001680 const struct pandecode_mapped_memory *mem,
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001681 mali_ptr payload, int job_no, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001682{
1683 struct midgard_payload_vertex_tiler *PANDECODE_PTR_VAR(v, mem, payload);
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001684 bool is_graphics = (h->job_type == MALI_JOB_TYPE_VERTEX) || (h->job_type == MALI_JOB_TYPE_TILER);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001685
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001686 struct mali_draw_packed draw_packed;
1687 memcpy(&draw_packed, &v->postfix, sizeof(draw_packed));
Boris Brezillon706974c2020-09-15 09:25:18 +02001688 pan_unpack(&draw_packed, DRAW, draw);
Alyssa Rosenzweig76028912020-08-26 17:05:41 -04001689 pandecode_vertex_tiler_postfix_pre(&draw, job_no, h->job_type, "", false, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001690
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -04001691 pandecode_vertex_tiler_prefix(&v->prefix, job_no, is_graphics);
Boris Brezillon670e8182020-09-09 17:56:53 +02001692 DUMP_CL(DRAW, &draw_packed, "Draw:\n");
Alyssa Rosenzweigb010a6d2020-04-06 20:31:32 -04001693
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001694 struct mali_primitive_packed prim_packed = v->prefix.primitive;
Boris Brezillon706974c2020-09-15 09:25:18 +02001695 pan_unpack(&prim_packed, PRIMITIVE, primitive);
Alyssa Rosenzweigb60d5672020-08-25 16:59:14 -04001696
1697 pandecode_primitive_size(v->primitive_size, primitive.point_size_array == 0);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001698
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001699 return sizeof(*v);
1700}
1701
1702static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001703pandecode_fragment_job(const struct pandecode_mapped_memory *mem,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001704 mali_ptr payload, int job_no,
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01001705 bool is_bifrost, unsigned gpu_id)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001706{
1707 const struct mali_payload_fragment *PANDECODE_PTR_VAR(s, mem, payload);
1708
Alyssa Rosenzweig89593642019-12-16 12:05:45 -05001709 bool is_mfbd = s->framebuffer & MALI_MFBD;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001710
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001711 if (!is_mfbd && is_bifrost)
1712 pandecode_msg("XXX: Bifrost fragment must use MFBD\n");
1713
1714 struct pandecode_fbd info;
1715
1716 if (is_mfbd)
Alyssa Rosenzweig3f5cd442020-02-28 07:17:53 -05001717 info = pandecode_mfbd_bfr(s->framebuffer & FBD_MASK, job_no, true, false, is_bifrost);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001718 else
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01001719 info = pandecode_sfbd(s->framebuffer & FBD_MASK, job_no, true, gpu_id);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001720
1721 /* Compute the tag for the tagged pointer. This contains the type of
1722 * FBD (MFBD/SFBD), and in the case of an MFBD, information about which
1723 * additional structures follow the MFBD header (an extra payload or
1724 * not, as well as a count of render targets) */
1725
Alyssa Rosenzweig89593642019-12-16 12:05:45 -05001726 unsigned expected_tag = is_mfbd ? MALI_MFBD : 0;
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001727
1728 if (is_mfbd) {
1729 if (info.has_extra)
1730 expected_tag |= MALI_MFBD_TAG_EXTRA;
1731
1732 expected_tag |= (MALI_POSITIVE(info.rt_count) << 2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001733 }
1734
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001735 if ((s->min_tile_coord | s->max_tile_coord) & ~(MALI_X_COORD_MASK | MALI_Y_COORD_MASK)) {
1736 pandecode_msg("XXX: unexpected tile coordinate bits\n");
1737 pandecode_prop("min_tile_coord = 0x%X\n", s->min_tile_coord);
Alyssa Rosenzweig52d6b4d2020-05-11 18:54:05 -04001738 pandecode_prop("max_tile_coord = 0x%X\n", s->max_tile_coord);
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001739 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001740
Alyssa Rosenzweigded9a682019-08-21 12:29:47 -07001741 /* Extract tile coordinates */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001742
Alyssa Rosenzweigded9a682019-08-21 12:29:47 -07001743 unsigned min_x = MALI_TILE_COORD_X(s->min_tile_coord) << MALI_TILE_SHIFT;
1744 unsigned min_y = MALI_TILE_COORD_Y(s->min_tile_coord) << MALI_TILE_SHIFT;
1745
1746 unsigned max_x = (MALI_TILE_COORD_X(s->max_tile_coord) + 1) << MALI_TILE_SHIFT;
1747 unsigned max_y = (MALI_TILE_COORD_Y(s->max_tile_coord) + 1) << MALI_TILE_SHIFT;
1748
1749 /* For the max, we also want the floored (rather than ceiled) version for checking */
1750
1751 unsigned max_x_f = (MALI_TILE_COORD_X(s->max_tile_coord)) << MALI_TILE_SHIFT;
1752 unsigned max_y_f = (MALI_TILE_COORD_Y(s->max_tile_coord)) << MALI_TILE_SHIFT;
1753
1754 /* Validate the coordinates are well-ordered */
1755
1756 if (min_x == max_x)
1757 pandecode_msg("XXX: empty X coordinates (%u = %u)\n", min_x, max_x);
1758 else if (min_x > max_x)
1759 pandecode_msg("XXX: misordered X coordinates (%u > %u)\n", min_x, max_x);
1760
1761 if (min_y == max_y)
1762 pandecode_msg("XXX: empty X coordinates (%u = %u)\n", min_x, max_x);
1763 else if (min_y > max_y)
1764 pandecode_msg("XXX: misordered X coordinates (%u > %u)\n", min_x, max_x);
1765
1766 /* Validate the coordinates fit inside the framebuffer. We use floor,
1767 * rather than ceil, for the max coordinates, since the tile
1768 * coordinates for something like an 800x600 framebuffer will actually
1769 * resolve to 800x608, which would otherwise trigger a Y-overflow */
1770
1771 if ((min_x > info.width) || (max_x_f > info.width))
1772 pandecode_msg("XXX: tile coordinates overflow in X direction\n");
1773
1774 if ((min_y > info.height) || (max_y_f > info.height))
1775 pandecode_msg("XXX: tile coordinates overflow in Y direction\n");
1776
1777 /* After validation, we print */
1778
1779 pandecode_log("fragment (%u, %u) ... (%u, %u)\n\n", min_x, min_y, max_x, max_y);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001780
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001781 /* The FBD is a tagged pointer */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001782
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001783 unsigned tag = (s->framebuffer & ~FBD_MASK);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001784
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001785 if (tag != expected_tag)
1786 pandecode_msg("XXX: expected FBD tag %X but got %X\n", expected_tag, tag);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001787
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001788 return sizeof(*s);
1789}
1790
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05001791/* Entrypoint to start tracing. jc_gpu_va is the GPU address for the first job
1792 * in the chain; later jobs are found by walking the chain. Bifrost is, well,
1793 * if it's bifrost or not. GPU ID is the more finegrained ID (at some point, we
1794 * might wish to combine this with the bifrost parameter) because some details
1795 * are model-specific even within a particular architecture. Minimal traces
1796 * *only* examine the job descriptors, skipping printing entirely if there is
1797 * no faults, and only descends into the payload if there are faults. This is
1798 * useful for looking for faults without the overhead of invasive traces. */
1799
Alyssa Rosenzweig59986462020-02-18 07:46:03 -05001800void
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05001801pandecode_jc(mali_ptr jc_gpu_va, bool bifrost, unsigned gpu_id, bool minimal)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001802{
Icecream9501d60d32020-07-16 16:12:13 +12001803 pandecode_dump_file_open();
1804
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001805 struct mali_job_descriptor_header *h;
Alyssa Rosenzweig59986462020-02-18 07:46:03 -05001806 unsigned job_descriptor_number = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001807
1808 do {
1809 struct pandecode_mapped_memory *mem =
1810 pandecode_find_mapped_gpu_mem_containing(jc_gpu_va);
1811
1812 void *payload;
1813
1814 h = PANDECODE_PTR(mem, jc_gpu_va, struct mali_job_descriptor_header);
1815
Alyssa Rosenzweigaac5a552020-08-21 09:31:43 -04001816 mali_ptr payload_ptr = jc_gpu_va + sizeof(*h);
Alyssa Rosenzweigd353b152020-08-21 09:36:14 -04001817 payload = pandecode_fetch_gpu_mem(mem, payload_ptr, 64);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001818
1819 int job_no = job_descriptor_number++;
1820
Alyssa Rosenzweig4122f742020-02-18 07:43:51 -05001821 /* If the job is good to go, skip it in minimal mode */
1822 if (minimal && (h->exception_status == 0x0 || h->exception_status == 0x1))
1823 continue;
1824
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02001825 pandecode_log("struct mali_job_descriptor_header job_%"PRIx64"_%d = {\n", jc_gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001826 pandecode_indent++;
1827
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001828 pandecode_prop("job_type = %s", mali_job_type_as_str(h->job_type));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001829
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001830 if (h->job_descriptor_size)
1831 pandecode_prop("job_descriptor_size = %d", h->job_descriptor_size);
1832
Alyssa Rosenzweige918dd82019-08-16 16:36:39 -07001833 if (h->exception_status && h->exception_status != 0x1)
Alyssa Rosenzweig358372b2019-08-09 16:04:24 -07001834 pandecode_prop("exception_status = %x (source ID: 0x%x access: %s exception: 0x%x)",
Tomeu Vizosofa36c192019-06-25 08:22:30 +02001835 h->exception_status,
1836 (h->exception_status >> 16) & 0xFFFF,
Alyssa Rosenzweig78445ce2020-08-11 21:19:52 -04001837 mali_exception_access_as_str((h->exception_status >> 8) & 0x3),
Tomeu Vizosofa36c192019-06-25 08:22:30 +02001838 h->exception_status & 0xFF);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001839
1840 if (h->first_incomplete_task)
1841 pandecode_prop("first_incomplete_task = %d", h->first_incomplete_task);
1842
1843 if (h->fault_pointer)
1844 pandecode_prop("fault_pointer = 0x%" PRIx64, h->fault_pointer);
1845
1846 if (h->job_barrier)
1847 pandecode_prop("job_barrier = %d", h->job_barrier);
1848
1849 pandecode_prop("job_index = %d", h->job_index);
1850
1851 if (h->unknown_flags)
1852 pandecode_prop("unknown_flags = %d", h->unknown_flags);
1853
1854 if (h->job_dependency_index_1)
1855 pandecode_prop("job_dependency_index_1 = %d", h->job_dependency_index_1);
1856
1857 if (h->job_dependency_index_2)
1858 pandecode_prop("job_dependency_index_2 = %d", h->job_dependency_index_2);
1859
1860 pandecode_indent--;
1861 pandecode_log("};\n");
1862
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001863 switch (h->job_type) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001864 case MALI_JOB_TYPE_WRITE_VALUE: {
Alyssa Rosenzweigadf716d2019-12-05 09:06:53 -05001865 struct mali_payload_write_value *s = payload;
1866 pandecode_log("struct mali_payload_write_value payload_%"PRIx64"_%d = {\n", payload_ptr, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001867 pandecode_indent++;
Alyssa Rosenzweig9eae9502019-12-04 08:59:29 -05001868 MEMORY_PROP(s, address);
1869
Alyssa Rosenzweigadf716d2019-12-05 09:06:53 -05001870 if (s->value_descriptor != MALI_WRITE_VALUE_ZERO) {
Alyssa Rosenzweig9eae9502019-12-04 08:59:29 -05001871 pandecode_msg("XXX: unknown value descriptor\n");
1872 pandecode_prop("value_descriptor = 0x%" PRIX32, s->value_descriptor);
1873 }
1874
1875 if (s->reserved) {
1876 pandecode_msg("XXX: set value tripped\n");
1877 pandecode_prop("reserved = 0x%" PRIX32, s->reserved);
1878 }
1879
1880 pandecode_prop("immediate = 0x%" PRIX64, s->immediate);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001881 pandecode_indent--;
1882 pandecode_log("};\n");
1883
1884 break;
1885 }
1886
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001887 case MALI_JOB_TYPE_TILER:
1888 case MALI_JOB_TYPE_VERTEX:
1889 case MALI_JOB_TYPE_COMPUTE:
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001890 if (bifrost) {
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001891 if (h->job_type == MALI_JOB_TYPE_TILER)
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001892 pandecode_tiler_job_bfr(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001893 else
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001894 pandecode_vertex_job_bfr(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001895 } else
Tomeu Vizoso072207b2019-11-07 08:27:53 +01001896 pandecode_vertex_or_tiler_job_mdg(h, mem, payload_ptr, job_no, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001897
1898 break;
1899
Alyssa Rosenzweig4b7056b2020-08-05 18:40:44 -04001900 case MALI_JOB_TYPE_FRAGMENT:
Tomeu Vizoso697f02c2019-11-12 12:15:02 +01001901 pandecode_fragment_job(mem, payload_ptr, job_no, bifrost, gpu_id);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001902 break;
1903
1904 default:
1905 break;
1906 }
Alyssa Rosenzweig65e5c192019-12-27 13:03:22 -05001907 } while ((jc_gpu_va = h->next_job));
Icecream95ef672182020-06-22 22:49:53 +12001908
1909 pandecode_map_read_write();
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001910}