From 783f8f728ce8e77885adbc7b2c12c39c3e3e5198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Mon, 11 Oct 2021 20:41:35 +0200 Subject: [PATCH] ac/nir/cull: Accept NaN and +/- Inf in face culling. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the determinant that we use for calculating triangle area is NaN, it's not possible to decide the facing of the triangle. This can happen when a coordinate of one of the triangle's vertices is INFINITY. It's better to just accept these triangles in the shader and let the PA deal with them. Let's do the same for +/- Infinity too. Though we haven't seen this yet, it may be troublesome as well. Fixes: 651a3da1b59446a6e392321d1dbbc1891a0544a8 Closes: #5470 Signed-off-by: Timur Kristóf Reviewed-by: Daniel Schürmann Part-of: --- src/amd/common/ac_nir_cull.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/amd/common/ac_nir_cull.c b/src/amd/common/ac_nir_cull.c index a5adf2a4614b..26e1f6515f46 100644 --- a/src/amd/common/ac_nir_cull.c +++ b/src/amd/common/ac_nir_cull.c @@ -75,7 +75,14 @@ cull_face(nir_builder *b, nir_ssa_def *pos[3][4], const position_w_info *w_info) nir_ssa_def *cull_front = nir_build_load_cull_front_face_enabled_amd(b); nir_ssa_def *cull_back = nir_build_load_cull_back_face_enabled_amd(b); - return nir_inot(b, nir_bcsel(b, front_facing, cull_front, cull_back)); + nir_ssa_def *face_culled = nir_bcsel(b, front_facing, cull_front, cull_back); + + /* Don't reject NaN and +/-infinity, these are tricky. + * Just trust fixed-function HW to handle these cases correctly. + */ + face_culled = nir_iand(b, face_culled, nir_fisfinite(b, det)); + + return nir_inot(b, face_culled); } static nir_ssa_def * -- GitLab