From 40b426c8f94c7307392971e34ee14743faa661e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Wed, 16 Aug 2023 15:30:49 -0400 Subject: [PATCH] ac: add a standalone IB parser program Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/amd/common/ac_parse_ib.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ src/amd/common/meson.build | 9 +++++++ 2 files changed, 72 insertions(+) create mode 100644 src/amd/common/ac_parse_ib.c diff --git a/src/amd/common/ac_parse_ib.c b/src/amd/common/ac_parse_ib.c new file mode 100644 index 0000000..d9cb1a6 --- /dev/null +++ b/src/amd/common/ac_parse_ib.c @@ -0,0 +1,63 @@ +/* + * Copyright © 2023 Advanced Micro Devices, Inc. + * + * SPDX-License-Identifier: MIT + */ + +#include "ac_debug.h" +#include +#include + +int main(int argc, char **argv) +{ + if (argc < 3) { + fprintf(stderr, "Usage: [LLVM processor] [IB filenames]\n"); + return 1; + } + + const char *gpu = argv[1]; + enum amd_gfx_level gfx_level; + enum radeon_family family = CHIP_UNKNOWN; + + for (unsigned i = 0; i < CHIP_LAST; i++) { + if (!strcmp(gpu, ac_get_llvm_processor_name(i))) { + family = i; + gfx_level = ac_get_gfx_level(i); + break; + } + } + + if (family == CHIP_UNKNOWN) { + fprintf(stderr, "Unknown LLVM processor.\n"); + return 1; + } + + for (unsigned i = 2; i < argc; i++) { + const char *filename = argv[i]; + + FILE *f = fopen(filename, "r"); + if (!f) { + fprintf(stderr, "Can't open IB: %s\n", filename); + continue; + } + + fseek(f, 0, SEEK_END); + int size = ftell(f); + fseek(f, 0, SEEK_SET); + + uint32_t *ib = (uint32_t*)malloc(size); + + if (fread(ib, size, 1, f) != 1) { + fprintf(stderr, "Can't read IB: %s\n", filename); + fclose(f); + free(ib); + continue; + } + fclose(f); + + ac_parse_ib(stdout, ib, size / 4, NULL, 0, filename, gfx_level, family, NULL, NULL); + free(ib); + } + + return 0; +} diff --git a/src/amd/common/meson.build b/src/amd/common/meson.build index 7b4f94e..e261f62 100644 --- a/src/amd/common/meson.build +++ b/src/amd/common/meson.build @@ -132,6 +132,15 @@ libamd_common = static_library( idep_amdgfxregs_h = declare_dependency(sources : [amdgfxregs_h]) +executable( + 'ac_parse_ib', + ['ac_parse_ib.c'], + link_with: [libamd_common], + include_directories : [ + inc_amd, inc_include, inc_src, + ], + dependencies : [idep_amdgfxregs_h, idep_mesautil, idep_nir_headers], +) if with_tests and not with_platform_windows test( -- 2.7.4