| 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 "genxml/gen_macros.h" |
| 9 |
#include "util/set.h" |
| 10 |
#include "decode.h" |
| 11 |
|
| 12 |
#if PAN_ARCH <= 9 |
| 13 |
|
| 14 |
static void |
| 15 |
pandecode_primitive(struct pandecode_context *ctx, |
| 16 |
const struct mali_primitive_packed *p) |
| 17 |
{ |
| 18 |
pan_unpack(p, PRIMITIVE, primitive); |
| 19 |
DUMP_UNPACKED(ctx, PRIMITIVE, primitive, "Primitive:\n"); |
| 20 |
|
| 21 |
#if PAN_ARCH < 9 |
| 22 |
/* Validate an index buffer is present if we need one. TODO: verify |
| 23 |
* relationship between invocation_count and index_count */ |
| 24 |
|
| 25 |
if (primitive.indices) { |
| 26 |
/* Grab the size */ |
| 27 |
unsigned size = (primitive.index_type == MALI_INDEX_TYPE_UINT32) |
| 28 |
? sizeof(uint32_t) |
| 29 |
: primitive.index_type; |
| 30 |
|
| 31 |
/* Ensure we got a size, and if so, validate the index buffer |
| 32 |
* is large enough to hold a full set of indices of the given |
| 33 |
* size */ |
| 34 |
|
| 35 |
if (!size) |
| 36 |
pandecode_log(ctx, "// XXX: index size missing\n"); |
| 37 |
else |
| 38 |
pandecode_validate_buffer(ctx, primitive.indices, |
| 39 |
primitive.index_count * size); |
| 40 |
} else if (primitive.index_type) |
| 41 |
pandecode_log(ctx, "// XXX: unexpected index size\n"); |
| 42 |
#endif |
| 43 |
} |
| 44 |
|
| 45 |
#if PAN_ARCH < 9 |
| 46 |
static void |
| 47 |
pandecode_attributes(struct pandecode_context *ctx, uint64_t addr, int count, |
| 48 |
bool varying, enum mali_job_type job_type) |
| 49 |
{ |
| 50 |
char *prefix = varying ? "Varying Buffer" : "Attribute Buffer"; |
| 51 |
assert(addr); |
| 52 |
|
| 53 |
if (!count) { |
| 54 |
pandecode_log(ctx, "// warn: No %s records\n", prefix); |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
MAP_ADDR(ctx, ATTRIBUTE_BUFFER, addr, cl); |
| 59 |
|
| 60 |
for (int i = 0; i < count; ++i) { |
| 61 |
pan_unpack(&cl[i], ATTRIBUTE_BUFFER, temp); |
| 62 |
DUMP_UNPACKED(ctx, ATTRIBUTE_BUFFER, temp, "%s:\n", prefix); |
| 63 |
|
| 64 |
switch (temp.type) { |
| 65 |
case MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR_WRITE_REDUCTION: |
| 66 |
case MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR: { |
| 67 |
pan_cast_and_unpack(&cl[i + 1], ATTRIBUTE_BUFFER_CONTINUATION_NPOT, |
| 68 |
temp2); |
| 69 |
pan_print(ctx->dump_stream, ATTRIBUTE_BUFFER_CONTINUATION_NPOT, temp2, |
| 70 |
(ctx->indent + 1) * 2); |
| 71 |
i++; |
| 72 |
break; |
| 73 |
} |
| 74 |
case MALI_ATTRIBUTE_TYPE_3D_LINEAR: |
| 75 |
case MALI_ATTRIBUTE_TYPE_3D_INTERLEAVED: { |
| 76 |
pan_cast_and_unpack(&cl[i + 1], ATTRIBUTE_BUFFER_CONTINUATION_3D, |
| 77 |
temp2); |
| 78 |
pan_print(ctx->dump_stream, ATTRIBUTE_BUFFER_CONTINUATION_3D, temp2, |
| 79 |
(ctx->indent + 1) * 2); |
| 80 |
i++; |
| 81 |
break; |
| 82 |
} |
| 83 |
default: |
| 84 |
break; |
| 85 |
} |
| 86 |
} |
| 87 |
pandecode_log(ctx, "\n"); |
| 88 |
} |
| 89 |
|
| 90 |
static unsigned |
| 91 |
pandecode_attribute_meta(struct pandecode_context *ctx, int count, |
| 92 |
uint64_t attribute, bool varying) |
| 93 |
{ |
| 94 |
unsigned max = 0; |
| 95 |
|
| 96 |
for (int i = 0; i < count; ++i, attribute += pan_size(ATTRIBUTE)) { |
| 97 |
MAP_ADDR(ctx, ATTRIBUTE, attribute, cl); |
| 98 |
pan_unpack(cl, ATTRIBUTE, a); |
| 99 |
DUMP_UNPACKED(ctx, ATTRIBUTE, a, "%s:\n", |
| 100 |
varying ? "Varying" : "Attribute"); |
| 101 |
max = MAX2(max, a.buffer_index); |
| 102 |
} |
| 103 |
|
| 104 |
pandecode_log(ctx, "\n"); |
| 105 |
return MIN2(max + 1, 256); |
| 106 |
} |
| 107 |
|
| 108 |
/* return bits [lo, hi) of word */ |
| 109 |
static uint32_t |
| 110 |
bits(uint32_t word, uint32_t lo, uint32_t hi) |
| 111 |
{ |
| 112 |
if (hi - lo >= 32) |
| 113 |
return word; // avoid undefined behavior with the shift |
| 114 |
|
| 115 |
if (lo >= 32) |
| 116 |
return 0; |
| 117 |
|
| 118 |
return (word >> lo) & ((1 << (hi - lo)) - 1); |
| 119 |
} |
| 120 |
|
| 121 |
static void |
| 122 |
pandecode_invocation(struct pandecode_context *ctx, |
| 123 |
const struct mali_invocation_packed *i) |
| 124 |
{ |
| 125 |
/* Decode invocation_count. See the comment before the definition of |
| 126 |
* invocation_count for an explanation. |
| 127 |
*/ |
| 128 |
pan_unpack(i, INVOCATION, invocation); |
| 129 |
|
| 130 |
unsigned size_x = |
| 131 |
bits(invocation.invocations, 0, invocation.size_y_shift) + 1; |
| 132 |
unsigned size_y = bits(invocation.invocations, invocation.size_y_shift, |
| 133 |
invocation.size_z_shift) + |
| 134 |
1; |
| 135 |
unsigned size_z = bits(invocation.invocations, invocation.size_z_shift, |
| 136 |
invocation.workgroups_x_shift) + |
| 137 |
1; |
| 138 |
|
| 139 |
unsigned groups_x = |
| 140 |
bits(invocation.invocations, invocation.workgroups_x_shift, |
| 141 |
invocation.workgroups_y_shift) + |
| 142 |
1; |
| 143 |
unsigned groups_y = |
| 144 |
bits(invocation.invocations, invocation.workgroups_y_shift, |
| 145 |
invocation.workgroups_z_shift) + |
| 146 |
1; |
| 147 |
unsigned groups_z = |
| 148 |
bits(invocation.invocations, invocation.workgroups_z_shift, 32) + 1; |
| 149 |
|
| 150 |
pandecode_log(ctx, "Invocation (%d, %d, %d) x (%d, %d, %d)\n", size_x, |
| 151 |
size_y, size_z, groups_x, groups_y, groups_z); |
| 152 |
|
| 153 |
DUMP_UNPACKED(ctx, INVOCATION, invocation, "Invocation:\n") |
| 154 |
} |
| 155 |
|
| 156 |
static void |
| 157 |
pandecode_textures(struct pandecode_context *ctx, uint64_t textures, |
| 158 |
unsigned texture_count) |
| 159 |
{ |
| 160 |
if (!textures) |
| 161 |
return; |
| 162 |
|
| 163 |
pandecode_log(ctx, "Textures %" PRIx64 ":\n", textures); |
| 164 |
ctx->indent++; |
| 165 |
|
| 166 |
#if PAN_ARCH >= 6 |
| 167 |
const void *cl = |
| 168 |
pandecode_fetch_gpu_mem(ctx, textures, pan_size(TEXTURE) * texture_count); |
| 169 |
|
| 170 |
for (unsigned tex = 0; tex < texture_count; ++tex) |
| 171 |
GENX(pandecode_texture)(ctx, cl + pan_size(TEXTURE) * tex, tex); |
| 172 |
#else |
| 173 |
uint64_t *PANDECODE_PTR_VAR(ctx, u, textures); |
| 174 |
|
| 175 |
for (int tex = 0; tex < texture_count; ++tex) { |
| 176 |
uint64_t *PANDECODE_PTR_VAR(ctx, u, textures + tex * sizeof(uint64_t)); |
| 177 |
char *a = pointer_as_memory_reference(ctx, *u); |
| 178 |
pandecode_log(ctx, "%s,\n", a); |
| 179 |
free(a); |
| 180 |
} |
| 181 |
|
| 182 |
/* Now, finally, descend down into the texture descriptor */ |
| 183 |
for (unsigned tex = 0; tex < texture_count; ++tex) { |
| 184 |
uint64_t *PANDECODE_PTR_VAR(ctx, u, textures + tex * sizeof(uint64_t)); |
| 185 |
GENX(pandecode_texture)(ctx, *u, tex); |
| 186 |
} |
| 187 |
#endif |
| 188 |
ctx->indent--; |
| 189 |
pandecode_log(ctx, "\n"); |
| 190 |
} |
| 191 |
|
| 192 |
static void |
| 193 |
pandecode_samplers(struct pandecode_context *ctx, uint64_t samplers, |
| 194 |
unsigned sampler_count) |
| 195 |
{ |
| 196 |
pandecode_log(ctx, "Samplers %" PRIx64 ":\n", samplers); |
| 197 |
ctx->indent++; |
| 198 |
|
| 199 |
for (int i = 0; i < sampler_count; ++i) |
| 200 |
DUMP_ADDR(ctx, SAMPLER, samplers + (pan_size(SAMPLER) * i), |
| 201 |
"Sampler %d:\n", i); |
| 202 |
|
| 203 |
ctx->indent--; |
| 204 |
pandecode_log(ctx, "\n"); |
| 205 |
} |
| 206 |
|
| 207 |
static void |
| 208 |
pandecode_uniform_buffers(struct pandecode_context *ctx, uint64_t pubufs, |
| 209 |
int ubufs_count) |
| 210 |
{ |
| 211 |
uint64_t *PANDECODE_PTR_VAR(ctx, ubufs, pubufs); |
| 212 |
|
| 213 |
for (int i = 0; i < ubufs_count; i++) { |
| 214 |
uint64_t addr = (ubufs[i] >> 10) << 2; |
| 215 |
unsigned size = addr ? (((ubufs[i] & ((1 << 10) - 1)) + 1) * 16) : 0; |
| 216 |
|
| 217 |
pandecode_validate_buffer(ctx, addr, size); |
| 218 |
|
| 219 |
char *ptr = pointer_as_memory_reference(ctx, addr); |
| 220 |
pandecode_log(ctx, "ubuf_%d[%u] = %s;\n", i, size, ptr); |
| 221 |
free(ptr); |
| 222 |
} |
| 223 |
|
| 224 |
pandecode_log(ctx, "\n"); |
| 225 |
} |
| 226 |
|
| 227 |
static void |
| 228 |
pandecode_uniforms(struct pandecode_context *ctx, uint64_t uniforms, |
| 229 |
unsigned uniform_count) |
| 230 |
{ |
| 231 |
pandecode_validate_buffer(ctx, uniforms, uniform_count * 16); |
| 232 |
|
| 233 |
char *ptr = pointer_as_memory_reference(ctx, uniforms); |
| 234 |
pandecode_log(ctx, "vec4 uniforms[%u] = %s;\n", uniform_count, ptr); |
| 235 |
free(ptr); |
| 236 |
pandecode_log(ctx, "\n"); |
| 237 |
} |
| 238 |
|
| 239 |
void |
| 240 |
GENX(pandecode_dcd)(struct pandecode_context *ctx, const struct MALI_DRAW *p, |
| 241 |
enum mali_job_type job_type, uint64_t gpu_id) |
| 242 |
{ |
| 243 |
#if PAN_ARCH >= 5 |
| 244 |
struct pandecode_fbd fbd_info = {.rt_count = 1}; |
| 245 |
#endif |
| 246 |
|
| 247 |
if (PAN_ARCH >= 6 || (PAN_ARCH == 5 && job_type != MALI_JOB_TYPE_TILER)) { |
| 248 |
#if PAN_ARCH >= 5 |
| 249 |
DUMP_ADDR(ctx, LOCAL_STORAGE, p->thread_storage & ~1, "Local Storage:\n"); |
| 250 |
#endif |
| 251 |
} else { |
| 252 |
#if PAN_ARCH == 5 |
| 253 |
/* On v5 only, the actual framebuffer pointer is tagged with extra |
| 254 |
* metadata that we validate but do not print. |
| 255 |
*/ |
| 256 |
const uint64_t *fbd = &p->fbd; |
| 257 |
pan_cast_and_unpack(fbd, FRAMEBUFFER_POINTER, ptr); |
| 258 |
|
| 259 |
if (!ptr.type || ptr.zs_crc_extension_present || |
| 260 |
ptr.render_target_count != 1) { |
| 261 |
|
| 262 |
fprintf(ctx->dump_stream, "Unexpected framebuffer pointer settings"); |
| 263 |
} |
| 264 |
|
| 265 |
GENX(pandecode_fbd)(ctx, ptr.pointer, false, gpu_id); |
| 266 |
#elif PAN_ARCH == 4 |
| 267 |
GENX(pandecode_fbd)(ctx, p->fbd, false, gpu_id); |
| 268 |
#endif |
| 269 |
} |
| 270 |
|
| 271 |
int varying_count = 0, attribute_count = 0, uniform_count = 0, |
| 272 |
uniform_buffer_count = 0; |
| 273 |
int texture_count = 0, sampler_count = 0; |
| 274 |
|
| 275 |
if (p->state) { |
| 276 |
struct mali_renderer_state_packed *cl = |
| 277 |
pandecode_fetch_gpu_mem(ctx, p->state, pan_size(RENDERER_STATE)); |
| 278 |
|
| 279 |
pan_unpack(cl, RENDERER_STATE, state); |
| 280 |
|
| 281 |
if (state.shader.shader & ~0xF) |
| 282 |
pandecode_shader_disassemble(ctx, state.shader.shader & ~0xF, gpu_id); |
| 283 |
|
| 284 |
#if PAN_ARCH >= 6 |
| 285 |
bool idvs = (job_type == MALI_JOB_TYPE_INDEXED_VERTEX); |
| 286 |
|
| 287 |
if (idvs && state.secondary_shader) |
| 288 |
pandecode_shader_disassemble(ctx, state.secondary_shader, gpu_id); |
| 289 |
#endif |
| 290 |
DUMP_UNPACKED(ctx, RENDERER_STATE, state, "State:\n"); |
| 291 |
ctx->indent++; |
| 292 |
|
| 293 |
/* Save for dumps */ |
| 294 |
attribute_count = state.shader.attribute_count; |
| 295 |
varying_count = state.shader.varying_count; |
| 296 |
texture_count = state.shader.texture_count; |
| 297 |
sampler_count = state.shader.sampler_count; |
| 298 |
uniform_buffer_count = state.properties.uniform_buffer_count; |
| 299 |
|
| 300 |
#if PAN_ARCH >= 6 |
| 301 |
uniform_count = state.preload.uniform_count; |
| 302 |
#else |
| 303 |
uniform_count = state.properties.uniform_count; |
| 304 |
#endif |
| 305 |
|
| 306 |
#if PAN_ARCH == 4 |
| 307 |
uint64_t shader = state.blend_shader & ~0xF; |
| 308 |
if (state.multisample_misc.blend_shader && shader) |
| 309 |
pandecode_shader_disassemble(ctx, shader, gpu_id); |
| 310 |
#endif |
| 311 |
ctx->indent--; |
| 312 |
pandecode_log(ctx, "\n"); |
| 313 |
|
| 314 |
/* MRT blend fields are used on v5+. Technically, they are optional on v5 |
| 315 |
* for backwards compatibility but we don't care about that. |
| 316 |
*/ |
| 317 |
#if PAN_ARCH >= 5 |
| 318 |
if ((job_type == MALI_JOB_TYPE_TILER || |
| 319 |
job_type == MALI_JOB_TYPE_FRAGMENT) && |
| 320 |
PAN_ARCH >= 5) { |
| 321 |
void *blend_base = ((void *)cl) + pan_size(RENDERER_STATE); |
| 322 |
|
| 323 |
for (unsigned i = 0; i < fbd_info.rt_count; i++) { |
| 324 |
uint64_t shader = |
| 325 |
GENX(pandecode_blend)(ctx, blend_base, i, state.shader.shader); |
| 326 |
if (shader & ~0xF) |
| 327 |
pandecode_shader_disassemble(ctx, shader, gpu_id); |
| 328 |
} |
| 329 |
} |
| 330 |
#endif |
| 331 |
} else |
| 332 |
pandecode_log(ctx, "// XXX: missing shader descriptor\n"); |
| 333 |
|
| 334 |
if (p->viewport) { |
| 335 |
DUMP_ADDR(ctx, VIEWPORT, p->viewport, "Viewport:\n"); |
| 336 |
pandecode_log(ctx, "\n"); |
| 337 |
} |
| 338 |
|
| 339 |
unsigned max_attr_index = 0; |
| 340 |
|
| 341 |
if (p->attributes) |
| 342 |
max_attr_index = |
| 343 |
pandecode_attribute_meta(ctx, attribute_count, p->attributes, false); |
| 344 |
|
| 345 |
if (p->attribute_buffers) |
| 346 |
pandecode_attributes(ctx, p->attribute_buffers, max_attr_index, false, |
| 347 |
job_type); |
| 348 |
|
| 349 |
if (p->varyings) { |
| 350 |
varying_count = |
| 351 |
pandecode_attribute_meta(ctx, varying_count, p->varyings, true); |
| 352 |
} |
| 353 |
|
| 354 |
if (p->varying_buffers) |
| 355 |
pandecode_attributes(ctx, p->varying_buffers, varying_count, true, |
| 356 |
job_type); |
| 357 |
|
| 358 |
if (p->uniform_buffers) { |
| 359 |
if (uniform_buffer_count) |
| 360 |
pandecode_uniform_buffers(ctx, p->uniform_buffers, |
| 361 |
uniform_buffer_count); |
| 362 |
else |
| 363 |
pandecode_log(ctx, "// warn: UBOs specified but not referenced\n"); |
| 364 |
} else if (uniform_buffer_count) |
| 365 |
pandecode_log(ctx, "// XXX: UBOs referenced but not specified\n"); |
| 366 |
|
| 367 |
/* We don't want to actually dump uniforms, but we do need to validate |
| 368 |
* that the counts we were given are sane */ |
| 369 |
|
| 370 |
if (p->push_uniforms) { |
| 371 |
if (uniform_count) |
| 372 |
pandecode_uniforms(ctx, p->push_uniforms, uniform_count); |
| 373 |
else |
| 374 |
pandecode_log(ctx, "// warn: Uniforms specified but not referenced\n"); |
| 375 |
} else if (uniform_count) |
| 376 |
pandecode_log(ctx, "// XXX: Uniforms referenced but not specified\n"); |
| 377 |
|
| 378 |
if (p->textures) |
| 379 |
pandecode_textures(ctx, p->textures, texture_count); |
| 380 |
|
| 381 |
if (p->samplers) |
| 382 |
pandecode_samplers(ctx, p->samplers, sampler_count); |
| 383 |
} |
| 384 |
|
| 385 |
static void |
| 386 |
pandecode_vertex_compute_geometry_job(struct pandecode_context *ctx, |
| 387 |
const struct MALI_JOB_HEADER *h, |
| 388 |
uint64_t job, uint64_t gpu_id) |
| 389 |
{ |
| 390 |
struct mali_compute_job_packed *PANDECODE_PTR_VAR(ctx, p, job); |
| 391 |
pan_section_unpack(p, COMPUTE_JOB, DRAW, draw); |
| 392 |
GENX(pandecode_dcd)(ctx, &draw, h->type, gpu_id); |
| 393 |
|
| 394 |
pandecode_log(ctx, "Vertex Job Payload:\n"); |
| 395 |
ctx->indent++; |
| 396 |
pandecode_invocation(ctx, pan_section_ptr(p, COMPUTE_JOB, INVOCATION)); |
| 397 |
DUMP_SECTION(ctx, COMPUTE_JOB, PARAMETERS, p, "Vertex Job Parameters:\n"); |
| 398 |
DUMP_UNPACKED(ctx, DRAW, draw, "Draw:\n"); |
| 399 |
ctx->indent--; |
| 400 |
pandecode_log(ctx, "\n"); |
| 401 |
} |
| 402 |
#endif |
| 403 |
|
| 404 |
static void |
| 405 |
pandecode_write_value_job(struct pandecode_context *ctx, uint64_t job) |
| 406 |
{ |
| 407 |
struct mali_write_value_job_packed *PANDECODE_PTR_VAR(ctx, p, job); |
| 408 |
pan_section_unpack(p, WRITE_VALUE_JOB, PAYLOAD, u); |
| 409 |
DUMP_SECTION(ctx, WRITE_VALUE_JOB, PAYLOAD, p, "Write Value Payload:\n"); |
| 410 |
pandecode_log(ctx, "\n"); |
| 411 |
} |
| 412 |
|
| 413 |
static void |
| 414 |
pandecode_cache_flush_job(struct pandecode_context *ctx, uint64_t job) |
| 415 |
{ |
| 416 |
struct mali_cache_flush_job_packed *PANDECODE_PTR_VAR(ctx, p, job); |
| 417 |
pan_section_unpack(p, CACHE_FLUSH_JOB, PAYLOAD, u); |
| 418 |
DUMP_SECTION(ctx, CACHE_FLUSH_JOB, PAYLOAD, p, "Cache Flush Payload:\n"); |
| 419 |
pandecode_log(ctx, "\n"); |
| 420 |
} |
| 421 |
|
| 422 |
static void |
| 423 |
pandecode_tiler_job(struct pandecode_context *ctx, |
| 424 |
const struct MALI_JOB_HEADER *h, uint64_t job, |
| 425 |
uint64_t gpu_id) |
| 426 |
{ |
| 427 |
struct mali_tiler_job_packed *PANDECODE_PTR_VAR(ctx, p, job); |
| 428 |
pan_section_unpack(p, TILER_JOB, DRAW, draw); |
| 429 |
GENX(pandecode_dcd)(ctx, &draw, h->type, gpu_id); |
| 430 |
pandecode_log(ctx, "Tiler Job Payload:\n"); |
| 431 |
ctx->indent++; |
| 432 |
|
| 433 |
#if PAN_ARCH < 9 |
| 434 |
pandecode_invocation(ctx, pan_section_ptr(p, TILER_JOB, INVOCATION)); |
| 435 |
#endif |
| 436 |
|
| 437 |
pandecode_primitive(ctx, pan_section_ptr(p, TILER_JOB, PRIMITIVE)); |
| 438 |
DUMP_UNPACKED(ctx, DRAW, draw, "Draw:\n"); |
| 439 |
|
| 440 |
DUMP_SECTION(ctx, TILER_JOB, PRIMITIVE_SIZE, p, "Primitive Size:\n"); |
| 441 |
|
| 442 |
#if PAN_ARCH >= 6 |
| 443 |
pan_section_unpack(p, TILER_JOB, TILER, tiler_ptr); |
| 444 |
GENX(pandecode_tiler)(ctx, tiler_ptr.address); |
| 445 |
|
| 446 |
#if PAN_ARCH >= 9 |
| 447 |
DUMP_SECTION(ctx, TILER_JOB, INSTANCE_COUNT, p, "Instance count:\n"); |
| 448 |
DUMP_SECTION(ctx, TILER_JOB, VERTEX_COUNT, p, "Vertex count:\n"); |
| 449 |
DUMP_SECTION(ctx, TILER_JOB, SCISSOR, p, "Scissor:\n"); |
| 450 |
DUMP_SECTION(ctx, TILER_JOB, INDICES, p, "Indices:\n"); |
| 451 |
#else |
| 452 |
pan_section_unpack(p, TILER_JOB, PADDING, padding); |
| 453 |
#endif |
| 454 |
|
| 455 |
#endif |
| 456 |
ctx->indent--; |
| 457 |
pandecode_log(ctx, "\n"); |
| 458 |
} |
| 459 |
|
| 460 |
static void |
| 461 |
pandecode_fragment_job(struct pandecode_context *ctx, uint64_t job, |
| 462 |
uint64_t gpu_id) |
| 463 |
{ |
| 464 |
struct mali_fragment_job_packed *PANDECODE_PTR_VAR(ctx, p, job); |
| 465 |
pan_section_unpack(p, FRAGMENT_JOB, PAYLOAD, s); |
| 466 |
|
| 467 |
uint64_t fbd_pointer; |
| 468 |
|
| 469 |
#if PAN_ARCH >= 5 |
| 470 |
/* On v5 and newer, the actual framebuffer pointer is tagged with extra |
| 471 |
* metadata that we need to disregard. |
| 472 |
*/ |
| 473 |
const uint64_t *framebuffer_packed_raw = &s.framebuffer; |
| 474 |
pan_cast_and_unpack(framebuffer_packed_raw, FRAMEBUFFER_POINTER, ptr); |
| 475 |
fbd_pointer = ptr.pointer; |
| 476 |
#else |
| 477 |
/* On v4, the framebuffer pointer is untagged. */ |
| 478 |
fbd_pointer = s.framebuffer; |
| 479 |
#endif |
| 480 |
|
| 481 |
UNUSED struct pandecode_fbd info = |
| 482 |
GENX(pandecode_fbd)(ctx, fbd_pointer, true, gpu_id); |
| 483 |
|
| 484 |
#if PAN_ARCH >= 5 |
| 485 |
if (!ptr.type || ptr.zs_crc_extension_present != info.has_extra || |
| 486 |
ptr.render_target_count != info.rt_count) { |
| 487 |
pandecode_log(ctx, "invalid FBD tag\n"); |
| 488 |
} |
| 489 |
#endif |
| 490 |
|
| 491 |
DUMP_UNPACKED(ctx, FRAGMENT_JOB_PAYLOAD, s, "Fragment Job Payload:\n"); |
| 492 |
|
| 493 |
pandecode_log(ctx, "\n"); |
| 494 |
} |
| 495 |
|
| 496 |
#if PAN_ARCH == 6 || PAN_ARCH == 7 |
| 497 |
static void |
| 498 |
pandecode_indexed_vertex_job(struct pandecode_context *ctx, |
| 499 |
const struct MALI_JOB_HEADER *h, uint64_t job, |
| 500 |
uint64_t gpu_id) |
| 501 |
{ |
| 502 |
struct mali_indexed_vertex_job_packed *PANDECODE_PTR_VAR(ctx, p, job); |
| 503 |
|
| 504 |
pandecode_log(ctx, "Vertex:\n"); |
| 505 |
pan_section_unpack(p, INDEXED_VERTEX_JOB, VERTEX_DRAW, vert_draw); |
| 506 |
ctx->indent++; |
| 507 |
GENX(pandecode_dcd)(ctx, &vert_draw, h->type, gpu_id); |
| 508 |
DUMP_UNPACKED(ctx, DRAW, vert_draw, "Vertex Draw:\n"); |
| 509 |
ctx->indent--; |
| 510 |
|
| 511 |
pandecode_log(ctx, "Fragment:\n"); |
| 512 |
pan_section_unpack(p, INDEXED_VERTEX_JOB, FRAGMENT_DRAW, frag_draw); |
| 513 |
ctx->indent++; |
| 514 |
GENX(pandecode_dcd)(ctx, &frag_draw, MALI_JOB_TYPE_FRAGMENT, gpu_id); |
| 515 |
DUMP_UNPACKED(ctx, DRAW, frag_draw, "Fragment Draw:\n"); |
| 516 |
ctx->indent--; |
| 517 |
|
| 518 |
pan_section_unpack(p, INDEXED_VERTEX_JOB, TILER, tiler_ptr); |
| 519 |
pandecode_log(ctx, "Tiler Job Payload:\n"); |
| 520 |
ctx->indent++; |
| 521 |
GENX(pandecode_tiler)(ctx, tiler_ptr.address); |
| 522 |
ctx->indent--; |
| 523 |
|
| 524 |
pandecode_invocation(ctx, |
| 525 |
pan_section_ptr(p, INDEXED_VERTEX_JOB, INVOCATION)); |
| 526 |
pandecode_primitive(ctx, pan_section_ptr(p, INDEXED_VERTEX_JOB, PRIMITIVE)); |
| 527 |
|
| 528 |
DUMP_SECTION(ctx, INDEXED_VERTEX_JOB, PRIMITIVE_SIZE, p, |
| 529 |
"Primitive Size:\n"); |
| 530 |
|
| 531 |
pan_section_unpack(p, INDEXED_VERTEX_JOB, PADDING, padding); |
| 532 |
} |
| 533 |
#endif |
| 534 |
|
| 535 |
#if PAN_ARCH == 9 |
| 536 |
static void |
| 537 |
pandecode_malloc_vertex_job(struct pandecode_context *ctx, uint64_t job, |
| 538 |
uint64_t gpu_id) |
| 539 |
{ |
| 540 |
struct mali_malloc_vertex_job_packed *PANDECODE_PTR_VAR(ctx, p, job); |
| 541 |
|
| 542 |
DUMP_SECTION(ctx, MALLOC_VERTEX_JOB, PRIMITIVE, p, "Primitive:\n"); |
| 543 |
DUMP_SECTION(ctx, MALLOC_VERTEX_JOB, INSTANCE_COUNT, p, "Instance count:\n"); |
| 544 |
DUMP_SECTION(ctx, MALLOC_VERTEX_JOB, ALLOCATION, p, "Allocation:\n"); |
| 545 |
DUMP_SECTION(ctx, MALLOC_VERTEX_JOB, TILER, p, "Tiler:\n"); |
| 546 |
DUMP_SECTION(ctx, MALLOC_VERTEX_JOB, SCISSOR, p, "Scissor:\n"); |
| 547 |
DUMP_SECTION(ctx, MALLOC_VERTEX_JOB, PRIMITIVE_SIZE, p, "Primitive Size:\n"); |
| 548 |
DUMP_SECTION(ctx, MALLOC_VERTEX_JOB, INDICES, p, "Indices:\n"); |
| 549 |
|
| 550 |
pan_section_unpack(p, MALLOC_VERTEX_JOB, DRAW, dcd); |
| 551 |
|
| 552 |
pan_section_unpack(p, MALLOC_VERTEX_JOB, TILER, tiler_ptr); |
| 553 |
pandecode_log(ctx, "Tiler Job Payload:\n"); |
| 554 |
ctx->indent++; |
| 555 |
if (tiler_ptr.address) |
| 556 |
GENX(pandecode_tiler)(ctx, tiler_ptr.address); |
| 557 |
else |
| 558 |
pandecode_log(ctx, "<omitted>\n"); |
| 559 |
ctx->indent--; |
| 560 |
|
| 561 |
GENX(pandecode_dcd)(ctx, &dcd, 0, gpu_id); |
| 562 |
|
| 563 |
pan_section_unpack(p, MALLOC_VERTEX_JOB, POSITION, position); |
| 564 |
pan_section_unpack(p, MALLOC_VERTEX_JOB, VARYING, varying); |
| 565 |
GENX(pandecode_shader_environment)(ctx, &position, gpu_id); |
| 566 |
GENX(pandecode_shader_environment)(ctx, &varying, gpu_id); |
| 567 |
} |
| 568 |
|
| 569 |
static void |
| 570 |
pandecode_compute_job(struct pandecode_context *ctx, uint64_t job, |
| 571 |
uint64_t gpu_id) |
| 572 |
{ |
| 573 |
struct mali_compute_job_packed *PANDECODE_PTR_VAR(ctx, p, job); |
| 574 |
pan_section_unpack(p, COMPUTE_JOB, PAYLOAD, payload); |
| 575 |
|
| 576 |
GENX(pandecode_shader_environment)(ctx, &payload.compute, gpu_id); |
| 577 |
DUMP_SECTION(ctx, COMPUTE_JOB, PAYLOAD, p, "Compute"); |
| 578 |
} |
| 579 |
#endif |
| 580 |
|
| 581 |
/* |
| 582 |
* Trace a job chain at a particular GPU address, interpreted for a particular |
| 583 |
* GPU using the job manager. |
| 584 |
*/ |
| 585 |
void |
| 586 |
GENX(pandecode_jc)(struct pandecode_context *ctx, uint64_t jc_gpu_va, |
| 587 |
uint64_t gpu_id) |
| 588 |
{ |
| 589 |
pandecode_dump_file_open(ctx); |
| 590 |
|
| 591 |
struct set *va_set = _mesa_pointer_set_create(NULL); |
| 592 |
struct set_entry *entry = NULL; |
| 593 |
|
| 594 |
uint64_t next_job = 0; |
| 595 |
|
| 596 |
do { |
| 597 |
struct mali_job_header_packed *hdr = |
| 598 |
PANDECODE_PTR(ctx, jc_gpu_va, struct mali_job_header_packed); |
| 599 |
|
| 600 |
entry = _mesa_set_search(va_set, hdr); |
| 601 |
if (entry != NULL) { |
| 602 |
fprintf(stdout, "Job list has a cycle\n"); |
| 603 |
break; |
| 604 |
} |
| 605 |
|
| 606 |
pan_unpack(hdr, JOB_HEADER, h); |
| 607 |
next_job = h.next; |
| 608 |
|
| 609 |
DUMP_UNPACKED(ctx, JOB_HEADER, h, "Job Header (%" PRIx64 "):\n", |
| 610 |
jc_gpu_va); |
| 611 |
pandecode_log(ctx, "\n"); |
| 612 |
|
| 613 |
switch (h.type) { |
| 614 |
case MALI_JOB_TYPE_WRITE_VALUE: |
| 615 |
pandecode_write_value_job(ctx, jc_gpu_va); |
| 616 |
break; |
| 617 |
|
| 618 |
case MALI_JOB_TYPE_CACHE_FLUSH: |
| 619 |
pandecode_cache_flush_job(ctx, jc_gpu_va); |
| 620 |
break; |
| 621 |
|
| 622 |
case MALI_JOB_TYPE_TILER: |
| 623 |
pandecode_tiler_job(ctx, &h, jc_gpu_va, gpu_id); |
| 624 |
break; |
| 625 |
|
| 626 |
#if PAN_ARCH < 9 |
| 627 |
case MALI_JOB_TYPE_VERTEX: |
| 628 |
case MALI_JOB_TYPE_COMPUTE: |
| 629 |
pandecode_vertex_compute_geometry_job(ctx, &h, jc_gpu_va, gpu_id); |
| 630 |
break; |
| 631 |
|
| 632 |
#if PAN_ARCH >= 6 |
| 633 |
case MALI_JOB_TYPE_INDEXED_VERTEX: |
| 634 |
pandecode_indexed_vertex_job(ctx, &h, jc_gpu_va, gpu_id); |
| 635 |
break; |
| 636 |
#endif |
| 637 |
#else |
| 638 |
case MALI_JOB_TYPE_COMPUTE: |
| 639 |
pandecode_compute_job(ctx, jc_gpu_va, gpu_id); |
| 640 |
break; |
| 641 |
|
| 642 |
case MALI_JOB_TYPE_MALLOC_VERTEX: |
| 643 |
pandecode_malloc_vertex_job(ctx, jc_gpu_va, gpu_id); |
| 644 |
break; |
| 645 |
#endif |
| 646 |
|
| 647 |
case MALI_JOB_TYPE_FRAGMENT: |
| 648 |
pandecode_fragment_job(ctx, jc_gpu_va, gpu_id); |
| 649 |
break; |
| 650 |
|
| 651 |
default: |
| 652 |
break; |
| 653 |
} |
| 654 |
|
| 655 |
/* Track the latest visited job CPU VA to detect cycles */ |
| 656 |
_mesa_set_add(va_set, hdr); |
| 657 |
} while ((jc_gpu_va = next_job)); |
| 658 |
|
| 659 |
_mesa_set_destroy(va_set, NULL); |
| 660 |
|
| 661 |
fflush(ctx->dump_stream); |
| 662 |
pandecode_map_read_write(ctx); |
| 663 |
} |
| 664 |
|
| 665 |
void |
| 666 |
GENX(pandecode_abort_on_fault)(struct pandecode_context *ctx, |
| 667 |
uint64_t jc_gpu_va) |
| 668 |
{ |
| 669 |
uint64_t next_job = 0; |
| 670 |
|
| 671 |
do { |
| 672 |
pan_unpack(PANDECODE_PTR(ctx, jc_gpu_va, struct mali_job_header_packed), |
| 673 |
JOB_HEADER, h); |
| 674 |
next_job = h.next; |
| 675 |
|
| 676 |
/* Ensure the job is marked COMPLETE */ |
| 677 |
if (h.exception_status != 0x1) { |
| 678 |
fprintf(stderr, "Incomplete job or timeout\n"); |
| 679 |
fflush(NULL); |
| 680 |
abort(); |
| 681 |
} |
| 682 |
} while ((jc_gpu_va = next_job)); |
| 683 |
|
| 684 |
pandecode_map_read_write(ctx); |
| 685 |
} |
| 686 |
|
| 687 |
#endif |