From f157a3de4e2aa58b7d4e579b269f4b6540674f09 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 16 Jul 2023 11:04:57 -0400 Subject: [PATCH] nir/lower_gs_intrinsics: Include primitive counts Generic GS lowering needs this, we already calculate it. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Antonino Maniscalco Part-of: --- src/compiler/nir/nir_intrinsics.py | 7 ++++--- src/compiler/nir/nir_lower_gs_intrinsics.c | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py index 4dfbc04e845..e5c9c592112 100644 --- a/src/compiler/nir/nir_intrinsics.py +++ b/src/compiler/nir/nir_intrinsics.py @@ -536,12 +536,13 @@ intrinsic("end_primitive", indices=[STREAM_ID]) # Alternatively, drivers may implement these intrinsics, and use # nir_lower_gs_intrinsics() to convert from the basic intrinsics. # -# These contain two additional unsigned integer sources: +# These contain three additional unsigned integer sources: # 1. The total number of vertices emitted so far. # 2. The number of vertices emitted for the current primitive # so far if we're counting, otherwise undef. -intrinsic("emit_vertex_with_counter", src_comp=[1, 1], indices=[STREAM_ID]) -intrinsic("end_primitive_with_counter", src_comp=[1, 1], indices=[STREAM_ID]) +# 3. The total number of primitives emitted so far. +intrinsic("emit_vertex_with_counter", src_comp=[1, 1, 1], indices=[STREAM_ID]) +intrinsic("end_primitive_with_counter", src_comp=[1, 1, 1], indices=[STREAM_ID]) # Contains the final total vertex and primitive counts in the current GS thread. intrinsic("set_vertex_and_primitive_count", src_comp=[1, 1], indices=[STREAM_ID]) diff --git a/src/compiler/nir/nir_lower_gs_intrinsics.c b/src/compiler/nir/nir_lower_gs_intrinsics.c index b03f1b8d531..332adcb40f5 100644 --- a/src/compiler/nir/nir_lower_gs_intrinsics.c +++ b/src/compiler/nir/nir_lower_gs_intrinsics.c @@ -87,6 +87,7 @@ rewrite_emit_vertex(nir_intrinsic_instr *intrin, struct state *state) assert(state->vertex_count_vars[stream] != NULL); nir_def *count = nir_load_var(b, state->vertex_count_vars[stream]); nir_def *count_per_primitive; + nir_def *primitive_count; if (state->count_vtx_per_prim) count_per_primitive = nir_load_var(b, state->vtxcnt_per_prim_vars[stream]); @@ -95,6 +96,11 @@ rewrite_emit_vertex(nir_intrinsic_instr *intrin, struct state *state) else count_per_primitive = nir_undef(b, 1, 32); + if (state->count_prims) + primitive_count = nir_load_var(b, state->primitive_count_vars[stream]); + else + primitive_count = nir_undef(b, 1, 32); + /* Create: if (vertex_count < max_vertices) and insert it. * * The new if statement needs to be hooked up to the control flow graph @@ -102,7 +108,8 @@ rewrite_emit_vertex(nir_intrinsic_instr *intrin, struct state *state) */ nir_push_if(b, nir_ilt_imm(b, count, b->shader->info.gs.vertices_out)); - nir_emit_vertex_with_counter(b, count, count_per_primitive, stream); + nir_emit_vertex_with_counter(b, count, count_per_primitive, primitive_count, + stream); /* Increment the vertex count by 1 */ nir_store_var(b, state->vertex_count_vars[stream], @@ -213,13 +220,20 @@ rewrite_end_primitive(nir_intrinsic_instr *intrin, struct state *state) assert(state->vertex_count_vars[stream] != NULL); nir_def *count = nir_load_var(b, state->vertex_count_vars[stream]); nir_def *count_per_primitive; + nir_def *primitive_count; if (state->count_vtx_per_prim) count_per_primitive = nir_load_var(b, state->vtxcnt_per_prim_vars[stream]); else count_per_primitive = nir_undef(b, count->num_components, count->bit_size); - nir_end_primitive_with_counter(b, count, count_per_primitive, stream); + if (state->count_prims) + primitive_count = nir_load_var(b, state->primitive_count_vars[stream]); + else + primitive_count = nir_undef(b, 1, 32); + + nir_end_primitive_with_counter(b, count, count_per_primitive, + primitive_count, stream); if (state->count_prims) { /* Increment the primitive count by 1 */