pan/{bi,va}: Lower terminate to demote

Bifrost/Valhall implementation is actually close to the demote behavior,
where discarded threads will continue execution until explicitly
terminated.

Given we'll need to support the demote behavior for Vulkan, let's use
nir_lower_terminate_to_demote(), which solves the problem, and allows
for extra dead-code elimination when a termination point is guaranteed
to be taken by all threads.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Lars-Ivar Hesselberg Simonsen <lars-ivar.simonsen@arm.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34676>
This commit is contained in:
Boris Brezillon 2025-04-23 15:46:48 +02:00 committed by Marge Bot
parent cd4400e27b
commit 83cbac00d3
2 changed files with 15 additions and 2 deletions

View file

@ -2134,11 +2134,11 @@ bi_emit_intrinsic(bi_builder *b, nir_intrinsic_instr *instr)
bi_emit_ld_tile(b, instr);
break;
case nir_intrinsic_terminate_if:
case nir_intrinsic_demote_if:
bi_discard_b32(b, bi_src_index(&instr->src[0]));
break;
case nir_intrinsic_terminate:
case nir_intrinsic_demote:
bi_discard_f32(b, bi_zero(), bi_zero(), BI_CMPF_EQ);
break;
@ -5703,6 +5703,18 @@ bifrost_preprocess_nir(nir_shader *nir, unsigned gpu_id)
{
MESA_TRACE_FUNC();
/* The DISCARD instruction just flags the thread as discarded, but the
* actual termination only happens when all threads in the quad are
* discarded, or when an instruction with a .discard flow is
* encountered (Valhall) or when a clause with a .terminate_discarded_thread
* is reached (Bifrost).
* We could do without nir_lower_terminate_to_demote(), but this allows
* for extra dead-code elimination when code sections are detected as
* being unused after a termination is crossed.
*/
if (nir->info.stage == MESA_SHADER_FRAGMENT)
NIR_PASS(_, nir, nir_lower_terminate_to_demote);
/* Ensure that halt are translated to returns and get ride of them */
NIR_PASS(_, nir, nir_shader_instructions_pass, bi_lower_halt_to_return,
nir_metadata_all, NULL);

View file

@ -147,6 +147,7 @@ void bifrost_compile_shader_nir(nir_shader *nir,
.scalarize_ddx = true, \
.support_indirect_inputs = (uint8_t)BITFIELD_MASK(PIPE_SHADER_TYPES), \
.lower_hadd = arch >= 11, \
.discard_is_demote = true, \
};
DEFINE_OPTIONS(6);