ac/nir/ngg: fix gs culling vertex liveness check for odd vertices

If vertex does not complete a primitive, it should not set the odd
flag which miss lead liveness check when culling is enabled.

For example, if odd flag is set regardless of complete flag, when
culling is enabled, 3 vertices of a triangle's init prim flag:
  [0x00 0x04 0x01]

then after culling, this triangle has been culled, their prim flag:
  [0x00 0x04 0x00]

the second vertex is miss treat as live because its odd flag (code
check prim_flag!=0 for liveness).

Fixes: 1bdeb961bd ("ac/nir/ngg: add gs culling")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8725
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22304>
(cherry picked from commit c082cdacae)
This commit is contained in:
Qiang Yu 2023-04-05 09:27:50 +08:00 committed by Dylan Baker
parent ad7f7ea007
commit 5ac5c276f3
2 changed files with 5 additions and 3 deletions

View file

@ -5914,7 +5914,7 @@
"description": "ac/nir/ngg: fix gs culling vertex liveness check for odd vertices",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "1bdeb961bd8c953713646ae0ea28cc5f21f4a232",
"notes": null

View file

@ -2733,6 +2733,7 @@ lower_ngg_gs_emit_vertex_with_counter(nir_builder *b, nir_intrinsic_instr *intri
/* Calculate and store per-vertex primitive flags based on vertex counts:
* - bit 0: whether this vertex finishes a primitive (a real primitive, not the strip)
* - bit 1: whether the primitive index is odd (if we are emitting triangle strips, otherwise always 0)
* only set when the vertex also finishes the primitive
* - bit 2: whether vertex is live (if culling is enabled: set after culling, otherwise always 1)
*/
@ -2746,8 +2747,9 @@ lower_ngg_gs_emit_vertex_with_counter(nir_builder *b, nir_intrinsic_instr *intri
nir_ssa_def *prim_flag = nir_ior(b, vertex_live_flag, complete_flag);
if (s->num_vertices_per_primitive == 3) {
nir_ssa_def *odd = nir_iand_imm(b, current_vtx_per_prim, 1);
prim_flag = nir_iadd_nuw(b, prim_flag, nir_ishl(b, odd, nir_imm_int(b, 1)));
nir_ssa_def *odd = nir_iand(b, current_vtx_per_prim, complete_flag);
nir_ssa_def *odd_flag = nir_ishl(b, odd, nir_imm_int(b, 1));
prim_flag = nir_ior(b, prim_flag, odd_flag);
}
nir_store_shared(b, nir_u2u8(b, prim_flag), gs_emit_vtx_addr, .base = s->lds_offs_primflags + stream, .align_mul = 4u);