ac/nir: fix ngg culling on gfx11
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 14 Dec 2022 17:50:24 +0000 (17:50 +0000)
committerMarge Bot <emma+marge@anholt.net>
Thu, 15 Dec 2022 13:30:25 +0000 (13:30 +0000)
This subtraction can underflow.

If subgroup_id*wave_size is larger than num_live_vertices_in_workgroup,
num_es_threads_var should be zero.

fossil-db (gfx1100, nggc):
Totals from 41388 (30.75% of 134574) affected shaders:
Instrs: 25700772 -> 25783544 (+0.32%)
CodeSize: 126950072 -> 127281160 (+0.26%)
Latency: 92809233 -> 92849566 (+0.04%); split: -0.00%, +0.04%
InvThroughput: 9526675 -> 9542194 (+0.16%)
Copies: 2031078 -> 2031074 (-0.00%)

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20321>

src/amd/common/ac_nir_lower_ngg.c

index f6643b2..75519b8 100644 (file)
@@ -1547,8 +1547,8 @@ add_deferred_attribute_culling(nir_builder *b, nir_cf_list *original_extracted_c
          nir_ssa_def *num_live_vertices_in_wave = num_live_vertices_in_workgroup;
          if (nogs_state->max_num_waves > 1) {
             num_live_vertices_in_wave =
-               nir_isub(b, num_live_vertices_in_wave,
-                        nir_imul_imm(b, nir_load_subgroup_id(b), nogs_state->options->wave_size));
+               nir_usub_sat(b, num_live_vertices_in_wave,
+                            nir_imul_imm(b, nir_load_subgroup_id(b), nogs_state->options->wave_size));
             num_live_vertices_in_wave = nir_umin(b, num_live_vertices_in_wave,
                                                  nir_imm_int(b, nogs_state->options->wave_size));
          }