From fa1564fb87e1a4b458b8088eeb1bef32d96b247e Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 9 Jan 2024 01:30:19 -0800 Subject: [PATCH] intel/brw: Recreate GS output registers after EmitVertex Geometry shaders write outputs multiple times, with EmitVertex() between them. The value of output variables becomes undefined after calling EmitVertex(), so we don't need to preserve those. This lets us recreate new registers after each EmitVertex(), assuming we aren't in control flow, allowing them to have separate live ranges. It also means that those registers are more likely to be written once, rather than having multiple writes, which can make optimization easier. This is pretty much a total hack, but it's helpful. Reviewed-by: Caio Oliveira Part-of: --- src/intel/compiler/brw_fs_nir.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp index a21d859b19e..dd3a3158001 100644 --- a/src/intel/compiler/brw_fs_nir.cpp +++ b/src/intel/compiler/brw_fs_nir.cpp @@ -3161,6 +3161,13 @@ fs_nir_emit_gs_intrinsic(nir_to_brw_state &ntb, case nir_intrinsic_emit_vertex_with_counter: emit_gs_vertex(ntb, instr->src[0], nir_intrinsic_stream_id(instr)); + + /* After an EmitVertex() call, the values of all outputs are undefined. + * If this is not in control flow, recreate a fresh set of output + * registers to keep their live ranges separate. + */ + if (instr->instr.block->cf_node.parent->type == nir_cf_node_function) + fs_nir_setup_outputs(ntb); break; case nir_intrinsic_end_primitive_with_counter: