From: Samuel Pitoiset Date: Tue, 12 Mar 2019 08:21:59 +0000 (+0100) Subject: ac/nir: use new LLVM 8 intrinsics for SSBO atomic operations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=29132af2347ede46a6d02422295a5fadbe5fe788;p=mesa.git ac/nir: use new LLVM 8 intrinsics for SSBO atomic operations Use the raw version (ie. IDXEN=0) because vindex is unused. Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen --- diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index e0ca6a5a548..ca198775f51 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -1628,57 +1628,75 @@ static void visit_store_ssbo(struct ac_nir_context *ctx, static LLVMValueRef visit_atomic_ssbo(struct ac_nir_context *ctx, const nir_intrinsic_instr *instr) { - const char *name; - LLVMValueRef params[6]; + const char *atomic_name; + char intrinsic_name[64]; + LLVMValueRef params[7]; int arg_count = 0; - - if (instr->intrinsic == nir_intrinsic_ssbo_atomic_comp_swap) { - params[arg_count++] = ac_llvm_extract_elem(&ctx->ac, get_src(ctx, instr->src[3]), 0); - } - params[arg_count++] = ac_llvm_extract_elem(&ctx->ac, get_src(ctx, instr->src[2]), 0); - params[arg_count++] = ctx->abi->load_ssbo(ctx->abi, - get_src(ctx, instr->src[0]), - true); - params[arg_count++] = ctx->ac.i32_0; /* vindex */ - params[arg_count++] = get_src(ctx, instr->src[1]); /* voffset */ - params[arg_count++] = ctx->ac.i1false; /* slc */ + int length; switch (instr->intrinsic) { case nir_intrinsic_ssbo_atomic_add: - name = "llvm.amdgcn.buffer.atomic.add"; + atomic_name = "add"; break; case nir_intrinsic_ssbo_atomic_imin: - name = "llvm.amdgcn.buffer.atomic.smin"; + atomic_name = "smin"; break; case nir_intrinsic_ssbo_atomic_umin: - name = "llvm.amdgcn.buffer.atomic.umin"; + atomic_name = "umin"; break; case nir_intrinsic_ssbo_atomic_imax: - name = "llvm.amdgcn.buffer.atomic.smax"; + atomic_name = "smax"; break; case nir_intrinsic_ssbo_atomic_umax: - name = "llvm.amdgcn.buffer.atomic.umax"; + atomic_name = "umax"; break; case nir_intrinsic_ssbo_atomic_and: - name = "llvm.amdgcn.buffer.atomic.and"; + atomic_name = "and"; break; case nir_intrinsic_ssbo_atomic_or: - name = "llvm.amdgcn.buffer.atomic.or"; + atomic_name = "or"; break; case nir_intrinsic_ssbo_atomic_xor: - name = "llvm.amdgcn.buffer.atomic.xor"; + atomic_name = "xor"; break; case nir_intrinsic_ssbo_atomic_exchange: - name = "llvm.amdgcn.buffer.atomic.swap"; + atomic_name = "swap"; break; case nir_intrinsic_ssbo_atomic_comp_swap: - name = "llvm.amdgcn.buffer.atomic.cmpswap"; + atomic_name = "cmpswap"; break; default: abort(); } - return ac_build_intrinsic(&ctx->ac, name, ctx->ac.i32, params, arg_count, 0); + if (instr->intrinsic == nir_intrinsic_ssbo_atomic_comp_swap) { + params[arg_count++] = ac_llvm_extract_elem(&ctx->ac, get_src(ctx, instr->src[3]), 0); + } + params[arg_count++] = ac_llvm_extract_elem(&ctx->ac, get_src(ctx, instr->src[2]), 0); + params[arg_count++] = ctx->abi->load_ssbo(ctx->abi, + get_src(ctx, instr->src[0]), + true); + + if (HAVE_LLVM >= 0x0800) { + params[arg_count++] = get_src(ctx, instr->src[1]); /* voffset */ + params[arg_count++] = ctx->ac.i32_0; /* soffset */ + params[arg_count++] = ctx->ac.i32_0; /* slc */ + + length = snprintf(intrinsic_name, sizeof(intrinsic_name), + "llvm.amdgcn.raw.buffer.atomic.%s.i32", + atomic_name); + } else { + params[arg_count++] = ctx->ac.i32_0; /* vindex */ + params[arg_count++] = get_src(ctx, instr->src[1]); /* voffset */ + params[arg_count++] = ctx->ac.i1false; /* slc */ + + length = snprintf(intrinsic_name, sizeof(intrinsic_name), + "llvm.amdgcn.buffer.atomic.%s", atomic_name); + } + + assert(length < sizeof(intrinsic_name)); + return ac_build_intrinsic(&ctx->ac, intrinsic_name, ctx->ac.i32, + params, arg_count, 0); } static LLVMValueRef visit_load_buffer(struct ac_nir_context *ctx,