nir/lower_gs_intrinsics: Remove end primitive for points
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 16 Jul 2023 13:06:06 +0000 (09:06 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 22 Aug 2023 20:24:40 +0000 (20:24 +0000)
EndPrimitive() for points is entirely pointless, so just remove it when lowering
EndPrimitive to simplify the IR. This is (maybe) an optimization everywhere, and
will be relied on for correctness on Asahi.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24798>

src/compiler/nir/nir_lower_gs_intrinsics.c

index dbf4e512860651d5edeeac1bb0c3b1da0622fbdb..5dd9e41974b2dd34285f5ac1c20f39d46eaaa211 100644 (file)
@@ -201,15 +201,21 @@ rewrite_end_primitive(nir_intrinsic_instr *intrin, struct state *state)
    nir_builder *b = state->builder;
    unsigned stream = nir_intrinsic_stream_id(intrin);
 
-   b->cursor = nir_before_instr(&intrin->instr);
+   b->cursor = nir_instr_remove(&intrin->instr);
+   state->progress = true;
+
+   /* end_primitive doesn't do anything for points, remove without replacing */
+   if (state->is_points) {
+      b->shader->info.gs.uses_end_primitive = false;
+      return;
+   }
+
    assert(state->vertex_count_vars[stream] != NULL);
    nir_def *count = nir_load_var(b, state->vertex_count_vars[stream]);
    nir_def *count_per_primitive;
 
    if (state->count_vtx_per_prim)
       count_per_primitive = nir_load_var(b, state->vtxcnt_per_prim_vars[stream]);
-   else if (state->is_points)
-      count_per_primitive = nir_imm_int(b, 0);
    else
       count_per_primitive = nir_undef(b, count->num_components, count->bit_size);
 
@@ -232,10 +238,6 @@ rewrite_end_primitive(nir_intrinsic_instr *intrin, struct state *state)
                     nir_imm_int(b, 0),
                     0x1); /* .x */
    }
-
-   nir_instr_remove(&intrin->instr);
-
-   state->progress = true;
 }
 
 static bool