diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 8dc0f54fb81..d02f3d28da8 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -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 } }; diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index f0bd76ab247..f3aba96a0c7 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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 | \ diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index f06ea2a8141..c96536b6129 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -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);