ac/nir: switch passes to use nir_shader_intrinsics_pass

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33024>
This commit is contained in:
Marek Olšák 2025-01-01 17:40:09 -05:00
parent d31b3513da
commit 51bbe2606d
5 changed files with 27 additions and 61 deletions

View file

@ -75,13 +75,9 @@ load_subgroup_id_lowered(lower_intrinsics_to_args_state *s, nir_builder *b)
}
static bool
lower_intrinsic_to_arg(nir_builder *b, nir_instr *instr, void *state)
lower_intrinsic_to_arg(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
{
if (instr->type != nir_instr_type_intrinsic)
return false;
lower_intrinsics_to_args_state *s = (lower_intrinsics_to_args_state *)state;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
nir_def *replacement = NULL;
b->cursor = nir_after_instr(&intrin->instr);
@ -358,14 +354,14 @@ lower_intrinsic_to_arg(nir_builder *b, nir_instr *instr, void *state)
case nir_intrinsic_overwrite_vs_arguments_amd:
s->vertex_id = intrin->src[0].ssa;
s->instance_id = intrin->src[1].ssa;
nir_instr_remove(instr);
nir_instr_remove(&intrin->instr);
return true;
case nir_intrinsic_overwrite_tes_arguments_amd:
s->tes_u = intrin->src[0].ssa;
s->tes_v = intrin->src[1].ssa;
s->tes_patch_id = intrin->src[2].ssa;
s->tes_rel_patch_id = intrin->src[3].ssa;
nir_instr_remove(instr);
nir_instr_remove(&intrin->instr);
return true;
case nir_intrinsic_load_vertex_id_zero_base:
if (!s->vertex_id)
@ -486,6 +482,6 @@ ac_nir_lower_intrinsics_to_args(nir_shader *shader, const enum amd_gfx_level gfx
.args = ac_args,
};
return nir_shader_instructions_pass(shader, lower_intrinsic_to_arg,
nir_metadata_control_flow, &state);
return nir_shader_intrinsics_pass(shader, lower_intrinsic_to_arg,
nir_metadata_control_flow, &state);
}

View file

@ -204,15 +204,10 @@ lower_legacy_gs_end_primitive_with_counter(nir_builder *b, nir_intrinsic_instr *
}
static bool
lower_legacy_gs_intrinsic(nir_builder *b, nir_instr *instr, void *state)
lower_legacy_gs_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
{
lower_legacy_gs_state *s = (lower_legacy_gs_state *) state;
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
if (intrin->intrinsic == nir_intrinsic_store_output)
return lower_legacy_gs_store_output(b, intrin, s);
else if (intrin->intrinsic == nir_intrinsic_emit_vertex_with_counter)
@ -251,8 +246,8 @@ ac_nir_lower_legacy_gs(nir_shader *nir,
break;
}
nir_shader_instructions_pass(nir, lower_legacy_gs_intrinsic,
nir_metadata_control_flow, &s);
nir_shader_intrinsics_pass(nir, lower_legacy_gs_intrinsic,
nir_metadata_control_flow, &s);
nir_function_impl *impl = nir_shader_get_entrypoint(nir);

View file

@ -595,15 +595,10 @@ add_clipdist_bit(nir_builder *b, nir_def *dist, unsigned index, nir_variable *ma
}
static bool
remove_culling_shader_output(nir_builder *b, nir_instr *instr, void *state)
remove_culling_shader_output(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
{
lower_ngg_nogs_state *s = (lower_ngg_nogs_state *) state;
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
/* These are not allowed in VS / TES */
assert(intrin->intrinsic != nir_intrinsic_store_per_vertex_output &&
intrin->intrinsic != nir_intrinsic_load_per_vertex_input);
@ -612,7 +607,7 @@ remove_culling_shader_output(nir_builder *b, nir_instr *instr, void *state)
if (intrin->intrinsic != nir_intrinsic_store_output)
return false;
b->cursor = nir_before_instr(instr);
b->cursor = nir_before_instr(&intrin->instr);
/* no indirect output */
assert(nir_src_is_const(intrin->src[1]) && nir_src_as_uint(intrin->src[1]) == 0);
@ -649,15 +644,15 @@ remove_culling_shader_output(nir_builder *b, nir_instr *instr, void *state)
}
/* Remove all output stores */
nir_instr_remove(instr);
nir_instr_remove(&intrin->instr);
return true;
}
static void
remove_culling_shader_outputs(nir_shader *culling_shader, lower_ngg_nogs_state *s)
{
nir_shader_instructions_pass(culling_shader, remove_culling_shader_output,
nir_metadata_control_flow, s);
nir_shader_intrinsics_pass(culling_shader, remove_culling_shader_output,
nir_metadata_control_flow, s);
/* Remove dead code resulting from the deleted outputs. */
bool progress;
@ -697,15 +692,10 @@ rewrite_uses_to_var(nir_builder *b, nir_def *old_def, nir_variable *replacement_
}
static bool
remove_extra_pos_output(nir_builder *b, nir_instr *instr, void *state)
remove_extra_pos_output(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
{
lower_ngg_nogs_state *s = (lower_ngg_nogs_state *) state;
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
/* These are not allowed in VS / TES */
assert(intrin->intrinsic != nir_intrinsic_store_per_vertex_output &&
intrin->intrinsic != nir_intrinsic_load_per_vertex_input);
@ -718,7 +708,7 @@ remove_extra_pos_output(nir_builder *b, nir_instr *instr, void *state)
if (io_sem.location != VARYING_SLOT_POS)
return false;
b->cursor = nir_before_instr(instr);
b->cursor = nir_before_instr(&intrin->instr);
/* In case other outputs use what we calculated for pos,
* try to avoid calculating it again by rewriting the usages
@ -727,7 +717,7 @@ remove_extra_pos_output(nir_builder *b, nir_instr *instr, void *state)
nir_def *store_val = intrin->src[0].ssa;
unsigned store_pos_component = nir_intrinsic_component(intrin);
nir_instr_remove(instr);
nir_instr_remove(&intrin->instr);
if (store_val->parent_instr->type == nir_instr_type_alu) {
nir_alu_instr *alu = nir_instr_as_alu(store_val->parent_instr);
@ -767,9 +757,8 @@ remove_extra_pos_output(nir_builder *b, nir_instr *instr, void *state)
static void
remove_extra_pos_outputs(nir_shader *shader, lower_ngg_nogs_state *s)
{
nir_shader_instructions_pass(shader, remove_extra_pos_output,
nir_metadata_control_flow,
s);
nir_shader_intrinsics_pass(shader, remove_extra_pos_output,
nir_metadata_control_flow, s);
}
static bool
@ -3004,15 +2993,10 @@ lower_ngg_gs_set_vertex_and_primitive_count(nir_builder *b, nir_intrinsic_instr
}
static bool
lower_ngg_gs_intrinsic(nir_builder *b, nir_instr *instr, void *state)
lower_ngg_gs_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
{
lower_ngg_gs_state *s = (lower_ngg_gs_state *) state;
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
if (intrin->intrinsic == nir_intrinsic_store_output)
return lower_ngg_gs_store_output(b, intrin, s);
else if (intrin->intrinsic == nir_intrinsic_emit_vertex_with_counter)
@ -3028,7 +3012,7 @@ lower_ngg_gs_intrinsic(nir_builder *b, nir_instr *instr, void *state)
static void
lower_ngg_gs_intrinsics(nir_shader *shader, lower_ngg_gs_state *s)
{
nir_shader_instructions_pass(shader, lower_ngg_gs_intrinsic, nir_metadata_none, s);
nir_shader_intrinsics_pass(shader, lower_ngg_gs_intrinsic, nir_metadata_none, s);
}
static void

View file

@ -338,15 +338,11 @@ fbfetch_color_buffer0(nir_builder *b, lower_ps_early_state *s)
}
static bool
lower_ps_intrinsic(nir_builder *b, nir_instr *instr, void *state)
lower_ps_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
{
lower_ps_early_state *s = (lower_ps_early_state *)state;
if (instr->type != nir_instr_type_intrinsic)
return false;
b->cursor = nir_before_instr(instr);
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
b->cursor = nir_before_instr(&intrin->instr);
switch (intrin->intrinsic) {
case nir_intrinsic_store_output:
@ -468,8 +464,8 @@ ac_nir_lower_ps_early(nir_shader *nir, const ac_nir_lower_ps_early_options *opti
/* Don't gather shader_info. Just gather the single thing we want to know. */
nir_shader_intrinsics_pass(nir, gather_frag_color_dual_src_blend, nir_metadata_all, &state);
bool progress = nir_shader_instructions_pass(nir, lower_ps_intrinsic,
nir_metadata_control_flow, &state);
bool progress = nir_shader_intrinsics_pass(nir, lower_ps_intrinsic,
nir_metadata_control_flow, &state);
if (state.persp_center || state.persp_centroid || state.persp_sample ||
state.linear_center || state.linear_centroid || state.linear_sample) {

View file

@ -176,15 +176,10 @@ gather_ps_store_output(nir_builder *b, nir_intrinsic_instr *intrin, lower_ps_sta
}
static bool
lower_ps_intrinsic(nir_builder *b, nir_instr *instr, void *state)
lower_ps_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
{
lower_ps_state *s = (lower_ps_state *)state;
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
case nir_intrinsic_store_output:
return gather_ps_store_output(b, intrin, s);
@ -706,8 +701,8 @@ ac_nir_lower_ps_late(nir_shader *nir, const ac_nir_lower_ps_late_options *option
.spi_shader_col_format = options->spi_shader_col_format,
};
bool progress = nir_shader_instructions_pass(nir, lower_ps_intrinsic,
nir_metadata_control_flow, &state);
bool progress = nir_shader_intrinsics_pass(nir, lower_ps_intrinsic,
nir_metadata_control_flow, &state);
progress |= export_ps_outputs(b, &state);
if (state.persp_centroid || state.linear_centroid) {