Mesa (master): ac: add ac_build_fract()

Samuel Pitoiset hakzsam at kemper.freedesktop.org
Mon Mar 5 10:05:24 UTC 2018


Module: Mesa
Branch: master
Commit: 459e33900ff7f569ecfe12bf876d2a3e77cb6747
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=459e33900ff7f569ecfe12bf876d2a3e77cb6747

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Fri Mar  2 15:01:30 2018 +0100

ac: add ac_build_fract()

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

---

 src/amd/common/ac_llvm_build.c                    | 22 ++++++++++++++
 src/amd/common/ac_llvm_build.h                    |  3 ++
 src/amd/common/ac_nir_to_llvm.c                   | 35 ++++++-----------------
 src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c | 13 ++++-----
 4 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 15144addb9..1a245bd8e6 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -1686,6 +1686,28 @@ void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16)
 			   ctx->voidt, args, 1, 0);
 }
 
+LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
+			    unsigned bitsize)
+{
+	LLVMTypeRef type;
+	char *intr;
+
+	if (bitsize == 32) {
+		intr = "llvm.floor.f32";
+		type = ctx->f32;
+	} else {
+		intr = "llvm.floor.f64";
+		type = ctx->f64;
+	}
+
+	LLVMValueRef params[] = {
+		src0,
+	};
+	LLVMValueRef floor = ac_build_intrinsic(ctx, intr, type, params, 1,
+						AC_FUNC_ATTR_READNONE);
+	return LLVMBuildFSub(ctx->builder, src0, floor, "");
+}
+
 void ac_get_image_intr_name(const char *base_name,
 			    LLVMTypeRef data_type,
 			    LLVMTypeRef coords_type,
diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h
index 0a49ad8ca1..1a480ebbca 100644
--- a/src/amd/common/ac_llvm_build.h
+++ b/src/amd/common/ac_llvm_build.h
@@ -335,6 +335,9 @@ LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
 
 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16);
 
+LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
+			   unsigned bitsize);
+
 void ac_get_image_intr_name(const char *base_name,
 			    LLVMTypeRef data_type,
 			    LLVMTypeRef coords_type,
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 40ddf28974..a2c0706102 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -1385,29 +1385,6 @@ static LLVMValueRef emit_isign(struct ac_llvm_context *ctx,
 	return val;
 }
 
-static LLVMValueRef emit_ffract(struct ac_llvm_context *ctx,
-				LLVMValueRef src0, unsigned bitsize)
-{
-	LLVMTypeRef type;
-	char *intr;
-
-	if (bitsize == 32) {
-		intr = "llvm.floor.f32";
-		type = ctx->f32;
-	} else {
-		intr = "llvm.floor.f64";
-		type = ctx->f64;
-	}
-
-	LLVMValueRef fsrc0 = ac_to_float(ctx, src0);
-	LLVMValueRef params[] = {
-		fsrc0,
-	};
-	LLVMValueRef floor = ac_build_intrinsic(ctx, intr, type, params, 1,
-						AC_FUNC_ATTR_READNONE);
-	return LLVMBuildFSub(ctx->builder, fsrc0, floor, "");
-}
-
 static LLVMValueRef emit_uint_carry(struct ac_llvm_context *ctx,
 				    const char *intrin,
 				    LLVMValueRef src0, LLVMValueRef src1)
@@ -1853,7 +1830,9 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
 		                              ac_to_float_type(&ctx->ac, def_type),src[0]);
 		break;
 	case nir_op_ffract:
-		result = emit_ffract(&ctx->ac, src[0], instr->dest.dest.ssa.bit_size);
+		src[0] = ac_to_float(&ctx->ac, src[0]);
+		result = ac_build_fract(&ctx->ac, src[0],
+					instr->dest.dest.ssa.bit_size);
 		break;
 	case nir_op_fsin:
 		result = emit_intrin_1f_param(&ctx->ac, "llvm.sin",
@@ -4104,9 +4083,13 @@ static LLVMValueRef load_sample_position(struct ac_shader_abi *abi,
 static LLVMValueRef load_sample_pos(struct ac_nir_context *ctx)
 {
 	LLVMValueRef values[2];
+	LLVMValueRef pos[2];
+
+	pos[0] = ac_to_float(&ctx->ac, ctx->abi->frag_pos[0]);
+	pos[1] = ac_to_float(&ctx->ac, ctx->abi->frag_pos[1]);
 
-	values[0] = emit_ffract(&ctx->ac, ctx->abi->frag_pos[0], 32);
-	values[1] = emit_ffract(&ctx->ac, ctx->abi->frag_pos[1], 32);
+	values[0] = ac_build_fract(&ctx->ac, pos[0], 32);
+	values[1] = ac_build_fract(&ctx->ac, pos[1], 32);
 	return ac_build_gather_values(&ctx->ac, values, 2);
 }
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
index cec33c38b4..c9ebc90d91 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
@@ -400,22 +400,19 @@ static void emit_frac(const struct lp_build_tgsi_action *action,
 		      struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
-	char *intr;
+	unsigned bitsize;
 
 	if (emit_data->info->opcode == TGSI_OPCODE_FRC)
-		intr = "llvm.floor.f32";
+		bitsize = 32;
 	else if (emit_data->info->opcode == TGSI_OPCODE_DFRAC)
-		intr = "llvm.floor.f64";
+		bitsize = 64;
 	else {
 		assert(0);
 		return;
 	}
 
-	LLVMValueRef floor = lp_build_intrinsic(ctx->ac.builder, intr, emit_data->dst_type,
-						&emit_data->args[0], 1,
-						LP_FUNC_ATTR_READNONE);
-	emit_data->output[emit_data->chan] = LLVMBuildFSub(ctx->ac.builder,
-			emit_data->args[0], floor, "");
+	emit_data->output[emit_data->chan] =
+		ac_build_fract(&ctx->ac, emit_data->args[0], bitsize);
 }
 
 static void emit_f2i(const struct lp_build_tgsi_action *action,




More information about the mesa-commit mailing list