| 1 |
/* |
| 2 |
* Copyright (C) 2017-2019 Alyssa Rosenzweig |
| 3 |
* Copyright (C) 2017-2019 Connor Abbott |
| 4 |
* Copyright (C) 2019 Collabora, Ltd. |
| 5 |
* SPDX-License-Identifier: MIT |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "decode.h" |
| 9 |
#include <ctype.h> |
| 10 |
#include <errno.h> |
| 11 |
#include <memory.h> |
| 12 |
#include <stdarg.h> |
| 13 |
#include <stdbool.h> |
| 14 |
#include <stdio.h> |
| 15 |
#include <stdlib.h> |
| 16 |
#include <genxml/gen_macros.h> |
| 17 |
#include <sys/mman.h> |
| 18 |
|
| 19 |
#include "util/set.h" |
| 20 |
#include "pan_format.h" |
| 21 |
|
| 22 |
#if PAN_ARCH <= 5 |
| 23 |
/* Midgard's tiler descriptor is embedded within the |
| 24 |
* larger FBD */ |
| 25 |
|
| 26 |
static void |
| 27 |
pandecode_midgard_tiler_descriptor(struct pandecode_context *ctx, |
| 28 |
const struct mali_tiler_context_packed *tp, |
| 29 |
const struct mali_tiler_weights_packed *wp) |
| 30 |
{ |
| 31 |
pan_unpack(tp, TILER_CONTEXT, t); |
| 32 |
DUMP_UNPACKED(ctx, TILER_CONTEXT, t, "Tiler:\n"); |
| 33 |
|
| 34 |
/* We've never seen weights used in practice, but they exist */ |
| 35 |
pan_unpack(wp, TILER_WEIGHTS, w); |
| 36 |
bool nonzero_weights = false; |
| 37 |
|
| 38 |
nonzero_weights |= w.weight0 != 0x0; |
| 39 |
nonzero_weights |= w.weight1 != 0x0; |
| 40 |
nonzero_weights |= w.weight2 != 0x0; |
| 41 |
nonzero_weights |= w.weight3 != 0x0; |
| 42 |
nonzero_weights |= w.weight4 != 0x0; |
| 43 |
nonzero_weights |= w.weight5 != 0x0; |
| 44 |
nonzero_weights |= w.weight6 != 0x0; |
| 45 |
nonzero_weights |= w.weight7 != 0x0; |
| 46 |
|
| 47 |
if (nonzero_weights) |
| 48 |
DUMP_UNPACKED(ctx, TILER_WEIGHTS, w, "Tiler Weights:\n"); |
| 49 |
} |
| 50 |
#endif |
| 51 |
|
| 52 |
#if PAN_ARCH >= 5 |
| 53 |
static const char * |
| 54 |
block_format_string(enum mali_block_format block_format) |
| 55 |
{ |
| 56 |
switch (block_format) { |
| 57 |
#if PAN_ARCH >= 7 |
| 58 |
case MALI_BLOCK_FORMAT_NO_WRITE: |
| 59 |
#else |
| 60 |
case MALI_BLOCK_FORMAT_TILED_LINEAR: |
| 61 |
#endif |
| 62 |
case MALI_BLOCK_FORMAT_TILED_U_INTERLEAVED: |
| 63 |
return "U-Tiled"; |
| 64 |
case MALI_BLOCK_FORMAT_LINEAR: |
| 65 |
return "Linear"; |
| 66 |
#if PAN_ARCH >= 10 |
| 67 |
case MALI_BLOCK_FORMAT_INTERLEAVED_64K: |
| 68 |
return "Interleaved 64K"; |
| 69 |
#endif |
| 70 |
case MALI_BLOCK_FORMAT_AFBC: |
| 71 |
return "AFBC"; |
| 72 |
#if PAN_ARCH >= 7 |
| 73 |
case MALI_BLOCK_FORMAT_AFBC_TILED: |
| 74 |
return "AFBC-Tiled"; |
| 75 |
#endif |
| 76 |
default: |
| 77 |
UNREACHABLE("unsupported block format"); |
| 78 |
return "???"; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
static void |
| 83 |
pandecode_rt(struct pandecode_context *ctx, unsigned index, uint64_t gpu_va) |
| 84 |
{ |
| 85 |
uint64_t rt_va = gpu_va + index * pan_size(RENDER_TARGET); |
| 86 |
const struct mali_render_target_packed *PANDECODE_PTR_VAR(ctx, rtp, rt_va); |
| 87 |
|
| 88 |
pan_unpack(rtp, RENDER_TARGET, rt); |
| 89 |
#if PAN_ARCH >= 10 |
| 90 |
switch (rt.rgb.writeback_mode) { |
| 91 |
case MALI_WRITEBACK_MODE_COMPAT: |
| 92 |
break; |
| 93 |
case MALI_WRITEBACK_MODE_AFRC_RGB: |
| 94 |
DUMP_UNPACKED(ctx, AFRC_RGB_RENDER_TARGET, rt.afrc_rgb, |
| 95 |
"AFRC RGB Color Render Target %d:\n", index); |
| 96 |
break; |
| 97 |
case MALI_WRITEBACK_MODE_AFRC_YUV: |
| 98 |
DUMP_UNPACKED(ctx, AFRC_YUV_RENDER_TARGET, rt.afrc_yuv, |
| 99 |
"AFRC YUV Color Render Target %d:\n", index); |
| 100 |
break; |
| 101 |
default: |
| 102 |
UNREACHABLE("Invalid writeback mode"); |
| 103 |
} |
| 104 |
#endif |
| 105 |
|
| 106 |
enum mali_block_format writeback_block_format = rt.rgb.writeback_block_format; |
| 107 |
switch (writeback_block_format) { |
| 108 |
#if PAN_ARCH >= 7 |
| 109 |
case MALI_BLOCK_FORMAT_NO_WRITE: |
| 110 |
#else |
| 111 |
case MALI_BLOCK_FORMAT_TILED_LINEAR: |
| 112 |
#endif |
| 113 |
case MALI_BLOCK_FORMAT_TILED_U_INTERLEAVED: |
| 114 |
case MALI_BLOCK_FORMAT_LINEAR: |
| 115 |
#if PAN_ARCH >= 10 |
| 116 |
case MALI_BLOCK_FORMAT_INTERLEAVED_64K: |
| 117 |
#endif |
| 118 |
if (rt.rgb.yuv_enable) { |
| 119 |
DUMP_UNPACKED(ctx, YUV_RENDER_TARGET, rt.yuv, |
| 120 |
"%s YUV Color Render Target %d:\n", |
| 121 |
block_format_string(writeback_block_format), |
| 122 |
index); |
| 123 |
} else { |
| 124 |
DUMP_UNPACKED(ctx, RGB_RENDER_TARGET, rt.rgb, |
| 125 |
"%s RGB Color Render Target %d:\n", |
| 126 |
block_format_string(writeback_block_format), |
| 127 |
index); |
| 128 |
} |
| 129 |
break; |
| 130 |
#if PAN_ARCH >= 7 |
| 131 |
case MALI_BLOCK_FORMAT_AFBC_TILED: |
| 132 |
#endif |
| 133 |
case MALI_BLOCK_FORMAT_AFBC: |
| 134 |
#if PAN_ARCH >= 6 |
| 135 |
if (rt.rgb.yuv_enable) { |
| 136 |
DUMP_UNPACKED(ctx, AFBC_YUV_RENDER_TARGET, rt.afbc_yuv, |
| 137 |
"%s YUV Color Render Target %d:\n", |
| 138 |
block_format_string(writeback_block_format), |
| 139 |
index); |
| 140 |
break; |
| 141 |
} |
| 142 |
#else |
| 143 |
assert(!rt.rgb.yuv_enable); |
| 144 |
#endif |
| 145 |
|
| 146 |
DUMP_UNPACKED(ctx, AFBC_RGB_RENDER_TARGET, rt.afbc_rgb, |
| 147 |
"%s RGB Color Render Target %d:\n", |
| 148 |
block_format_string(writeback_block_format), |
| 149 |
index); |
| 150 |
break; |
| 151 |
} |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
static void |
| 156 |
pandecode_rts(struct pandecode_context *ctx, uint64_t gpu_va, |
| 157 |
const struct MALI_FRAMEBUFFER_PARAMETERS *fb) |
| 158 |
{ |
| 159 |
pandecode_log(ctx, "Color Render Targets @%" PRIx64 ":\n", gpu_va); |
| 160 |
ctx->indent++; |
| 161 |
|
| 162 |
for (int i = 0; i < (fb->render_target_count); i++) |
| 163 |
pandecode_rt(ctx, i, gpu_va); |
| 164 |
|
| 165 |
ctx->indent--; |
| 166 |
pandecode_log(ctx, "\n"); |
| 167 |
} |
| 168 |
|
| 169 |
static void |
| 170 |
pandecode_zs_crc_ext(struct pandecode_context *ctx, uint64_t gpu_va) |
| 171 |
{ |
| 172 |
const struct mali_zs_crc_extension_packed *PANDECODE_PTR_VAR( |
| 173 |
ctx, zs_crc_packed, (uint64_t)gpu_va); |
| 174 |
|
| 175 |
pan_unpack(zs_crc_packed, ZS_CRC_EXTENSION, zs_crc); |
| 176 |
DUMP_UNPACKED(ctx, CRC, zs_crc.crc, "CRC:\n"); |
| 177 |
|
| 178 |
switch (zs_crc.zs.block_format) { |
| 179 |
#if PAN_ARCH >= 7 |
| 180 |
case MALI_BLOCK_FORMAT_NO_WRITE: |
| 181 |
#else |
| 182 |
case MALI_BLOCK_FORMAT_TILED_LINEAR: |
| 183 |
#endif |
| 184 |
case MALI_BLOCK_FORMAT_TILED_U_INTERLEAVED: |
| 185 |
case MALI_BLOCK_FORMAT_LINEAR: |
| 186 |
#if PAN_ARCH >= 10 |
| 187 |
case MALI_BLOCK_FORMAT_INTERLEAVED_64K: |
| 188 |
#endif |
| 189 |
DUMP_UNPACKED(ctx, ZS_TARGET, zs_crc.zs, "ZS:\n"); |
| 190 |
break; |
| 191 |
#if PAN_ARCH >= 7 |
| 192 |
case MALI_BLOCK_FORMAT_AFBC_TILED: |
| 193 |
#endif |
| 194 |
case MALI_BLOCK_FORMAT_AFBC: |
| 195 |
DUMP_UNPACKED(ctx, AFBC_ZS_TARGET, zs_crc.afbc_zs, "ZS:\n"); |
| 196 |
break; |
| 197 |
|
| 198 |
default: |
| 199 |
UNREACHABLE("Invalid block format"); |
| 200 |
} |
| 201 |
|
| 202 |
switch (zs_crc.s.block_format) { |
| 203 |
#if PAN_ARCH >= 7 |
| 204 |
case MALI_BLOCK_FORMAT_NO_WRITE: |
| 205 |
#else |
| 206 |
case MALI_BLOCK_FORMAT_TILED_LINEAR: |
| 207 |
#endif |
| 208 |
case MALI_BLOCK_FORMAT_TILED_U_INTERLEAVED: |
| 209 |
case MALI_BLOCK_FORMAT_LINEAR: |
| 210 |
#if PAN_ARCH >= 10 |
| 211 |
case MALI_BLOCK_FORMAT_INTERLEAVED_64K: |
| 212 |
#endif |
| 213 |
DUMP_UNPACKED(ctx, S_TARGET, zs_crc.s, "S:\n"); |
| 214 |
break; |
| 215 |
#if PAN_ARCH >= 9 |
| 216 |
case MALI_BLOCK_FORMAT_AFBC_TILED: |
| 217 |
case MALI_BLOCK_FORMAT_AFBC: |
| 218 |
DUMP_UNPACKED(ctx, AFBC_S_TARGET, zs_crc.afbc_s, "S:\n"); |
| 219 |
break; |
| 220 |
#endif |
| 221 |
|
| 222 |
default: |
| 223 |
UNREACHABLE("Invalid block format"); |
| 224 |
} |
| 225 |
|
| 226 |
pandecode_log(ctx, "\n"); |
| 227 |
} |
| 228 |
#endif |
| 229 |
|
| 230 |
|
| 231 |
#if PAN_ARCH >= 6 |
| 232 |
static void |
| 233 |
pandecode_sample_locations(struct pandecode_context *ctx, const void *fb) |
| 234 |
{ |
| 235 |
pan_section_unpack(fb, FRAMEBUFFER, PARAMETERS, params); |
| 236 |
|
| 237 |
const uint16_t *PANDECODE_PTR_VAR(ctx, samples, params.sample_locations); |
| 238 |
|
| 239 |
pandecode_log(ctx, "Sample locations @%" PRIx64 ":\n", |
| 240 |
params.sample_locations); |
| 241 |
for (int i = 0; i < 33; i++) { |
| 242 |
pandecode_log(ctx, " (%d, %d),\n", samples[2 * i] - 128, |
| 243 |
samples[2 * i + 1] - 128); |
| 244 |
} |
| 245 |
} |
| 246 |
#endif |
| 247 |
|
| 248 |
struct pandecode_fbd |
| 249 |
GENX(pandecode_fbd)(struct pandecode_context *ctx, uint64_t gpu_va, |
| 250 |
bool is_fragment, uint64_t gpu_id) |
| 251 |
{ |
| 252 |
const void *PANDECODE_PTR_VAR(ctx, fb, (uint64_t)gpu_va); |
| 253 |
pan_section_unpack(fb, FRAMEBUFFER, PARAMETERS, params); |
| 254 |
DUMP_UNPACKED(ctx, FRAMEBUFFER_PARAMETERS, params, "Parameters:\n"); |
| 255 |
|
| 256 |
#if PAN_ARCH >= 6 |
| 257 |
pandecode_sample_locations(ctx, fb); |
| 258 |
|
| 259 |
unsigned dcd_size = pan_size(DRAW); |
| 260 |
unsigned job_type_param = 0; |
| 261 |
|
| 262 |
#if PAN_ARCH <= 9 |
| 263 |
job_type_param = MALI_JOB_TYPE_FRAGMENT; |
| 264 |
#endif |
| 265 |
|
| 266 |
if (params.pre_frame_0 != MALI_PRE_POST_FRAME_SHADER_MODE_NEVER) { |
| 267 |
const struct mali_draw_packed *PANDECODE_PTR_VAR( |
| 268 |
ctx, dcd, params.frame_shader_dcds + (0 * dcd_size)); |
| 269 |
pan_unpack(dcd, DRAW, draw); |
| 270 |
pandecode_log(ctx, "Pre frame 0 @%" PRIx64 " (mode=%d):\n", |
| 271 |
params.frame_shader_dcds, params.pre_frame_0); |
| 272 |
ctx->indent++; |
| 273 |
GENX(pandecode_dcd)(ctx, &draw, job_type_param, gpu_id); |
| 274 |
ctx->indent--; |
| 275 |
} |
| 276 |
|
| 277 |
if (params.pre_frame_1 != MALI_PRE_POST_FRAME_SHADER_MODE_NEVER) { |
| 278 |
const struct mali_draw_packed *PANDECODE_PTR_VAR( |
| 279 |
ctx, dcd, params.frame_shader_dcds + (1 * dcd_size)); |
| 280 |
pan_unpack(dcd, DRAW, draw); |
| 281 |
pandecode_log(ctx, "Pre frame 1 @%" PRIx64 ":\n", |
| 282 |
params.frame_shader_dcds + (1 * dcd_size)); |
| 283 |
ctx->indent++; |
| 284 |
GENX(pandecode_dcd)(ctx, &draw, job_type_param, gpu_id); |
| 285 |
ctx->indent--; |
| 286 |
} |
| 287 |
|
| 288 |
if (params.post_frame != MALI_PRE_POST_FRAME_SHADER_MODE_NEVER) { |
| 289 |
const struct mali_draw_packed *PANDECODE_PTR_VAR( |
| 290 |
ctx, dcd, params.frame_shader_dcds + (2 * dcd_size)); |
| 291 |
pan_unpack(dcd, DRAW, draw); |
| 292 |
pandecode_log(ctx, "Post frame:\n"); |
| 293 |
ctx->indent++; |
| 294 |
GENX(pandecode_dcd)(ctx, &draw, job_type_param, gpu_id); |
| 295 |
ctx->indent--; |
| 296 |
} |
| 297 |
#else |
| 298 |
DUMP_SECTION(ctx, FRAMEBUFFER, LOCAL_STORAGE, fb, "Local Storage:\n"); |
| 299 |
|
| 300 |
const void *t = pan_section_ptr(fb, FRAMEBUFFER, TILER); |
| 301 |
const void *w = pan_section_ptr(fb, FRAMEBUFFER, TILER_WEIGHTS); |
| 302 |
pandecode_midgard_tiler_descriptor(ctx, t, w); |
| 303 |
#endif |
| 304 |
|
| 305 |
pandecode_log(ctx, "Framebuffer @%" PRIx64 ":\n", gpu_va); |
| 306 |
ctx->indent++; |
| 307 |
|
| 308 |
DUMP_UNPACKED(ctx, FRAMEBUFFER_PARAMETERS, params, "Parameters:\n"); |
| 309 |
#if PAN_ARCH >= 6 |
| 310 |
if (params.tiler) |
| 311 |
GENX(pandecode_tiler)(ctx, params.tiler); |
| 312 |
#endif |
| 313 |
|
| 314 |
ctx->indent--; |
| 315 |
pandecode_log(ctx, "\n"); |
| 316 |
|
| 317 |
#if PAN_ARCH >= 5 |
| 318 |
gpu_va += pan_size(FRAMEBUFFER); |
| 319 |
|
| 320 |
if (params.has_zs_crc_extension) { |
| 321 |
pandecode_zs_crc_ext(ctx, gpu_va); |
| 322 |
|
| 323 |
gpu_va += pan_size(ZS_CRC_EXTENSION); |
| 324 |
} |
| 325 |
|
| 326 |
if (is_fragment) |
| 327 |
pandecode_rts(ctx, gpu_va, ¶ms); |
| 328 |
|
| 329 |
return (struct pandecode_fbd){ |
| 330 |
.rt_count = params.render_target_count, |
| 331 |
.has_extra = params.has_zs_crc_extension, |
| 332 |
}; |
| 333 |
#else |
| 334 |
/* Dummy unpack of the padding section to make sure all words are 0. |
| 335 |
* No need to call print here since the section is supposed to be empty. |
| 336 |
*/ |
| 337 |
pan_section_unpack(fb, FRAMEBUFFER, PADDING_1, padding1); |
| 338 |
pan_section_unpack(fb, FRAMEBUFFER, PADDING_2, padding2); |
| 339 |
|
| 340 |
return (struct pandecode_fbd){ |
| 341 |
.rt_count = 1, |
| 342 |
}; |
| 343 |
#endif |
| 344 |
} |
| 345 |
|
| 346 |
#if PAN_ARCH >= 5 |
| 347 |
uint64_t |
| 348 |
GENX(pandecode_blend)(struct pandecode_context *ctx, |
| 349 |
struct mali_blend_packed *descs, int rt_no, |
| 350 |
uint64_t frag_shader) |
| 351 |
{ |
| 352 |
pan_unpack(&descs[rt_no], BLEND, b); |
| 353 |
DUMP_UNPACKED(ctx, BLEND, b, "Blend RT %d:\n", rt_no); |
| 354 |
#if PAN_ARCH >= 6 |
| 355 |
if (b.internal.mode != MALI_BLEND_MODE_SHADER) |
| 356 |
return 0; |
| 357 |
/* If we don't have a frag shader, we can't extract the LSB of the blend |
| 358 |
* shader so return NULL in that case. It doesn't matter, because the |
| 359 |
* blend shader won't be executed anyway, so disassembling is not |
| 360 |
* super useful. */ |
| 361 |
if (!frag_shader) |
| 362 |
return 0; |
| 363 |
|
| 364 |
return (frag_shader & 0xFFFFFFFF00000000ULL) | b.internal.shader.pc; |
| 365 |
#else |
| 366 |
return b.blend_shader ? (b.shader_pc & ~0xf) : 0; |
| 367 |
#endif |
| 368 |
} |
| 369 |
#endif |
| 370 |
|
| 371 |
#if PAN_ARCH < 9 |
| 372 |
static bool |
| 373 |
pan_is_yuv_format(uint32_t packed) |
| 374 |
{ |
| 375 |
#if PAN_ARCH == 7 |
| 376 |
enum mali_format mali_fmt = packed >> 12; |
| 377 |
return mali_fmt >= MALI_YUV8 && mali_fmt <= MALI_CUSTOM_YUV_5; |
| 378 |
#else |
| 379 |
/* Currently only supported by panfrost on v7 */ |
| 380 |
assert(0); |
| 381 |
return false; |
| 382 |
#endif |
| 383 |
} |
| 384 |
|
| 385 |
static void |
| 386 |
pandecode_texture_payload(struct pandecode_context *ctx, uint64_t payload, |
| 387 |
const struct MALI_TEXTURE *tex) |
| 388 |
{ |
| 389 |
unsigned nr_samples = |
| 390 |
tex->dimension == MALI_TEXTURE_DIMENSION_3D ? 1 : tex->sample_count; |
| 391 |
|
| 392 |
if (!payload) |
| 393 |
return; |
| 394 |
|
| 395 |
/* A bunch of bitmap pointers follow. |
| 396 |
* We work out the correct number, |
| 397 |
* based on the mipmap/cubemap |
| 398 |
* properties, but dump extra |
| 399 |
* possibilities to futureproof */ |
| 400 |
|
| 401 |
int bitmap_count = tex->levels; |
| 402 |
|
| 403 |
/* Miptree for each face */ |
| 404 |
if (tex->dimension == MALI_TEXTURE_DIMENSION_CUBE) |
| 405 |
bitmap_count *= 6; |
| 406 |
|
| 407 |
/* Array of layers */ |
| 408 |
bitmap_count *= nr_samples; |
| 409 |
|
| 410 |
/* Array of textures */ |
| 411 |
bitmap_count *= tex->array_size; |
| 412 |
|
| 413 |
#define PANDECODE_EMIT_TEX_PAYLOAD_DESC(T, msg) \ |
| 414 |
for (int i = 0; i < bitmap_count; ++i) { \ |
| 415 |
uint64_t addr = payload + pan_size(T) * i; \ |
| 416 |
pan_unpack(PANDECODE_PTR(ctx, addr, MALI_##T##_PACKED_T), T, s); \ |
| 417 |
DUMP_UNPACKED(ctx, T, s, msg " @%" PRIx64 ":\n", addr) \ |
| 418 |
} |
| 419 |
|
| 420 |
#if PAN_ARCH <= 5 |
| 421 |
switch (tex->surface_type) { |
| 422 |
case MALI_SURFACE_TYPE_32: |
| 423 |
PANDECODE_EMIT_TEX_PAYLOAD_DESC(SURFACE_32, "Surface 32"); |
| 424 |
break; |
| 425 |
case MALI_SURFACE_TYPE_64: |
| 426 |
PANDECODE_EMIT_TEX_PAYLOAD_DESC(SURFACE, "Surface"); |
| 427 |
break; |
| 428 |
case MALI_SURFACE_TYPE_32_WITH_ROW_STRIDE: |
| 429 |
PANDECODE_EMIT_TEX_PAYLOAD_DESC(SURFACE_32, "Surface 32 With Row Stride"); |
| 430 |
break; |
| 431 |
case MALI_SURFACE_TYPE_64_WITH_STRIDES: |
| 432 |
PANDECODE_EMIT_TEX_PAYLOAD_DESC(SURFACE_WITH_STRIDE, |
| 433 |
"Surface With Stride"); |
| 434 |
break; |
| 435 |
default: |
| 436 |
fprintf(ctx->dump_stream, "Unknown surface descriptor type %X\n", |
| 437 |
tex->surface_type); |
| 438 |
break; |
| 439 |
} |
| 440 |
#elif PAN_ARCH == 6 |
| 441 |
PANDECODE_EMIT_TEX_PAYLOAD_DESC(SURFACE_WITH_STRIDE, "Surface With Stride"); |
| 442 |
#else |
| 443 |
STATIC_ASSERT(PAN_ARCH == 7); |
| 444 |
if (pan_is_yuv_format(tex->format)) { |
| 445 |
PANDECODE_EMIT_TEX_PAYLOAD_DESC(MULTIPLANAR_SURFACE, "Surface YUV"); |
| 446 |
} else { |
| 447 |
PANDECODE_EMIT_TEX_PAYLOAD_DESC(SURFACE_WITH_STRIDE, |
| 448 |
"Surface With Stride"); |
| 449 |
} |
| 450 |
#endif |
| 451 |
|
| 452 |
#undef PANDECODE_EMIT_TEX_PAYLOAD_DESC |
| 453 |
} |
| 454 |
#endif |
| 455 |
|
| 456 |
#if PAN_ARCH >= 9 |
| 457 |
static void |
| 458 |
pandecode_tex_plane(struct pandecode_context *ctx, uint64_t u, unsigned idx) |
| 459 |
{ |
| 460 |
const struct mali_plane_header_packed *cl = |
| 461 |
pandecode_fetch_gpu_mem(ctx, u, pan_size(PLANE_HEADER)); |
| 462 |
|
| 463 |
pan_unpack(cl, PLANE_HEADER, temp); |
| 464 |
|
| 465 |
switch (temp.plane_type) { |
| 466 |
case MALI_PLANE_TYPE_NULL: |
| 467 |
DUMP_ADDR(ctx, NULL_PLANE, u, "Plane %u:\n", idx); |
| 468 |
break; |
| 469 |
case MALI_PLANE_TYPE_GENERIC: |
| 470 |
DUMP_ADDR(ctx, GENERIC_PLANE, u, "Plane %u:\n", idx); |
| 471 |
break; |
| 472 |
case MALI_PLANE_TYPE_CHROMA_2P: |
| 473 |
DUMP_ADDR(ctx, CHROMA_2P_PLANE, u, "Plane %u:\n", idx); |
| 474 |
break; |
| 475 |
case MALI_PLANE_TYPE_ASTC_2D: |
| 476 |
DUMP_ADDR(ctx, ASTC_2D_PLANE, u, "Plane %u:\n", idx); |
| 477 |
break; |
| 478 |
case MALI_PLANE_TYPE_ASTC_3D: |
| 479 |
DUMP_ADDR(ctx, ASTC_3D_PLANE, u, "Plane %u:\n", idx); |
| 480 |
break; |
| 481 |
case MALI_PLANE_TYPE_AFBC: |
| 482 |
DUMP_ADDR(ctx, AFBC_PLANE, u, "Plane %u:\n", idx); |
| 483 |
break; |
| 484 |
#if PAN_ARCH >= 10 |
| 485 |
case MALI_PLANE_TYPE_AFRC: |
| 486 |
DUMP_ADDR(ctx, AFRC_PLANE, u, "Plane %u:\n", idx); |
| 487 |
break; |
| 488 |
case MALI_PLANE_TYPE_AFRC_CHROMA_2P: |
| 489 |
DUMP_ADDR(ctx, AFRC_CHROMA_2P_PLANE, u, "Plane %u:\n", idx); |
| 490 |
break; |
| 491 |
#endif |
| 492 |
default: |
| 493 |
UNREACHABLE("Unknown plane type"); |
| 494 |
} |
| 495 |
} |
| 496 |
#endif |
| 497 |
|
| 498 |
#if PAN_ARCH <= 5 |
| 499 |
void |
| 500 |
GENX(pandecode_texture)(struct pandecode_context *ctx, uint64_t u, unsigned tex) |
| 501 |
{ |
| 502 |
const struct mali_texture_packed *cl = |
| 503 |
pandecode_fetch_gpu_mem(ctx, u, pan_size(TEXTURE)); |
| 504 |
|
| 505 |
pan_unpack(cl, TEXTURE, temp); |
| 506 |
DUMP_UNPACKED(ctx, TEXTURE, temp, "Texture:\n") |
| 507 |
|
| 508 |
ctx->indent++; |
| 509 |
pandecode_texture_payload(ctx, u + pan_size(TEXTURE), &temp); |
| 510 |
ctx->indent--; |
| 511 |
} |
| 512 |
#else |
| 513 |
void |
| 514 |
GENX(pandecode_texture)(struct pandecode_context *ctx, |
| 515 |
const struct mali_texture_packed *cl, unsigned tex) |
| 516 |
{ |
| 517 |
pan_unpack(cl, TEXTURE, temp); |
| 518 |
DUMP_UNPACKED(ctx, TEXTURE, temp, "Texture:\n") |
| 519 |
|
| 520 |
ctx->indent++; |
| 521 |
|
| 522 |
#if PAN_ARCH >= 9 |
| 523 |
int plane_count = temp.levels * temp.array_size; |
| 524 |
|
| 525 |
/* Miptree for each face */ |
| 526 |
if (temp.dimension == MALI_TEXTURE_DIMENSION_CUBE) |
| 527 |
plane_count *= 6; |
| 528 |
|
| 529 |
for (unsigned i = 0; i < plane_count; ++i) |
| 530 |
pandecode_tex_plane(ctx, temp.surfaces + i * pan_size(NULL_PLANE), i); |
| 531 |
#else |
| 532 |
pandecode_texture_payload(ctx, temp.surfaces, &temp); |
| 533 |
#endif |
| 534 |
ctx->indent--; |
| 535 |
} |
| 536 |
#endif |
| 537 |
|
| 538 |
#if PAN_ARCH >= 6 |
| 539 |
void |
| 540 |
GENX(pandecode_tiler)(struct pandecode_context *ctx, uint64_t gpu_va) |
| 541 |
{ |
| 542 |
pan_unpack(PANDECODE_PTR(ctx, gpu_va, struct mali_tiler_context_packed), |
| 543 |
TILER_CONTEXT, t); |
| 544 |
|
| 545 |
if (t.heap) { |
| 546 |
pan_unpack(PANDECODE_PTR(ctx, t.heap, struct mali_tiler_heap_packed), |
| 547 |
TILER_HEAP, h); |
| 548 |
DUMP_UNPACKED(ctx, TILER_HEAP, h, "Tiler Heap:\n"); |
| 549 |
} |
| 550 |
|
| 551 |
DUMP_UNPACKED(ctx, TILER_CONTEXT, t, "Tiler Context @%" PRIx64 ":\n", |
| 552 |
gpu_va); |
| 553 |
} |
| 554 |
#endif |
| 555 |
|
| 556 |
#if PAN_ARCH >= 9 |
| 557 |
void |
| 558 |
GENX(pandecode_fau)(struct pandecode_context *ctx, uint64_t addr, |
| 559 |
unsigned count, const char *name) |
| 560 |
{ |
| 561 |
if (count == 0) |
| 562 |
return; |
| 563 |
|
| 564 |
const uint32_t *PANDECODE_PTR_VAR(ctx, raw, addr); |
| 565 |
|
| 566 |
pandecode_validate_buffer(ctx, addr, count * 8); |
| 567 |
|
| 568 |
fprintf(ctx->dump_stream, "%s @%" PRIx64 ":\n", name, addr); |
| 569 |
for (unsigned i = 0; i < count; ++i) { |
| 570 |
fprintf(ctx->dump_stream, " %08X %08X\n", raw[2 * i], raw[2 * i + 1]); |
| 571 |
} |
| 572 |
fprintf(ctx->dump_stream, "\n"); |
| 573 |
} |
| 574 |
|
| 575 |
uint64_t |
| 576 |
GENX(pandecode_shader)(struct pandecode_context *ctx, uint64_t addr, |
| 577 |
const char *label, uint64_t gpu_id) |
| 578 |
{ |
| 579 |
MAP_ADDR(ctx, SHADER_PROGRAM, addr, cl); |
| 580 |
pan_unpack(cl, SHADER_PROGRAM, desc); |
| 581 |
|
| 582 |
assert(desc.type == 8); |
| 583 |
|
| 584 |
DUMP_UNPACKED(ctx, SHADER_PROGRAM, desc, "%s Shader @%" PRIx64 ":\n", label, |
| 585 |
addr); |
| 586 |
pandecode_shader_disassemble(ctx, desc.binary, gpu_id); |
| 587 |
return desc.binary; |
| 588 |
} |
| 589 |
|
| 590 |
static unsigned |
| 591 |
pandecode_buffer(struct pandecode_context *ctx, |
| 592 |
const struct mali_buffer_packed *cl, uint64_t addr, |
| 593 |
uint64_t end_of_entry_addr) |
| 594 |
{ |
| 595 |
pan_unpack(cl, BUFFER, buffer) |
| 596 |
; |
| 597 |
DUMP_UNPACKED(ctx, BUFFER, buffer, "Buffer @%" PRIx64 ":\n", addr); |
| 598 |
|
| 599 |
/* If the address is the following descriptor and is within the resource |
| 600 |
* entry, this descriptor is an IUB. */ |
| 601 |
if (buffer.address == (addr + 0x20) && buffer.address < end_of_entry_addr) { |
| 602 |
assert((buffer.size % 0x20) == 0); |
| 603 |
|
| 604 |
const uint8_t *cl_bytes = (uint8_t *)cl; |
| 605 |
const uint32_t *words = (uint32_t *)(cl_bytes + 0x20); |
| 606 |
unsigned count = buffer.size / (2 * sizeof(uint32_t)); |
| 607 |
|
| 608 |
ctx->indent++; |
| 609 |
pandecode_log(ctx, "IUB @%" PRIx64 ":\n", buffer.address); |
| 610 |
ctx->indent++; |
| 611 |
for (unsigned i = 0; i < count; ++i) |
| 612 |
pandecode_log(ctx, "%08X %08X\n", words[2 * i], words[2 * i + 1]); |
| 613 |
ctx->indent--; |
| 614 |
ctx->indent--; |
| 615 |
pandecode_log(ctx, "\n"); |
| 616 |
|
| 617 |
return buffer.size; |
| 618 |
} |
| 619 |
|
| 620 |
return 0; |
| 621 |
} |
| 622 |
|
| 623 |
static void |
| 624 |
pandecode_resources(struct pandecode_context *ctx, uint64_t addr, unsigned size) |
| 625 |
{ |
| 626 |
const uint8_t *cl = pandecode_fetch_gpu_mem(ctx, addr, size); |
| 627 |
assert((size % 0x20) == 0); |
| 628 |
|
| 629 |
for (unsigned i = 0; i < size; i += 0x20) { |
| 630 |
pan_unpack((const struct mali_descriptor_header_packed *)&cl[i], |
| 631 |
DESCRIPTOR_HEADER, header) |
| 632 |
; |
| 633 |
switch (header.type) { |
| 634 |
case MALI_DESCRIPTOR_TYPE_NULL: |
| 635 |
DUMP_CL(ctx, NULL_DESCRIPTOR, cl + i, "NullDescriptor @%" PRIx64 "\n", |
| 636 |
addr + i); |
| 637 |
break; |
| 638 |
case MALI_DESCRIPTOR_TYPE_SAMPLER: |
| 639 |
DUMP_CL(ctx, SAMPLER, cl + i, "Sampler @%" PRIx64 ":\n", addr + i); |
| 640 |
break; |
| 641 |
case MALI_DESCRIPTOR_TYPE_TEXTURE: |
| 642 |
pandecode_log(ctx, "Texture @%" PRIx64 "\n", addr + i); |
| 643 |
GENX(pandecode_texture)(ctx, (struct mali_texture_packed *)&cl[i], i); |
| 644 |
break; |
| 645 |
case MALI_DESCRIPTOR_TYPE_ATTRIBUTE: |
| 646 |
DUMP_CL(ctx, ATTRIBUTE, cl + i, "Attribute @%" PRIx64 ":\n", addr + i); |
| 647 |
break; |
| 648 |
case MALI_DESCRIPTOR_TYPE_BUFFER: |
| 649 |
i += pandecode_buffer(ctx, (const struct mali_buffer_packed *)&cl[i], |
| 650 |
addr + i, addr + size); |
| 651 |
break; |
| 652 |
default: |
| 653 |
fprintf(ctx->dump_stream, "Unknown descriptor type %X\n", header.type); |
| 654 |
break; |
| 655 |
} |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
void |
| 660 |
GENX(pandecode_resource_tables)(struct pandecode_context *ctx, uint64_t addr, |
| 661 |
const char *label) |
| 662 |
{ |
| 663 |
if (!addr) |
| 664 |
return; |
| 665 |
|
| 666 |
unsigned count = addr & 0x3F; |
| 667 |
addr = addr & ~0x3F; |
| 668 |
|
| 669 |
const struct mali_resource_packed *cl = |
| 670 |
pandecode_fetch_gpu_mem(ctx, addr, MALI_RESOURCE_LENGTH * count); |
| 671 |
|
| 672 |
pandecode_log(ctx, "%s resource table @%" PRIx64 "\n", label, addr); |
| 673 |
ctx->indent += 2; |
| 674 |
for (unsigned i = 0; i < count; ++i) { |
| 675 |
pan_unpack(&cl[i], RESOURCE, entry); |
| 676 |
DUMP_UNPACKED(ctx, RESOURCE, entry, "Entry %u @%" PRIx64 ":\n", i, |
| 677 |
addr + i * MALI_RESOURCE_LENGTH); |
| 678 |
|
| 679 |
ctx->indent += 2; |
| 680 |
if (entry.address) |
| 681 |
pandecode_resources(ctx, entry.address, entry.size); |
| 682 |
ctx->indent -= 2; |
| 683 |
} |
| 684 |
ctx->indent -= 2; |
| 685 |
} |
| 686 |
|
| 687 |
void |
| 688 |
GENX(pandecode_depth_stencil)(struct pandecode_context *ctx, uint64_t addr) |
| 689 |
{ |
| 690 |
MAP_ADDR(ctx, DEPTH_STENCIL, addr, cl); |
| 691 |
pan_unpack(cl, DEPTH_STENCIL, desc); |
| 692 |
DUMP_UNPACKED(ctx, DEPTH_STENCIL, desc, "Depth/stencil"); |
| 693 |
} |
| 694 |
|
| 695 |
#if PAN_ARCH < 12 |
| 696 |
void |
| 697 |
GENX(pandecode_shader_environment)(struct pandecode_context *ctx, |
| 698 |
const struct MALI_SHADER_ENVIRONMENT *p, |
| 699 |
uint64_t gpu_id) |
| 700 |
{ |
| 701 |
if (p->shader) |
| 702 |
GENX(pandecode_shader)(ctx, p->shader, "Shader", gpu_id); |
| 703 |
|
| 704 |
GENX(pandecode_resource_tables)(ctx, p->resources, "Resources"); |
| 705 |
|
| 706 |
if (p->thread_storage) |
| 707 |
DUMP_ADDR(ctx, LOCAL_STORAGE, p->thread_storage, "Local Storage:\n"); |
| 708 |
|
| 709 |
if (p->fau) |
| 710 |
GENX(pandecode_fau)(ctx, p->fau, p->fau_count, "FAU"); |
| 711 |
} |
| 712 |
#endif |
| 713 |
|
| 714 |
void |
| 715 |
GENX(pandecode_blend_descs)(struct pandecode_context *ctx, uint64_t blend, |
| 716 |
unsigned count, uint64_t frag_shader, |
| 717 |
uint64_t gpu_id) |
| 718 |
{ |
| 719 |
for (unsigned i = 0; i < count; ++i) { |
| 720 |
struct mali_blend_packed *PANDECODE_PTR_VAR(ctx, blend_descs, blend); |
| 721 |
|
| 722 |
uint64_t blend_shader = |
| 723 |
GENX(pandecode_blend)(ctx, blend_descs, i, frag_shader); |
| 724 |
if (blend_shader) { |
| 725 |
fprintf(ctx->dump_stream, "Blend shader %u @%" PRIx64 "", i, |
| 726 |
blend_shader); |
| 727 |
pandecode_shader_disassemble(ctx, blend_shader, gpu_id); |
| 728 |
} |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
void |
| 733 |
GENX(pandecode_dcd)(struct pandecode_context *ctx, const struct MALI_DRAW *p, |
| 734 |
unsigned unused, uint64_t gpu_id) |
| 735 |
{ |
| 736 |
uint64_t frag_shader = 0; |
| 737 |
|
| 738 |
GENX(pandecode_depth_stencil)(ctx, p->depth_stencil); |
| 739 |
GENX(pandecode_blend_descs) |
| 740 |
(ctx, p->blend, p->blend_count, frag_shader, gpu_id); |
| 741 |
#if PAN_ARCH >= 12 |
| 742 |
if (p->vertex_shader) |
| 743 |
GENX(pandecode_shader)(ctx, p->vertex_shader, "Vertex Shader", gpu_id); |
| 744 |
|
| 745 |
GENX(pandecode_resource_tables)(ctx, p->vertex_resources, |
| 746 |
"Vertex Resources"); |
| 747 |
|
| 748 |
if (p->vertex_fau.pointer) |
| 749 |
GENX(pandecode_fau)(ctx, p->vertex_fau.pointer, p->vertex_fau.count, |
| 750 |
"Vertex FAU"); |
| 751 |
|
| 752 |
if (p->fragment_shader) |
| 753 |
GENX(pandecode_shader)(ctx, p->fragment_shader, "Fragment Shader", |
| 754 |
gpu_id); |
| 755 |
|
| 756 |
GENX(pandecode_resource_tables)(ctx, p->fragment_resources, |
| 757 |
"Fragment Resources"); |
| 758 |
|
| 759 |
if (p->fragment_fau.pointer) |
| 760 |
GENX(pandecode_fau)(ctx, p->fragment_fau.pointer, p->fragment_fau.count, |
| 761 |
"Fragment FAU"); |
| 762 |
|
| 763 |
if (p->thread_storage) |
| 764 |
DUMP_ADDR(ctx, LOCAL_STORAGE, p->thread_storage, "Local Storage:\n"); |
| 765 |
#else |
| 766 |
GENX(pandecode_shader_environment)(ctx, &p->shader, gpu_id); |
| 767 |
#endif |
| 768 |
DUMP_UNPACKED(ctx, DRAW, *p, "Draw:\n"); |
| 769 |
} |
| 770 |
#endif |