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

Author: Timur Kristóf <[email protected]>
Date:   Wed Aug  3 11:40:12 2022 +0200

ac/nir/cull: Change if condition for bounding box culling.

The previous code checked all_w_positive in the if condition.
Instead, always execute the bbox culling code and include
all_w_positive at the end.

We assume checking in the if is not beneficial because it's
very unlikely that there is no primitive in a wave whose W are
not all positive.

This allows moving other things to the condition
in the next commit.

Fossil DB stats on Navi 21:

Totals from 60918 (45.16% of 134906) affected shaders:
CodeSize: 160574204 -> 160330564 (-0.15%); split: -0.15%, +0.00%
Instrs: 30538297 -> 30477385 (-0.20%); split: -0.20%, +0.00%
Latency: 139810902 -> 139802763 (-0.01%); split: -0.01%, +0.00%
InvThroughput: 21198449 -> 21198444 (-0.00%); split: -0.00%, +0.00%
SClause: 749810 -> 749811 (+0.00%)
Copies: 2701474 -> 2701482 (+0.00%); split: -0.00%, +0.00%

Signed-off-by: Timur Kristóf <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
Reviewed-by: Qiang Yu <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17870>

---

 src/amd/common/ac_nir_cull.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/amd/common/ac_nir_cull.c b/src/amd/common/ac_nir_cull.c
index ceb4a3276e3..e9ed1128662 100644
--- a/src/amd/common/ac_nir_cull.c
+++ b/src/amd/common/ac_nir_cull.c
@@ -155,9 +155,8 @@ ac_nir_cull_triangle(nir_builder *b,
    accepted = nir_iand(b, accepted, cull_face(b, pos, &w_info));
 
    nir_ssa_def *bbox_accepted = NULL;
-   nir_ssa_def *try_cull_bbox = nir_iand(b, accepted, w_info.all_w_positive);
 
-   nir_if *if_cull_bbox = nir_push_if(b, try_cull_bbox);
+   nir_if *if_accepted = nir_push_if(b, accepted);
    {
       nir_ssa_def *bbox_min[3] = {0}, *bbox_max[3] = {0};
       calc_bbox(b, pos, bbox_min, bbox_max);
@@ -166,9 +165,9 @@ ac_nir_cull_triangle(nir_builder *b,
       nir_ssa_def *prim_is_small = cull_small_primitive(b, bbox_min, bbox_max);
       nir_ssa_def *prim_invisible = nir_ior(b, prim_outside_view, 
prim_is_small);
 
-      bbox_accepted = nir_inot(b, prim_invisible);
+      bbox_accepted = nir_iand(b, nir_inot(b, prim_invisible), 
w_info.all_w_positive);
    }
-   nir_pop_if(b, if_cull_bbox);
+   nir_pop_if(b, if_accepted);
    accepted = nir_iand(b, accepted, nir_if_phi(b, bbox_accepted, accepted));
 
    return accepted;

Reply via email to