From 323d32bb0030f6253f67cc66b4e850fa144e27a9 Mon Sep 17 00:00:00 2001 From: Lorenzo Rossi Date: Fri, 5 Jun 2026 17:00:33 +0200 Subject: [PATCH] panfrost: Separate the compiler from libpanfrost Previously libpanfrost depended on the panfrost compiler, that was just used for the pan_disassemble function used to disassemble and print shaders. We'll need to add a dependency from kraid tests to libpanfrost and this made things harder due to meson shenanigans. This commit splits the dependency between libpanfrost and the compiler by adding the disassembler as a callback, so that the user can provide its own disassembler. Signed-off-by: Lorenzo Rossi Reviewed-by: Faith Ekstrand Part-of: --- src/gallium/drivers/panfrost/pan_device.c | 4 +++- src/panfrost/genxml/decode.h | 2 ++ src/panfrost/genxml/decode_common.c | 11 ++++++++++- src/panfrost/lib/meson.build | 2 +- src/panfrost/lib/wrap.h | 7 +++++++ src/panfrost/tools/meson.build | 1 + src/panfrost/tools/panfrostdump.c | 2 ++ src/panfrost/vulkan/panvk_vX_device.c | 4 +++- 8 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_device.c b/src/gallium/drivers/panfrost/pan_device.c index 1e222aa9141..fddabbb380d 100644 --- a/src/gallium/drivers/panfrost/pan_device.c +++ b/src/gallium/drivers/panfrost/pan_device.c @@ -84,8 +84,10 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev) list_inithead(&dev->bo_cache.buckets[i]); /* Initialize pandecode before we start allocating */ - if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) + if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) { dev->decode_ctx = pandecode_create_context(!(dev->debug & PAN_DBG_TRACE)); + pandecode_set_disassemble(dev->decode_ctx, pan_disassemble); + } /* Tiler heap is internally required by the tiler, which can only be * active for a single job chain at once, so a single heap can be diff --git a/src/panfrost/genxml/decode.h b/src/panfrost/genxml/decode.h index 47fe28f798f..e5829b06e31 100644 --- a/src/panfrost/genxml/decode.h +++ b/src/panfrost/genxml/decode.h @@ -23,6 +23,8 @@ struct pandecode_context { int dump_frame_count; simple_mtx_t lock; + pandecode_shader_disassemble_cb dissassemble; + /* On CSF context, set to true if the root CS ring buffer * is managed in userspace. The blob does that, and mesa might use * usermode queues too at some point. diff --git a/src/panfrost/genxml/decode_common.c b/src/panfrost/genxml/decode_common.c index 399fec9f335..26a8026379f 100644 --- a/src/panfrost/genxml/decode_common.c +++ b/src/panfrost/genxml/decode_common.c @@ -485,6 +485,14 @@ pandecode_cs_trace(struct pandecode_context *ctx, uint64_t trace_gpu_va, simple_mtx_unlock(&ctx->lock); } +void +pandecode_set_disassemble(struct pandecode_context *ctx, + pandecode_shader_disassemble_cb cb) +{ + assert(ctx->dissassemble == NULL && "pandecode_set_disassemble already called"); + ctx->dissassemble = cb; +} + void pandecode_shader_disassemble(struct pandecode_context *ctx, uint64_t shader_ptr, uint64_t gpu_id) @@ -503,7 +511,8 @@ pandecode_shader_disassemble(struct pandecode_context *ctx, uint64_t shader_ptr, code, shader_ptr, sz); bool verbose = pan_arch(gpu_id) >= 6; - pan_disassemble(ctx->dump_stream, code, sz, gpu_id, verbose); + if (ctx->dissassemble) + ctx->dissassemble(ctx->dump_stream, code, sz, gpu_id, verbose); pandecode_log_cont(ctx, "\n\n"); } diff --git a/src/panfrost/lib/meson.build b/src/panfrost/lib/meson.build index 080b8ac993d..55b67576b5c 100644 --- a/src/panfrost/lib/meson.build +++ b/src/panfrost/lib/meson.build @@ -69,7 +69,7 @@ libpanfrost_lib = static_library( ) libpanfrost_dep = declare_dependency( - link_with: [libpanfrost_lib, libpanfrost_decode, libpanfrost_compiler, libpanfrost_pixel_format, libpanfrost_per_arch], + link_with: [libpanfrost_lib, libpanfrost_decode, libpanfrost_pixel_format, libpanfrost_per_arch], include_directories: [inc_include, inc_src, inc_panfrost], dependencies: [deps_for_libpanfrost, libpankmod_dep, idep_nir], ) diff --git a/src/panfrost/lib/wrap.h b/src/panfrost/lib/wrap.h index 3c14aa64590..8e15c2e9f80 100644 --- a/src/panfrost/lib/wrap.h +++ b/src/panfrost/lib/wrap.h @@ -24,12 +24,19 @@ // TODO: update panwrap +typedef void (*pandecode_shader_disassemble_cb)(FILE *fp, const void *code, + size_t size, uint64_t gpu_id, + bool verbose); + struct pandecode_context; struct pandecode_context *pandecode_create_context(bool to_stderr); void pandecode_next_frame(struct pandecode_context *ctx); +void pandecode_set_disassemble(struct pandecode_context *ctx, + pandecode_shader_disassemble_cb cb); + void pandecode_destroy_context(struct pandecode_context *ctx); void pandecode_inject_mmap(struct pandecode_context *ctx, uint64_t gpu_va, diff --git a/src/panfrost/tools/meson.build b/src/panfrost/tools/meson.build index 35bcaedfd4d..2d5bef1b3a9 100644 --- a/src/panfrost/tools/meson.build +++ b/src/panfrost/tools/meson.build @@ -8,6 +8,7 @@ coredumpdec = executable( gnu_symbol_visibility : 'hidden', include_directories : [inc_include, inc_src], dependencies: [libpanfrost_dep], + link_with: [libpanfrost_compiler], build_by_default : true, install: true ) diff --git a/src/panfrost/tools/panfrostdump.c b/src/panfrost/tools/panfrostdump.c index bb650bc6faf..8f0b01baeb0 100644 --- a/src/panfrost/tools/panfrostdump.c +++ b/src/panfrost/tools/panfrostdump.c @@ -32,6 +32,7 @@ #include #include "decode.h" +#include "pan_compiler.h" /* Same as panfrost_dump_object_header, but with field * entries in host byte order @@ -236,6 +237,7 @@ main(int argc, char *argv[]) atexit(cleanup); struct pandecode_context *ctx = pandecode_create_context(false); + pandecode_set_disassemble(ctx, pan_disassemble); hdr_fp = fopen(argv[optind], "r"); if (!hdr_fp) { diff --git a/src/panfrost/vulkan/panvk_vX_device.c b/src/panfrost/vulkan/panvk_vX_device.c index 93b8a8e21af..1c1e726c6f6 100644 --- a/src/panfrost/vulkan/panvk_vX_device.c +++ b/src/panfrost/vulkan/panvk_vX_device.c @@ -405,8 +405,10 @@ panvk_per_arch(create_device)(struct panvk_physical_device *physical_device, goto err_finish_dev; } - if (PANVK_DEBUG(TRACE) || PANVK_DEBUG(SYNC) || PANVK_DEBUG(DUMP)) + if (PANVK_DEBUG(TRACE) || PANVK_DEBUG(SYNC) || PANVK_DEBUG(DUMP)) { device->debug.decode_ctx = pandecode_create_context(false); + pandecode_set_disassemble(device->debug.decode_ctx, pan_disassemble); + } /* 48bit address space clamped by the physical device limits, with the lower * 32MB reserved. */