mesa/src/intel/decoder/intel_batch_decoder_gen.c
Jianxun Zhang 2a681c4f8b
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
intel/decoder: Print more information in shader's headline
Print out the kernel start pointer (KSP) and the hash of
referenced shader in its headline. This saves some search
in GPU hang dumps,  base on the work of

72bc74f0be and
fd11e4b4d3

An example from a decoded GPU hang dump:

0xeffeffefe19c:  0x10000002:  MI_STORE_DATA_IMM
0xeffeffefe19c:  0x10000002 : Dword 0
    DWord Length: 2
    Force Write Completion Check : false
    Store Qword: 0
    Use Global GTT: false
0xeffeffefe1a0:  0xffe000c0 : Dword 1
    Core Mode Enable: 0
0xeffeffefe1a4:  0x0000effe : Dword 2
    Address: 0xeffeffe000c0
0xeffeffefe1a8:  0x82f94895 : Dword 3 <--- No need to search here
0xeffeffefe1ac:  0x72080025 : Dword 4
    Immediate Data: 2197375125
0xeffeffefe1ac:  0x72080025:  COMPUTE_WALKER
0xeffeffefe1ac:  0x72080025 : Dword 0
...
    body: <struct COMPUTE_WALKER_BODY>
...
    Interface Descriptor: <struct INTERFACE_DESCRIPTOR_DATA>
...
0xeffeffefe1f4:  0x00001f40 : Dword 0
    Kernel Start Pointer: 0x00001f40 <--- No need to search here
...
0xeffeffefe244:  0x00000000 : Dword 37
    Inline Data[7]: 0

Referenced compute shader (ksp: 0x1f40 hash: 0x7208002582f94895): <- ksp & hash printed here
send(1)         g3UD            g2UD            nullUD ...
                ugm MsgDesc: ( load, a64, d32, V64, ...
add(1)          g16<2>UD        g2<0,1,0>UD     0x00000100UD

Note: Shader hash output rquires 'ANV_DEBUG=shader-hash' when running
the workload.

Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40418>
2026-06-11 03:28:29 +00:00

92 lines
3.1 KiB
C

/*
* Copyright © 2017 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#include "intel_decoder.h"
#include "intel_decoder_private.h"
#include "compiler/gen/gen.h"
#include "util/ralloc.h"
static void
ctx_disassemble_program_gen(struct intel_batch_decode_ctx *ctx,
uint32_t ksp,
const char *short_name,
const char *name)
{
uint64_t addr = ctx->instruction_base + ksp;
struct intel_batch_decode_bo bo = ctx_get_bo(ctx, true, addr);
if (!bo.map)
return;
fprintf(ctx->fp, "\nReferenced %s (ksp: 0x%" PRIx32, name, ksp);
if (ctx->shader_hash.last_inst &&
!strcmp(ctx->shader_hash.last_inst->name, "MI_STORE_DATA_IMM")) {
/* We only consider a recorded hash valid when the previously parsed
* instruction is the token.
*/
fprintf(ctx->fp, " hash: 0x%" PRIx64 "): \n", ctx->shader_hash.hash);
/* FIXME: Only the hash of the first shader is available now.
*
* For a targeted shader submission command which can have more than
* one shader, the dummy MI_STORE_DATA_IMM token instruction only
* contains the hash of the first shader. In this case, we invalidate
* the last instruction here so that the following shaders won't be
* printed out with the hash of the first.
*/
ctx->shader_hash.last_inst = NULL;
} else {
fprintf(ctx->fp, "):\n");
}
const int size = gen_find_shader_size(&ctx->devinfo, bo.map, 0, bo.size);
if (size > 0) {
void *tmp_ctx = ralloc_context(NULL);
gen_decode_params decode = {
.devinfo = &ctx->devinfo,
.raw_bytes = bo.map,
.raw_bytes_size = size,
.mem_ctx = tmp_ctx,
};
gen_decode(&decode);
gen_print_params print = {
.devinfo = &ctx->devinfo,
.fp = ctx->fp,
.insts = decode.insts,
.num_insts = decode.num_insts,
.errors = decode.errors,
.num_errors = decode.num_errors,
.raw_bytes = bo.map,
.raw_bytes_size = size,
};
gen_print(&print);
ralloc_free(tmp_ctx);
}
if (ctx->shader_binary) {
ctx->shader_binary(ctx->user_data, short_name, addr,
bo.map, size);
}
}
void
intel_batch_decode_ctx_init_gen(struct intel_batch_decode_ctx *ctx,
const struct intel_device_info *devinfo,
FILE *fp, enum intel_batch_decode_flags flags,
const char *xml_path,
struct intel_batch_decode_bo (*get_bo)(void *,
bool,
uint64_t),
unsigned (*get_state_size)(void *, uint64_t,
uint64_t),
void *user_data)
{
intel_batch_decode_ctx_init(ctx, devinfo, fp, flags, xml_path,
get_bo, get_state_size, user_data);
ctx->disassemble_program = ctx_disassemble_program_gen;
}