ac/llvm: use amdgpu-color-export/amdgpu-depth-export
authorRhys Perry <pendingchaos02@gmail.com>
Fri, 16 Dec 2022 12:24:40 +0000 (12:24 +0000)
committerMarge Bot <emma+marge@anholt.net>
Mon, 2 Jan 2023 12:00:04 +0000 (12:00 +0000)
These are necessary to use the correct export target on GFX11:
https://reviews.llvm.org/D128185

Fixes artifacts on Lara in Rise of the Tomb Raider benchmark and hair in
The Witcher 3 (classic).

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20357>

src/amd/llvm/ac_llvm_build.c

index 9a2b37e..ae2e18b 100644 (file)
@@ -2028,6 +2028,15 @@ void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a)
 
       ac_build_intrinsic(ctx, "llvm.amdgcn.exp.f32", ctx->voidt, args, 8, 0);
    }
+
+   if (LLVM_VERSION_MAJOR >= 15 && a->target == V_008DFC_SQ_EXP_MRTZ) {
+      LLVMAddTargetDependentFunctionAttr(ctx->main_function.value, "amdgpu-depth-export", "1");
+   } else if (LLVM_VERSION_MAJOR >= 15 && a->target <= V_008DFC_SQ_EXP_NULL) {
+      /* We need this attribute even for NULL targets, so that an export is created for full-wave
+       * discards on GFX10+.
+       */
+      LLVMAddTargetDependentFunctionAttr(ctx->main_function.value, "amdgpu-color-export", "1");
+   }
 }
 
 void ac_build_export_null(struct ac_llvm_context *ctx, bool uses_discard)
@@ -4619,6 +4628,12 @@ struct ac_llvm_pointer ac_build_main(const struct ac_shader_args *args, struct a
    /* Disable denormals for FP32: */
    LLVMAddTargetDependentFunctionAttr(main_function, "denormal-fp-math-f32",
                                       "preserve-sign,preserve-sign");
+
+   if (LLVM_VERSION_MAJOR >= 15 && convention == AC_LLVM_AMDGPU_PS) {
+      LLVMAddTargetDependentFunctionAttr(main_function, "amdgpu-depth-export", "0");
+      LLVMAddTargetDependentFunctionAttr(main_function, "amdgpu-color-export", "0");
+   }
+
    return ctx->main_function;
 }