Module: Mesa
Branch: main
Commit: 0976dfeca29527c2175c6925d46cba84391910c3
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0976dfeca29527c2175c6925d46cba84391910c3

Author: antonino <antonino.manisca...@collabora.com>
Date:   Mon Nov  6 12:26:23 2023 +0100

nir/zink: drop NIH helper in favor of `mesa_vertices_per_prim`

`lower_pv_mode_vertices_for_prim` and `decomposed_primitive_size` return
the same values as `mesa_vertices_per_prim` for the primitives that can
be used as output in geometry shaders.

Reviewed-by: Alyssa Rosenzweig <aly...@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26117>

---

 src/compiler/nir/nir_lower_gs_intrinsics.c | 21 ++++-----------------
 src/gallium/drivers/zink/zink_compiler.c   | 17 +----------------
 2 files changed, 5 insertions(+), 33 deletions(-)

diff --git a/src/compiler/nir/nir_lower_gs_intrinsics.c 
b/src/compiler/nir/nir_lower_gs_intrinsics.c
index 15cc69663fd..9d956f841af 100644
--- a/src/compiler/nir/nir_lower_gs_intrinsics.c
+++ b/src/compiler/nir/nir_lower_gs_intrinsics.c
@@ -69,21 +69,6 @@ struct state {
    bool progress;
 };
 
-static unsigned
-decomposed_primitive_size(nir_builder *b)
-{
-   enum mesa_prim outprim = b->shader->info.gs.output_primitive;
-
-   if (outprim == MESA_PRIM_POINTS)
-      return 1;
-   else if (outprim == MESA_PRIM_LINE_STRIP)
-      return 2;
-   else if (outprim == MESA_PRIM_TRIANGLE_STRIP)
-      return 3;
-   else
-      unreachable("Invalid GS output primitive type.");
-}
-
 /**
  * Replace emit_vertex intrinsics with:
  *
@@ -158,7 +143,8 @@ 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 = decomposed_primitive_size(b);
+      unsigned min_verts =
+         mesa_vertices_per_prim(b->shader->info.gs.output_primitive);
       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
@@ -200,7 +186,8 @@ overwrite_incomplete_primitives(struct state *state, 
unsigned stream)
    assert(state->count_vtx_per_prim);
 
    nir_builder *b = state->builder;
-   unsigned outprim_min_vertices = decomposed_primitive_size(b);
+   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 =
diff --git a/src/gallium/drivers/zink/zink_compiler.c 
b/src/gallium/drivers/zink/zink_compiler.c
index 2e56a57b077..6be551defef 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -484,21 +484,6 @@ lower_pv_mode_gs_instr(nir_builder *b, nir_instr *instr, 
void *data)
    }
 }
 
-static unsigned int
-lower_pv_mode_vertices_for_prim(enum mesa_prim prim)
-{
-   switch (prim) {
-   case MESA_PRIM_POINTS:
-      return 1;
-   case MESA_PRIM_LINE_STRIP:
-      return 2;
-   case MESA_PRIM_TRIANGLE_STRIP:
-      return 3;
-   default:
-      unreachable("unsupported primitive for gs output");
-   }
-}
-
 static bool
 lower_pv_mode_gs(nir_shader *shader, unsigned prim)
 {
@@ -510,7 +495,7 @@ lower_pv_mode_gs(nir_shader *shader, unsigned prim)
    b = nir_builder_at(nir_before_impl(entry));
 
    state.primitive_vert_count =
-      lower_pv_mode_vertices_for_prim(shader->info.gs.output_primitive);
+      mesa_vertices_per_prim(shader->info.gs.output_primitive);
    state.ring_size = shader->info.gs.vertices_out;
 
    nir_foreach_variable_with_modes(var, shader, nir_var_shader_out) {

Reply via email to