nir: store variable names to io instrs during io lowering

this creates a reference between variables and their access instrs
before the variables are deleted, which improves debugging

Acked-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28814>
This commit is contained in:
Mike Blumenkrantz 2024-04-18 10:54:02 -04:00 committed by Marge Bot
parent dbe2927472
commit 3541ed8502
3 changed files with 24 additions and 0 deletions

View File

@ -1909,6 +1909,9 @@ typedef struct {
int const_index[NIR_INTRINSIC_MAX_CONST_INDEX];
/* a variable name associated with this instr; cannot be modified or freed */
const char *name;
nir_src src[];
} nir_intrinsic_instr;

View File

@ -39,8 +39,22 @@ struct lower_io_state {
int (*type_size)(const struct glsl_type *type, bool);
nir_variable_mode modes;
nir_lower_io_options options;
struct set variable_names;
};
static const char *
add_variable_name(struct lower_io_state *state, const char *name)
{
if (!name)
return NULL;
bool found = false;
struct set_entry *entry = _mesa_set_search_or_add(&state->variable_names, name, &found);
if (!found)
entry->key = (void*)ralloc_strdup(state->builder.shader, name);
return entry->key;
}
static nir_intrinsic_op
ssbo_atomic_for_deref(nir_intrinsic_op deref_op)
{
@ -313,6 +327,7 @@ emit_load(struct lower_io_state *state,
nir_intrinsic_instr *load =
nir_intrinsic_instr_create(state->builder.shader, op);
load->num_components = num_components;
load->name = add_variable_name(state, var->name);
nir_intrinsic_set_base(load, var->data.driver_location);
if (nir_intrinsic_has_range(load)) {
@ -448,6 +463,7 @@ emit_store(struct lower_io_state *state, nir_def *data,
nir_intrinsic_instr *store =
nir_intrinsic_instr_create(state->builder.shader, op);
store->num_components = num_components;
store->name = add_variable_name(state, var->name);
store->src[0] = nir_src_for_ssa(data);
@ -769,6 +785,8 @@ nir_lower_io_impl(nir_function_impl *impl,
state.modes = modes;
state.type_size = type_size;
state.options = options;
_mesa_set_init(&state.variable_names, state.dead_ctx,
_mesa_hash_string, _mesa_key_string_equal);
ASSERTED nir_variable_mode supported_modes =
nir_var_shader_in | nir_var_shader_out | nir_var_uniform;

View File

@ -67,6 +67,9 @@ sweep_block(nir_shader *nir, nir_block *block)
nir_foreach_phi_src(src, nir_instr_as_phi(instr))
gc_mark_live(nir->gctx, src);
break;
case nir_instr_type_intrinsic:
ralloc_steal(nir, (void*)nir_instr_as_intrinsic(instr)->name);
break;
default:
break;
}