nir/print: print const value near each use of const ssa variable

Without/with NIR_DEBUG=print,print_const:

-vec4 32 ssa_60 = fadd ssa_59, ssa_58
+vec4 32 ssa_60 = fadd ssa_59 /*(0xbf800000, 0x3e800000, 0x00000000, 0x3f800000) = (-1.000000, 0.250000, 0.000000, 1.000000)*/, ssa_58

Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13880>
This commit is contained in:
Marcin Ślusarz 2021-11-19 15:47:56 +01:00 committed by Marge Bot
parent 23f8f836e0
commit 504e5cb4e8
3 changed files with 24 additions and 5 deletions

View file

@ -85,6 +85,8 @@ static const struct debug_named_value nir_debug_control[] = {
"Dump resulting callable shader after each successful lowering/optimization call" },
{ "print_ks", NIR_DEBUG_PRINT_KS,
"Dump resulting kernel shader after each successful lowering/optimization call" },
{ "print_consts", NIR_DEBUG_PRINT_CONSTS,
"Print const value near each use of const SSA variable" },
{ NULL }
};

View file

@ -91,6 +91,7 @@ extern bool nir_debug_print_shader[MESA_SHADER_KERNEL + 1];
#define NIR_DEBUG_PRINT_IS (1u << 17)
#define NIR_DEBUG_PRINT_CBS (1u << 18)
#define NIR_DEBUG_PRINT_KS (1u << 19)
#define NIR_DEBUG_PRINT_CONSTS (1u << 20)
#define NIR_DEBUG_PRINT (NIR_DEBUG_PRINT_VS | \
NIR_DEBUG_PRINT_TCS | \

View file

@ -111,20 +111,18 @@ print_ssa_def(nir_ssa_def *def, print_state *state)
}
static void
print_load_const_instr(nir_load_const_instr *instr, print_state *state)
print_const_from_load(nir_load_const_instr *instr, print_state *state)
{
FILE *fp = state->fp;
print_ssa_def(&instr->def, state);
fprintf(fp, " = load_const (");
/*
* we don't really know the type of the constant (if it will be used as a
* float or an int), so just print the raw constant in hex for fidelity
* and then print in float again for readability.
*/
fprintf(fp, "(");
for (unsigned i = 0; i < instr->def.num_components; i++) {
if (i != 0)
fprintf(fp, ", ");
@ -177,11 +175,29 @@ print_load_const_instr(nir_load_const_instr *instr, print_state *state)
fprintf(fp, ")");
}
static void
print_load_const_instr(nir_load_const_instr *instr, print_state *state)
{
FILE *fp = state->fp;
print_ssa_def(&instr->def, state);
fprintf(fp, " = load_const ");
print_const_from_load(instr, state);
}
static void
print_ssa_use(nir_ssa_def *def, print_state *state)
{
FILE *fp = state->fp;
fprintf(fp, "ssa_%u", def->index);
nir_instr *instr = def->parent_instr;
if (instr->type == nir_instr_type_load_const && NIR_DEBUG(PRINT_CONSTS)) {
fprintf(fp, " /*");
print_const_from_load(nir_instr_as_load_const(instr), state);
fprintf(fp, "*/");
}
}
static void print_src(const nir_src *src, print_state *state);