nir: lower is/load_helper to zero if no helper lanes are needed
authorDaniel Schürmann <daniel@schuermann.dev>
Mon, 15 Feb 2021 15:13:39 +0000 (16:13 +0100)
committerMarge Bot <eric+marge@anholt.net>
Wed, 17 Feb 2021 21:53:52 +0000 (21:53 +0000)
If there are no helper invocations required during the
execution of the shader, we can assume that there also
are no helper invocations active.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9058>

src/compiler/nir/nir_lower_discard_or_demote.c

index f039d2879fa667f3220b69e83667a61d251c0890..037022503e824f6564c5ff06333fc78a3ee73c31 100644 (file)
@@ -62,8 +62,15 @@ nir_lower_demote_to_discard_instr(nir_builder *b, nir_instr *instr, void *data)
       intrin->intrinsic = nir_intrinsic_discard_if;
       return true;
    case nir_intrinsic_is_helper_invocation:
-      intrin->intrinsic = nir_intrinsic_load_helper_invocation;
+   case nir_intrinsic_load_helper_invocation: {
+      /* If the shader doesn't need helper invocations,
+       * we can assume there are none */
+      b->cursor = nir_before_instr(instr);
+      nir_ssa_def *zero = nir_imm_false(b);
+      nir_ssa_def_rewrite_uses_ssa(&intrin->dest.ssa, zero);
+      nir_instr_remove_v(instr);
       return true;
+   }
    default:
       return false;
    }