From 55ae25f2d733d3dc5db25233aa70b3932be3b106 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 1 Dec 2025 10:30:06 -0500 Subject: [PATCH] pan: Move disassembly wrappers to a new pan_compiler.h This is going to be where we put the compiler interface. For now, disassembly wrappers are as good a place to start as any. Acked-by: Erik Faye-Lund Acked-by: Boris Brezillon Part-of: --- src/panfrost/compiler/meson.build | 2 ++ src/panfrost/compiler/pan_compiler.c | 43 +++++++++++++++++++++++++++ src/panfrost/compiler/pan_compiler.h | 34 +++++++++++++++++++++ src/panfrost/genxml/decode_common.c | 12 ++------ src/panfrost/lib/pan_shader.h | 15 ---------- src/panfrost/vulkan/panvk_vX_shader.c | 5 ++-- 6 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 src/panfrost/compiler/pan_compiler.c create mode 100644 src/panfrost/compiler/pan_compiler.h diff --git a/src/panfrost/compiler/meson.build b/src/panfrost/compiler/meson.build index c781801a71c..bad5804d777 100644 --- a/src/panfrost/compiler/meson.build +++ b/src/panfrost/compiler/meson.build @@ -2,6 +2,8 @@ # SPDX-License-Identifier: MIT libpanfrost_compiler_files = files( + 'pan_compiler.c', + 'pan_compiler.h', 'pan_ir.c', 'pan_ir.h', 'pan_nir_collect_varyings.c', diff --git a/src/panfrost/compiler/pan_compiler.c b/src/panfrost/compiler/pan_compiler.c new file mode 100644 index 00000000000..393933d5388 --- /dev/null +++ b/src/panfrost/compiler/pan_compiler.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2025 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#include "pan_compiler.h" + +#include "bifrost/bifrost/disassemble.h" +#include "bifrost/valhall/disassemble.h" +#include "midgard/disassemble.h" + +#include "panfrost/model/pan_model.h" + +void +pan_disassemble(FILE *fp, const void *code, size_t size, + unsigned gpu_id, bool verbose) +{ + if (pan_arch(gpu_id) >= 9) + disassemble_valhall(fp, (const uint64_t *)code, size, verbose); + else if (pan_arch(gpu_id) >= 6) + disassemble_bifrost(fp, code, size, verbose); + else + disassemble_midgard(fp, code, size, gpu_id, verbose); +} diff --git a/src/panfrost/compiler/pan_compiler.h b/src/panfrost/compiler/pan_compiler.h new file mode 100644 index 00000000000..073c597438a --- /dev/null +++ b/src/panfrost/compiler/pan_compiler.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2025 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#ifndef __PAN_COMPILER_H__ +#define __PAN_COMPILER_H__ + +#include +#include + +void pan_disassemble(FILE *fp, const void *code, size_t size, + unsigned gpu_id, bool verbose); + +#endif /* __PAN_COMPILER_H__ */ diff --git a/src/panfrost/genxml/decode_common.c b/src/panfrost/genxml/decode_common.c index 6f1abb5c326..ee96cbedff6 100644 --- a/src/panfrost/genxml/decode_common.c +++ b/src/panfrost/genxml/decode_common.c @@ -38,9 +38,7 @@ #include "util/u_process.h" #include "decode.h" -#include "compiler/bifrost/bifrost/disassemble.h" -#include "compiler/bifrost/valhall/disassemble.h" -#include "midgard/disassemble.h" +#include "compiler/pan_compiler.h" /* Used to distiguish dumped files, otherwise we would have to print the ctx * pointer, which is annoying for the user since it changes with every run */ @@ -513,12 +511,8 @@ pandecode_shader_disassemble(struct pandecode_context *ctx, uint64_t shader_ptr, pandecode_log_cont(ctx, "\nShader %p (GPU VA %" PRIx64 ") sz %" PRId64 "\n", code, shader_ptr, sz); - if (pan_arch(gpu_id) >= 9) { - disassemble_valhall(ctx->dump_stream, (const uint64_t *)code, sz, true); - } else if (pan_arch(gpu_id) >= 6) - disassemble_bifrost(ctx->dump_stream, code, sz, false); - else - disassemble_midgard(ctx->dump_stream, code, sz, gpu_id, true); + bool verbose = pan_arch(gpu_id) >= 6 && pan_arch(gpu_id) < 9; + pan_disassemble(ctx->dump_stream, code, sz, gpu_id, verbose); pandecode_log_cont(ctx, "\n\n"); } diff --git a/src/panfrost/lib/pan_shader.h b/src/panfrost/lib/pan_shader.h index c8d08a6f478..fab1bdc3a20 100644 --- a/src/panfrost/lib/pan_shader.h +++ b/src/panfrost/lib/pan_shader.h @@ -27,9 +27,6 @@ #include "compiler/nir/nir.h" #include "genxml/gen_macros.h" -#include "panfrost/compiler/bifrost/bifrost/disassemble.h" -#include "panfrost/compiler/bifrost/valhall/disassemble.h" -#include "panfrost/compiler/midgard/disassemble.h" #include "panfrost/lib/pan_props.h" #include "panfrost/compiler/pan_ir.h" #include "panfrost/compiler/pan_nir_lower_framebuffer.h" @@ -101,18 +98,6 @@ pan_shader_lower_texture_late(nir_shader *nir, unsigned gpu_id) bifrost_lower_texture_late_nir(nir, gpu_id); } -static inline void -pan_shader_disassemble(FILE *fp, const void *code, size_t size, unsigned gpu_id, - bool verbose) -{ - if (pan_arch(gpu_id) >= 9) - disassemble_valhall(fp, (const uint64_t *)code, size, verbose); - else if (pan_arch(gpu_id) >= 6) - disassemble_bifrost(fp, code, size, verbose); - else - disassemble_midgard(fp, code, size, gpu_id, verbose); -} - void pan_shader_compile(nir_shader *nir, struct pan_compile_inputs *inputs, struct util_dynarray *binary, struct pan_shader_info *info); diff --git a/src/panfrost/vulkan/panvk_vX_shader.c b/src/panfrost/vulkan/panvk_vX_shader.c index cf149417fe5..1e1dcdc02a6 100644 --- a/src/panfrost/vulkan/panvk_vX_shader.c +++ b/src/panfrost/vulkan/panvk_vX_shader.c @@ -55,6 +55,7 @@ #include "vk_ycbcr_conversion.h" #include "compiler/bifrost/bifrost_nir.h" +#include "compiler/pan_compiler.h" #include "pan_shader.h" #include "vk_log.h" @@ -995,8 +996,8 @@ panvk_compile_nir(struct panvk_device *dev, nir_shader *nir, struct u_memstream mem; if (u_memstream_open(&mem, &data, &disasm_size)) { FILE *const stream = u_memstream_get(&mem); - pan_shader_disassemble(stream, shader->bin_ptr, shader->bin_size, - compile_input->gpu_id, false); + pan_disassemble(stream, shader->bin_ptr, shader->bin_size, + compile_input->gpu_id, false); u_memstream_close(&mem); } }