xref: /aosp_15_r20/external/mesa3d/src/intel/tools/aubinator_error_decode_lib.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2024 Intel Corporation
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "aubinator_error_decode_lib.h"
7 
8 #include <inttypes.h>
9 #include <stddef.h>
10 #include <stdlib.h>
11 #include <string.h>
12 
13 #include "util/macros.h"
14 
ring_name_to_class(const char * ring_name,enum intel_engine_class * class)15 int ring_name_to_class(const char *ring_name, enum intel_engine_class *class)
16 {
17    static const char *class_names[] = {
18       [INTEL_ENGINE_CLASS_RENDER] = "rcs",
19       [INTEL_ENGINE_CLASS_COMPUTE] = "ccs",
20       [INTEL_ENGINE_CLASS_COPY] = "bcs",
21       [INTEL_ENGINE_CLASS_VIDEO] = "vcs",
22       [INTEL_ENGINE_CLASS_VIDEO_ENHANCE] = "vecs",
23    };
24    for (size_t i = 0; i < ARRAY_SIZE(class_names); i++) {
25       if (strncmp(ring_name, class_names[i], strlen(class_names[i])))
26          continue;
27 
28       *class = i;
29       return atoi(ring_name + strlen(class_names[i]));
30    }
31 
32    static const struct {
33       const char *name;
34       unsigned int class;
35       int instance;
36    } legacy_names[] = {
37       { "render", INTEL_ENGINE_CLASS_RENDER, 0 },
38       { "blt", INTEL_ENGINE_CLASS_COPY, 0 },
39       { "bsd", INTEL_ENGINE_CLASS_VIDEO, 0 },
40       { "bsd2", INTEL_ENGINE_CLASS_VIDEO, 1 },
41       { "vebox", INTEL_ENGINE_CLASS_VIDEO_ENHANCE, 0 },
42    };
43    for (size_t i = 0; i < ARRAY_SIZE(legacy_names); i++) {
44       if (strcmp(ring_name, legacy_names[i].name))
45          continue;
46 
47       *class = legacy_names[i].class;
48       return legacy_names[i].instance;
49    }
50 
51    return -1;
52 }
53 
54 void
dump_shader_binary(void * user_data,const char * short_name,uint64_t address,const void * data,unsigned data_length)55 dump_shader_binary(void *user_data, const char *short_name,
56                    uint64_t address, const void *data,
57                    unsigned data_length)
58 {
59    char filename[128];
60    snprintf(filename, sizeof(filename), "%s_0x%016"PRIx64".bin",
61             short_name, address);
62 
63    FILE *f = fopen(filename, "w");
64    if (f == NULL) {
65       fprintf(stderr, "Unable to open %s\n", filename);
66       return;
67    }
68    fwrite(data, data_length, 1, f);
69    fclose(f);
70 }
71