Debian Codegraph @

src/imagination/pco/pco_debug.c

raw
1 /*
2 * Copyright © 2024 Imagination Technologies Ltd.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 /**
8 * \file pco_debug.c
9 *
10 * \brief Debug-related functions.
11 */
12
13 #include "pco.h"
14 #include "pco_internal.h"
15 #include "util/macros.h"
16 #include "util/u_call_once.h"
17 #include "util/u_debug.h"
18
19 #include <stdbool.h>
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <unistd.h>
24
25 static const struct debug_named_value pco_debug_options[] = {
26 { "val_skip", PCO_DEBUG_VAL_SKIP, "Skip IR validation." },
27 { "reindex", PCO_DEBUG_REINDEX, "Reindex IR at the end of each pass." },
28 { "no_pred_cf", PCO_DEBUG_NO_PRED_CF, "No predicated execution in CF." },
29 { "alloc_extra_vtxins",
30 PCO_DEBUG_ALLOC_EXTRA_VTXINS,
31 "Allocates additional vertex input registers." },
32 { "int_smp",
33 PCO_DEBUG_INT_SMP,
34 "Enable integer coordinate support for sampler instructions." },
35 DEBUG_NAMED_VALUE_END,
36 };
37
38 static const struct debug_named_value pco_debug_print_options[] = {
39 { "vs", PCO_DEBUG_PRINT_VS, "Print the IR for vertex shaders." },
40 { "fs", PCO_DEBUG_PRINT_FS, "Print the IR for fragment shaders." },
41 { "cs", PCO_DEBUG_PRINT_CS, "Print the IR for compute shaders." },
42 { "all", PCO_DEBUG_PRINT_ALL, "Print the IR for all shaders." },
43 { "internal",
44 PCO_DEBUG_PRINT_INTERNAL,
45 "Print the IR for internal shader types." },
46 { "passes", PCO_DEBUG_PRINT_PASSES, "Print the IR after each pass." },
47 { "nir", PCO_DEBUG_PRINT_NIR, "Print the resulting NIR." },
48 { "binary", PCO_DEBUG_PRINT_BINARY, "Print the resulting binary." },
49 { "verbose", PCO_DEBUG_PRINT_VERBOSE, "Print verbose IR." },
50 { "ra", PCO_DEBUG_PRINT_RA, "Print register alloc info." },
51 { "stats", PCO_DEBUG_PRINT_STATS, "Print shader stats." },
52 DEBUG_NAMED_VALUE_END,
53 };
54
55 DEBUG_GET_ONCE_FLAGS_OPTION(pco_debug, "PCO_DEBUG", pco_debug_options, 0U)
56 uint64_t pco_debug = 0U;
57
58 DEBUG_GET_ONCE_FLAGS_OPTION(pco_debug_print,
59 "PCO_DEBUG_PRINT",
60 pco_debug_print_options,
61 0U)
62 uint64_t pco_debug_print = 0U;
63
64 DEBUG_GET_ONCE_OPTION(pco_skip_passes, "PCO_SKIP_PASSES", "")
65 const char *pco_skip_passes = "";
66
67 DEBUG_GET_ONCE_OPTION(pco_color, "PCO_COLOR", NULL)
68 bool pco_color = false;
69
70 static void pco_debug_init_once(void)
71 {
72 /* Get debug flags. */
73 pco_debug = debug_get_option_pco_debug();
74 pco_debug_print = debug_get_option_pco_debug_print();
75 pco_skip_passes = debug_get_option_pco_skip_passes();
76
77 /* Get/parse color option. */
78 const char *color_opt = debug_get_option_pco_color();
79 if (!color_opt || !strcmp(color_opt, "auto") || !strcmp(color_opt, "a"))
80 pco_color = isatty(fileno(stdout));
81 else if (!strcmp(color_opt, "on") || !strcmp(color_opt, "1"))
82 pco_color = true;
83 else if (!strcmp(color_opt, "off") || !strcmp(color_opt, "0"))
84 pco_color = false;
85 }
86
87 void pco_debug_init(void)
88 {
89 static util_once_flag flag = UTIL_ONCE_FLAG_INIT;
90 util_call_once(&flag, pco_debug_init_once);
91 }