nir/lower_gs_intrinsics: Include primitive counts

Generic GS lowering needs this, we already calculate it.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Antonino Maniscalco <antonino.maniscalco@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26056>
This commit is contained in:
Alyssa Rosenzweig 2023-07-16 11:04:57 -04:00 committed by Marge Bot
parent a147801f9b
commit f157a3de4e
2 changed files with 20 additions and 5 deletions

View file

@ -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])

View file

@ -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 */