• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    DEBUG_NAMED_VALUE_END,
29 };
30 
31 static const struct debug_named_value pco_debug_print_options[] = {
32    { "vs", PCO_DEBUG_PRINT_VS, "Print the IR for vertex shaders." },
33    { "fs", PCO_DEBUG_PRINT_FS, "Print the IR for fragment shaders." },
34    { "cs", PCO_DEBUG_PRINT_CS, "Print the IR for compute shaders." },
35    { "all", PCO_DEBUG_PRINT_ALL, "Print the IR for all shaders." },
36    { "internal",
37      PCO_DEBUG_PRINT_INTERNAL,
38      "Print the IR for internal shader types." },
39    { "passes", PCO_DEBUG_PRINT_PASSES, "Print the IR after each pass." },
40    { "nir", PCO_DEBUG_PRINT_NIR, "Print the resulting NIR." },
41    { "binary", PCO_DEBUG_PRINT_BINARY, "Print the resulting binary." },
42    { "verbose", PCO_DEBUG_PRINT_VERBOSE, "Print verbose IR." },
43    { "ra", PCO_DEBUG_PRINT_RA, "Print register alloc info." },
44    DEBUG_NAMED_VALUE_END,
45 };
46 
47 DEBUG_GET_ONCE_FLAGS_OPTION(pco_debug, "PCO_DEBUG", pco_debug_options, 0U)
48 uint64_t pco_debug = 0U;
49 
50 DEBUG_GET_ONCE_FLAGS_OPTION(pco_debug_print,
51                             "PCO_DEBUG_PRINT",
52                             pco_debug_print_options,
53                             0U)
54 uint64_t pco_debug_print = 0U;
55 
56 DEBUG_GET_ONCE_OPTION(pco_skip_passes, "PCO_SKIP_PASSES", "")
57 const char *pco_skip_passes = "";
58 
59 DEBUG_GET_ONCE_OPTION(pco_color, "PCO_COLOR", NULL)
60 bool pco_color = false;
61 
pco_debug_init_once(void)62 static void pco_debug_init_once(void)
63 {
64    /* Get debug flags. */
65    pco_debug = debug_get_option_pco_debug();
66    pco_debug_print = debug_get_option_pco_debug_print();
67    pco_skip_passes = debug_get_option_pco_skip_passes();
68 
69    /* Get/parse color option. */
70    const char *color_opt = debug_get_option_pco_color();
71    if (!color_opt || !strcmp(color_opt, "auto") || !strcmp(color_opt, "a"))
72       pco_color = isatty(fileno(stdout));
73    else if (!strcmp(color_opt, "on") || !strcmp(color_opt, "1"))
74       pco_color = true;
75    else if (!strcmp(color_opt, "off") || !strcmp(color_opt, "0"))
76       pco_color = false;
77 }
78 
pco_debug_init(void)79 void pco_debug_init(void)
80 {
81    static util_once_flag flag = UTIL_ONCE_FLAG_INIT;
82    util_call_once(&flag, pco_debug_init_once);
83 }
84