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