pco: add env debug option parsing

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32258>
This commit is contained in:
Simon Perretta
2024-04-05 20:28:54 +01:00
committed by Marge Bot
parent e90c851b8c
commit 3349b5b296
5 changed files with 158 additions and 0 deletions

View File

@@ -1990,6 +1990,46 @@ PowerVR driver environment variables
Color is forced off if set to ``off``/``0`` or on if set to ``on``/``1``.
Defaults to ``auto``.
.. envvar:: PCO_DEBUG
A comma-separated list of named flags for the PCO compiler,
which control various compilation options:
``val_skip``
Skip IR validation.
.. envvar:: PCO_SKIP_PASSES
A comma-separated list of passes to skip.
.. envvar:: PCO_PRINT
A comma-separated list of named flags for the PCO compiler,
which control debug printing options:
``vs``
Print the IR for vertex shaders.
``fs``
Print the IR for fragment shaders.
``cs``
Print the IR for compute shaders.
``all``
Print the IR for all shaders.
``internal``
Print the IR for internal shader types.
``passes``
Print the IR after each pass.
``nir``
Print the resulting NIR.
``binary``
Print the resulting binary.
.. envvar:: PCO_COLOR
if set to ``auto`` PCO IR will be colorized if stdout is not a pipe.
Color is forced off if set to ``off``/``0`` or on if set to ``on``/``1``.
Defaults to ``auto``.
i915 driver environment variables
---------------------------------

View File

@@ -6,6 +6,7 @@ inc_powervr_compiler = include_directories(['.'])
libpowervr_compiler_files = files(
'pco.c',
'pco_binary.c',
'pco_debug.c',
'pco_ir.c',
'pco_nir.c',
'pco_trans_nir.c',

View File

@@ -28,6 +28,8 @@ pco_ctx *pco_ctx_create(const struct pvr_device_info *dev_info, void *mem_ctx)
ctx->dev_info = dev_info;
pco_debug_init();
return ctx;
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
/**
* \file pco_debug.c
*
* \brief Debug-related functions.
*/
#include "pco.h"
#include "pco_internal.h"
#include "util/macros.h"
#include "util/u_call_once.h"
#include "util/u_debug.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static const struct debug_named_value pco_debug_options[] = {
{ "val_skip", PCO_DEBUG_VAL_SKIP, "Skip IR validation." },
DEBUG_NAMED_VALUE_END,
};
static const struct debug_named_value pco_debug_print_options[] = {
{ "vs", PCO_DEBUG_PRINT_VS, "Print the IR for vertex shaders." },
{ "fs", PCO_DEBUG_PRINT_FS, "Print the IR for fragment shaders." },
{ "cs", PCO_DEBUG_PRINT_CS, "Print the IR for compute shaders." },
{ "all", PCO_DEBUG_PRINT_ALL, "Print the IR for all shaders." },
{ "internal",
PCO_DEBUG_PRINT_INTERNAL,
"Print the IR for internal shader types." },
{ "passes", PCO_DEBUG_PRINT_PASSES, "Print the IR after each pass." },
{ "nir", PCO_DEBUG_PRINT_NIR, "Print the resulting NIR." },
{ "binary", PCO_DEBUG_PRINT_BINARY, "Print the resulting binary." },
DEBUG_NAMED_VALUE_END,
};
DEBUG_GET_ONCE_FLAGS_OPTION(pco_debug, "PCO_DEBUG", pco_debug_options, 0U)
uint64_t pco_debug = 0U;
DEBUG_GET_ONCE_FLAGS_OPTION(pco_debug_print,
"PCO_DEBUG_PRINT",
pco_debug_print_options,
0U)
uint64_t pco_debug_print = 0U;
DEBUG_GET_ONCE_OPTION(pco_skip_passes, "PCO_SKIP_PASSES", "")
const char *pco_skip_passes = "";
DEBUG_GET_ONCE_OPTION(pco_color, "PCO_COLOR", NULL)
bool pco_color = false;
static void pco_debug_init_once(void)
{
/* Get debug flags. */
pco_debug = debug_get_option_pco_debug();
pco_debug_print = debug_get_option_pco_debug_print();
pco_skip_passes = debug_get_option_pco_skip_passes();
/* Get/parse color option. */
const char *color_opt = debug_get_option_pco_color();
if (!color_opt || !strcmp(color_opt, "auto") || !strcmp(color_opt, "a"))
pco_color = isatty(fileno(stdout));
else if (!strcmp(color_opt, "on") || !strcmp(color_opt, "1"))
pco_color = true;
else if (!strcmp(color_opt, "off") || !strcmp(color_opt, "0"))
pco_color = false;
}
void pco_debug_init(void)
{
static util_once_flag flag = UTIL_ONCE_FLAG_INIT;
util_call_once(&flag, pco_debug_init_once);
}

View File

@@ -15,6 +15,10 @@
#include "pco.h"
#include "spirv/nir_spirv.h"
#include "util/macros.h"
#include <stdbool.h>
#include <stdint.h>
/** PCO compiler context. */
typedef struct _pco_ctx {
@@ -28,4 +32,35 @@ typedef struct _pco_ctx {
struct spirv_to_nir_options spirv_options;
} pco_ctx;
/* Debug. */
enum pco_debug {
PCO_DEBUG_VAL_SKIP = BITFIELD64_BIT(0),
};
extern uint64_t pco_debug;
#define PCO_DEBUG(flag) unlikely(pco_debug &(PCO_DEBUG_##flag))
enum pco_debug_print {
PCO_DEBUG_PRINT_VS = BITFIELD64_BIT(0),
PCO_DEBUG_PRINT_FS = BITFIELD64_BIT(1),
PCO_DEBUG_PRINT_CS = BITFIELD64_BIT(2),
PCO_DEBUG_PRINT_ALL = PCO_DEBUG_PRINT_VS | PCO_DEBUG_PRINT_FS |
PCO_DEBUG_PRINT_CS,
PCO_DEBUG_PRINT_INTERNAL = BITFIELD64_BIT(3),
PCO_DEBUG_PRINT_PASSES = BITFIELD64_BIT(4),
PCO_DEBUG_PRINT_NIR = BITFIELD64_BIT(5),
PCO_DEBUG_PRINT_BINARY = BITFIELD64_BIT(6),
};
extern uint64_t pco_debug_print;
extern const char *pco_skip_passes;
#define PCO_DEBUG_PRINT(flag) \
unlikely(pco_debug_print &(PCO_DEBUG_PRINT_##flag))
extern bool pco_color;
void pco_debug_init(void);
#endif /* PCO_INTERNAL_H */