[Mesa-dev] [PATCH 13/15] radeonsi: use a faster version of PK2H

Marek Olšák maraeo at gmail.com
Mon Aug 21 21:54:12 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

+ 4 piglit regressions, but it's correct accorcing to the GL spec and
performance is more important than piglit.
---
 src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c | 29 +++++++----------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
index 12f8de4..405469d 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
@@ -649,41 +649,28 @@ static void pk2h_fetch_args(struct lp_build_tgsi_context *bld_base,
 	emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst,
 						 0, TGSI_CHAN_X);
 	emit_data->args[1] = lp_build_emit_fetch(bld_base, emit_data->inst,
 						 0, TGSI_CHAN_Y);
 }
 
 static void emit_pk2h(const struct lp_build_tgsi_action *action,
 		      struct lp_build_tgsi_context *bld_base,
 		      struct lp_build_emit_data *emit_data)
 {
-	LLVMBuilderRef builder = bld_base->base.gallivm->builder;
-	LLVMContextRef context = bld_base->base.gallivm->context;
-	struct lp_build_context *uint_bld = &bld_base->uint_bld;
-	LLVMTypeRef fp16, i16;
-	LLVMValueRef const16, comp[2];
-	unsigned i;
-
-	fp16 = LLVMHalfTypeInContext(context);
-	i16 = LLVMInt16TypeInContext(context);
-	const16 = lp_build_const_int32(uint_bld->gallivm, 16);
-
-	for (i = 0; i < 2; i++) {
-		comp[i] = LLVMBuildFPTrunc(builder, emit_data->args[i], fp16, "");
-		comp[i] = LLVMBuildBitCast(builder, comp[i], i16, "");
-		comp[i] = LLVMBuildZExt(builder, comp[i], uint_bld->elem_type, "");
-	}
-
-	comp[1] = LLVMBuildShl(builder, comp[1], const16, "");
-	comp[0] = LLVMBuildOr(builder, comp[0], comp[1], "");
-
-	emit_data->output[emit_data->chan] = comp[0];
+	/* From the GLSL 4.50 spec:
+	 *   "The rounding mode cannot be set and is undefined."
+	 *
+	 * v_cvt_pkrtz_f16 rounds to zero, but it's fastest.
+	 */
+	emit_data->output[emit_data->chan] =
+		ac_build_cvt_pkrtz_f16(&si_shader_context(bld_base)->ac,
+				       emit_data->args);
 }
 
 static void up2h_fetch_args(struct lp_build_tgsi_context *bld_base,
 			    struct lp_build_emit_data *emit_data)
 {
 	emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst,
 						 0, TGSI_CHAN_X);
 }
 
 static void emit_up2h(const struct lp_build_tgsi_action *action,
-- 
2.7.4



More information about the mesa-dev mailing list