blob: aef69da1c48172de2f8e15b49112ba1a1977da6e [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
26#include <panfrost-job.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <memory.h>
30#include <stdbool.h>
31#include <stdarg.h>
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 "pan_pretty_print.h"
38#include "midgard/disassemble.h"
39#include "bifrost/disassemble.h"
40
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -070041#include "pan_encoder.h"
42
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -070043int pandecode_jc(mali_ptr jc_gpu_va, bool bifrost);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000044
45#define MEMORY_PROP(obj, p) {\
Alyssa Rosenzweig2608da12019-06-19 09:35:57 -070046 if (obj->p) { \
47 char *a = pointer_as_memory_reference(obj->p); \
48 pandecode_prop("%s = %s", #p, a); \
49 free(a); \
50 } \
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000051}
52
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -070053#define MEMORY_PROP_DIR(obj, p) {\
54 if (obj.p) { \
55 char *a = pointer_as_memory_reference(obj.p); \
56 pandecode_prop("%s = %s", #p, a); \
57 free(a); \
58 } \
59}
60
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +000061/* Semantic logging type.
62 *
63 * Raw: for raw messages to be printed as is.
64 * Message: for helpful information to be commented out in replays.
65 * Property: for properties of a struct
66 *
67 * Use one of pandecode_log, pandecode_msg, or pandecode_prop as syntax sugar.
68 */
69
70enum pandecode_log_type {
71 PANDECODE_RAW,
72 PANDECODE_MESSAGE,
73 PANDECODE_PROPERTY
74};
75
76#define pandecode_log(...) pandecode_log_typed(PANDECODE_RAW, __VA_ARGS__)
77#define pandecode_msg(...) pandecode_log_typed(PANDECODE_MESSAGE, __VA_ARGS__)
78#define pandecode_prop(...) pandecode_log_typed(PANDECODE_PROPERTY, __VA_ARGS__)
79
80unsigned pandecode_indent = 0;
81
82static void
83pandecode_make_indent(void)
84{
85 for (unsigned i = 0; i < pandecode_indent; ++i)
86 printf(" ");
87}
88
89static void
90pandecode_log_typed(enum pandecode_log_type type, const char *format, ...)
91{
92 va_list ap;
93
94 pandecode_make_indent();
95
96 if (type == PANDECODE_MESSAGE)
97 printf("// ");
98 else if (type == PANDECODE_PROPERTY)
99 printf(".");
100
101 va_start(ap, format);
102 vprintf(format, ap);
103 va_end(ap);
104
105 if (type == PANDECODE_PROPERTY)
106 printf(",\n");
107}
108
109static void
110pandecode_log_cont(const char *format, ...)
111{
112 va_list ap;
113
114 va_start(ap, format);
115 vprintf(format, ap);
116 va_end(ap);
117}
118
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700119/* To check for memory safety issues, validates that the given pointer in GPU
120 * memory is valid, containing at least sz bytes. The goal is to eliminate
121 * GPU-side memory bugs (NULL pointer dereferences, buffer overflows, or buffer
122 * overruns) by statically validating pointers.
123 */
124
125static void
126pandecode_validate_buffer(mali_ptr addr, size_t sz)
127{
128 if (!addr) {
129 pandecode_msg("XXX: null pointer deref");
130 return;
131 }
132
133 /* Find a BO */
134
135 struct pandecode_mapped_memory *bo =
136 pandecode_find_mapped_gpu_mem_containing(addr);
137
138 if (!bo) {
139 pandecode_msg("XXX: invalid memory dereference\n");
140 return;
141 }
142
143 /* Bounds check */
144
145 unsigned offset = addr - bo->gpu_va;
146 unsigned total = offset + sz;
147
148 if (total > bo->length) {
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -0700149 pandecode_msg("XXX: buffer overrun. "
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700150 "Chunk of size %d at offset %d in buffer of size %d. "
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -0700151 "Overrun by %d bytes. \n",
Alyssa Rosenzweig4391c652019-08-19 15:14:48 -0700152 sz, offset, bo->length, total - bo->length);
153 return;
154 }
155}
156
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000157struct pandecode_flag_info {
158 u64 flag;
159 const char *name;
160};
161
162static void
163pandecode_log_decoded_flags(const struct pandecode_flag_info *flag_info,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700164 u64 flags)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000165{
166 bool decodable_flags_found = false;
167
168 for (int i = 0; flag_info[i].name; i++) {
169 if ((flags & flag_info[i].flag) != flag_info[i].flag)
170 continue;
171
172 if (!decodable_flags_found) {
173 decodable_flags_found = true;
174 } else {
175 pandecode_log_cont(" | ");
176 }
177
178 pandecode_log_cont("%s", flag_info[i].name);
179
180 flags &= ~flag_info[i].flag;
181 }
182
183 if (decodable_flags_found) {
184 if (flags)
185 pandecode_log_cont(" | 0x%" PRIx64, flags);
186 } else {
187 pandecode_log_cont("0x%" PRIx64, flags);
188 }
189}
190
191#define FLAG_INFO(flag) { MALI_##flag, "MALI_" #flag }
192static const struct pandecode_flag_info gl_enable_flag_info[] = {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000193 FLAG_INFO(OCCLUSION_QUERY),
194 FLAG_INFO(OCCLUSION_PRECISE),
Alyssa Rosenzweig2adf35e2019-05-23 03:01:32 +0000195 FLAG_INFO(FRONT_CCW_TOP),
196 FLAG_INFO(CULL_FACE_FRONT),
197 FLAG_INFO(CULL_FACE_BACK),
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000198 {}
199};
200#undef FLAG_INFO
201
202#define FLAG_INFO(flag) { MALI_CLEAR_##flag, "MALI_CLEAR_" #flag }
203static const struct pandecode_flag_info clear_flag_info[] = {
204 FLAG_INFO(FAST),
205 FLAG_INFO(SLOW),
206 FLAG_INFO(SLOW_STENCIL),
207 {}
208};
209#undef FLAG_INFO
210
211#define FLAG_INFO(flag) { MALI_MASK_##flag, "MALI_MASK_" #flag }
212static const struct pandecode_flag_info mask_flag_info[] = {
213 FLAG_INFO(R),
214 FLAG_INFO(G),
215 FLAG_INFO(B),
216 FLAG_INFO(A),
217 {}
218};
219#undef FLAG_INFO
220
221#define FLAG_INFO(flag) { MALI_##flag, "MALI_" #flag }
222static const struct pandecode_flag_info u3_flag_info[] = {
223 FLAG_INFO(HAS_MSAA),
224 FLAG_INFO(CAN_DISCARD),
225 FLAG_INFO(HAS_BLEND_SHADER),
226 FLAG_INFO(DEPTH_TEST),
227 {}
228};
229
230static const struct pandecode_flag_info u4_flag_info[] = {
231 FLAG_INFO(NO_MSAA),
232 FLAG_INFO(NO_DITHER),
233 FLAG_INFO(DEPTH_RANGE_A),
234 FLAG_INFO(DEPTH_RANGE_B),
235 FLAG_INFO(STENCIL_TEST),
236 FLAG_INFO(SAMPLE_ALPHA_TO_COVERAGE_NO_BLEND_SHADER),
237 {}
238};
239#undef FLAG_INFO
240
241#define FLAG_INFO(flag) { MALI_FRAMEBUFFER_##flag, "MALI_FRAMEBUFFER_" #flag }
242static const struct pandecode_flag_info fb_fmt_flag_info[] = {
243 FLAG_INFO(MSAA_A),
244 FLAG_INFO(MSAA_B),
245 FLAG_INFO(MSAA_8),
246 {}
247};
248#undef FLAG_INFO
249
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000250#define FLAG_INFO(flag) { MALI_MFBD_FORMAT_##flag, "MALI_MFBD_FORMAT_" #flag }
251static const struct pandecode_flag_info mfbd_fmt_flag_info[] = {
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000252 FLAG_INFO(MSAA),
Alyssa Rosenzweig31a4ef82019-06-17 16:01:24 -0700253 FLAG_INFO(SRGB),
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000254 {}
255};
256#undef FLAG_INFO
257
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +0000258#define FLAG_INFO(flag) { MALI_EXTRA_##flag, "MALI_EXTRA_" #flag }
259static const struct pandecode_flag_info mfbd_extra_flag_info[] = {
260 FLAG_INFO(PRESENT),
261 FLAG_INFO(AFBC),
262 FLAG_INFO(ZS),
263 {}
264};
265#undef FLAG_INFO
266
Alyssa Rosenzweig7cccc892019-04-05 01:17:21 +0000267#define FLAG_INFO(flag) { MALI_##flag, "MALI_" #flag }
Alyssa Rosenzweigbd2fc602019-06-20 16:41:39 -0700268static const struct pandecode_flag_info shader_midgard1_flag_info [] = {
Alyssa Rosenzweig8d1adc02019-06-07 16:00:49 -0700269 FLAG_INFO(EARLY_Z),
Alyssa Rosenzweig7cccc892019-04-05 01:17:21 +0000270 FLAG_INFO(READS_TILEBUFFER),
271 FLAG_INFO(READS_ZS),
272 {}
273};
274#undef FLAG_INFO
275
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700276#define FLAG_INFO(flag) { MALI_MFBD_##flag, "MALI_MFBD_" #flag }
277static const struct pandecode_flag_info mfbd_flag_info [] = {
278 FLAG_INFO(DEPTH_WRITE),
279 FLAG_INFO(EXTRA),
280 {}
281};
282#undef FLAG_INFO
283
Alyssa Rosenzweigcf6cad32019-07-31 08:50:02 -0700284#define FLAG_INFO(flag) { MALI_SAMP_##flag, "MALI_SAMP_" #flag }
285static const struct pandecode_flag_info sampler_flag_info [] = {
286 FLAG_INFO(MAG_NEAREST),
287 FLAG_INFO(MIN_NEAREST),
288 FLAG_INFO(MIP_LINEAR_1),
289 FLAG_INFO(MIP_LINEAR_2),
Alyssa Rosenzweig3e47a112019-07-31 09:08:07 -0700290 FLAG_INFO(NORM_COORDS),
Alyssa Rosenzweigcf6cad32019-07-31 08:50:02 -0700291 {}
292};
293#undef FLAG_INFO
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700294
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000295extern char *replace_fragment;
296extern char *replace_vertex;
297
298static char *
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -0700299pandecode_job_type(enum mali_job_type type)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000300{
301#define DEFINE_CASE(name) case JOB_TYPE_ ## name: return "JOB_TYPE_" #name
302
303 switch (type) {
304 DEFINE_CASE(NULL);
305 DEFINE_CASE(SET_VALUE);
306 DEFINE_CASE(CACHE_FLUSH);
307 DEFINE_CASE(COMPUTE);
308 DEFINE_CASE(VERTEX);
309 DEFINE_CASE(TILER);
310 DEFINE_CASE(FUSED);
311 DEFINE_CASE(FRAGMENT);
312
313 case JOB_NOT_STARTED:
314 return "NOT_STARTED";
315
316 default:
317 pandecode_log("Warning! Unknown job type %x\n", type);
318 return "!?!?!?";
319 }
320
321#undef DEFINE_CASE
322}
323
324static char *
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -0700325pandecode_draw_mode(enum mali_draw_mode mode)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000326{
327#define DEFINE_CASE(name) case MALI_ ## name: return "MALI_" #name
328
329 switch (mode) {
330 DEFINE_CASE(DRAW_NONE);
331 DEFINE_CASE(POINTS);
332 DEFINE_CASE(LINES);
333 DEFINE_CASE(TRIANGLES);
334 DEFINE_CASE(TRIANGLE_STRIP);
335 DEFINE_CASE(TRIANGLE_FAN);
336 DEFINE_CASE(LINE_STRIP);
337 DEFINE_CASE(LINE_LOOP);
338 DEFINE_CASE(POLYGON);
339 DEFINE_CASE(QUADS);
340 DEFINE_CASE(QUAD_STRIP);
341
342 default:
Alyssa Rosenzweigdcde5bd2019-08-20 11:24:32 -0700343 pandecode_msg("XXX: invalid draw mode %X\n", mode);
344 return "";
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000345 }
346
347#undef DEFINE_CASE
348}
349
350#define DEFINE_CASE(name) case MALI_FUNC_ ## name: return "MALI_FUNC_" #name
351static char *
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -0700352pandecode_func(enum mali_func mode)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000353{
354 switch (mode) {
355 DEFINE_CASE(NEVER);
356 DEFINE_CASE(LESS);
357 DEFINE_CASE(EQUAL);
358 DEFINE_CASE(LEQUAL);
359 DEFINE_CASE(GREATER);
360 DEFINE_CASE(NOTEQUAL);
361 DEFINE_CASE(GEQUAL);
362 DEFINE_CASE(ALWAYS);
363
364 default:
Alyssa Rosenzweigdcde5bd2019-08-20 11:24:32 -0700365 pandecode_msg("XXX: invalid func %X\n", mode);
366 return "";
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000367 }
368}
369#undef DEFINE_CASE
370
371/* Why is this duplicated? Who knows... */
372#define DEFINE_CASE(name) case MALI_ALT_FUNC_ ## name: return "MALI_ALT_FUNC_" #name
373static char *
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -0700374pandecode_alt_func(enum mali_alt_func mode)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000375{
376 switch (mode) {
377 DEFINE_CASE(NEVER);
378 DEFINE_CASE(LESS);
379 DEFINE_CASE(EQUAL);
380 DEFINE_CASE(LEQUAL);
381 DEFINE_CASE(GREATER);
382 DEFINE_CASE(NOTEQUAL);
383 DEFINE_CASE(GEQUAL);
384 DEFINE_CASE(ALWAYS);
385
386 default:
Alyssa Rosenzweigdcde5bd2019-08-20 11:24:32 -0700387 pandecode_msg("XXX: invalid alt func %X\n", mode);
388 return "";
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000389 }
390}
391#undef DEFINE_CASE
392
393#define DEFINE_CASE(name) case MALI_STENCIL_ ## name: return "MALI_STENCIL_" #name
394static char *
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -0700395pandecode_stencil_op(enum mali_stencil_op op)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000396{
397 switch (op) {
398 DEFINE_CASE(KEEP);
399 DEFINE_CASE(REPLACE);
400 DEFINE_CASE(ZERO);
401 DEFINE_CASE(INVERT);
402 DEFINE_CASE(INCR_WRAP);
403 DEFINE_CASE(DECR_WRAP);
404 DEFINE_CASE(INCR);
405 DEFINE_CASE(DECR);
406
407 default:
Alyssa Rosenzweigdcde5bd2019-08-20 11:24:32 -0700408 pandecode_msg("XXX: invalid stencil op %X\n", op);
409 return "";
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000410 }
411}
412
413#undef DEFINE_CASE
414
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -0700415static char *pandecode_attr_mode_short(enum mali_attr_mode mode)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000416{
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700417 switch(mode) {
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -0700418 /* TODO: Combine to just "instanced" once this can be done
419 * unambiguously in all known cases */
420 case MALI_ATTR_POT_DIVIDE:
421 return "instanced_pot";
422 case MALI_ATTR_MODULO:
423 return "instanced_mod";
424 case MALI_ATTR_NPOT_DIVIDE:
425 return "instanced_npot";
426 case MALI_ATTR_IMAGE:
427 return "image";
428 case MALI_ATTR_INTERNAL:
429 return "internal";
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700430 default:
Alyssa Rosenzweigdcde5bd2019-08-20 11:24:32 -0700431 pandecode_msg("XXX: invalid attribute mode %X\n", mode);
432 return "";
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700433 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000434}
435
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -0700436static const char *
437pandecode_special_varying(uint64_t v)
438{
439 switch(v) {
440 case MALI_VARYING_FRAG_COORD:
441 return "gl_FragCoord";
442 case MALI_VARYING_FRONT_FACING:
443 return "gl_FrontFacing";
444 case MALI_VARYING_POINT_COORD:
445 return "gl_PointCoord";
446 default:
447 pandecode_msg("XXX: invalid special varying %X\n", v);
448 return "";
449 }
450}
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000451
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000452#define DEFINE_CASE(name) case MALI_WRAP_## name: return "MALI_WRAP_" #name
453static char *
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -0700454pandecode_wrap_mode(enum mali_wrap_mode op)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000455{
456 switch (op) {
457 DEFINE_CASE(REPEAT);
458 DEFINE_CASE(CLAMP_TO_EDGE);
459 DEFINE_CASE(CLAMP_TO_BORDER);
460 DEFINE_CASE(MIRRORED_REPEAT);
461
462 default:
Alyssa Rosenzweigdcde5bd2019-08-20 11:24:32 -0700463 pandecode_msg("XXX: invalid wrap mode %X\n", op);
464 return "";
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000465 }
466}
467#undef DEFINE_CASE
468
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700469#define DEFINE_CASE(name) case MALI_MFBD_BLOCK_## name: return "MALI_MFBD_BLOCK_" #name
470static char *
471pandecode_mfbd_block_format(enum mali_mfbd_block_format fmt)
472{
473 switch (fmt) {
474 DEFINE_CASE(TILED);
475 DEFINE_CASE(UNKNOWN);
476 DEFINE_CASE(LINEAR);
477 DEFINE_CASE(AFBC);
478
479 default:
480 unreachable("Invalid case");
481 }
482}
483#undef DEFINE_CASE
484
Alyssa Rosenzweig358372b2019-08-09 16:04:24 -0700485#define DEFINE_CASE(name) case MALI_EXCEPTION_ACCESS_## name: return ""#name
486static char *
Alyssa Rosenzweigdcde5bd2019-08-20 11:24:32 -0700487pandecode_exception_access(enum mali_exception_access access)
Alyssa Rosenzweig358372b2019-08-09 16:04:24 -0700488{
Alyssa Rosenzweigdcde5bd2019-08-20 11:24:32 -0700489 switch (access) {
Alyssa Rosenzweig358372b2019-08-09 16:04:24 -0700490 DEFINE_CASE(NONE);
491 DEFINE_CASE(EXECUTE);
492 DEFINE_CASE(READ);
493 DEFINE_CASE(WRITE);
494
495 default:
496 unreachable("Invalid case");
497 }
498}
499#undef DEFINE_CASE
500
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700501/* Midgard's tiler descriptor is embedded within the
502 * larger FBD */
503
504static void
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700505pandecode_midgard_tiler_descriptor(
506 const struct midgard_tiler_descriptor *t,
507 unsigned width,
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700508 unsigned height,
509 bool is_fragment)
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700510{
511 pandecode_log(".tiler = {\n");
512 pandecode_indent++;
513
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700514 if (t->hierarchy_mask == MALI_TILER_DISABLED)
515 pandecode_prop("hierarchy_mask = MALI_TILER_DISABLED");
516 else
517 pandecode_prop("hierarchy_mask = 0x%" PRIx16, t->hierarchy_mask);
518
519 /* We know this name from the kernel, but we never see it nonzero */
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700520
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700521 if (t->flags)
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -0700522 pandecode_msg("XXX: unexpected tiler flags 0x%" PRIx16, t->flags);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700523
524 MEMORY_PROP(t, polygon_list);
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700525
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700526 /* The body is offset from the base of the polygon list */
527 assert(t->polygon_list_body > t->polygon_list);
528 unsigned body_offset = t->polygon_list_body - t->polygon_list;
529
530 /* It needs to fit inside the reported size */
531 assert(t->polygon_list_size >= body_offset);
532
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700533 /* Check that we fit */
534 struct pandecode_mapped_memory *plist =
535 pandecode_find_mapped_gpu_mem_containing(t->polygon_list);
536
537 assert(t->polygon_list_size <= plist->length);
538
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700539 /* Now that we've sanity checked, we'll try to calculate the sizes
540 * ourselves for comparison */
541
542 unsigned ref_header = panfrost_tiler_header_size(width, height, t->hierarchy_mask);
Alyssa Rosenzweigf5c29342019-08-19 14:30:53 -0700543 unsigned ref_size = panfrost_tiler_full_size(width, height, t->hierarchy_mask);
Alyssa Rosenzweiga8bd3ad2019-08-19 11:48:32 -0700544
545 if (!((ref_header == body_offset) && (ref_size == t->polygon_list_size))) {
546 pandecode_msg("XXX: bad polygon list size (expected %d / 0x%x)\n",
547 ref_header, ref_size);
548 pandecode_prop("polygon_list_size = 0x%x", t->polygon_list_size);
549 pandecode_msg("body offset %d\n", body_offset);
550 }
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700551
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700552 /* The tiler heap has a start and end specified -- it should be
553 * identical to what we have in the BO. The exception is if tiling is
554 * disabled. */
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700555
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700556 MEMORY_PROP(t, heap_start);
Alyssa Rosenzweig52101e42019-08-19 10:38:25 -0700557 assert(t->heap_end >= t->heap_start);
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700558
559 struct pandecode_mapped_memory *heap =
560 pandecode_find_mapped_gpu_mem_containing(t->heap_start);
561
562 unsigned heap_size = t->heap_end - t->heap_start;
Alyssa Rosenzweig13d07972019-08-19 10:56:23 -0700563
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700564 /* Tiling is enabled with a special flag */
565 unsigned hierarchy_mask = t->hierarchy_mask & MALI_HIERARCHY_MASK;
566 unsigned tiler_flags = t->hierarchy_mask ^ hierarchy_mask;
567
568 bool tiling_enabled = hierarchy_mask;
569
570 if (tiling_enabled) {
571 /* When tiling is enabled, the heap should be a tight fit */
572 unsigned heap_offset = t->heap_start - heap->gpu_va;
573 if ((heap_offset + heap_size) != heap->length) {
574 pandecode_msg("XXX: heap size %d (expected %d)\n",
575 heap_size, heap->length - heap_offset);
576 }
577
578 /* We should also have no other flags */
579 if (tiler_flags)
580 pandecode_msg("XXX: unexpected tiler %X\n", tiler_flags);
581 } else {
582 /* When tiling is disabled, we should have that flag and no others */
583
584 if (tiler_flags != MALI_TILER_DISABLED) {
585 pandecode_msg("XXX: unexpected tiler flag %X, expected MALI_TILER_DISABLED\n",
586 tiler_flags);
587 }
588
589 /* We should also have an empty heap */
590 if (heap_size) {
591 pandecode_msg("XXX: tiler heap size %d given, expected empty\n",
592 heap_size);
593 }
594
595 /* Disabled tiling is used only for clear-only jobs, which are
596 * purely FRAGMENT, so we should never see this for
597 * non-FRAGMENT descriptors. */
598
599 if (!is_fragment)
600 pandecode_msg("XXX: tiler disabled for non-FRAGMENT job\n");
601 }
602
603 /* We've never seen weights used in practice, but we know from the
604 * kernel these fields is there */
Alyssa Rosenzweig31fc52a2019-07-10 07:22:19 -0700605
606 bool nonzero_weights = false;
607
608 for (unsigned w = 0; w < ARRAY_SIZE(t->weights); ++w) {
609 nonzero_weights |= t->weights[w] != 0x0;
610 }
611
612 if (nonzero_weights) {
613 pandecode_log(".weights = {");
614
615 for (unsigned w = 0; w < ARRAY_SIZE(t->weights); ++w) {
616 pandecode_log("%d, ", t->weights[w]);
617 }
618
619 pandecode_log("},");
620 }
621
622 pandecode_indent--;
623 pandecode_log("}\n");
624}
625
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700626/* Information about the framebuffer passed back for
627 * additional analysis */
628
629struct pandecode_fbd {
630 unsigned width;
631 unsigned height;
632 unsigned rt_count;
633 bool has_extra;
634};
635
636static struct pandecode_fbd
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700637pandecode_sfbd(uint64_t gpu_va, int job_no, bool is_fragment)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000638{
639 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
640 const struct mali_single_framebuffer *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
641
Alyssa Rosenzweigd6d6d632019-08-30 17:00:09 -0700642 struct pandecode_fbd info = {
643 .has_extra = false,
644 .rt_count = 1
645 };
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700646
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +0200647 pandecode_log("struct mali_single_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000648 pandecode_indent++;
649
650 pandecode_prop("unknown1 = 0x%" PRIx32, s->unknown1);
651 pandecode_prop("unknown2 = 0x%" PRIx32, s->unknown2);
652
653 pandecode_log(".format = ");
654 pandecode_log_decoded_flags(fb_fmt_flag_info, s->format);
655 pandecode_log_cont(",\n");
656
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700657 info.width = s->width + 1;
658 info.height = s->height + 1;
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700659
660 pandecode_prop("width = MALI_POSITIVE(%" PRId16 ")", info.width);
661 pandecode_prop("height = MALI_POSITIVE(%" PRId16 ")", info.height);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000662
663 MEMORY_PROP(s, framebuffer);
664 pandecode_prop("stride = %d", s->stride);
665
666 /* Earlier in the actual commandstream -- right before width -- but we
667 * delay to flow nicer */
668
669 pandecode_log(".clear_flags = ");
670 pandecode_log_decoded_flags(clear_flag_info, s->clear_flags);
671 pandecode_log_cont(",\n");
672
673 if (s->depth_buffer | s->depth_buffer_enable) {
674 MEMORY_PROP(s, depth_buffer);
675 pandecode_prop("depth_buffer_enable = %s", DS_ENABLE(s->depth_buffer_enable));
676 }
677
678 if (s->stencil_buffer | s->stencil_buffer_enable) {
679 MEMORY_PROP(s, stencil_buffer);
680 pandecode_prop("stencil_buffer_enable = %s", DS_ENABLE(s->stencil_buffer_enable));
681 }
682
683 if (s->clear_color_1 | s->clear_color_2 | s->clear_color_3 | s->clear_color_4) {
684 pandecode_prop("clear_color_1 = 0x%" PRIx32, s->clear_color_1);
685 pandecode_prop("clear_color_2 = 0x%" PRIx32, s->clear_color_2);
686 pandecode_prop("clear_color_3 = 0x%" PRIx32, s->clear_color_3);
687 pandecode_prop("clear_color_4 = 0x%" PRIx32, s->clear_color_4);
688 }
689
690 if (s->clear_depth_1 != 0 || s->clear_depth_2 != 0 || s->clear_depth_3 != 0 || s->clear_depth_4 != 0) {
691 pandecode_prop("clear_depth_1 = %f", s->clear_depth_1);
692 pandecode_prop("clear_depth_2 = %f", s->clear_depth_2);
693 pandecode_prop("clear_depth_3 = %f", s->clear_depth_3);
694 pandecode_prop("clear_depth_4 = %f", s->clear_depth_4);
695 }
696
697 if (s->clear_stencil) {
698 pandecode_prop("clear_stencil = 0x%x", s->clear_stencil);
699 }
700
701 MEMORY_PROP(s, unknown_address_0);
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -0700702 const struct midgard_tiler_descriptor t = s->tiler;
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700703 pandecode_midgard_tiler_descriptor(&t, s->width + 1, s->height + 1, is_fragment);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000704
705 pandecode_indent--;
706 pandecode_log("};\n");
707
708 pandecode_prop("zero0 = 0x%" PRIx64, s->zero0);
709 pandecode_prop("zero1 = 0x%" PRIx64, s->zero1);
710 pandecode_prop("zero2 = 0x%" PRIx32, s->zero2);
711 pandecode_prop("zero4 = 0x%" PRIx32, s->zero4);
712
713 printf(".zero3 = {");
714
715 for (int i = 0; i < sizeof(s->zero3) / sizeof(s->zero3[0]); ++i)
716 printf("%X, ", s->zero3[i]);
717
718 printf("},\n");
719
720 printf(".zero6 = {");
721
722 for (int i = 0; i < sizeof(s->zero6) / sizeof(s->zero6[0]); ++i)
723 printf("%X, ", s->zero6[i]);
724
725 printf("},\n");
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700726
727 return info;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000728}
729
730static void
Alyssa Rosenzweig1f7dfee2019-06-19 08:55:03 -0700731pandecode_u32_slide(unsigned name, const u32 *slide, unsigned count)
732{
733 pandecode_log(".unknown%d = {", name);
734
735 for (int i = 0; i < count; ++i)
736 printf("%X, ", slide[i]);
737
738 pandecode_log("},\n");
739}
740
741#define SHORT_SLIDE(num) \
742 pandecode_u32_slide(num, s->unknown ## num, ARRAY_SIZE(s->unknown ## num))
743
744static void
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700745pandecode_compute_fbd(uint64_t gpu_va, int job_no)
746{
747 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
748 const struct mali_compute_fbd *PANDECODE_PTR_VAR(s, mem, (mali_ptr) gpu_va);
749
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +0200750 pandecode_log("struct mali_compute_fbd framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700751 pandecode_indent++;
752
Alyssa Rosenzweig1f7dfee2019-06-19 08:55:03 -0700753 SHORT_SLIDE(1);
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -0700754
755 pandecode_indent--;
756 printf("},\n");
757}
758
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700759/* Extracts the number of components associated with a Mali format */
760
761static unsigned
762pandecode_format_component_count(enum mali_format fmt)
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000763{
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700764 /* Mask out the format class */
765 unsigned top = fmt & 0b11100000;
766
767 switch (top) {
768 case MALI_FORMAT_SNORM:
769 case MALI_FORMAT_UINT:
770 case MALI_FORMAT_UNORM:
771 case MALI_FORMAT_SINT:
772 return ((fmt >> 3) & 3) + 1;
773 default:
774 /* TODO: Validate */
775 return 4;
776 }
777}
778
779/* Extracts a mask of accessed components from a 12-bit Mali swizzle */
780
781static unsigned
782pandecode_access_mask_from_channel_swizzle(unsigned swizzle)
783{
784 unsigned mask = 0;
785 assert(MALI_CHANNEL_RED == 0);
786
787 for (unsigned c = 0; c < 4; ++c) {
788 enum mali_channel chan = (swizzle >> (3*c)) & 0x7;
789
790 if (chan <= MALI_CHANNEL_ALPHA)
791 mask |= (1 << chan);
792 }
793
794 return mask;
795}
796
797/* Validates that a (format, swizzle) pair is valid, in the sense that the
798 * swizzle doesn't access any components that are undefined in the format.
799 * Returns whether the swizzle is trivial (doesn't do any swizzling) and can be
800 * omitted */
801
802static bool
803pandecode_validate_format_swizzle(enum mali_format fmt, unsigned swizzle)
804{
805 unsigned nr_comp = pandecode_format_component_count(fmt);
806 unsigned access_mask = pandecode_access_mask_from_channel_swizzle(swizzle);
807 unsigned valid_mask = (1 << nr_comp) - 1;
808 unsigned invalid_mask = ~valid_mask;
809
810 if (access_mask & invalid_mask) {
811 pandecode_msg("XXX: invalid components accessed\n");
812 return false;
813 }
814
815 /* Check for the default non-swizzling swizzle so we can suppress
816 * useless printing for the defaults */
817
818 unsigned default_swizzles[4] = {
819 MALI_CHANNEL_RED | (MALI_CHANNEL_ZERO << 3) | (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9),
820 MALI_CHANNEL_RED | (MALI_CHANNEL_GREEN << 3) | (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9),
821 MALI_CHANNEL_RED | (MALI_CHANNEL_GREEN << 3) | (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ONE << 9),
822 MALI_CHANNEL_RED | (MALI_CHANNEL_GREEN << 3) | (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ALPHA << 9)
823 };
824
825 return (swizzle == default_swizzles[nr_comp - 1]);
826}
827
828/* Maps MALI_RGBA32F to rgba32f, etc */
829
830static void
Alyssa Rosenzweig9b203952019-08-20 15:24:45 -0700831pandecode_format_short(enum mali_format fmt, bool srgb)
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700832{
833 /* We want a type-like format, so cut off the initial MALI_ */
834 char *format = pandecode_format(fmt);
835 format += strlen("MALI_");
836
837 unsigned len = strlen(format);
838 char *lower_format = calloc(1, len + 1);
839
840 for (unsigned i = 0; i < len; ++i)
841 lower_format[i] = tolower(format[i]);
842
Alyssa Rosenzweig9b203952019-08-20 15:24:45 -0700843 /* Sanity check sRGB flag is applied to RGB, per the name */
844 if (srgb && lower_format[0] != 'r')
845 pandecode_msg("XXX: sRGB applied to non-colour format\n");
846
847 /* Just prefix with an s, so you get formats like srgba8_unorm */
848 if (srgb)
849 pandecode_log_cont("s");
850
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700851 pandecode_log_cont("%s", lower_format);
852 free(lower_format);
853}
854
855static void
856pandecode_swizzle(unsigned swizzle, enum mali_format format)
857{
858 /* First, do some validation */
859 bool trivial_swizzle = pandecode_validate_format_swizzle(
860 format, swizzle);
861
862 if (trivial_swizzle)
863 return;
864
865 /* Next, print the swizzle */
866 pandecode_log_cont(".");
867
868 static const char components[] = "rgba01";
869
870 for (unsigned c = 0; c < 4; ++c) {
871 enum mali_channel chan = (swizzle >> (3 * c)) & 0x7;
872
873 if (chan >= MALI_CHANNEL_RESERVED_0) {
874 pandecode_log("XXX: invalid swizzle channel %d\n", chan);
875 continue;
876 }
877 pandecode_log_cont("%c", components[chan]);
878 }
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000879}
880
881static void
882pandecode_rt_format(struct mali_rt_format format)
883{
884 pandecode_log(".format = {\n");
885 pandecode_indent++;
886
887 pandecode_prop("unk1 = 0x%" PRIx32, format.unk1);
888 pandecode_prop("unk2 = 0x%" PRIx32, format.unk2);
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700889 pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
890
891 pandecode_prop("block = %s",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700892 pandecode_mfbd_block_format(format.block));
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000893
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -0700894 /* TODO: Map formats so we can check swizzles and print nicely */
895 pandecode_log("swizzle");
896 pandecode_swizzle(format.swizzle, MALI_RGBA8_UNORM);
897 pandecode_log_cont(",\n");
898
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000899 pandecode_prop("nr_channels = MALI_POSITIVE(%d)",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -0700900 MALI_NEGATIVE(format.nr_channels));
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000901
902 pandecode_log(".flags = ");
903 pandecode_log_decoded_flags(mfbd_fmt_flag_info, format.flags);
904 pandecode_log_cont(",\n");
905
Alyssa Rosenzweige49204c2019-08-20 11:11:46 -0700906 /* In theory, the no_preload bit can be cleared to enable MFBD preload,
907 * which is a faster hardware-based alternative to the wallpaper method
908 * to preserve framebuffer contents across frames. In practice, MFBD
909 * preload is buggy on Midgard, and so this is a chicken bit. If this
910 * bit isn't set, most likely something broke unrelated to preload */
911
912 if (!format.no_preload) {
913 pandecode_msg("XXX: buggy MFBD preload enabled - chicken bit should be clear\n");
914 pandecode_prop("no_preload = 0x%" PRIx32, format.no_preload);
915 }
Alyssa Rosenzweigb78e04c2019-08-14 16:01:38 -0700916
917 if (format.zero)
918 pandecode_prop("zero = 0x%" PRIx32, format.zero);
Alyssa Rosenzweigf9430472019-02-24 06:22:23 +0000919
920 pandecode_indent--;
921 pandecode_log("},\n");
922}
923
924static void
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700925pandecode_render_target(uint64_t gpu_va, unsigned job_no, const struct bifrost_framebuffer *fb)
926{
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +0200927 pandecode_log("struct bifrost_render_target rts_list_%"PRIx64"_%d[] = {\n", gpu_va, job_no);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700928 pandecode_indent++;
929
930 for (int i = 0; i < MALI_NEGATIVE(fb->rt_count_1); i++) {
931 mali_ptr rt_va = gpu_va + i * sizeof(struct bifrost_render_target);
932 struct pandecode_mapped_memory *mem =
933 pandecode_find_mapped_gpu_mem_containing(rt_va);
934 const struct bifrost_render_target *PANDECODE_PTR_VAR(rt, mem, (mali_ptr) rt_va);
935
936 pandecode_log("{\n");
937 pandecode_indent++;
938
939 pandecode_rt_format(rt->format);
940
Tomeu Vizosob26c2b42019-06-25 08:21:15 +0200941 if (rt->format.block == MALI_MFBD_BLOCK_AFBC) {
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700942 pandecode_log(".afbc = {\n");
943 pandecode_indent++;
944
945 char *a = pointer_as_memory_reference(rt->afbc.metadata);
946 pandecode_prop("metadata = %s", a);
947 free(a);
948
949 pandecode_prop("stride = %d", rt->afbc.stride);
950 pandecode_prop("unk = 0x%" PRIx32, rt->afbc.unk);
951
952 pandecode_indent--;
953 pandecode_log("},\n");
Alyssa Rosenzweigc9b62332019-08-20 11:06:07 -0700954 } else if (rt->afbc.metadata || rt->afbc.stride || rt->afbc.unk) {
955 pandecode_msg("XXX: AFBC disabled but AFBC field set (0x%lX, 0x%x, 0x%x)\n",
956 rt->afbc.metadata,
957 rt->afbc.stride,
958 rt->afbc.unk);
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700959 }
960
961 MEMORY_PROP(rt, framebuffer);
962 pandecode_prop("framebuffer_stride = %d", rt->framebuffer_stride);
963
964 if (rt->clear_color_1 | rt->clear_color_2 | rt->clear_color_3 | rt->clear_color_4) {
965 pandecode_prop("clear_color_1 = 0x%" PRIx32, rt->clear_color_1);
966 pandecode_prop("clear_color_2 = 0x%" PRIx32, rt->clear_color_2);
967 pandecode_prop("clear_color_3 = 0x%" PRIx32, rt->clear_color_3);
968 pandecode_prop("clear_color_4 = 0x%" PRIx32, rt->clear_color_4);
969 }
970
971 if (rt->zero1 || rt->zero2 || rt->zero3) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -0700972 pandecode_msg("XXX: render target zeros tripped\n");
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -0700973 pandecode_prop("zero1 = 0x%" PRIx64, rt->zero1);
974 pandecode_prop("zero2 = 0x%" PRIx32, rt->zero2);
975 pandecode_prop("zero3 = 0x%" PRIx32, rt->zero3);
976 }
977
978 pandecode_indent--;
979 pandecode_log("},\n");
980 }
981
982 pandecode_indent--;
983 pandecode_log("};\n");
984}
985
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700986static struct pandecode_fbd
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -0700987pandecode_mfbd_bfr(uint64_t gpu_va, int job_no, bool is_fragment)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000988{
989 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
990 const struct bifrost_framebuffer *PANDECODE_PTR_VAR(fb, mem, (mali_ptr) gpu_va);
991
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -0700992 struct pandecode_fbd info;
993
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +0000994 if (fb->sample_locations) {
995 /* The blob stores all possible sample locations in a single buffer
996 * allocated on startup, and just switches the pointer when switching
997 * MSAA state. For now, we just put the data into the cmdstream, but we
998 * should do something like what the blob does with a real driver.
999 *
1000 * There seem to be 32 slots for sample locations, followed by another
1001 * 16. The second 16 is just the center location followed by 15 zeros
1002 * in all the cases I've identified (maybe shader vs. depth/color
1003 * samples?).
1004 */
1005
1006 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(fb->sample_locations);
1007
1008 const u16 *PANDECODE_PTR_VAR(samples, smem, fb->sample_locations);
1009
1010 pandecode_log("uint16_t sample_locations_%d[] = {\n", job_no);
1011 pandecode_indent++;
1012
1013 for (int i = 0; i < 32 + 16; i++) {
1014 pandecode_log("%d, %d,\n", samples[2 * i], samples[2 * i + 1]);
1015 }
1016
1017 pandecode_indent--;
1018 pandecode_log("};\n");
1019 }
1020
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02001021 pandecode_log("struct bifrost_framebuffer framebuffer_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001022 pandecode_indent++;
1023
1024 pandecode_prop("unk0 = 0x%x", fb->unk0);
1025
1026 if (fb->sample_locations)
1027 pandecode_prop("sample_locations = sample_locations_%d", job_no);
1028
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -07001029 /* Assume that unknown1 was emitted in the last job for
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001030 * now */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001031 MEMORY_PROP(fb, unknown1);
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -07001032
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001033 info.width = fb->width1 + 1;
1034 info.height = fb->height1 + 1;
1035 info.rt_count = fb->rt_count_1 + 1;
1036
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001037 pandecode_prop("width1 = MALI_POSITIVE(%d)", fb->width1 + 1);
1038 pandecode_prop("height1 = MALI_POSITIVE(%d)", fb->height1 + 1);
1039 pandecode_prop("width2 = MALI_POSITIVE(%d)", fb->width2 + 1);
1040 pandecode_prop("height2 = MALI_POSITIVE(%d)", fb->height2 + 1);
1041
1042 pandecode_prop("unk1 = 0x%x", fb->unk1);
1043 pandecode_prop("unk2 = 0x%x", fb->unk2);
1044 pandecode_prop("rt_count_1 = MALI_POSITIVE(%d)", fb->rt_count_1 + 1);
1045 pandecode_prop("rt_count_2 = %d", fb->rt_count_2);
1046
Alyssa Rosenzweigac689462019-06-14 11:14:01 -07001047 pandecode_log(".mfbd_flags = ");
1048 pandecode_log_decoded_flags(mfbd_flag_info, fb->mfbd_flags);
1049 pandecode_log_cont(",\n");
1050
Alyssa Rosenzweig3752f762019-08-20 11:25:29 -07001051 if (fb->clear_stencil)
1052 pandecode_prop("clear_stencil = 0x%x", fb->clear_stencil);
1053
1054 if (fb->clear_depth)
1055 pandecode_prop("clear_depth = %f", fb->clear_depth);
1056
1057 /* TODO: What is this? Let's not blow up.. */
1058 if (fb->unknown2 != 0x1F)
1059 pandecode_prop("unknown2 = 0x%x", fb->unknown2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001060
1061 pandecode_prop("unknown2 = 0x%x", fb->unknown2);
1062 MEMORY_PROP(fb, scratchpad);
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -07001063 const struct midgard_tiler_descriptor t = fb->tiler;
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -07001064 pandecode_midgard_tiler_descriptor(&t, fb->width1 + 1, fb->height1 + 1, is_fragment);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001065
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -07001066 if (fb->zero3 || fb->zero4) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001067 pandecode_msg("XXX: framebuffer zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001068 pandecode_prop("zero3 = 0x%" PRIx32, fb->zero3);
1069 pandecode_prop("zero4 = 0x%" PRIx32, fb->zero4);
Alyssa Rosenzweig85e745f2019-06-12 09:33:06 -07001070 }
1071
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001072 pandecode_indent--;
1073 pandecode_log("};\n");
1074
1075 gpu_va += sizeof(struct bifrost_framebuffer);
1076
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001077 info.has_extra = (fb->mfbd_flags & MALI_MFBD_EXTRA) && is_fragment;
1078
1079 if (info.has_extra) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001080 mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
1081 const struct bifrost_fb_extra *PANDECODE_PTR_VAR(fbx, mem, (mali_ptr) gpu_va);
1082
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02001083 pandecode_log("struct bifrost_fb_extra fb_extra_%"PRIx64"_%d = {\n", gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001084 pandecode_indent++;
1085
1086 MEMORY_PROP(fbx, checksum);
1087
1088 if (fbx->checksum_stride)
1089 pandecode_prop("checksum_stride = %d", fbx->checksum_stride);
1090
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +00001091 pandecode_log(".flags = ");
1092 pandecode_log_decoded_flags(mfbd_extra_flag_info, fbx->flags);
1093 pandecode_log_cont(",\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001094
Alyssa Rosenzweig587ad372019-03-09 00:45:23 +00001095 if (fbx->flags & MALI_EXTRA_AFBC_ZS) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001096 pandecode_log(".ds_afbc = {\n");
1097 pandecode_indent++;
1098
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -07001099 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil_afbc_metadata);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001100 pandecode_prop("depth_stencil_afbc_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001101 fbx->ds_afbc.depth_stencil_afbc_stride);
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -07001102 MEMORY_PROP_DIR(fbx->ds_afbc, depth_stencil);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001103
1104 if (fbx->ds_afbc.zero1 || fbx->ds_afbc.padding) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001105 pandecode_msg("XXX: Depth/stencil AFBC zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001106 pandecode_prop("zero1 = 0x%" PRIx32,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001107 fbx->ds_afbc.zero1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001108 pandecode_prop("padding = 0x%" PRIx64,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001109 fbx->ds_afbc.padding);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001110 }
1111
1112 pandecode_indent--;
1113 pandecode_log("},\n");
1114 } else {
1115 pandecode_log(".ds_linear = {\n");
1116 pandecode_indent++;
1117
1118 if (fbx->ds_linear.depth) {
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -07001119 MEMORY_PROP_DIR(fbx->ds_linear, depth);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001120 pandecode_prop("depth_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001121 fbx->ds_linear.depth_stride);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001122 }
1123
1124 if (fbx->ds_linear.stencil) {
Alyssa Rosenzweig0c1874a2019-07-12 08:47:35 -07001125 MEMORY_PROP_DIR(fbx->ds_linear, stencil);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001126 pandecode_prop("stencil_stride = %d",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001127 fbx->ds_linear.stencil_stride);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001128 }
1129
1130 if (fbx->ds_linear.depth_stride_zero ||
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001131 fbx->ds_linear.stencil_stride_zero ||
1132 fbx->ds_linear.zero1 || fbx->ds_linear.zero2) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001133 pandecode_msg("XXX: Depth/stencil zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001134 pandecode_prop("depth_stride_zero = 0x%x",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001135 fbx->ds_linear.depth_stride_zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001136 pandecode_prop("stencil_stride_zero = 0x%x",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001137 fbx->ds_linear.stencil_stride_zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001138 pandecode_prop("zero1 = 0x%" PRIx32,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001139 fbx->ds_linear.zero1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001140 pandecode_prop("zero2 = 0x%" PRIx32,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001141 fbx->ds_linear.zero2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001142 }
1143
1144 pandecode_indent--;
1145 pandecode_log("},\n");
1146 }
1147
1148 if (fbx->zero3 || fbx->zero4) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001149 pandecode_msg("XXX: fb_extra zeros tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001150 pandecode_prop("zero3 = 0x%" PRIx64, fbx->zero3);
1151 pandecode_prop("zero4 = 0x%" PRIx64, fbx->zero4);
1152 }
1153
1154 pandecode_indent--;
1155 pandecode_log("};\n");
1156
1157 gpu_va += sizeof(struct bifrost_fb_extra);
1158 }
1159
Alyssa Rosenzweig897110a2019-08-19 14:47:50 -07001160 if (is_fragment)
Alyssa Rosenzweig8c88bd02019-06-11 14:56:30 -07001161 pandecode_render_target(gpu_va, job_no, fb);
Alyssa Rosenzweiga9fc1c82019-06-23 11:29:46 -07001162
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07001163 return info;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001164}
1165
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -07001166/* Just add a comment decoding the shift/odd fields forming the padded vertices
1167 * count */
1168
1169static void
1170pandecode_padded_vertices(unsigned shift, unsigned k)
1171{
1172 unsigned odd = 2*k + 1;
1173 unsigned pot = 1 << shift;
1174 pandecode_msg("padded_num_vertices = %d\n", odd * pot);
1175}
1176
1177/* Given a magic divisor, recover what we were trying to divide by.
1178 *
1179 * Let m represent the magic divisor. By definition, m is an element on Z, whre
1180 * 0 <= m < 2^N, for N bits in m.
1181 *
1182 * Let q represent the number we would like to divide by.
1183 *
1184 * By definition of a magic divisor for N-bit unsigned integers (a number you
1185 * multiply by to magically get division), m is a number such that:
1186 *
1187 * (m * x) & (2^N - 1) = floor(x/q).
1188 * for all x on Z where 0 <= x < 2^N
1189 *
1190 * Ignore the case where any of the above values equals zero; it is irrelevant
1191 * for our purposes (instanced arrays).
1192 *
1193 * Choose x = q. Then:
1194 *
1195 * (m * x) & (2^N - 1) = floor(x/q).
1196 * (m * q) & (2^N - 1) = floor(q/q).
1197 *
1198 * floor(q/q) = floor(1) = 1, therefore:
1199 *
1200 * (m * q) & (2^N - 1) = 1
1201 *
1202 * Recall the identity that the bitwise AND of one less than a power-of-two
1203 * equals the modulo with that power of two, i.e. for all x:
1204 *
1205 * x & (2^N - 1) = x % N
1206 *
1207 * Therefore:
1208 *
1209 * mq % (2^N) = 1
1210 *
1211 * By definition, a modular multiplicative inverse of a number m is the number
1212 * q such that with respect to a modulos M:
1213 *
1214 * mq % M = 1
1215 *
1216 * Therefore, q is the modular multiplicative inverse of m with modulus 2^N.
1217 *
1218 */
1219
1220static void
1221pandecode_magic_divisor(uint32_t magic, unsigned shift, unsigned orig_divisor, unsigned extra)
1222{
Alyssa Rosenzweigd07c8462019-07-22 08:34:26 -07001223#if 0
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -07001224 /* Compute the modular inverse of `magic` with respect to 2^(32 -
1225 * shift) the most lame way possible... just repeatedly add.
1226 * Asymptoptically slow but nobody cares in practice, unless you have
1227 * massive numbers of vertices or high divisors. */
1228
1229 unsigned inverse = 0;
1230
1231 /* Magic implicitly has the highest bit set */
1232 magic |= (1 << 31);
1233
1234 /* Depending on rounding direction */
1235 if (extra)
1236 magic++;
1237
1238 for (;;) {
1239 uint32_t product = magic * inverse;
1240
1241 if (shift) {
1242 product >>= shift;
1243 }
1244
1245 if (product == 1)
1246 break;
1247
1248 ++inverse;
1249 }
1250
1251 pandecode_msg("dividing by %d (maybe off by two)\n", inverse);
1252
1253 /* Recall we're supposed to divide by (gl_level_divisor *
1254 * padded_num_vertices) */
1255
1256 unsigned padded_num_vertices = inverse / orig_divisor;
1257
1258 pandecode_msg("padded_num_vertices = %d\n", padded_num_vertices);
Alyssa Rosenzweigd07c8462019-07-22 08:34:26 -07001259#endif
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -07001260}
1261
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001262static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001263pandecode_attributes(const struct pandecode_mapped_memory *mem,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001264 mali_ptr addr, int job_no, char *suffix,
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -07001265 int count, bool varying, enum mali_job_type job_type)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001266{
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -07001267 char *prefix = varying ? "varying" : "attribute";
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001268 assert(addr);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001269
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07001270 if (!count) {
1271 pandecode_msg("warn: No %s records\n", prefix);
Alyssa Rosenzweig5ad83012019-08-08 09:23:29 -07001272 return;
1273 }
1274
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001275 union mali_attr *attr = pandecode_fetch_gpu_mem(mem, addr, sizeof(union mali_attr) * count);
1276
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001277 for (int i = 0; i < count; ++i) {
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -07001278 /* First, check for special records */
1279 if (attr[i].elements < MALI_VARYING_SPECIAL) {
1280 /* Special records are always varyings */
1281
1282 if (!varying)
1283 pandecode_msg("XXX: Special varying in attribute field\n");
1284
1285 if (job_type != JOB_TYPE_TILER)
1286 pandecode_msg("XXX: Special varying in non-FS\n");
1287
1288 /* We're special, so all fields should be zero */
1289 unsigned zero = attr[i].stride | attr[i].size;
1290 zero |= attr[i].shift | attr[i].extra_flags;
1291
1292 if (zero)
1293 pandecode_msg("XXX: Special varying has non-zero fields\n");
1294 else {
1295 /* Print the special varying name */
1296 pandecode_log("varying_%d = %s;", i, pandecode_special_varying(attr[i].elements));
1297 continue;
1298 }
1299 }
1300
Alyssa Rosenzweigbe5e30c2019-08-20 15:59:03 -07001301 enum mali_attr_mode mode = attr[i].elements & 7;
1302
1303 if (mode == MALI_ATTR_UNUSED)
1304 pandecode_msg("XXX: unused attribute record\n");
1305
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -07001306 /* For non-linear records, we need to print the type of record */
1307 if (mode != MALI_ATTR_LINEAR)
1308 pandecode_log_cont("%s ", pandecode_attr_mode_short(mode));
1309
1310 /* Print the name to link with attr_meta */
1311 pandecode_log_cont("%s_%d", prefix, i);
1312
1313 /* Print the stride and size */
1314 pandecode_log_cont("<%u>[%u]", attr[i].stride, attr[i].size);
1315
Alyssa Rosenzweigcaec0b32019-08-22 13:09:00 -07001316 /* TODO: Sanity check the quotient itself. It must be equal to
1317 * (or be greater than, if the driver added padding) the padded
1318 * vertex count. */
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -07001319
1320 /* Finally, print the pointer */
Alyssa Rosenzweigbe5e30c2019-08-20 15:59:03 -07001321 mali_ptr raw_elements = attr[i].elements & ~7;
1322 char *a = pointer_as_memory_reference(raw_elements);
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -07001323 pandecode_log_cont(" = (%s);\n", a);
Alyssa Rosenzweigbe5e30c2019-08-20 15:59:03 -07001324 free(a);
1325
Alyssa Rosenzweig62e66732019-08-20 16:02:38 -07001326 /* Check the pointer */
1327 pandecode_validate_buffer(raw_elements, attr[i].size);
1328
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -07001329 /* shift/extra_flags exist only for instanced */
1330 if (attr[i].shift | attr[i].extra_flags) {
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001331 /* These are set to random values by the blob for
1332 * varyings, most likely a symptom of uninitialized
1333 * memory where the hardware masked the bug. As such we
1334 * put this at a warning, not an error. */
1335
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -07001336 if (mode == MALI_ATTR_LINEAR)
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001337 pandecode_msg("warn: instancing fields set for linear\n");
Alyssa Rosenzweigfc69a5c2019-08-21 08:05:02 -07001338
1339 pandecode_prop("shift = %d", attr[i].shift);
1340 pandecode_prop("extra_flags = %d", attr[i].extra_flags);
1341 }
Alyssa Rosenzweige9e22542019-06-27 10:18:22 -07001342
1343 /* Decode further where possible */
1344
1345 if (mode == MALI_ATTR_MODULO) {
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -07001346 pandecode_padded_vertices(
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001347 attr[i].shift,
1348 attr[i].extra_flags);
Alyssa Rosenzweige9e22542019-06-27 10:18:22 -07001349 }
1350
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001351 if (mode == MALI_ATTR_NPOT_DIVIDE) {
1352 i++;
1353 pandecode_log("{\n");
1354 pandecode_indent++;
1355 pandecode_prop("unk = 0x%x", attr[i].unk);
1356 pandecode_prop("magic_divisor = 0x%08x", attr[i].magic_divisor);
1357 if (attr[i].zero != 0)
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001358 pandecode_prop("XXX: zero tripped (0x%x)\n", attr[i].zero);
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001359 pandecode_prop("divisor = %d", attr[i].divisor);
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -07001360 pandecode_magic_divisor(attr[i].magic_divisor, attr[i - 1].shift, attr[i].divisor, attr[i - 1].extra_flags);
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001361 pandecode_indent--;
1362 pandecode_log("}, \n");
1363 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001364
1365 }
1366
Alyssa Rosenzweiga68fe4b2019-08-21 11:43:13 -07001367 pandecode_log("\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001368}
1369
1370static mali_ptr
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001371pandecode_shader_address(const char *name, mali_ptr ptr)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001372{
1373 /* TODO: Decode flags */
1374 mali_ptr shader_ptr = ptr & ~15;
1375
1376 char *a = pointer_as_memory_reference(shader_ptr);
1377 pandecode_prop("%s = (%s) | %d", name, a, (int) (ptr & 15));
1378 free(a);
1379
1380 return shader_ptr;
1381}
1382
1383static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001384pandecode_stencil(const char *name, const struct mali_stencil_test *stencil)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001385{
Alyssa Rosenzweig9ce45ac2019-08-21 08:59:57 -07001386 unsigned any_nonzero =
1387 stencil->ref | stencil->mask | stencil->func |
1388 stencil->sfail | stencil->dpfail | stencil->dppass;
1389
1390 if (any_nonzero == 0)
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07001391 return;
1392
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -07001393 const char *func = pandecode_func(stencil->func);
1394 const char *sfail = pandecode_stencil_op(stencil->sfail);
1395 const char *dpfail = pandecode_stencil_op(stencil->dpfail);
1396 const char *dppass = pandecode_stencil_op(stencil->dppass);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001397
1398 if (stencil->zero)
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001399 pandecode_msg("XXX: stencil zero tripped: %X\n", stencil->zero);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001400
1401 pandecode_log(".stencil_%s = {\n", name);
1402 pandecode_indent++;
1403 pandecode_prop("ref = %d", stencil->ref);
1404 pandecode_prop("mask = 0x%02X", stencil->mask);
1405 pandecode_prop("func = %s", func);
1406 pandecode_prop("sfail = %s", sfail);
1407 pandecode_prop("dpfail = %s", dpfail);
1408 pandecode_prop("dppass = %s", dppass);
1409 pandecode_indent--;
1410 pandecode_log("},\n");
1411}
1412
1413static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001414pandecode_blend_equation(const struct mali_blend_equation *blend)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001415{
1416 if (blend->zero1)
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001417 pandecode_msg("XXX: blend zero tripped: %X\n", blend->zero1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001418
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001419 pandecode_log(".equation = {\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001420 pandecode_indent++;
1421
1422 pandecode_prop("rgb_mode = 0x%X", blend->rgb_mode);
1423 pandecode_prop("alpha_mode = 0x%X", blend->alpha_mode);
1424
1425 pandecode_log(".color_mask = ");
1426 pandecode_log_decoded_flags(mask_flag_info, blend->color_mask);
1427 pandecode_log_cont(",\n");
1428
1429 pandecode_indent--;
1430 pandecode_log("},\n");
1431}
1432
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001433/* Decodes a Bifrost blend constant. See the notes in bifrost_blend_rt */
1434
1435static unsigned
1436decode_bifrost_constant(u16 constant)
1437{
1438 float lo = (float) (constant & 0xFF);
1439 float hi = (float) (constant >> 8);
1440
1441 return (hi / 255.0) + (lo / 65535.0);
1442}
1443
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001444static mali_ptr
1445pandecode_bifrost_blend(void *descs, int job_no, int rt_no)
1446{
1447 struct bifrost_blend_rt *b =
1448 ((struct bifrost_blend_rt *) descs) + rt_no;
1449
1450 pandecode_log("struct bifrost_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1451 pandecode_indent++;
1452
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001453 pandecode_prop("flags = 0x%" PRIx16, b->flags);
1454 pandecode_prop("constant = 0x%" PRIx8 " /* %f */",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001455 b->constant, decode_bifrost_constant(b->constant));
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001456
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001457 /* TODO figure out blend shader enable bit */
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001458 pandecode_blend_equation(&b->equation);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001459 pandecode_prop("unk2 = 0x%" PRIx16, b->unk2);
1460 pandecode_prop("index = 0x%" PRIx16, b->index);
1461 pandecode_prop("shader = 0x%" PRIx32, b->shader);
1462
1463 pandecode_indent--;
1464 pandecode_log("},\n");
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001465
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001466 return 0;
1467}
1468
1469static mali_ptr
1470pandecode_midgard_blend(union midgard_blend *blend, bool is_shader)
1471{
Alyssa Rosenzweig9ce45ac2019-08-21 08:59:57 -07001472 /* constant/equation is in a union */
1473 if (!blend->shader)
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07001474 return 0;
1475
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001476 pandecode_log(".blend = {\n");
1477 pandecode_indent++;
1478
1479 if (is_shader) {
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001480 pandecode_shader_address("shader", blend->shader);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001481 } else {
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001482 pandecode_blend_equation(&blend->equation);
Alyssa Rosenzweigae705382019-05-18 20:48:43 +00001483 pandecode_prop("constant = %f", blend->constant);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001484 }
1485
1486 pandecode_indent--;
1487 pandecode_log("},\n");
1488
1489 /* Return blend shader to disassemble if present */
1490 return is_shader ? (blend->shader & ~0xF) : 0;
1491}
1492
1493static mali_ptr
1494pandecode_midgard_blend_mrt(void *descs, int job_no, int rt_no)
1495{
1496 struct midgard_blend_rt *b =
1497 ((struct midgard_blend_rt *) descs) + rt_no;
1498
1499 /* Flags determine presence of blend shader */
1500 bool is_shader = (b->flags & 0xF) >= 0x2;
1501
1502 pandecode_log("struct midgard_blend_rt blend_rt_%d_%d = {\n", job_no, rt_no);
1503 pandecode_indent++;
1504
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001505 pandecode_prop("flags = 0x%" PRIx64, b->flags);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001506
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -07001507 union midgard_blend blend = b->blend;
1508 mali_ptr shader = pandecode_midgard_blend(&blend, is_shader);
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00001509
1510 pandecode_indent--;
1511 pandecode_log("};\n");
1512
1513 return shader;
1514}
1515
Alyssa Rosenzweig2208eb92019-08-20 13:59:26 -07001516/* Attributes and varyings have descriptor records, which contain information
1517 * about their format and ordering with the attribute/varying buffers. We'll
1518 * want to validate that the combinations specified are self-consistent.
1519 */
1520
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001521static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001522pandecode_attribute_meta(int job_no, int count, const struct mali_vertex_tiler_postfix *v, bool varying, char *suffix)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001523{
1524 char base[128];
1525 char *prefix = varying ? "varying" : "attribute";
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001526 unsigned max_index = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001527 snprintf(base, sizeof(base), "%s_meta", prefix);
1528
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001529 struct mali_attr_meta *attr_meta;
Alyssa Rosenzweig26ed4312019-08-22 11:21:35 -07001530 mali_ptr p = varying ? v->varying_meta : v->attribute_meta;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001531
1532 struct pandecode_mapped_memory *attr_mem = pandecode_find_mapped_gpu_mem_containing(p);
1533
1534 for (int i = 0; i < count; ++i, p += sizeof(struct mali_attr_meta)) {
1535 attr_meta = pandecode_fetch_gpu_mem(attr_mem, p,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001536 sizeof(*attr_mem));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001537
Alyssa Rosenzweiga94fb782019-08-20 13:33:39 -07001538 /* If the record is discard, it should be zero for everything else */
1539
1540 if (attr_meta->format == MALI_VARYING_DISCARD) {
1541 uint64_t zero =
1542 attr_meta->index |
1543 attr_meta->unknown1 |
1544 attr_meta->unknown3 |
1545 attr_meta->src_offset;
1546
1547 if (zero)
1548 pandecode_msg("XXX: expected empty record for varying discard\n");
1549
1550 /* We want to look for a literal 0000 swizzle -- this
1551 * is not encoded with all zeroes, however */
1552
1553 enum mali_channel z = MALI_CHANNEL_ZERO;
1554 unsigned zero_swizzle = z | (z << 3) | (z << 6) | (z << 9);
1555 bool good_swizzle = attr_meta->swizzle == zero_swizzle;
1556
1557 if (!good_swizzle)
1558 pandecode_msg("XXX: expected zero swizzle for discard\n");
1559
1560 if (!varying)
1561 pandecode_msg("XXX: cannot discard attribute\n");
1562
1563 /* If we're all good, omit the record */
1564 if (!zero && varying && good_swizzle) {
1565 pandecode_log("/* discarded varying */\n");
1566 continue;
1567 }
1568 }
1569
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07001570 if (attr_meta->index > max_index)
1571 max_index = attr_meta->index;
Alyssa Rosenzweig2208eb92019-08-20 13:59:26 -07001572
Alyssa Rosenzweig00be5d72019-08-20 13:19:40 -07001573 if (attr_meta->unknown1 != 0x2) {
1574 pandecode_msg("XXX: expected unknown1 = 0x2\n");
1575 pandecode_prop("unknown1 = 0x%" PRIx64, (u64) attr_meta->unknown1);
1576 }
1577
1578 if (attr_meta->unknown3) {
1579 pandecode_msg("XXX: unexpected unknown3 set\n");
1580 pandecode_prop("unknown3 = 0x%" PRIx64, (u64) attr_meta->unknown3);
1581 }
1582
Alyssa Rosenzweig9b203952019-08-20 15:24:45 -07001583 pandecode_format_short(attr_meta->format, false);
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -07001584 pandecode_log_cont(" %s_%u", prefix, attr_meta->index);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001585
Alyssa Rosenzweige09392f2019-08-20 14:34:09 -07001586 if (attr_meta->src_offset)
1587 pandecode_log_cont("[%u]", attr_meta->src_offset);
1588
1589 pandecode_swizzle(attr_meta->swizzle, attr_meta->format);
1590
1591 pandecode_log_cont(";\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001592 }
1593
Alyssa Rosenzweiga68fe4b2019-08-21 11:43:13 -07001594 pandecode_log("\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001595
Alyssa Rosenzweig9e66ff32019-07-31 11:52:52 -07001596 return count ? (max_index + 1) : 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001597}
1598
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001599/* return bits [lo, hi) of word */
1600static u32
1601bits(u32 word, u32 lo, u32 hi)
1602{
1603 if (hi - lo >= 32)
1604 return word; // avoid undefined behavior with the shift
1605
1606 return (word >> lo) & ((1 << (hi - lo)) - 1);
1607}
1608
1609static void
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001610pandecode_vertex_tiler_prefix(struct mali_vertex_tiler_prefix *p, int job_no, bool noninstanced)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001611{
1612 pandecode_log_cont("{\n");
1613 pandecode_indent++;
1614
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001615 /* Decode invocation_count. See the comment before the definition of
1616 * invocation_count for an explanation.
1617 */
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001618
1619 unsigned size_x = bits(p->invocation_count, 0, p->size_y_shift) + 1;
1620 unsigned size_y = bits(p->invocation_count, p->size_y_shift, p->size_z_shift) + 1;
1621 unsigned size_z = bits(p->invocation_count, p->size_z_shift, p->workgroups_x_shift) + 1;
1622
1623 unsigned groups_x = bits(p->invocation_count, p->workgroups_x_shift, p->workgroups_y_shift) + 1;
1624 unsigned groups_y = bits(p->invocation_count, p->workgroups_y_shift, p->workgroups_z_shift) + 1;
1625 unsigned groups_z = bits(p->invocation_count, p->workgroups_z_shift, 32) + 1;
1626
1627 /* Even though we have this decoded, we want to ensure that the
1628 * representation is "unique" so we don't lose anything by printing only
1629 * the final result. More specifically, we need to check that we were
1630 * passed something in canonical form, since the definition per the
1631 * hardware is inherently not unique. How? Well, take the resulting
1632 * decode and pack it ourselves! If it is bit exact with what we
1633 * decoded, we're good to go. */
1634
1635 struct mali_vertex_tiler_prefix ref;
1636 panfrost_pack_work_groups_compute(&ref, groups_x, groups_y, groups_z, size_x, size_y, size_z, noninstanced);
1637
1638 bool canonical =
1639 (p->invocation_count == ref.invocation_count) &&
1640 (p->size_y_shift == ref.size_y_shift) &&
1641 (p->size_z_shift == ref.size_z_shift) &&
1642 (p->workgroups_x_shift == ref.workgroups_x_shift) &&
1643 (p->workgroups_y_shift == ref.workgroups_y_shift) &&
Alyssa Rosenzweig6c67bd02019-08-16 16:31:34 -07001644 (p->workgroups_z_shift == ref.workgroups_z_shift) &&
1645 (p->workgroups_x_shift_2 == ref.workgroups_x_shift_2);
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001646
1647 if (!canonical) {
1648 pandecode_msg("XXX: non-canonical workgroups packing\n");
1649 pandecode_msg("expected: %X, %d, %d, %d, %d, %d\n",
1650 ref.invocation_count,
1651 ref.size_y_shift,
1652 ref.size_z_shift,
1653 ref.workgroups_x_shift,
1654 ref.workgroups_y_shift,
Alyssa Rosenzweig6c67bd02019-08-16 16:31:34 -07001655 ref.workgroups_z_shift,
1656 ref.workgroups_x_shift_2);
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001657
1658 pandecode_prop("invocation_count = 0x%" PRIx32, p->invocation_count);
1659 pandecode_prop("size_y_shift = %d", p->size_y_shift);
1660 pandecode_prop("size_z_shift = %d", p->size_z_shift);
1661 pandecode_prop("workgroups_x_shift = %d", p->workgroups_x_shift);
1662 pandecode_prop("workgroups_y_shift = %d", p->workgroups_y_shift);
1663 pandecode_prop("workgroups_z_shift = %d", p->workgroups_z_shift);
Alyssa Rosenzweig6c67bd02019-08-16 16:31:34 -07001664 pandecode_prop("workgroups_x_shift_2 = %d", p->workgroups_x_shift_2);
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07001665 }
1666
1667 /* Regardless, print the decode */
1668 pandecode_msg("size (%d, %d, %d), count (%d, %d, %d)\n",
1669 size_x, size_y, size_z,
1670 groups_x, groups_y, groups_z);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001671
1672 /* TODO: Decode */
Alyssa Rosenzweig2608da12019-06-19 09:35:57 -07001673 if (p->unknown_draw)
1674 pandecode_prop("unknown_draw = 0x%" PRIx32, p->unknown_draw);
1675
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001676 pandecode_prop("workgroups_x_shift_3 = 0x%" PRIx32, p->workgroups_x_shift_3);
1677
Alyssa Rosenzweigd9f33952019-08-16 13:30:39 -07001678 if (p->draw_mode != MALI_DRAW_NONE)
1679 pandecode_prop("draw_mode = %s", pandecode_draw_mode(p->draw_mode));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001680
1681 /* Index count only exists for tiler jobs anyway */
1682
1683 if (p->index_count)
1684 pandecode_prop("index_count = MALI_POSITIVE(%" PRId32 ")", p->index_count + 1);
1685
Alyssa Rosenzweigf38ce6e2019-08-21 16:06:23 -07001686
1687 unsigned index_raw_size = (p->unknown_draw & MALI_DRAW_INDEXED_SIZE);
1688 index_raw_size >>= MALI_DRAW_INDEXED_SHIFT;
1689
1690 /* Validate an index buffer is present if we need one. TODO: verify
1691 * relationship between invocation_count and index_count */
1692
1693 if (p->indices) {
1694 unsigned count = p->index_count;
1695
1696 /* Grab the size */
1697 unsigned size = (index_raw_size == 0x3) ? 4 : index_raw_size;
1698
1699 /* Ensure we got a size, and if so, validate the index buffer
1700 * is large enough to hold a full set of indices of the given
1701 * size */
1702
1703 if (!index_raw_size)
1704 pandecode_msg("XXX: index size missing\n");
1705 else
1706 pandecode_validate_buffer(p->indices, count * size);
1707 } else if (index_raw_size)
1708 pandecode_msg("XXX: unexpected index size %u\n", index_raw_size);
1709
Rohan Garg16edd562019-07-17 18:50:13 +02001710 if (p->offset_bias_correction)
1711 pandecode_prop("offset_bias_correction = %d", p->offset_bias_correction);
Alyssa Rosenzweig4fcd3182019-03-31 04:15:46 +00001712
Alyssa Rosenzweigc0642eb2019-08-20 13:21:28 -07001713 /* TODO: Figure out what this is. It's not zero */
1714 pandecode_prop("zero1 = 0x%" PRIx32, p->zero1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001715
1716 pandecode_indent--;
1717 pandecode_log("},\n");
1718}
1719
1720static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001721pandecode_uniform_buffers(mali_ptr pubufs, int ubufs_count, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001722{
1723 struct pandecode_mapped_memory *umem = pandecode_find_mapped_gpu_mem_containing(pubufs);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001724 struct mali_uniform_buffer_meta *PANDECODE_PTR_VAR(ubufs, umem, pubufs);
1725
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001726 for (int i = 0; i < ubufs_count; i++) {
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001727 unsigned size = (ubufs[i].size + 1) * 16;
1728 mali_ptr addr = ubufs[i].ptr << 2;
1729
1730 pandecode_validate_buffer(addr, size);
1731
1732 char *ptr = pointer_as_memory_reference(ubufs[i].ptr << 2);
Alyssa Rosenzweig6ec33b42019-08-21 11:46:06 -07001733 pandecode_log("ubuf_%d[%u] = %s;\n", i, size, ptr);
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07001734 free(ptr);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001735 }
1736
Alyssa Rosenzweig6ec33b42019-08-21 11:46:06 -07001737 pandecode_log("\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001738}
1739
1740static void
Alyssa Rosenzweigae84f162019-08-22 11:30:13 -07001741pandecode_uniforms(mali_ptr uniforms, unsigned uniform_count)
1742{
1743 pandecode_validate_buffer(uniforms, uniform_count * 16);
1744
1745 char *ptr = pointer_as_memory_reference(uniforms);
1746 pandecode_log("vec4 uniforms[%u] = %s;\n", uniform_count, ptr);
1747 free(ptr);
1748}
1749
1750static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07001751pandecode_scratchpad(uintptr_t pscratchpad, int job_no, char *suffix)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001752{
1753
1754 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(pscratchpad);
1755
1756 struct bifrost_scratchpad *PANDECODE_PTR_VAR(scratchpad, mem, pscratchpad);
1757
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07001758 if (scratchpad->zero) {
1759 pandecode_msg("XXX: scratchpad zero tripped");
1760 pandecode_prop("zero = 0x%x\n", scratchpad->zero);
1761 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001762
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02001763 pandecode_log("struct bifrost_scratchpad scratchpad_%"PRIx64"_%d%s = {\n", pscratchpad, job_no, suffix);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001764 pandecode_indent++;
1765
1766 pandecode_prop("flags = 0x%x", scratchpad->flags);
1767 MEMORY_PROP(scratchpad, gpu_scratchpad);
1768
1769 pandecode_indent--;
1770 pandecode_log("};\n");
1771}
1772
Alyssa Rosenzweigc4a4f3d2019-08-14 09:19:54 -07001773static unsigned shader_id = 0;
1774
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001775static struct midgard_disasm_stats
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001776pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
Alyssa Rosenzweig9b067d92019-08-21 14:28:36 -07001777 bool is_bifrost)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001778{
1779 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(shader_ptr);
1780 uint8_t *PANDECODE_PTR_VAR(code, mem, shader_ptr);
1781
1782 /* Compute maximum possible size */
1783 size_t sz = mem->length - (shader_ptr - mem->gpu_va);
1784
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001785 /* Print some boilerplate to clearly denote the assembly (which doesn't
1786 * obey indentation rules), and actually do the disassembly! */
1787
1788 printf("\n\n");
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001789
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001790 struct midgard_disasm_stats stats;
Alyssa Rosenzweigc4a4f3d2019-08-14 09:19:54 -07001791
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001792 if (is_bifrost) {
1793 disassemble_bifrost(code, sz, false);
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001794
1795 /* TODO: Extend stats to Bifrost */
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001796 stats.texture_count = -128;
1797 stats.sampler_count = -128;
1798 stats.attribute_count = -128;
1799 stats.varying_count = -128;
1800 stats.uniform_count = -128;
1801 stats.uniform_buffer_count = -128;
1802 stats.work_count = -128;
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001803
1804 stats.instruction_count = 0;
1805 stats.bundle_count = 0;
1806 stats.quadword_count = 0;
Alyssa Rosenzweigd6d6d632019-08-30 17:00:09 -07001807 stats.helper_invocations = false;
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001808 } else {
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001809 stats = disassemble_midgard(code, sz);
Alyssa Rosenzweig50382df2019-05-18 18:58:56 +00001810 }
1811
Alyssa Rosenzweig58fc2602019-08-21 14:00:46 -07001812 /* Print shader-db stats */
1813
1814 unsigned nr_threads =
1815 (stats.work_count <= 4) ? 4 :
1816 (stats.work_count <= 8) ? 2 :
1817 1;
1818
1819 printf("shader%d - %s shader: "
1820 "%u inst, %u bundles, %u quadwords, "
1821 "%u registers, %u threads, 0 loops\n\n\n",
1822 shader_id++,
1823 (type == JOB_TYPE_TILER) ? "FRAGMENT" : "VERTEX",
1824 stats.instruction_count, stats.bundle_count, stats.quadword_count,
1825 stats.work_count, nr_threads);
1826
1827
1828 return stats;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00001829}
1830
1831static void
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001832pandecode_texture(mali_ptr u,
1833 struct pandecode_mapped_memory *tmem,
1834 unsigned job_no, unsigned tex)
1835{
1836 struct mali_texture_descriptor *PANDECODE_PTR_VAR(t, tmem, u);
1837
1838 pandecode_log("struct mali_texture_descriptor texture_descriptor_%"PRIx64"_%d_%d = {\n", u, job_no, tex);
1839 pandecode_indent++;
1840
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001841 struct mali_texture_format f = t->format;
1842
Alyssa Rosenzweig024f9cf2019-08-20 14:58:46 -07001843 /* See the definiton of enum mali_texture_type */
1844
Alyssa Rosenzweig68b90302019-08-20 15:46:39 -07001845 bool is_cube = f.type == MALI_TEX_CUBE;
1846 unsigned dimension = is_cube ? 2 : f.type;
1847
1848 pandecode_make_indent();
1849
1850 /* TODO: Are there others? */
1851 bool is_zs = f.format == MALI_Z32_UNORM;
1852
1853 /* Recall Z/S switched the meaning of linear/tiled .. */
1854 if (is_zs && f.layout == MALI_TEXTURE_LINEAR)
1855 pandecode_msg("XXX: depth/stencil cannot be tiled\n");
1856
1857 /* Print the layout. Default is linear; a modifier can denote AFBC or
1858 * u-interleaved/tiled modes */
1859
1860 if (f.layout == MALI_TEXTURE_AFBC)
1861 pandecode_log_cont("afbc");
1862 else if (f.layout == MALI_TEXTURE_TILED)
1863 pandecode_log_cont(is_zs ? "linear" : "tiled");
1864 else if (f.layout == MALI_TEXTURE_LINEAR)
1865 pandecode_log_cont("linear");
1866 else
1867 pandecode_msg("XXX: invalid texture layout 0x%X\n", f.layout);
1868
1869 pandecode_swizzle(t->swizzle, f.format);
1870 pandecode_log_cont(" ");
1871
1872 /* Distinguish cube/2D with modifier */
1873
1874 if (is_cube)
1875 pandecode_log_cont("cube ");
1876
1877 pandecode_format_short(f.format, f.srgb);
1878 pandecode_swizzle(f.swizzle, f.format);
Alyssa Rosenzweig024f9cf2019-08-20 14:58:46 -07001879
1880 /* All four width/height/depth/array_size dimensions are present
1881 * regardless of the type of texture, but it is an error to have
1882 * non-zero dimensions for unused dimensions. Verify this. array_size
1883 * can always be set, as can width. */
1884
1885 if (t->height && dimension < 2)
1886 pandecode_msg("XXX: nonzero height for <2D texture\n");
1887
1888 if (t->depth && dimension < 3)
1889 pandecode_msg("XXX: nonzero depth for <2D texture\n");
1890
1891 /* Print only the dimensions that are actually there */
1892
Alyssa Rosenzweig68b90302019-08-20 15:46:39 -07001893 pandecode_log_cont(": %d", t->width + 1);
Alyssa Rosenzweig024f9cf2019-08-20 14:58:46 -07001894
1895 if (dimension >= 2)
1896 pandecode_log_cont("x%u", t->height + 1);
1897
1898 if (dimension >= 3)
1899 pandecode_log_cont("x%u", t->depth + 1);
1900
1901 if (t->array_size)
1902 pandecode_log_cont("[%u]", t->array_size + 1);
1903
Alyssa Rosenzweig96f6b8a2019-08-20 15:24:18 -07001904 if (t->levels)
1905 pandecode_log_cont(" mip %u", t->levels);
Alyssa Rosenzweig024f9cf2019-08-20 14:58:46 -07001906
Alyssa Rosenzweig96f6b8a2019-08-20 15:24:18 -07001907 pandecode_log_cont("\n");
Alyssa Rosenzweig024f9cf2019-08-20 14:58:46 -07001908
Alyssa Rosenzweig9f15f4d2019-08-20 15:36:00 -07001909 if (f.unknown1 | f.zero) {
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001910 pandecode_msg("XXX: texture format zero tripped\n");
1911 pandecode_prop("unknown1 = %" PRId32, f.unknown1);
Alyssa Rosenzweig9f15f4d2019-08-20 15:36:00 -07001912 pandecode_prop("zero = %" PRId32, f.zero);
1913 }
1914
1915 if (!f.unknown2) {
1916 pandecode_msg("XXX: expected unknown texture bit set\n");
1917 pandecode_prop("unknown2 = %" PRId32, f.unknown1);
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001918 }
1919
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001920 if (t->swizzle_zero) {
1921 pandecode_msg("XXX: swizzle zero tripped\n");
1922 pandecode_prop("swizzle_zero = %d", t->swizzle_zero);
1923 }
1924
1925 if (t->unknown3 | t->unknown3A | t->unknown5 | t->unknown6 | t->unknown7) {
1926 pandecode_msg("XXX: texture zero tripped\n");
1927 pandecode_prop("unknown3 = %" PRId16, t->unknown3);
1928 pandecode_prop("unknown3A = %" PRId8, t->unknown3A);
1929 pandecode_prop("unknown5 = 0x%" PRIx32, t->unknown5);
1930 pandecode_prop("unknown6 = 0x%" PRIx32, t->unknown6);
1931 pandecode_prop("unknown7 = 0x%" PRIx32, t->unknown7);
1932 }
1933
1934 pandecode_log(".payload = {\n");
1935 pandecode_indent++;
1936
1937 /* A bunch of bitmap pointers follow.
1938 * We work out the correct number,
1939 * based on the mipmap/cubemap
1940 * properties, but dump extra
1941 * possibilities to futureproof */
1942
Alyssa Rosenzweig96f6b8a2019-08-20 15:24:18 -07001943 int bitmap_count = MALI_NEGATIVE(t->levels);
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001944
1945 /* Miptree for each face */
1946 if (f.type == MALI_TEX_CUBE)
1947 bitmap_count *= 6;
1948
1949 /* Array of textures */
1950 bitmap_count *= MALI_NEGATIVE(t->array_size);
1951
1952 /* Stride for each element */
Alyssa Rosenzweig9f15f4d2019-08-20 15:36:00 -07001953 if (f.manual_stride)
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001954 bitmap_count *= 2;
1955
1956 /* Sanity check the size */
1957 int max_count = sizeof(t->payload) / sizeof(t->payload[0]);
1958 assert (bitmap_count <= max_count);
1959
1960 for (int i = 0; i < bitmap_count; ++i) {
1961 /* How we dump depends if this is a stride or a pointer */
1962
Alyssa Rosenzweig9f15f4d2019-08-20 15:36:00 -07001963 if (f.manual_stride && (i & 1)) {
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07001964 /* signed 32-bit snuck in as a 64-bit pointer */
1965 uint64_t stride_set = t->payload[i];
1966 uint32_t clamped_stride = stride_set;
1967 int32_t stride = clamped_stride;
1968 assert(stride_set == clamped_stride);
1969 pandecode_log("(mali_ptr) %d /* stride */, \n", stride);
1970 } else {
1971 char *a = pointer_as_memory_reference(t->payload[i]);
1972 pandecode_log("%s, \n", a);
1973 free(a);
1974 }
1975 }
1976
1977 pandecode_indent--;
1978 pandecode_log("},\n");
1979
1980 pandecode_indent--;
1981 pandecode_log("};\n");
1982}
1983
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001984/* 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 */
1985
1986static void
1987pandecode_shader_prop(const char *name, unsigned claim, signed truth, bool fuzzy)
1988{
1989 /* Nothing to do */
1990 if (claim == truth)
1991 return;
1992
1993 if (fuzzy)
1994 assert(truth >= 0);
1995
1996 if ((truth >= 0) && !fuzzy) {
Alyssa Rosenzweigf48136e2019-08-22 09:02:48 -07001997 pandecode_msg("%s: expected %s = %d, claimed %u\n",
1998 (truth < claim) ? "warn" : "XXX",
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07001999 name, truth, claim);
2000 } else if ((claim > -truth) && !fuzzy) {
2001 pandecode_msg("XXX: expected %s <= %u, claimed %u\n",
2002 name, -truth, claim);
2003 } else if (fuzzy && (claim < truth))
2004 pandecode_msg("XXX: expected %s >= %u, claimed %u\n",
2005 name, truth, claim);
2006
2007 pandecode_log(".%s = %" PRId16, name, claim);
2008
2009 if (fuzzy)
2010 pandecode_log_cont(" /* %u used */", truth);
2011
2012 pandecode_log_cont(",\n");
2013}
2014
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07002015static void
2016pandecode_vertex_tiler_postfix_pre(
2017 const struct mali_vertex_tiler_postfix *p,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002018 int job_no, enum mali_job_type job_type,
2019 char *suffix, bool is_bifrost)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002020{
2021 mali_ptr shader_meta_ptr = (u64) (uintptr_t) (p->_shader_upper << 4);
2022 struct pandecode_mapped_memory *attr_mem;
2023
2024 /* On Bifrost, since the tiler heap (for tiler jobs) and the scratchpad
2025 * are the only things actually needed from the FBD, vertex/tiler jobs
2026 * no longer reference the FBD -- instead, this field points to some
2027 * info about the scratchpad.
2028 */
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002029
2030 struct pandecode_fbd fbd_info = {
2031 /* Default for Bifrost */
2032 .rt_count = 1
2033 };
2034
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002035 if (is_bifrost)
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002036 pandecode_scratchpad(p->framebuffer & ~FBD_TYPE, job_no, suffix);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002037 else if (p->framebuffer & MALI_MFBD)
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002038 fbd_info = pandecode_mfbd_bfr((u64) ((uintptr_t) p->framebuffer) & FBD_MASK, job_no, false);
Alyssa Rosenzweig0aa5d892019-06-19 08:41:51 -07002039 else if (job_type == JOB_TYPE_COMPUTE)
2040 pandecode_compute_fbd((u64) (uintptr_t) p->framebuffer, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002041 else
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002042 fbd_info = pandecode_sfbd((u64) (uintptr_t) p->framebuffer, job_no, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002043
2044 int varying_count = 0, attribute_count = 0, uniform_count = 0, uniform_buffer_count = 0;
2045 int texture_count = 0, sampler_count = 0;
2046
2047 if (shader_meta_ptr) {
2048 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(shader_meta_ptr);
2049 struct mali_shader_meta *PANDECODE_PTR_VAR(s, smem, shader_meta_ptr);
2050
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07002051 /* Disassemble ahead-of-time to get stats. Initialize with
2052 * stats for the missing-shader case so we get validation
2053 * there, too */
2054
2055 struct midgard_disasm_stats info = {
2056 .texture_count = 0,
2057 .sampler_count = 0,
2058 .attribute_count = 0,
2059 .varying_count = 0,
2060 .work_count = 1,
2061
2062 .uniform_count = -128,
2063 .uniform_buffer_count = 0
2064 };
Alyssa Rosenzweig9b067d92019-08-21 14:28:36 -07002065
2066 if (s->shader & ~0xF)
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07002067 info = pandecode_shader_disassemble(s->shader & ~0xF, job_no, job_type, is_bifrost);
Alyssa Rosenzweig9b067d92019-08-21 14:28:36 -07002068
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02002069 pandecode_log("struct mali_shader_meta shader_meta_%"PRIx64"_%d%s = {\n", shader_meta_ptr, job_no, suffix);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002070 pandecode_indent++;
2071
2072 /* Save for dumps */
2073 attribute_count = s->attribute_count;
2074 varying_count = s->varying_count;
2075 texture_count = s->texture_count;
2076 sampler_count = s->sampler_count;
2077
2078 if (is_bifrost) {
2079 uniform_count = s->bifrost2.uniform_count;
2080 uniform_buffer_count = s->bifrost1.uniform_buffer_count;
2081 } else {
Alyssa Rosenzweigd7473e22019-08-21 14:15:05 -07002082 uniform_count = s->midgard1.uniform_count;
Alyssa Rosenzweigbd2fc602019-06-20 16:41:39 -07002083 uniform_buffer_count = s->midgard1.uniform_buffer_count;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002084 }
2085
Alyssa Rosenzweig9b067d92019-08-21 14:28:36 -07002086 pandecode_shader_address("shader", s->shader);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002087
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07002088 pandecode_shader_prop("texture_count", s->texture_count, info.texture_count, false);
2089 pandecode_shader_prop("sampler_count", s->sampler_count, info.sampler_count, false);
2090 pandecode_shader_prop("attribute_count", s->attribute_count, info.attribute_count, false);
2091 pandecode_shader_prop("varying_count", s->varying_count, info.varying_count, false);
2092 pandecode_shader_prop("uniform_buffer_count",
2093 uniform_buffer_count,
2094 info.uniform_buffer_count, true);
2095
2096 if (!is_bifrost) {
2097 pandecode_shader_prop("uniform_count",
2098 uniform_count,
2099 info.uniform_count, false);
2100
2101 pandecode_shader_prop("work_count",
2102 s->midgard1.work_count, info.work_count, false);
2103 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002104
2105 if (is_bifrost) {
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07002106 pandecode_prop("bifrost1.unk1 = 0x%" PRIx32, s->bifrost1.unk1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002107 } else {
Alyssa Rosenzweig21a85fd2019-08-22 16:36:10 -07002108 bool helpers = s->midgard1.flags & MALI_HELPER_INVOCATIONS;
2109 s->midgard1.flags &= ~MALI_HELPER_INVOCATIONS;
2110
2111 if (helpers != info.helper_invocations) {
2112 pandecode_msg("XXX: expected helpers %u but got %u\n",
2113 info.helper_invocations, helpers);
2114 }
2115
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07002116 pandecode_log(".midgard1.flags = ");
Alyssa Rosenzweigbd2fc602019-06-20 16:41:39 -07002117 pandecode_log_decoded_flags(shader_midgard1_flag_info, s->midgard1.flags);
Alyssa Rosenzweig7cccc892019-04-05 01:17:21 +00002118 pandecode_log_cont(",\n");
2119
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07002120 pandecode_prop("midgard1.unknown2 = 0x%" PRIx32, s->midgard1.unknown2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002121 }
2122
2123 if (s->depth_units || s->depth_factor) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002124 pandecode_prop("depth_factor = %f", s->depth_factor);
Alyssa Rosenzweig7a36c722019-07-11 07:01:56 -07002125 pandecode_prop("depth_units = %f", s->depth_units);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002126 }
2127
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002128 if (s->alpha_coverage) {
2129 bool invert_alpha_coverage = s->alpha_coverage & 0xFFF0;
2130 uint16_t inverted_coverage = invert_alpha_coverage ? ~s->alpha_coverage : s->alpha_coverage;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002131
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002132 pandecode_prop("alpha_coverage = %sMALI_ALPHA_COVERAGE(%f)",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002133 invert_alpha_coverage ? "~" : "",
2134 MALI_GET_ALPHA_COVERAGE(inverted_coverage));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002135 }
2136
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002137 if (s->unknown2_3 || s->unknown2_4) {
2138 pandecode_log(".unknown2_3 = ");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002139
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002140 int unknown2_3 = s->unknown2_3;
2141 int unknown2_4 = s->unknown2_4;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002142
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002143 /* We're not quite sure what these flags mean without the depth test, if anything */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002144
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002145 if (unknown2_3 & (MALI_DEPTH_TEST | MALI_DEPTH_FUNC_MASK)) {
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -07002146 const char *func = pandecode_func(MALI_GET_DEPTH_FUNC(unknown2_3));
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002147 unknown2_3 &= ~MALI_DEPTH_FUNC_MASK;
2148
2149 pandecode_log_cont("MALI_DEPTH_FUNC(%s) | ", func);
2150 }
2151
2152 pandecode_log_decoded_flags(u3_flag_info, unknown2_3);
2153 pandecode_log_cont(",\n");
2154
2155 pandecode_log(".unknown2_4 = ");
2156 pandecode_log_decoded_flags(u4_flag_info, unknown2_4);
2157 pandecode_log_cont(",\n");
2158 }
2159
2160 if (s->stencil_mask_front || s->stencil_mask_back) {
2161 pandecode_prop("stencil_mask_front = 0x%02X", s->stencil_mask_front);
2162 pandecode_prop("stencil_mask_back = 0x%02X", s->stencil_mask_back);
2163 }
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002164
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002165 pandecode_stencil("front", &s->stencil_front);
2166 pandecode_stencil("back", &s->stencil_back);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002167
2168 if (is_bifrost) {
2169 pandecode_log(".bifrost2 = {\n");
2170 pandecode_indent++;
2171
2172 pandecode_prop("unk3 = 0x%" PRIx32, s->bifrost2.unk3);
2173 pandecode_prop("preload_regs = 0x%" PRIx32, s->bifrost2.preload_regs);
2174 pandecode_prop("uniform_count = %" PRId32, s->bifrost2.uniform_count);
2175 pandecode_prop("unk4 = 0x%" PRIx32, s->bifrost2.unk4);
2176
2177 pandecode_indent--;
2178 pandecode_log("},\n");
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002179 } else if (s->midgard2.unknown2_7) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002180 pandecode_log(".midgard2 = {\n");
2181 pandecode_indent++;
2182
2183 pandecode_prop("unknown2_7 = 0x%" PRIx32, s->midgard2.unknown2_7);
2184 pandecode_indent--;
2185 pandecode_log("},\n");
2186 }
2187
Alyssa Rosenzweigb6d46d02019-06-19 09:31:16 -07002188 if (s->unknown2_8)
2189 pandecode_prop("unknown2_8 = 0x%" PRIx32, s->unknown2_8);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002190
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002191 if (!is_bifrost) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00002192 /* TODO: Blend shaders routing/disasm */
2193
Alyssa Rosenzweig9ffe0612019-07-12 08:45:51 -07002194 union midgard_blend blend = s->blend;
2195 pandecode_midgard_blend(&blend, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002196 }
2197
2198 pandecode_indent--;
2199 pandecode_log("};\n");
2200
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00002201 /* MRT blend fields are used whenever MFBD is used, with
2202 * per-RT descriptors */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002203
2204 if (job_type == JOB_TYPE_TILER) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00002205 void* blend_base = (void *) (s + 1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002206
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002207 for (unsigned i = 0; i < fbd_info.rt_count; i++) {
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00002208 mali_ptr shader = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002209
Alyssa Rosenzweig050b9342019-05-04 21:57:01 +00002210 if (is_bifrost)
2211 shader = pandecode_bifrost_blend(blend_base, job_no, i);
2212 else
2213 shader = pandecode_midgard_blend_mrt(blend_base, job_no, i);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002214
Alyssa Rosenzweig139708b2019-08-21 14:04:05 -07002215 if (shader & ~0xF) {
2216 struct midgard_disasm_stats stats =
Alyssa Rosenzweig9b067d92019-08-21 14:28:36 -07002217 pandecode_shader_disassemble(shader, job_no, job_type, false);
Alyssa Rosenzweig139708b2019-08-21 14:04:05 -07002218
2219 bool has_texture = (stats.texture_count > 0);
2220 bool has_sampler = (stats.sampler_count > 0);
2221 bool has_attribute = (stats.attribute_count > 0);
2222 bool has_varying = (stats.varying_count > 0);
2223 bool has_uniform = (stats.uniform_count > 0);
2224 bool has_ubo = (stats.uniform_buffer_count > 0);
2225
2226 if (has_texture || has_sampler)
2227 pandecode_msg("XXX: blend shader accessing textures\n");
2228
2229 if (has_attribute || has_varying)
2230 pandecode_msg("XXX: blend shader accessing interstage\n");
2231
2232 if (has_uniform || has_ubo)
2233 pandecode_msg("XXX: blend shader accessing uniforms\n");
2234 }
2235
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002236 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002237 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002238 } else
Alyssa Rosenzweig5f9a1c72019-08-21 14:16:32 -07002239 pandecode_msg("XXX: missing shader descriptor\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002240
2241 if (p->viewport) {
2242 struct pandecode_mapped_memory *fmem = pandecode_find_mapped_gpu_mem_containing(p->viewport);
2243 struct mali_viewport *PANDECODE_PTR_VAR(f, fmem, p->viewport);
2244
Tomeu Vizoso75b53a12019-07-12 16:42:52 +02002245 pandecode_log("struct mali_viewport viewport_%"PRIx64"_%d%s = {\n", p->viewport, job_no, suffix);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002246 pandecode_indent++;
2247
2248 pandecode_prop("clip_minx = %f", f->clip_minx);
2249 pandecode_prop("clip_miny = %f", f->clip_miny);
2250 pandecode_prop("clip_minz = %f", f->clip_minz);
2251 pandecode_prop("clip_maxx = %f", f->clip_maxx);
2252 pandecode_prop("clip_maxy = %f", f->clip_maxy);
2253 pandecode_prop("clip_maxz = %f", f->clip_maxz);
2254
2255 /* Only the higher coordinates are MALI_POSITIVE scaled */
2256
2257 pandecode_prop("viewport0 = { %d, %d }",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002258 f->viewport0[0], f->viewport0[1]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002259
2260 pandecode_prop("viewport1 = { MALI_POSITIVE(%d), MALI_POSITIVE(%d) }",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002261 f->viewport1[0] + 1, f->viewport1[1] + 1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002262
2263 pandecode_indent--;
2264 pandecode_log("};\n");
2265 }
2266
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07002267 unsigned max_attr_index = 0;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002268
Alyssa Rosenzweiged464e02019-08-22 13:07:01 -07002269 if (p->attribute_meta)
2270 max_attr_index = pandecode_attribute_meta(job_no, attribute_count, p, false, suffix);
2271
2272 if (p->attributes) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002273 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->attributes);
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -07002274 pandecode_attributes(attr_mem, p->attributes, job_no, suffix, max_attr_index, false, job_type);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002275 }
2276
2277 /* Varyings are encoded like attributes but not actually sent; we just
2278 * pass a zero buffer with the right stride/size set, (or whatever)
2279 * since the GPU will write to it itself */
2280
Alyssa Rosenzweig9e66ff32019-07-31 11:52:52 -07002281 if (p->varying_meta) {
2282 varying_count = pandecode_attribute_meta(job_no, varying_count, p, true, suffix);
2283 }
2284
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002285 if (p->varyings) {
2286 attr_mem = pandecode_find_mapped_gpu_mem_containing(p->varyings);
2287
2288 /* Number of descriptors depends on whether there are
2289 * non-internal varyings */
2290
Alyssa Rosenzweigf4678f32019-08-22 13:27:38 -07002291 pandecode_attributes(attr_mem, p->varyings, job_no, suffix, varying_count, true, job_type);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002292 }
2293
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002294 if (p->uniform_buffers) {
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07002295 if (uniform_buffer_count)
2296 pandecode_uniform_buffers(p->uniform_buffers, uniform_buffer_count, job_no);
2297 else
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07002298 pandecode_msg("warn: UBOs specified but not referenced\n");
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07002299 } else if (uniform_buffer_count)
2300 pandecode_msg("XXX: UBOs referenced but not specified\n");
2301
2302 /* We don't want to actually dump uniforms, but we do need to validate
2303 * that the counts we were given are sane */
2304
2305 if (p->uniforms) {
2306 if (uniform_count)
Alyssa Rosenzweigae84f162019-08-22 11:30:13 -07002307 pandecode_uniforms(p->uniforms, uniform_count);
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07002308 else
Alyssa Rosenzweigcbbf7542019-08-21 14:57:23 -07002309 pandecode_msg("warn: Uniforms specified but not referenced\n");
Alyssa Rosenzweig4aeb6942019-08-19 15:16:01 -07002310 } else if (uniform_count)
Alyssa Rosenzweigd7473e22019-08-21 14:15:05 -07002311 pandecode_msg("XXX: Uniforms referenced but not specified\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002312
2313 if (p->texture_trampoline) {
2314 struct pandecode_mapped_memory *mmem = pandecode_find_mapped_gpu_mem_containing(p->texture_trampoline);
2315
2316 if (mmem) {
2317 mali_ptr *PANDECODE_PTR_VAR(u, mmem, p->texture_trampoline);
2318
Tomeu Vizoso75b53a12019-07-12 16:42:52 +02002319 pandecode_log("uint64_t texture_trampoline_%"PRIx64"_%d[] = {\n", p->texture_trampoline, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002320 pandecode_indent++;
2321
2322 for (int tex = 0; tex < texture_count; ++tex) {
2323 mali_ptr *PANDECODE_PTR_VAR(u, mmem, p->texture_trampoline + tex * sizeof(mali_ptr));
2324 char *a = pointer_as_memory_reference(*u);
2325 pandecode_log("%s,\n", a);
2326 free(a);
2327 }
2328
2329 pandecode_indent--;
2330 pandecode_log("};\n");
2331
2332 /* Now, finally, descend down into the texture descriptor */
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07002333 for (unsigned tex = 0; tex < texture_count; ++tex) {
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002334 mali_ptr *PANDECODE_PTR_VAR(u, mmem, p->texture_trampoline + tex * sizeof(mali_ptr));
2335 struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(*u);
Alyssa Rosenzweig8fc4ca82019-08-20 14:48:55 -07002336 if (tmem)
2337 pandecode_texture(*u, tmem, job_no, tex);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002338 }
2339 }
2340 }
2341
2342 if (p->sampler_descriptor) {
2343 struct pandecode_mapped_memory *smem = pandecode_find_mapped_gpu_mem_containing(p->sampler_descriptor);
2344
2345 if (smem) {
2346 struct mali_sampler_descriptor *s;
2347
2348 mali_ptr d = p->sampler_descriptor;
2349
2350 for (int i = 0; i < sampler_count; ++i) {
2351 s = pandecode_fetch_gpu_mem(smem, d + sizeof(*s) * i, sizeof(*s));
2352
Tomeu Vizoso75b53a12019-07-12 16:42:52 +02002353 pandecode_log("struct mali_sampler_descriptor sampler_descriptor_%"PRIx64"_%d_%d = {\n", d + sizeof(*s) * i, job_no, i);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002354 pandecode_indent++;
2355
Alyssa Rosenzweigcf6cad32019-07-31 08:50:02 -07002356 pandecode_log(".filter_mode = ");
2357 pandecode_log_decoded_flags(sampler_flag_info, s->filter_mode);
2358 pandecode_log_cont(",\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002359
2360 pandecode_prop("min_lod = FIXED_16(%f)", DECODE_FIXED_16(s->min_lod));
2361 pandecode_prop("max_lod = FIXED_16(%f)", DECODE_FIXED_16(s->max_lod));
2362
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -07002363 pandecode_prop("wrap_s = %s", pandecode_wrap_mode(s->wrap_s));
2364 pandecode_prop("wrap_t = %s", pandecode_wrap_mode(s->wrap_t));
2365 pandecode_prop("wrap_r = %s", pandecode_wrap_mode(s->wrap_r));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002366
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -07002367 pandecode_prop("compare_func = %s", pandecode_alt_func(s->compare_func));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002368
2369 if (s->zero || s->zero2) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07002370 pandecode_msg("XXX: sampler zero tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002371 pandecode_prop("zero = 0x%X, 0x%X\n", s->zero, s->zero2);
2372 }
2373
Alyssa Rosenzweig17adcfc2019-06-24 09:16:11 -07002374 pandecode_prop("seamless_cube_map = %d", s->seamless_cube_map);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002375
2376 pandecode_prop("border_color = { %f, %f, %f, %f }",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002377 s->border_color[0],
2378 s->border_color[1],
2379 s->border_color[2],
2380 s->border_color[3]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002381
2382 pandecode_indent--;
2383 pandecode_log("};\n");
2384 }
2385 }
2386 }
2387}
2388
2389static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002390pandecode_vertex_tiler_postfix(const struct mali_vertex_tiler_postfix *p, int job_no, bool is_bifrost)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002391{
Alyssa Rosenzweig740f86c2019-08-16 13:28:06 -07002392 if (!(p->position_varying || p->occlusion_counter || p->flags))
2393 return;
2394
2395 pandecode_log(".postfix = {\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002396 pandecode_indent++;
2397
2398 MEMORY_PROP(p, position_varying);
Alyssa Rosenzweig740f86c2019-08-16 13:28:06 -07002399 MEMORY_PROP(p, occlusion_counter);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002400
Alyssa Rosenzweig740f86c2019-08-16 13:28:06 -07002401 if (p->flags)
2402 pandecode_prop("flags = %d", p->flags);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002403
2404 pandecode_indent--;
2405 pandecode_log("},\n");
2406}
2407
2408static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002409pandecode_vertex_only_bfr(struct bifrost_vertex_only *v)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002410{
2411 pandecode_log_cont("{\n");
2412 pandecode_indent++;
2413
2414 pandecode_prop("unk2 = 0x%x", v->unk2);
2415
2416 if (v->zero0 || v->zero1) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07002417 pandecode_msg("XXX: vertex only zero tripped");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002418 pandecode_prop("zero0 = 0x%" PRIx32, v->zero0);
2419 pandecode_prop("zero1 = 0x%" PRIx64, v->zero1);
2420 }
2421
2422 pandecode_indent--;
2423 pandecode_log("}\n");
2424}
2425
2426static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002427pandecode_tiler_heap_meta(mali_ptr gpu_va, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002428{
2429
2430 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
2431 const struct bifrost_tiler_heap_meta *PANDECODE_PTR_VAR(h, mem, gpu_va);
2432
2433 pandecode_log("struct mali_tiler_heap_meta tiler_heap_meta_%d = {\n", job_no);
2434 pandecode_indent++;
2435
2436 if (h->zero) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07002437 pandecode_msg("XXX: tiler heap zero tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002438 pandecode_prop("zero = 0x%x", h->zero);
2439 }
2440
2441 for (int i = 0; i < 12; i++) {
2442 if (h->zeros[i] != 0) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07002443 pandecode_msg("XXX: tiler heap zero %d tripped, value %x\n",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002444 i, h->zeros[i]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002445 }
2446 }
2447
2448 pandecode_prop("heap_size = 0x%x", h->heap_size);
2449 MEMORY_PROP(h, tiler_heap_start);
2450 MEMORY_PROP(h, tiler_heap_free);
2451
2452 /* this might point to the beginning of another buffer, when it's
2453 * really the end of the tiler heap buffer, so we have to be careful
Alyssa Rosenzweig17752ba2019-07-18 12:28:56 -07002454 * here. but for zero length, we need the same pointer.
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002455 */
Alyssa Rosenzweig17752ba2019-07-18 12:28:56 -07002456
2457 if (h->tiler_heap_end == h->tiler_heap_start) {
2458 MEMORY_PROP(h, tiler_heap_start);
2459 } else {
2460 char *a = pointer_as_memory_reference(h->tiler_heap_end - 1);
2461 pandecode_prop("tiler_heap_end = %s + 1", a);
2462 free(a);
2463 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002464
2465 pandecode_indent--;
2466 pandecode_log("};\n");
2467}
2468
2469static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002470pandecode_tiler_meta(mali_ptr gpu_va, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002471{
2472 struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
2473 const struct bifrost_tiler_meta *PANDECODE_PTR_VAR(t, mem, gpu_va);
2474
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002475 pandecode_tiler_heap_meta(t->tiler_heap_meta, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002476
Alyssa Rosenzweig7f26bb32019-06-13 10:25:32 -07002477 pandecode_log("struct bifrost_tiler_meta tiler_meta_%d = {\n", job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002478 pandecode_indent++;
2479
2480 if (t->zero0 || t->zero1) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07002481 pandecode_msg("XXX: tiler meta zero tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002482 pandecode_prop("zero0 = 0x%" PRIx64, t->zero0);
2483 pandecode_prop("zero1 = 0x%" PRIx64, t->zero1);
2484 }
2485
Alyssa Rosenzweig7f26bb32019-06-13 10:25:32 -07002486 pandecode_prop("hierarchy_mask = 0x%" PRIx16, t->hierarchy_mask);
2487 pandecode_prop("flags = 0x%" PRIx16, t->flags);
2488
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002489 pandecode_prop("width = MALI_POSITIVE(%d)", t->width + 1);
2490 pandecode_prop("height = MALI_POSITIVE(%d)", t->height + 1);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002491
2492 for (int i = 0; i < 12; i++) {
2493 if (t->zeros[i] != 0) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07002494 pandecode_msg("XXX: tiler heap zero %d tripped, value %" PRIx64 "\n",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002495 i, t->zeros[i]);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002496 }
2497 }
2498
2499 pandecode_indent--;
2500 pandecode_log("};\n");
2501}
2502
2503static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002504pandecode_gl_enables(uint32_t gl_enables, int job_type)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002505{
2506 pandecode_log(".gl_enables = ");
2507
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002508 pandecode_log_decoded_flags(gl_enable_flag_info, gl_enables);
2509
2510 pandecode_log_cont(",\n");
2511}
2512
2513static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002514pandecode_primitive_size(union midgard_primitive_size u, bool constant)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002515{
Alyssa Rosenzweig2608da12019-06-19 09:35:57 -07002516 if (u.pointer == 0x0)
2517 return;
2518
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002519 pandecode_log(".primitive_size = {\n");
2520 pandecode_indent++;
2521
Alyssa Rosenzweigb517e362019-03-15 03:21:27 +00002522 if (constant) {
2523 pandecode_prop("constant = %f", u.constant);
2524 } else {
2525 MEMORY_PROP((&u), pointer);
2526 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002527
2528 pandecode_indent--;
2529 pandecode_log("},\n");
2530}
2531
2532static void
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002533pandecode_tiler_only_bfr(const struct bifrost_tiler_only *t, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002534{
2535 pandecode_log_cont("{\n");
2536 pandecode_indent++;
2537
2538 /* TODO: gl_PointSize on Bifrost */
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002539 pandecode_primitive_size(t->primitive_size, true);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002540
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002541 pandecode_gl_enables(t->gl_enables, JOB_TYPE_TILER);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002542
2543 if (t->zero1 || t->zero2 || t->zero3 || t->zero4 || t->zero5
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002544 || t->zero6 || t->zero7 || t->zero8) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07002545 pandecode_msg("XXX: tiler only zero tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002546 pandecode_prop("zero1 = 0x%" PRIx64, t->zero1);
2547 pandecode_prop("zero2 = 0x%" PRIx64, t->zero2);
2548 pandecode_prop("zero3 = 0x%" PRIx64, t->zero3);
2549 pandecode_prop("zero4 = 0x%" PRIx64, t->zero4);
2550 pandecode_prop("zero5 = 0x%" PRIx64, t->zero5);
2551 pandecode_prop("zero6 = 0x%" PRIx64, t->zero6);
2552 pandecode_prop("zero7 = 0x%" PRIx32, t->zero7);
2553 pandecode_prop("zero8 = 0x%" PRIx64, t->zero8);
2554 }
2555
2556 pandecode_indent--;
2557 pandecode_log("},\n");
2558}
2559
2560static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002561pandecode_vertex_job_bfr(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002562 const struct pandecode_mapped_memory *mem,
2563 mali_ptr payload, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002564{
2565 struct bifrost_payload_vertex *PANDECODE_PTR_VAR(v, mem, payload);
2566
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002567 pandecode_vertex_tiler_postfix_pre(&v->postfix, job_no, h->job_type, "", true);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002568
2569 pandecode_log("struct bifrost_payload_vertex payload_%d = {\n", job_no);
2570 pandecode_indent++;
2571
2572 pandecode_log(".prefix = ");
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07002573 pandecode_vertex_tiler_prefix(&v->prefix, job_no, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002574
2575 pandecode_log(".vertex = ");
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002576 pandecode_vertex_only_bfr(&v->vertex);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002577
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002578 pandecode_vertex_tiler_postfix(&v->postfix, job_no, true);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002579
2580 pandecode_indent--;
2581 pandecode_log("};\n");
2582
2583 return sizeof(*v);
2584}
2585
2586static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002587pandecode_tiler_job_bfr(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002588 const struct pandecode_mapped_memory *mem,
2589 mali_ptr payload, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002590{
2591 struct bifrost_payload_tiler *PANDECODE_PTR_VAR(t, mem, payload);
2592
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002593 pandecode_vertex_tiler_postfix_pre(&t->postfix, job_no, h->job_type, "", true);
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002594 pandecode_tiler_meta(t->tiler.tiler_meta, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002595
2596 pandecode_log("struct bifrost_payload_tiler payload_%d = {\n", job_no);
2597 pandecode_indent++;
2598
2599 pandecode_log(".prefix = ");
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07002600 pandecode_vertex_tiler_prefix(&t->prefix, job_no, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002601
2602 pandecode_log(".tiler = ");
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002603 pandecode_tiler_only_bfr(&t->tiler, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002604
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002605 pandecode_vertex_tiler_postfix(&t->postfix, job_no, true);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002606
2607 pandecode_indent--;
2608 pandecode_log("};\n");
2609
2610 return sizeof(*t);
2611}
2612
2613static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002614pandecode_vertex_or_tiler_job_mdg(const struct mali_job_descriptor_header *h,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002615 const struct pandecode_mapped_memory *mem,
2616 mali_ptr payload, int job_no)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002617{
2618 struct midgard_payload_vertex_tiler *PANDECODE_PTR_VAR(v, mem, payload);
2619
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002620 pandecode_vertex_tiler_postfix_pre(&v->postfix, job_no, h->job_type, "", false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002621
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002622 pandecode_log("struct midgard_payload_vertex_tiler payload_%d = {\n", job_no);
2623 pandecode_indent++;
2624
Alyssa Rosenzweigb517e362019-03-15 03:21:27 +00002625 bool has_primitive_pointer = v->prefix.unknown_draw & MALI_DRAW_VARYING_SIZE;
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002626 pandecode_primitive_size(v->primitive_size, !has_primitive_pointer);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002627
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07002628 bool instanced = v->instance_shift || v->instance_odd;
2629 bool is_graphics = (h->job_type == JOB_TYPE_VERTEX) || (h->job_type == JOB_TYPE_TILER);
2630
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002631 pandecode_log(".prefix = ");
Alyssa Rosenzweig25ed9302019-08-16 16:22:38 -07002632 pandecode_vertex_tiler_prefix(&v->prefix, job_no, !instanced && is_graphics);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002633
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002634 pandecode_gl_enables(v->gl_enables, h->job_type);
Alyssa Rosenzweig2608da12019-06-19 09:35:57 -07002635
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -07002636 if (v->instance_shift || v->instance_odd) {
2637 pandecode_prop("instance_shift = 0x%d /* %d */",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002638 v->instance_shift, 1 << v->instance_shift);
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -07002639 pandecode_prop("instance_odd = 0x%X /* %d */",
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002640 v->instance_odd, (2 * v->instance_odd) + 1);
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -07002641
2642 pandecode_padded_vertices(v->instance_shift, v->instance_odd);
2643 }
2644
Rohan Garg16edd562019-07-17 18:50:13 +02002645 if (v->offset_start)
2646 pandecode_prop("offset_start = %d", v->offset_start);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002647
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002648 if (v->zero5) {
Alyssa Rosenzweig89c53702019-08-20 11:18:46 -07002649 pandecode_msg("XXX: midgard payload zero tripped\n");
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002650 pandecode_prop("zero5 = 0x%" PRIx64, v->zero5);
2651 }
2652
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002653 pandecode_vertex_tiler_postfix(&v->postfix, job_no, false);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002654
2655 pandecode_indent--;
2656 pandecode_log("};\n");
2657
2658 return sizeof(*v);
2659}
2660
2661static int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002662pandecode_fragment_job(const struct pandecode_mapped_memory *mem,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002663 mali_ptr payload, int job_no,
2664 bool is_bifrost)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002665{
2666 const struct mali_payload_fragment *PANDECODE_PTR_VAR(s, mem, payload);
2667
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002668 bool is_mfbd = (s->framebuffer & FBD_TYPE) == MALI_MFBD;
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002669
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002670 /* Bifrost theoretically may retain support for SFBD on compute jobs,
2671 * but for graphics workloads with a FRAGMENT payload, use MFBD */
2672
2673 if (!is_mfbd && is_bifrost)
2674 pandecode_msg("XXX: Bifrost fragment must use MFBD\n");
2675
2676 struct pandecode_fbd info;
2677
2678 if (is_mfbd)
2679 info = pandecode_mfbd_bfr(s->framebuffer & FBD_MASK, job_no, true);
2680 else
2681 info = pandecode_sfbd(s->framebuffer & FBD_MASK, job_no, true);
2682
2683 /* Compute the tag for the tagged pointer. This contains the type of
2684 * FBD (MFBD/SFBD), and in the case of an MFBD, information about which
2685 * additional structures follow the MFBD header (an extra payload or
2686 * not, as well as a count of render targets) */
2687
2688 unsigned expected_tag = is_mfbd ? MALI_MFBD : MALI_SFBD;
2689
2690 if (is_mfbd) {
2691 if (info.has_extra)
2692 expected_tag |= MALI_MFBD_TAG_EXTRA;
2693
2694 expected_tag |= (MALI_POSITIVE(info.rt_count) << 2);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002695 }
2696
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002697 if ((s->min_tile_coord | s->max_tile_coord) & ~(MALI_X_COORD_MASK | MALI_Y_COORD_MASK)) {
2698 pandecode_msg("XXX: unexpected tile coordinate bits\n");
2699 pandecode_prop("min_tile_coord = 0x%X\n", s->min_tile_coord);
2700 pandecode_prop("max_tile_coord = 0x%X\n", s->min_tile_coord);
2701 }
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002702
Alyssa Rosenzweigded9a682019-08-21 12:29:47 -07002703 /* Extract tile coordinates */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002704
Alyssa Rosenzweigded9a682019-08-21 12:29:47 -07002705 unsigned min_x = MALI_TILE_COORD_X(s->min_tile_coord) << MALI_TILE_SHIFT;
2706 unsigned min_y = MALI_TILE_COORD_Y(s->min_tile_coord) << MALI_TILE_SHIFT;
2707
2708 unsigned max_x = (MALI_TILE_COORD_X(s->max_tile_coord) + 1) << MALI_TILE_SHIFT;
2709 unsigned max_y = (MALI_TILE_COORD_Y(s->max_tile_coord) + 1) << MALI_TILE_SHIFT;
2710
2711 /* For the max, we also want the floored (rather than ceiled) version for checking */
2712
2713 unsigned max_x_f = (MALI_TILE_COORD_X(s->max_tile_coord)) << MALI_TILE_SHIFT;
2714 unsigned max_y_f = (MALI_TILE_COORD_Y(s->max_tile_coord)) << MALI_TILE_SHIFT;
2715
2716 /* Validate the coordinates are well-ordered */
2717
2718 if (min_x == max_x)
2719 pandecode_msg("XXX: empty X coordinates (%u = %u)\n", min_x, max_x);
2720 else if (min_x > max_x)
2721 pandecode_msg("XXX: misordered X coordinates (%u > %u)\n", min_x, max_x);
2722
2723 if (min_y == max_y)
2724 pandecode_msg("XXX: empty X coordinates (%u = %u)\n", min_x, max_x);
2725 else if (min_y > max_y)
2726 pandecode_msg("XXX: misordered X coordinates (%u > %u)\n", min_x, max_x);
2727
2728 /* Validate the coordinates fit inside the framebuffer. We use floor,
2729 * rather than ceil, for the max coordinates, since the tile
2730 * coordinates for something like an 800x600 framebuffer will actually
2731 * resolve to 800x608, which would otherwise trigger a Y-overflow */
2732
2733 if ((min_x > info.width) || (max_x_f > info.width))
2734 pandecode_msg("XXX: tile coordinates overflow in X direction\n");
2735
2736 if ((min_y > info.height) || (max_y_f > info.height))
2737 pandecode_msg("XXX: tile coordinates overflow in Y direction\n");
2738
2739 /* After validation, we print */
2740
2741 pandecode_log("fragment (%u, %u) ... (%u, %u)\n\n", min_x, min_y, max_x, max_y);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002742
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002743 /* The FBD is a tagged pointer */
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002744
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002745 unsigned tag = (s->framebuffer & ~FBD_MASK);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002746
Alyssa Rosenzweigf06e8f72019-08-21 12:06:50 -07002747 if (tag != expected_tag)
2748 pandecode_msg("XXX: expected FBD tag %X but got %X\n", expected_tag, tag);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002749
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002750 return sizeof(*s);
2751}
2752
2753static int job_descriptor_number = 0;
2754
2755int
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002756pandecode_jc(mali_ptr jc_gpu_va, bool bifrost)
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002757{
2758 struct mali_job_descriptor_header *h;
2759
2760 int start_number = 0;
2761
2762 bool first = true;
2763 bool last_size;
2764
2765 do {
2766 struct pandecode_mapped_memory *mem =
2767 pandecode_find_mapped_gpu_mem_containing(jc_gpu_va);
2768
2769 void *payload;
2770
2771 h = PANDECODE_PTR(mem, jc_gpu_va, struct mali_job_descriptor_header);
2772
2773 /* On Midgard, for 32-bit jobs except for fragment jobs, the
2774 * high 32-bits of the 64-bit pointer are reused to store
2775 * something else.
2776 */
2777 int offset = h->job_descriptor_size == MALI_JOB_32 &&
2778 h->job_type != JOB_TYPE_FRAGMENT ? 4 : 0;
2779 mali_ptr payload_ptr = jc_gpu_va + sizeof(*h) - offset;
2780
2781 payload = pandecode_fetch_gpu_mem(mem, payload_ptr,
Alyssa Rosenzweig7318b522019-07-10 10:36:16 -07002782 MALI_PAYLOAD_SIZE);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002783
2784 int job_no = job_descriptor_number++;
2785
2786 if (first)
2787 start_number = job_no;
2788
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02002789 pandecode_log("struct mali_job_descriptor_header job_%"PRIx64"_%d = {\n", jc_gpu_va, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002790 pandecode_indent++;
2791
Alyssa Rosenzweig0d5abfd2019-07-12 08:54:49 -07002792 pandecode_prop("job_type = %s", pandecode_job_type(h->job_type));
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002793
2794 /* Save for next job fixing */
2795 last_size = h->job_descriptor_size;
2796
2797 if (h->job_descriptor_size)
2798 pandecode_prop("job_descriptor_size = %d", h->job_descriptor_size);
2799
Alyssa Rosenzweige918dd82019-08-16 16:36:39 -07002800 if (h->exception_status && h->exception_status != 0x1)
Alyssa Rosenzweig358372b2019-08-09 16:04:24 -07002801 pandecode_prop("exception_status = %x (source ID: 0x%x access: %s exception: 0x%x)",
Tomeu Vizosofa36c192019-06-25 08:22:30 +02002802 h->exception_status,
2803 (h->exception_status >> 16) & 0xFFFF,
Alyssa Rosenzweig358372b2019-08-09 16:04:24 -07002804 pandecode_exception_access((h->exception_status >> 8) & 0x3),
Tomeu Vizosofa36c192019-06-25 08:22:30 +02002805 h->exception_status & 0xFF);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002806
2807 if (h->first_incomplete_task)
2808 pandecode_prop("first_incomplete_task = %d", h->first_incomplete_task);
2809
2810 if (h->fault_pointer)
2811 pandecode_prop("fault_pointer = 0x%" PRIx64, h->fault_pointer);
2812
2813 if (h->job_barrier)
2814 pandecode_prop("job_barrier = %d", h->job_barrier);
2815
2816 pandecode_prop("job_index = %d", h->job_index);
2817
2818 if (h->unknown_flags)
2819 pandecode_prop("unknown_flags = %d", h->unknown_flags);
2820
2821 if (h->job_dependency_index_1)
2822 pandecode_prop("job_dependency_index_1 = %d", h->job_dependency_index_1);
2823
2824 if (h->job_dependency_index_2)
2825 pandecode_prop("job_dependency_index_2 = %d", h->job_dependency_index_2);
2826
2827 pandecode_indent--;
2828 pandecode_log("};\n");
2829
2830 /* Do not touch the field yet -- decode the payload first, and
2831 * don't touch that either. This is essential for the uploads
2832 * to occur in sequence and therefore be dynamically allocated
2833 * correctly. Do note the size, however, for that related
2834 * reason. */
2835
2836 switch (h->job_type) {
2837 case JOB_TYPE_SET_VALUE: {
2838 struct mali_payload_set_value *s = payload;
Tomeu Vizoso9bef1f12019-06-25 09:20:51 +02002839 pandecode_log("struct mali_payload_set_value payload_%"PRIx64"_%d = {\n", payload_ptr, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002840 pandecode_indent++;
2841 MEMORY_PROP(s, out);
2842 pandecode_prop("unknown = 0x%" PRIX64, s->unknown);
2843 pandecode_indent--;
2844 pandecode_log("};\n");
2845
2846 break;
2847 }
2848
2849 case JOB_TYPE_TILER:
2850 case JOB_TYPE_VERTEX:
2851 case JOB_TYPE_COMPUTE:
2852 if (bifrost) {
2853 if (h->job_type == JOB_TYPE_TILER)
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002854 pandecode_tiler_job_bfr(h, mem, payload_ptr, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002855 else
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002856 pandecode_vertex_job_bfr(h, mem, payload_ptr, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002857 } else
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002858 pandecode_vertex_or_tiler_job_mdg(h, mem, payload_ptr, job_no);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002859
2860 break;
2861
2862 case JOB_TYPE_FRAGMENT:
Alyssa Rosenzweig7103baf2019-07-12 08:57:10 -07002863 pandecode_fragment_job(mem, payload_ptr, job_no, bifrost);
Alyssa Rosenzweigf6117822019-02-19 05:50:14 +00002864 break;
2865
2866 default:
2867 break;
2868 }
2869
2870 /* Handle linkage */
2871
2872 if (!first) {
2873 pandecode_log("((struct mali_job_descriptor_header *) (uintptr_t) job_%d_p)->", job_no - 1);
2874
2875 if (last_size)
2876 pandecode_log_cont("next_job_64 = job_%d_p;\n\n", job_no);
2877 else
2878 pandecode_log_cont("next_job_32 = (u32) (uintptr_t) job_%d_p;\n\n", job_no);
2879 }
2880
2881 first = false;
2882
2883 } while ((jc_gpu_va = h->job_descriptor_size ? h->next_job_64 : h->next_job_32));
2884
2885 return start_number;
2886}