From 5af1828440fac8215952903bd9e8bbc8b50ec7b8 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 9 May 2024 10:24:23 -0400 Subject: [PATCH] asahi: mv vertex_id_for_topology_class into GS lowering not used with tess. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/agx_nir_lower_gs.c | 37 +++++++++++++++++++++++++++++- src/asahi/lib/agx_nir_lower_gs.h | 4 ---- src/asahi/lib/agx_nir_lower_ia.c | 39 +++----------------------------- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/asahi/lib/agx_nir_lower_gs.c b/src/asahi/lib/agx_nir_lower_gs.c index daf46db4330..2308da298af 100644 --- a/src/asahi/lib/agx_nir_lower_gs.c +++ b/src/asahi/lib/agx_nir_lower_gs.c @@ -167,6 +167,41 @@ load_instance_id(nir_builder *b) return nir_channel(b, nir_load_global_invocation_id(b, 32), 1); } +/* Geometry shaders use software input assembly. The software vertex shader + * is invoked for each index, and the geometry shader applies the topology. This + * helper applies the topology. + */ +static nir_def * +vertex_id_for_topology_class(nir_builder *b, nir_def *vert, enum mesa_prim cls) +{ + nir_def *prim = nir_load_primitive_id(b); + nir_def *flatshade_first = nir_ieq_imm(b, nir_load_provoking_last(b), 0); + nir_def *nr = nir_load_num_vertices(b); + nir_def *topology = nir_load_input_topology_agx(b); + + switch (cls) { + case MESA_PRIM_POINTS: + return prim; + + case MESA_PRIM_LINES: + return libagx_vertex_id_for_line_class(b, topology, prim, vert, nr); + + case MESA_PRIM_TRIANGLES: + return libagx_vertex_id_for_tri_class(b, topology, prim, vert, + flatshade_first); + + case MESA_PRIM_LINES_ADJACENCY: + return libagx_vertex_id_for_line_adj_class(b, topology, prim, vert); + + case MESA_PRIM_TRIANGLES_ADJACENCY: + return libagx_vertex_id_for_tri_adj_class(b, topology, prim, vert, nr, + flatshade_first); + + default: + unreachable("invalid topology class"); + } +} + nir_def * agx_load_per_vertex_input(nir_builder *b, nir_intrinsic_instr *intr, nir_def *vertex) @@ -193,7 +228,7 @@ lower_gs_inputs(nir_builder *b, nir_intrinsic_instr *intr, void *_) /* Calculate the vertex ID we're pulling, based on the topology class */ nir_def *vert_in_prim = intr->src[0].ssa; - nir_def *vertex = agx_vertex_id_for_topology_class( + nir_def *vertex = vertex_id_for_topology_class( b, vert_in_prim, b->shader->info.gs.input_primitive); /* The unrolled vertex ID uses the input_vertices, which differs from what diff --git a/src/asahi/lib/agx_nir_lower_gs.h b/src/asahi/lib/agx_nir_lower_gs.h index a5f2a76651a..f73084552f0 100644 --- a/src/asahi/lib/agx_nir_lower_gs.h +++ b/src/asahi/lib/agx_nir_lower_gs.h @@ -23,10 +23,6 @@ struct nir_def *agx_load_per_vertex_input(struct nir_builder *b, nir_intrinsic_instr *intr, struct nir_def *vertex); -struct nir_def *agx_vertex_id_for_topology_class(struct nir_builder *b, - struct nir_def *vert, - enum mesa_prim clas); - bool agx_nir_lower_index_buffer(struct nir_shader *s, unsigned index_size_B, bool patches); diff --git a/src/asahi/lib/agx_nir_lower_ia.c b/src/asahi/lib/agx_nir_lower_ia.c index 0a0a20f971b..0d846a55006 100644 --- a/src/asahi/lib/agx_nir_lower_ia.c +++ b/src/asahi/lib/agx_nir_lower_ia.c @@ -15,43 +15,10 @@ #include "shader_enums.h" /* - * This file implements input assembly in software for geometry/tessellation - * shaders. load_vertex_id is lowered based on the topology. Most of the logic - * lives in CL library routines. + * This file implements basic input assembly in software. It runs on software + * vertex shaders, as part of geometry/tessellation lowering. It does not apply + * the topology, which happens in the geometry shader. */ - -nir_def * -agx_vertex_id_for_topology_class(nir_builder *b, nir_def *vert, - enum mesa_prim cls) -{ - nir_def *prim = nir_load_primitive_id(b); - nir_def *flatshade_first = nir_ieq_imm(b, nir_load_provoking_last(b), 0); - nir_def *nr = nir_load_num_vertices(b); - nir_def *topology = nir_load_input_topology_agx(b); - - switch (cls) { - case MESA_PRIM_POINTS: - return prim; - - case MESA_PRIM_LINES: - return libagx_vertex_id_for_line_class(b, topology, prim, vert, nr); - - case MESA_PRIM_TRIANGLES: - return libagx_vertex_id_for_tri_class(b, topology, prim, vert, - flatshade_first); - - case MESA_PRIM_LINES_ADJACENCY: - return libagx_vertex_id_for_line_adj_class(b, topology, prim, vert); - - case MESA_PRIM_TRIANGLES_ADJACENCY: - return libagx_vertex_id_for_tri_adj_class(b, topology, prim, vert, nr, - flatshade_first); - - default: - unreachable("invalid topology class"); - } -} - struct state { unsigned index_size; bool patches;