diff --git a/src/intel/tools/aubinator_error_decode.c b/src/intel/tools/aubinator_error_decode.c index 778ea949260..319159891bd 100644 --- a/src/intel/tools/aubinator_error_decode.c +++ b/src/intel/tools/aubinator_error_decode.c @@ -38,6 +38,7 @@ #include #include +#include "aubinator_error_decode_lib.h" #include "aubinator_error_decode_xe.h" #include "compiler/brw_compiler.h" #include "compiler/elk/elk_compiler.h" @@ -106,46 +107,6 @@ static const struct ring_register_mapping fault_registers[] = { { INTEL_ENGINE_CLASS_VIDEO_ENHANCE, 0, "VECS_FAULT_REG" }, }; -static int ring_name_to_class(const char *ring_name, - enum intel_engine_class *class) -{ - static const char *class_names[] = { - [INTEL_ENGINE_CLASS_RENDER] = "rcs", - [INTEL_ENGINE_CLASS_COMPUTE] = "ccs", - [INTEL_ENGINE_CLASS_COPY] = "bcs", - [INTEL_ENGINE_CLASS_VIDEO] = "vcs", - [INTEL_ENGINE_CLASS_VIDEO_ENHANCE] = "vecs", - }; - for (size_t i = 0; i < ARRAY_SIZE(class_names); i++) { - if (strncmp(ring_name, class_names[i], strlen(class_names[i]))) - continue; - - *class = i; - return atoi(ring_name + strlen(class_names[i])); - } - - static const struct { - const char *name; - unsigned int class; - int instance; - } legacy_names[] = { - { "render", INTEL_ENGINE_CLASS_RENDER, 0 }, - { "blt", INTEL_ENGINE_CLASS_COPY, 0 }, - { "bsd", INTEL_ENGINE_CLASS_VIDEO, 0 }, - { "bsd2", INTEL_ENGINE_CLASS_VIDEO, 1 }, - { "vebox", INTEL_ENGINE_CLASS_VIDEO_ENHANCE, 0 }, - }; - for (size_t i = 0; i < ARRAY_SIZE(legacy_names); i++) { - if (strcmp(ring_name, legacy_names[i].name)) - continue; - - *class = legacy_names[i].class; - return legacy_names[i].instance; - } - - return -1; -} - static const char * register_name_from_ring(const struct ring_register_mapping *mapping, unsigned nb_mapping, @@ -365,16 +326,7 @@ static int ascii85_decode(const char *in, uint32_t **out, bool inflate) return 0; } - if (*in == 'z') { - in++; - } else { - v += in[0] - 33; v *= 85; - v += in[1] - 33; v *= 85; - v += in[2] - 33; v *= 85; - v += in[3] - 33; v *= 85; - v += in[4] - 33; - in += 5; - } + in = ascii85_decode_char(in, &v); (*out)[len++] = v; } @@ -413,25 +365,7 @@ get_intel_batch_bo(void *user_data, bool ppgtt, uint64_t address) } static void -dump_shader_binary(void *user_data, const char *short_name, - uint64_t address, const void *data, - unsigned data_length) -{ - char filename[128]; - snprintf(filename, sizeof(filename), "%s_0x%016"PRIx64".bin", - short_name, address); - - FILE *f = fopen(filename, "w"); - if (f == NULL) { - fprintf(stderr, "Unable to open %s\n", filename); - return; - } - fwrite(data, data_length, 1, f); - fclose(f); -} - -static void -read_i915_data_file(FILE *file) +read_i915_data_file(FILE *file, enum intel_batch_decode_flags batch_flags) { struct intel_spec *spec = NULL; long long unsigned fence; @@ -732,15 +666,6 @@ read_i915_data_file(FILE *file) } } - enum intel_batch_decode_flags batch_flags = 0; - if (option_color == COLOR_ALWAYS) - batch_flags |= INTEL_BATCH_DECODE_IN_COLOR; - if (option_full_decode) - batch_flags |= INTEL_BATCH_DECODE_FULL; - if (option_print_offsets) - batch_flags |= INTEL_BATCH_DECODE_OFFSETS; - batch_flags |= INTEL_BATCH_DECODE_FLOATS; - struct intel_batch_decode_ctx batch_ctx; if (devinfo.ver >= 9) { intel_batch_decode_ctx_init_brw(&batch_ctx, &brw, &devinfo, stdout, @@ -912,6 +837,7 @@ open_i915_error_state_file(const char *path) int main(int argc, char *argv[]) { + enum intel_batch_decode_flags batch_flags = 0; FILE *file; int c, i; bool help = false, pager = true; @@ -1004,12 +930,20 @@ main(int argc, char *argv[]) if (isatty(1) && pager) setup_pager(); + if (option_color == COLOR_ALWAYS) + batch_flags |= INTEL_BATCH_DECODE_IN_COLOR; + if (option_full_decode) + batch_flags |= INTEL_BATCH_DECODE_FULL; + if (option_print_offsets) + batch_flags |= INTEL_BATCH_DECODE_OFFSETS; + batch_flags |= INTEL_BATCH_DECODE_FLOATS; + getline(&line, &line_size, file); rewind(file); if (strncmp(line, XE_KMD_ERROR_DUMP_IDENTIFIER, strlen(XE_KMD_ERROR_DUMP_IDENTIFIER)) == 0) - read_xe_data_file(file); + read_xe_data_file(file, batch_flags); else - read_i915_data_file(file); + read_i915_data_file(file, batch_flags); free(line); fclose(file); diff --git a/src/intel/tools/aubinator_error_decode_lib.c b/src/intel/tools/aubinator_error_decode_lib.c new file mode 100644 index 00000000000..7ad6ac5e5fa --- /dev/null +++ b/src/intel/tools/aubinator_error_decode_lib.c @@ -0,0 +1,89 @@ +/* + * Copyright 2024 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#include "aubinator_error_decode_lib.h" + +#include +#include +#include +#include + +#include "util/macros.h" + +int ring_name_to_class(const char *ring_name, enum intel_engine_class *class) +{ + static const char *class_names[] = { + [INTEL_ENGINE_CLASS_RENDER] = "rcs", + [INTEL_ENGINE_CLASS_COMPUTE] = "ccs", + [INTEL_ENGINE_CLASS_COPY] = "bcs", + [INTEL_ENGINE_CLASS_VIDEO] = "vcs", + [INTEL_ENGINE_CLASS_VIDEO_ENHANCE] = "vecs", + }; + for (size_t i = 0; i < ARRAY_SIZE(class_names); i++) { + if (strncmp(ring_name, class_names[i], strlen(class_names[i]))) + continue; + + *class = i; + return atoi(ring_name + strlen(class_names[i])); + } + + static const struct { + const char *name; + unsigned int class; + int instance; + } legacy_names[] = { + { "render", INTEL_ENGINE_CLASS_RENDER, 0 }, + { "blt", INTEL_ENGINE_CLASS_COPY, 0 }, + { "bsd", INTEL_ENGINE_CLASS_VIDEO, 0 }, + { "bsd2", INTEL_ENGINE_CLASS_VIDEO, 1 }, + { "vebox", INTEL_ENGINE_CLASS_VIDEO_ENHANCE, 0 }, + }; + for (size_t i = 0; i < ARRAY_SIZE(legacy_names); i++) { + if (strcmp(ring_name, legacy_names[i].name)) + continue; + + *class = legacy_names[i].class; + return legacy_names[i].instance; + } + + return -1; +} + +void +dump_shader_binary(void *user_data, const char *short_name, + uint64_t address, const void *data, + unsigned data_length) +{ + char filename[128]; + snprintf(filename, sizeof(filename), "%s_0x%016"PRIx64".bin", + short_name, address); + + FILE *f = fopen(filename, "w"); + if (f == NULL) { + fprintf(stderr, "Unable to open %s\n", filename); + return; + } + fwrite(data, data_length, 1, f); + fclose(f); +} + +const char * +ascii85_decode_char(const char *in, uint32_t *v) +{ + *v = 0; + + if (*in == 'z') { + in++; + } else { + *v += in[0] - 33; *v *= 85; + *v += in[1] - 33; *v *= 85; + *v += in[2] - 33; *v *= 85; + *v += in[3] - 33; *v *= 85; + *v += in[4] - 33; + in += 5; + } + + return in; +} diff --git a/src/intel/tools/aubinator_error_decode_lib.h b/src/intel/tools/aubinator_error_decode_lib.h new file mode 100644 index 00000000000..6984259fceb --- /dev/null +++ b/src/intel/tools/aubinator_error_decode_lib.h @@ -0,0 +1,17 @@ +/* + * Copyright 2024 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include "intel/common/intel_engine.h" + +int ring_name_to_class(const char *ring_name, enum intel_engine_class *class); + +void +dump_shader_binary(void *user_data, const char *short_name, + uint64_t address, const void *data, + unsigned data_length); + +const char *ascii85_decode_char(const char *in, uint32_t *v); \ No newline at end of file diff --git a/src/intel/tools/aubinator_error_decode_xe.c b/src/intel/tools/aubinator_error_decode_xe.c index 6ea0b273bd4..49895af9a6d 100644 --- a/src/intel/tools/aubinator_error_decode_xe.c +++ b/src/intel/tools/aubinator_error_decode_xe.c @@ -6,6 +6,6 @@ #include "aubinator_error_decode_xe.h" void -read_xe_data_file(FILE *file) +read_xe_data_file(FILE *file, enum intel_batch_decode_flags batch_flags) { } diff --git a/src/intel/tools/aubinator_error_decode_xe.h b/src/intel/tools/aubinator_error_decode_xe.h index 9fd35d860d3..f3d0970267c 100644 --- a/src/intel/tools/aubinator_error_decode_xe.h +++ b/src/intel/tools/aubinator_error_decode_xe.h @@ -7,4 +7,6 @@ #include -void read_xe_data_file(FILE *file); +#include "decoder/intel_decoder.h" + +void read_xe_data_file(FILE *file, enum intel_batch_decode_flags batch_flags); diff --git a/src/intel/tools/meson.build b/src/intel/tools/meson.build index c6324737552..733ddd7087b 100644 --- a/src/intel/tools/meson.build +++ b/src/intel/tools/meson.build @@ -44,6 +44,8 @@ aubinator = executable( aubinator_error_decode = executable( 'aubinator_error_decode', files('aubinator_error_decode.c', + 'aubinator_error_decode_lib.c', + 'aubinator_error_decode_lib.h', 'aubinator_error_decode_xe.c', 'aubinator_error_decode_xe.h'), dependencies : [idep_mesautil, dep_zlib, dep_thread, idep_intel_dev,