From: Marek Olšák Date: Sat, 22 Sep 2018 01:30:09 +0000 (-0400) Subject: ac: add ac_build_round X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=77903c8cfbaa609d132ea5e5fbca062e0b2f0808;p=mesa.git ac: add ac_build_round --- diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c index 81158940b8d..d11c12fcd13 100644 --- a/src/amd/common/ac_llvm_build.c +++ b/src/amd/common/ac_llvm_build.c @@ -558,6 +558,22 @@ LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx, return ac_build_gather_values(ctx, chan, 4); } +LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value) +{ + unsigned type_size = ac_get_type_size(LLVMTypeOf(value)); + const char *name; + + if (type_size == 2) + name = "llvm.rint.f16"; + else if (type_size == 4) + name = "llvm.rint.f32"; + else + name = "llvm.rint.f64"; + + return ac_build_intrinsic(ctx, name, LLVMTypeOf(value), &value, 1, + AC_FUNC_ATTR_READNONE); +} + LLVMValueRef ac_build_fdiv(struct ac_llvm_context *ctx, LLVMValueRef num, @@ -675,8 +691,7 @@ ac_prepare_cube_coords(struct ac_llvm_context *ctx, LLVMValueRef invma; if (is_array && !is_lod) { - LLVMValueRef tmp = coords_arg[3]; - tmp = ac_build_intrinsic(ctx, "llvm.rint.f32", ctx->f32, &tmp, 1, 0); + LLVMValueRef tmp = ac_build_round(ctx, coords_arg[3]); /* Section 8.9 (Texture Functions) of the GLSL 4.50 spec says: * diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h index 73f8a6b70cd..65235fb7352 100644 --- a/src/amd/common/ac_llvm_build.h +++ b/src/amd/common/ac_llvm_build.h @@ -175,6 +175,7 @@ ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned num_channels); +LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value); LLVMValueRef ac_build_fdiv(struct ac_llvm_context *ctx, diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index 312383db36c..ffc64a79d95 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -3311,7 +3311,7 @@ static LLVMValueRef apply_round_slice(struct ac_llvm_context *ctx, LLVMValueRef coord) { coord = ac_to_float(ctx, coord); - coord = ac_build_intrinsic(ctx, "llvm.rint.f32", ctx->f32, &coord, 1, 0); + coord = ac_build_round(ctx, coord); coord = ac_to_integer(ctx, coord); return coord; } diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c index cabc448a082..8c44831bccb 100644 --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c @@ -1446,9 +1446,7 @@ static void build_tex_intrinsic(const struct lp_build_tgsi_action *action, opcode != TGSI_OPCODE_TXF_LZ && ctx->screen->info.chip_class <= VI) { unsigned array_coord = target == TGSI_TEXTURE_1D_ARRAY ? 1 : 2; - args.coords[array_coord] = - ac_build_intrinsic(&ctx->ac, "llvm.rint.f32", ctx->f32, - &args.coords[array_coord], 1, 0); + args.coords[array_coord] = ac_build_round(&ctx->ac, args.coords[array_coord]); } /* 1D textures are allocated and used as 2D on GFX9. */