From f1aeb46a34a58fce4d87009e7f4f203ae64fcb37 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 21 Apr 2025 13:40:19 -0400 Subject: [PATCH] nir: factor out nir_verts_in_output_prim helper very useful for geometry shader lowering code. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Mary Guillemard Part-of: --- src/compiler/nir/nir.h | 7 +++++++ src/compiler/nir/nir_lower_gs_intrinsics.c | 7 ++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index ff3c5d3b6db..491c98f3033 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6447,6 +6447,13 @@ void nir_print_use_dominators(nir_use_dominance_state *state, nir_instr **instructions, unsigned num_instructions); +static inline unsigned +nir_verts_in_output_prim(nir_shader *gs) +{ + assert(gs->info.stage == MESA_SHADER_GEOMETRY); + return mesa_vertices_per_prim(gs->info.gs.output_primitive); +} + #include "nir_inline_helpers.h" #ifdef __cplusplus diff --git a/src/compiler/nir/nir_lower_gs_intrinsics.c b/src/compiler/nir/nir_lower_gs_intrinsics.c index d37833b7066..b6dc21d2992 100644 --- a/src/compiler/nir/nir_lower_gs_intrinsics.c +++ b/src/compiler/nir/nir_lower_gs_intrinsics.c @@ -142,8 +142,7 @@ rewrite_emit_vertex(nir_intrinsic_instr *intrin, struct state *state) /* We form a new primitive for every vertex emitted after the first * complete primitive (since we're outputting strips). */ - unsigned min_verts = - mesa_vertices_per_prim(b->shader->info.gs.output_primitive); + unsigned min_verts = nir_verts_in_output_prim(b->shader); nir_def *new_prim = nir_uge_imm(b, vtx_per_prim_cnt, min_verts); /* Increment the decomposed primitive count by 1 if we formed a complete @@ -185,8 +184,6 @@ overwrite_incomplete_primitives(struct state *state, unsigned stream) assert(state->count_vtx_per_prim); nir_builder *b = state->builder; - unsigned outprim_min_vertices = - mesa_vertices_per_prim(b->shader->info.gs.output_primitive); /* Total count of vertices emitted so far. */ nir_def *vtxcnt_total = @@ -198,7 +195,7 @@ overwrite_incomplete_primitives(struct state *state, unsigned stream) /* See if the current primitive is a incomplete */ nir_def *is_inc_prim = - nir_ilt_imm(b, vtxcnt_per_primitive, outprim_min_vertices); + nir_ilt_imm(b, vtxcnt_per_primitive, nir_verts_in_output_prim(b->shader)); /* Number of vertices in the incomplete primitive */ nir_def *num_inc_vtx =