ac: add ac_build_round

This commit is contained in:
Marek Olšák 2018-09-21 21:30:09 -04:00
parent fa023f293e
commit 77903c8cfb
4 changed files with 20 additions and 6 deletions

View file

@ -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:
*

View file

@ -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,

View file

@ -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;
}

View file

@ -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. */