Mesa (staging/21.2): ac/nir/cull: Accept NaN and +/- Inf in face culling.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Oct 14 16:03:58 UTC 2021


Module: Mesa
Branch: staging/21.2
Commit: c52e6a9463ea725d2c4d183ec02b095d49b1c812
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c52e6a9463ea725d2c4d183ec02b095d49b1c812

Author: Timur Kristóf <timur.kristof at gmail.com>
Date:   Mon Oct 11 20:41:35 2021 +0200

ac/nir/cull: Accept NaN and +/- Inf in face culling.

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 <timur.kristof at gmail.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13299>
(cherry picked from commit 783f8f728ce8e77885adbc7b2c12c39c3e3e5198)

---

 .pick_status.json            | 2 +-
 src/amd/common/ac_nir_cull.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 09596b02bfe..7021a0cceba 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -4,7 +4,7 @@
         "description": "ac/nir/cull: Accept NaN and +/- Inf in face culling.",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "651a3da1b59446a6e392321d1dbbc1891a0544a8"
     },
diff --git a/src/amd/common/ac_nir_cull.c b/src/amd/common/ac_nir_cull.c
index a5adf2a4614..26e1f6515f4 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 *



More information about the mesa-commit mailing list