microsoft/spirv_to_dxil: Properly handle load- and is_helper_invocation
authorPedro J. Estébanez <pedrojrulez@gmail.com>
Tue, 22 Nov 2022 11:45:56 +0000 (12:45 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Dec 2022 16:29:13 +0000 (16:29 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19908>

src/microsoft/compiler/nir_to_dxil.c
src/microsoft/spirv_to_dxil/dxil_spirv_nir.c

index 55c14a1..00720f9 100644 (file)
@@ -4559,7 +4559,7 @@ emit_intrinsic(struct ntd_context *ctx, nir_intrinsic_instr *intr)
    case nir_intrinsic_load_sample_pos_from_id:
       return emit_load_sample_pos_from_id(ctx, intr);
 
-   case nir_intrinsic_load_helper_invocation:
+   case nir_intrinsic_is_helper_invocation:
       return emit_load_unary_external_function(
          ctx, intr, "dx.op.isHelperLane", DXIL_INTR_IS_HELPER_LANE);
 
@@ -6097,6 +6097,12 @@ nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
    NIR_PASS_V(s, nir_lower_pack);
    NIR_PASS_V(s, dxil_nir_lower_system_values);
    NIR_PASS_V(s, nir_lower_io_to_scalar, nir_var_shader_in | nir_var_system_value | nir_var_shader_out);
+   if (opts->shader_model_max < SHADER_MODEL_6_6) {
+      /* In a later pass, load_helper_invocation will be lowered to sample mask based fallback,
+       * so both load- and is- will be emulated eventually.
+       */
+      NIR_PASS_V(s, nir_lower_is_helper_invocation);
+   }
 
    if (ctx->mod.shader_kind == DXIL_HULL_SHADER)
       NIR_PASS_V(s, dxil_nir_split_tess_ctrl, &ctx->tess_ctrl_patch_constant_func);
index dc15f4e..5e04114 100644 (file)
@@ -630,6 +630,12 @@ dxil_spirv_nir_passes(nir_shader *nir,
                      .use_layer_id_sysval = true,
                  });
 
+      /* This will lower load_helper to a memoized is_helper if needed; otherwise, load_helper
+       * will stay, but trivially translatable to IsHelperLane(), which will be known to be
+       * constant across the invocation since no demotion would have been used.
+       */
+      NIR_PASS_V(nir, nir_lower_discard_or_demote, nir->info.use_legacy_math_rules);
+
       NIR_PASS_V(nir, dxil_nir_lower_discard_and_terminate);
       NIR_PASS_V(nir, nir_lower_returns);
       NIR_PASS_V(nir, dxil_nir_lower_sample_pos);