ac/llvm: handle demote in LLVM 13 that just added support for it
authorMarek Olšák <marek.olsak@amd.com>
Tue, 2 Mar 2021 10:07:12 +0000 (05:07 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 17 Mar 2021 00:42:27 +0000 (00:42 +0000)
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9362>

src/amd/llvm/ac_llvm_build.c
src/amd/llvm/ac_nir_to_llvm.c

index 10b5e02..f6156a9 100644 (file)
@@ -4499,8 +4499,15 @@ LLVMValueRef ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef inte
 
 LLVMValueRef ac_build_load_helper_invocation(struct ac_llvm_context *ctx)
 {
-   LLVMValueRef result =
-      ac_build_intrinsic(ctx, "llvm.amdgcn.ps.live", ctx->i1, NULL, 0, AC_FUNC_ATTR_READNONE);
+   LLVMValueRef result;
+
+   if (LLVM_VERSION_MAJOR >= 13) {
+      result = ac_build_intrinsic(ctx, "llvm.amdgcn.live.mask", ctx->i1, NULL, 0,
+                                  AC_FUNC_ATTR_READONLY | AC_FUNC_ATTR_INACCESSIBLE_MEM_ONLY);
+   } else {
+      result = ac_build_intrinsic(ctx, "llvm.amdgcn.ps.live", ctx->i1, NULL, 0,
+                                  AC_FUNC_ATTR_READNONE);
+   }
    return LLVMBuildNot(ctx->builder, result, "");
 }
 
@@ -4509,6 +4516,9 @@ LLVMValueRef ac_build_is_helper_invocation(struct ac_llvm_context *ctx)
    if (!ctx->postponed_kill)
       return ac_build_load_helper_invocation(ctx);
 
+   /* postponed_kill should be NULL on LLVM 13+ */
+   assert(LLVM_VERSION_MAJOR < 13);
+
    /* !(exact && postponed) */
    LLVMValueRef exact =
       ac_build_intrinsic(ctx, "llvm.amdgcn.ps.live", ctx->i1, NULL, 0, AC_FUNC_ATTR_READNONE);
index 53e9bfa..fffe766 100644 (file)
@@ -2865,6 +2865,12 @@ static void emit_demote(struct ac_nir_context *ctx, const nir_intrinsic_instr *i
       cond = ctx->ac.i1false;
    }
 
+   if (LLVM_VERSION_MAJOR >= 13) {
+      /* This demotes the pixel if the condition is false. */
+      ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.wqm.demote", ctx->ac.voidt, &cond, 1, 0);
+      return;
+   }
+
    LLVMValueRef mask = LLVMBuildLoad(ctx->ac.builder, ctx->ac.postponed_kill, "");
    mask = LLVMBuildAnd(ctx->ac.builder, mask, cond, "");
    LLVMBuildStore(ctx->ac.builder, mask, ctx->ac.postponed_kill);
@@ -5035,7 +5041,8 @@ void ac_nir_translate(struct ac_llvm_context *ac, struct ac_shader_abi *abi,
    if (gl_shader_stage_is_compute(nir->info.stage))
       setup_shared(&ctx, nir);
 
-   if (nir->info.stage == MESA_SHADER_FRAGMENT && nir->info.fs.uses_demote) {
+   if (nir->info.stage == MESA_SHADER_FRAGMENT && nir->info.fs.uses_demote &&
+       LLVM_VERSION_MAJOR < 13) {
       /* true = don't kill. */
       ctx.ac.postponed_kill = ac_build_alloca_init(&ctx.ac, ctx.ac.i1true, "");
    }