nir: Add nir_lower_halt_to_return

This is a lowering pass that was implemented by multiple drivers.

Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33003>
This commit is contained in:
Konstantin Seurer
2025-02-13 22:38:01 +01:00
committed by Marge Bot
parent db383ceb64
commit aacfc663cb
6 changed files with 34 additions and 51 deletions
+1
View File
@@ -175,6 +175,7 @@ else
'nir_lower_global_vars_to_local.c',
'nir_lower_goto_ifs.c',
'nir_lower_gs_intrinsics.c',
'nir_lower_halt_to_return.c',
'nir_lower_helper_writes.c',
'nir_lower_load_const_to_scalar.c',
'nir_lower_locals_to_regs.c',
+2
View File
@@ -5848,6 +5848,8 @@ typedef enum {
bool nir_lower_gs_intrinsics(nir_shader *shader, nir_lower_gs_intrinsics_flags options);
bool nir_lower_halt_to_return(nir_shader *nir);
bool nir_lower_tess_coord_z(nir_shader *shader, bool triangles);
typedef struct nir_lower_task_shader_options {
@@ -0,0 +1,28 @@
/*
* Copyright © 2025 Valve Corporation
* SPDX-License-Identifier: MIT
*/
#include "nir.h"
#include "nir_builder.h"
static bool
pass(nir_builder *b, nir_instr *instr, void *data)
{
if (instr->type != nir_instr_type_jump)
return false;
nir_jump_instr *jump = nir_instr_as_jump(instr);
if (jump->type == nir_jump_halt) {
jump->type = nir_jump_return;
return true;
}
return false;
}
bool
nir_lower_halt_to_return(nir_shader *nir)
{
return nir_shader_instructions_pass(nir, pass, nir_metadata_all, NULL);
}