treewide: Also handle struct nir_builder form

Via Coccinelle patch:

    @def@
    typedef bool;
    typedef nir_builder;
    typedef nir_instr;
    typedef nir_def;
    identifier fn, instr, intr, x, builder, data;
    @@

    static fn(struct nir_builder* builder,
    -nir_instr *instr,
    +nir_intrinsic_instr *intr,
    ...)
    {
    (
    -   if (instr->type != nir_instr_type_intrinsic)
    -      return false;
    -   nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
    |
    -   nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
    -   if (instr->type != nir_instr_type_intrinsic)
    -      return false;
    )

    <...
    (
    -instr->x
    +intr->instr.x
    |
    -instr
    +&intr->instr
    )
    ...>

    }

    @pass depends on def@
    identifier def.fn;
    expression shader, progress;
    @@

    (
    -nir_shader_instructions_pass(shader, fn,
    +nir_shader_intrinsics_pass(shader, fn,
    ...)
    |
    -NIR_PASS_V(shader, nir_shader_instructions_pass, fn,
    +NIR_PASS_V(shader, nir_shader_intrinsics_pass, fn,
    ...)
    |
    -NIR_PASS(progress, shader, nir_shader_instructions_pass, fn,
    +NIR_PASS(progress, shader, nir_shader_intrinsics_pass, fn,
    ...)
    )

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24852>
This commit is contained in:
Alyssa Rosenzweig
2023-08-23 12:53:26 -04:00
committed by Marge Bot
parent 465b138f01
commit cda1961835
14 changed files with 64 additions and 128 deletions
+12 -22
View File
@@ -1567,14 +1567,10 @@ dxil_reassign_driver_locations(nir_shader* s, nir_variable_mode modes,
}
static bool
lower_ubo_array_one_to_static(struct nir_builder *b, nir_instr *inst,
lower_ubo_array_one_to_static(struct nir_builder *b,
nir_intrinsic_instr *intrin,
void *cb_data)
{
if (inst->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(inst);
if (intrin->intrinsic != nir_intrinsic_load_vulkan_descriptor)
return false;
@@ -1617,8 +1613,9 @@ lower_ubo_array_one_to_static(struct nir_builder *b, nir_instr *inst,
bool
dxil_nir_lower_ubo_array_one_to_static(nir_shader *s)
{
bool progress = nir_shader_instructions_pass(
s, lower_ubo_array_one_to_static, nir_metadata_none, NULL);
bool progress = nir_shader_intrinsics_pass(s,
lower_ubo_array_one_to_static,
nir_metadata_none, NULL);
return progress;
}
@@ -1784,20 +1781,16 @@ remove_after_discard(struct nir_builder *builder, nir_instr *instr,
}
static bool
lower_kill(struct nir_builder *builder, nir_instr *instr, void *_cb_data)
lower_kill(struct nir_builder *builder, nir_intrinsic_instr *intr,
void *_cb_data)
{
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
if (intr->intrinsic != nir_intrinsic_discard &&
intr->intrinsic != nir_intrinsic_terminate &&
intr->intrinsic != nir_intrinsic_discard_if &&
intr->intrinsic != nir_intrinsic_terminate_if)
return false;
builder->cursor = nir_instr_remove(instr);
builder->cursor = nir_instr_remove(&intr->instr);
if (intr->intrinsic == nir_intrinsic_discard ||
intr->intrinsic == nir_intrinsic_terminate) {
nir_demote(builder);
@@ -1822,16 +1815,13 @@ dxil_nir_lower_discard_and_terminate(nir_shader *s)
state.active_block = NULL;
nir_shader_instructions_pass(s, remove_after_discard, nir_metadata_none,
&state);
return nir_shader_instructions_pass(s, lower_kill, nir_metadata_none,
return nir_shader_intrinsics_pass(s, lower_kill, nir_metadata_none,
NULL);
}
static bool
update_writes(struct nir_builder *b, nir_instr *instr, void *_state)
update_writes(struct nir_builder *b, nir_intrinsic_instr *intr, void *_state)
{
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
if (intr->intrinsic != nir_intrinsic_store_output)
return false;
@@ -1844,7 +1834,7 @@ update_writes(struct nir_builder *b, nir_instr *instr, void *_state)
if (src->num_components == 4 && write_mask == 0xf)
return false;
b->cursor = nir_before_instr(instr);
b->cursor = nir_before_instr(&intr->instr);
unsigned first_comp = nir_intrinsic_component(intr);
nir_def *channels[4] = { NULL, NULL, NULL, NULL };
assert(first_comp + src->num_components <= ARRAY_SIZE(channels));
@@ -1872,7 +1862,7 @@ dxil_nir_ensure_position_writes(nir_shader *s)
if ((s->info.outputs_written & VARYING_BIT_POS) == 0)
return false;
return nir_shader_instructions_pass(s, update_writes,
return nir_shader_intrinsics_pass(s, update_writes,
nir_metadata_block_index | nir_metadata_dominance,
NULL);
}
+4 -9
View File
@@ -497,14 +497,9 @@ dxil_spirv_nir_lower_yz_flip(nir_shader *shader,
}
static bool
discard_psiz_access(struct nir_builder *builder, nir_instr *instr,
discard_psiz_access(struct nir_builder *builder, nir_intrinsic_instr *intrin,
void *cb_data)
{
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
if (intrin->intrinsic != nir_intrinsic_store_deref &&
intrin->intrinsic != nir_intrinsic_load_deref)
return false;
@@ -514,12 +509,12 @@ discard_psiz_access(struct nir_builder *builder, nir_instr *instr,
var->data.location != VARYING_SLOT_PSIZ)
return false;
builder->cursor = nir_before_instr(instr);
builder->cursor = nir_before_instr(&intrin->instr);
if (intrin->intrinsic == nir_intrinsic_load_deref)
nir_def_rewrite_uses(&intrin->def, nir_imm_float(builder, 1.0));
nir_instr_remove(instr);
nir_instr_remove(&intrin->instr);
return true;
}
@@ -542,7 +537,7 @@ dxil_spirv_nir_discard_point_size_var(nir_shader *shader)
if (!psiz)
return false;
if (!nir_shader_instructions_pass(shader, discard_psiz_access,
if (!nir_shader_intrinsics_pass(shader, discard_psiz_access,
nir_metadata_block_index |
nir_metadata_dominance |
nir_metadata_loop_analysis,
+3 -7
View File
@@ -275,14 +275,10 @@ dzn_pipeline_get_nir_shader(struct dzn_device *device,
}
static bool
adjust_resource_index_binding(struct nir_builder *builder, nir_instr *instr,
adjust_resource_index_binding(struct nir_builder *builder,
nir_intrinsic_instr *intrin,
void *cb_data)
{
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
if (intrin->intrinsic != nir_intrinsic_vulkan_resource_index)
return false;
@@ -379,7 +375,7 @@ adjust_var_bindings(nir_shader *shader,
}
return ret;
} else {
return nir_shader_instructions_pass(shader, adjust_resource_index_binding,
return nir_shader_intrinsics_pass(shader, adjust_resource_index_binding,
nir_metadata_all, (void *)layout);
}
}