ac/nir: add support for nir_intrinsic_shared_atomic_fadd
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 21 Jul 2020 08:49:36 +0000 (10:49 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 22 Jul 2020 08:20:53 +0000 (10:20 +0200)
Only LLVM 10+ has support.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6000>

src/amd/llvm/ac_nir_to_llvm.c

index 862ae5c30ff9410b25134b755ed743712564c513..47539cfb56a1248123311c1ada961a1c26bff6ee 100644 (file)
@@ -3404,11 +3404,26 @@ static LLVMValueRef visit_var_atomic(struct ac_nir_context *ctx,
                case nir_intrinsic_deref_atomic_exchange:
                        op = LLVMAtomicRMWBinOpXchg;
                        break;
+#if LLVM_VERSION_MAJOR >= 10
+               case nir_intrinsic_shared_atomic_fadd:
+               case nir_intrinsic_deref_atomic_fadd:
+                       op = LLVMAtomicRMWBinOpFAdd;
+                       break;
+#endif
                default:
                        return NULL;
                }
 
-               result = ac_build_atomic_rmw(&ctx->ac, op, ptr, ac_to_integer(&ctx->ac, src), sync_scope);
+               LLVMValueRef val;
+
+               if (instr->intrinsic == nir_intrinsic_shared_atomic_fadd ||
+                   instr->intrinsic == nir_intrinsic_deref_atomic_fadd) {
+                       val = ac_to_float(&ctx->ac, src);
+               } else {
+                       val = ac_to_integer(&ctx->ac, src);
+               }
+
+               result = ac_build_atomic_rmw(&ctx->ac, op, ptr, val, sync_scope);
        }
 
        if (ctx->ac.postponed_kill)
@@ -3944,7 +3959,8 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
        case nir_intrinsic_shared_atomic_or:
        case nir_intrinsic_shared_atomic_xor:
        case nir_intrinsic_shared_atomic_exchange:
-       case nir_intrinsic_shared_atomic_comp_swap: {
+       case nir_intrinsic_shared_atomic_comp_swap:
+       case nir_intrinsic_shared_atomic_fadd: {
                LLVMValueRef ptr = get_memory_ptr(ctx, instr->src[0],
                                                  instr->src[1].ssa->bit_size);
                result = visit_var_atomic(ctx, instr, ptr, 1);
@@ -3959,7 +3975,8 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
        case nir_intrinsic_deref_atomic_or:
        case nir_intrinsic_deref_atomic_xor:
        case nir_intrinsic_deref_atomic_exchange:
-       case nir_intrinsic_deref_atomic_comp_swap: {
+       case nir_intrinsic_deref_atomic_comp_swap:
+       case nir_intrinsic_deref_atomic_fadd: {
                LLVMValueRef ptr = get_src(ctx, instr->src[0]);
                result = visit_var_atomic(ctx, instr, ptr, 1);
                break;