mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-30 21:21:39 +02:00
microsoft/compiler: Remove code after discard/terminate in later optimization steps
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27996>
This commit is contained in:
parent
3d4dfae7eb
commit
ba17f5ca6a
1 changed files with 9 additions and 36 deletions
|
|
@ -1835,36 +1835,6 @@ dxil_nir_fix_io_uint_type(nir_shader *s, uint64_t in_mask, uint64_t out_mask)
|
|||
return progress;
|
||||
}
|
||||
|
||||
struct remove_after_discard_state {
|
||||
struct nir_block *active_block;
|
||||
};
|
||||
|
||||
static bool
|
||||
remove_after_discard(struct nir_builder *builder, nir_instr *instr,
|
||||
void *cb_data)
|
||||
{
|
||||
struct remove_after_discard_state *state = cb_data;
|
||||
if (instr->block == state->active_block) {
|
||||
nir_instr_remove_v(instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
state->active_block = instr->block;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
lower_kill(struct nir_builder *builder, nir_intrinsic_instr *intr,
|
||||
void *_cb_data)
|
||||
|
|
@ -1876,14 +1846,22 @@ lower_kill(struct nir_builder *builder, nir_intrinsic_instr *intr,
|
|||
return false;
|
||||
|
||||
builder->cursor = nir_instr_remove(&intr->instr);
|
||||
nir_def *condition;
|
||||
|
||||
if (intr->intrinsic == nir_intrinsic_discard ||
|
||||
intr->intrinsic == nir_intrinsic_terminate) {
|
||||
nir_demote(builder);
|
||||
condition = nir_imm_true(builder);
|
||||
} else {
|
||||
nir_demote_if(builder, intr->src[0].ssa);
|
||||
condition = intr->src[0].ssa;
|
||||
}
|
||||
|
||||
/* Create a new block by branching on the discard condition so that this return
|
||||
* is definitely the last instruction in its own block */
|
||||
nir_if *nif = nir_push_if(builder, condition);
|
||||
nir_jump(builder, nir_jump_return);
|
||||
nir_pop_if(builder, nif);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1896,12 +1874,7 @@ dxil_nir_lower_discard_and_terminate(nir_shader *s)
|
|||
|
||||
// This pass only works if all functions have been inlined
|
||||
assert(exec_list_length(&s->functions) == 1);
|
||||
struct remove_after_discard_state state;
|
||||
state.active_block = NULL;
|
||||
nir_shader_instructions_pass(s, remove_after_discard, nir_metadata_none,
|
||||
&state);
|
||||
return nir_shader_intrinsics_pass(s, lower_kill, nir_metadata_none,
|
||||
NULL);
|
||||
return nir_shader_intrinsics_pass(s, lower_kill, nir_metadata_none, NULL);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue