[Mesa-dev] [PATCH 11/11] radeonsi: use f32_0 and f32_1

Marek Olšák maraeo at gmail.com
Fri Sep 29 14:49:55 UTC 2017


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

---
 src/gallium/drivers/radeonsi/si_shader.c           | 28 ++++++++++------------
 src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c  | 18 +++++++-------
 src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c  |  4 ++--
 .../drivers/radeonsi/si_shader_tgsi_setup.c        |  2 +-
 4 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index db9a0d7..f3f5b23 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -1664,28 +1664,28 @@ void si_load_system_value(struct si_shader_context *ctx,
 		 * doesn't support smoothing.
 		 */
 		value = LLVMGetParam(ctx->main_fn, SI_PARAM_SAMPLE_COVERAGE);
 		break;
 
 	case TGSI_SEMANTIC_TESSCOORD:
 	{
 		LLVMValueRef coord[4] = {
 			LLVMGetParam(ctx->main_fn, ctx->param_tes_u),
 			LLVMGetParam(ctx->main_fn, ctx->param_tes_v),
-			bld->zero,
-			bld->zero
+			ctx->ac.f32_0,
+			ctx->ac.f32_0
 		};
 
 		/* For triangles, the vector should be (u, v, 1-u-v). */
 		if (ctx->shader->selector->info.properties[TGSI_PROPERTY_TES_PRIM_MODE] ==
 		    PIPE_PRIM_TRIANGLES)
-			coord[2] = lp_build_sub(bld, bld->one,
+			coord[2] = lp_build_sub(bld, ctx->ac.f32_1,
 						lp_build_add(bld, coord[0], coord[1]));
 
 		value = lp_build_gather_values(&ctx->gallivm, coord, 4);
 		break;
 	}
 
 	case TGSI_SEMANTIC_VERTICESIN:
 		if (ctx->type == PIPE_SHADER_TESS_CTRL)
 			value = unpack_param(ctx, ctx->param_tcs_out_lds_layout, 26, 6);
 		else if (ctx->type == PIPE_SHADER_TESS_EVAL)
@@ -2083,21 +2083,21 @@ static void si_llvm_init_export_args(struct lp_build_tgsi_context *bld_base,
 			val[chan] = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MAX,
 							      val[chan],
 							      LLVMConstReal(ctx->f32, -1));
 			/* Convert to a signed integer in [-32767, 32767]. */
 			val[chan] = LLVMBuildFMul(builder, val[chan],
 						  LLVMConstReal(ctx->f32, 32767), "");
 			/* If positive, add 0.5, else add -0.5. */
 			val[chan] = LLVMBuildFAdd(builder, val[chan],
 					LLVMBuildSelect(builder,
 						LLVMBuildFCmp(builder, LLVMRealOGE,
-							      val[chan], base->zero, ""),
+							      val[chan], ctx->ac.f32_0, ""),
 						LLVMConstReal(ctx->f32, 0.5),
 						LLVMConstReal(ctx->f32, -0.5), ""), "");
 			val[chan] = LLVMBuildFPToSI(builder, val[chan], ctx->i32, "");
 		}
 
 		args->compr = 1; /* COMPR flag */
 		args->out[0] = ac_to_float(&ctx->ac, si_llvm_pack_two_int32_as_int16(ctx, val));
 		args->out[1] = ac_to_float(&ctx->ac, si_llvm_pack_two_int32_as_int16(ctx, val+2));
 		break;
 
@@ -2459,21 +2459,20 @@ static void si_build_param_exports(struct si_shader_context *ctx,
 	shader->info.nr_param_exports = param_count;
 }
 
 /* Generate export instructions for hardware VS shader stage */
 static void si_llvm_export_vs(struct lp_build_tgsi_context *bld_base,
 			      struct si_shader_output_values *outputs,
 			      unsigned noutput)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	struct si_shader *shader = ctx->shader;
-	struct lp_build_context *base = &bld_base->base;
 	struct ac_export_args pos_args[4] = {};
 	LLVMValueRef psize_value = NULL, edgeflag_value = NULL, layer_value = NULL, viewport_index_value = NULL;
 	unsigned pos_idx;
 	int i;
 
 	/* Build position exports. */
 	for (i = 0; i < noutput; i++) {
 		switch (outputs[i].semantic_name) {
 		case TGSI_SEMANTIC_POSITION:
 			si_llvm_init_export_args(bld_base, outputs[i].values,
@@ -2508,43 +2507,43 @@ static void si_llvm_export_vs(struct lp_build_tgsi_context *bld_base,
 		}
 	}
 
 	/* We need to add the position output manually if it's missing. */
 	if (!pos_args[0].out[0]) {
 		pos_args[0].enabled_channels = 0xf; /* writemask */
 		pos_args[0].valid_mask = 0; /* EXEC mask */
 		pos_args[0].done = 0; /* last export? */
 		pos_args[0].target = V_008DFC_SQ_EXP_POS;
 		pos_args[0].compr = 0; /* COMPR flag */
-		pos_args[0].out[0] = base->zero; /* X */
-		pos_args[0].out[1] = base->zero; /* Y */
-		pos_args[0].out[2] = base->zero; /* Z */
-		pos_args[0].out[3] = base->one;  /* W */
+		pos_args[0].out[0] = ctx->ac.f32_0; /* X */
+		pos_args[0].out[1] = ctx->ac.f32_0; /* Y */
+		pos_args[0].out[2] = ctx->ac.f32_0; /* Z */
+		pos_args[0].out[3] = ctx->ac.f32_1;  /* W */
 	}
 
 	/* Write the misc vector (point size, edgeflag, layer, viewport). */
 	if (shader->selector->info.writes_psize ||
 	    shader->selector->info.writes_edgeflag ||
 	    shader->selector->info.writes_viewport_index ||
 	    shader->selector->info.writes_layer) {
 		pos_args[1].enabled_channels = shader->selector->info.writes_psize |
 					       (shader->selector->info.writes_edgeflag << 1) |
 					       (shader->selector->info.writes_layer << 2);
 
 		pos_args[1].valid_mask = 0; /* EXEC mask */
 		pos_args[1].done = 0; /* last export? */
 		pos_args[1].target = V_008DFC_SQ_EXP_POS + 1;
 		pos_args[1].compr = 0; /* COMPR flag */
-		pos_args[1].out[0] = base->zero; /* X */
-		pos_args[1].out[1] = base->zero; /* Y */
-		pos_args[1].out[2] = base->zero; /* Z */
-		pos_args[1].out[3] = base->zero; /* W */
+		pos_args[1].out[0] = ctx->ac.f32_0; /* X */
+		pos_args[1].out[1] = ctx->ac.f32_0; /* Y */
+		pos_args[1].out[2] = ctx->ac.f32_0; /* Z */
+		pos_args[1].out[3] = ctx->ac.f32_0; /* W */
 
 		if (shader->selector->info.writes_psize)
 			pos_args[1].out[0] = psize_value;
 
 		if (shader->selector->info.writes_edgeflag) {
 			/* The output is a float, but the hw expects an integer
 			 * with the first bit containing the edge flag. */
 			edgeflag_value = LLVMBuildFPToUI(ctx->ac.builder,
 							 edgeflag_value,
 							 ctx->i32, "");
@@ -3338,31 +3337,30 @@ static void si_export_mrt_z(struct lp_build_tgsi_context *bld_base,
 
 	memcpy(&exp->args[exp->num++], &args, sizeof(args));
 }
 
 static void si_export_mrt_color(struct lp_build_tgsi_context *bld_base,
 				LLVMValueRef *color, unsigned index,
 				unsigned samplemask_param,
 				bool is_last, struct si_ps_exports *exp)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
-	struct lp_build_context *base = &bld_base->base;
 	int i;
 
 	/* Clamp color */
 	if (ctx->shader->key.part.ps.epilog.clamp_color)
 		for (i = 0; i < 4; i++)
 			color[i] = ac_build_clamp(&ctx->ac, color[i]);
 
 	/* Alpha to one */
 	if (ctx->shader->key.part.ps.epilog.alpha_to_one)
-		color[3] = base->one;
+		color[3] = ctx->ac.f32_1;
 
 	/* Alpha test */
 	if (index == 0 &&
 	    ctx->shader->key.part.ps.epilog.alpha_func != PIPE_FUNC_ALWAYS)
 		si_alpha_test(bld_base, color[3]);
 
 	/* Line & polygon smoothing */
 	if (ctx->shader->key.part.ps.epilog.poly_line_smoothing)
 		color[3] = si_scale_alpha_by_sample_mask(bld_base, color[3],
 							 samplemask_param);
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
index 563b305..fc705c3 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
@@ -33,33 +33,33 @@ static void kill_if_fetch_args(struct lp_build_tgsi_context *bld_base,
 {
 	const struct tgsi_full_instruction *inst = emit_data->inst;
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMBuilderRef builder = ctx->ac.builder;
 	unsigned i;
 	LLVMValueRef conds[TGSI_NUM_CHANNELS];
 
 	for (i = 0; i < TGSI_NUM_CHANNELS; i++) {
 		LLVMValueRef value = lp_build_emit_fetch(bld_base, inst, 0, i);
 		conds[i] = LLVMBuildFCmp(builder, LLVMRealOLT, value,
-					bld_base->base.zero, "");
+					ctx->ac.f32_0, "");
 	}
 
 	/* Or the conditions together */
 	for (i = TGSI_NUM_CHANNELS - 1; i > 0; i--) {
 		conds[i - 1] = LLVMBuildOr(builder, conds[i], conds[i - 1], "");
 	}
 
 	emit_data->dst_type = ctx->voidt;
 	emit_data->arg_count = 1;
 	emit_data->args[0] = LLVMBuildSelect(builder, conds[0],
 					LLVMConstReal(ctx->f32, -1.0f),
-					bld_base->base.zero, "");
+					ctx->ac.f32_0, "");
 }
 
 static void kil_emit(const struct lp_build_tgsi_action *action,
 		     struct lp_build_tgsi_context *bld_base,
 		     struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMBuilderRef builder = ctx->ac.builder;
 
 	if (ctx->postponed_kill) {
@@ -137,21 +137,21 @@ static void emit_ucmp(const struct lp_build_tgsi_action *action,
 }
 
 static void emit_cmp(const struct lp_build_tgsi_action *action,
 		     struct lp_build_tgsi_context *bld_base,
 		     struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMValueRef cond, *args = emit_data->args;
 
 	cond = LLVMBuildFCmp(ctx->ac.builder, LLVMRealOLT, args[0],
-			     bld_base->base.zero, "");
+			     ctx->ac.f32_0, "");
 
 	emit_data->output[emit_data->chan] =
 		LLVMBuildSelect(ctx->ac.builder, cond, args[1], args[2], "");
 }
 
 static void emit_set_cond(const struct lp_build_tgsi_action *action,
 			  struct lp_build_tgsi_context *bld_base,
 			  struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
@@ -168,21 +168,21 @@ static void emit_set_cond(const struct lp_build_tgsi_action *action,
 	case TGSI_OPCODE_SLT: pred = LLVMRealOLT; break;
 	case TGSI_OPCODE_SNE: pred = LLVMRealUNE; break;
 	case TGSI_OPCODE_SGT: pred = LLVMRealOGT; break;
 	default: assert(!"unknown instruction"); pred = 0; break;
 	}
 
 	cond = LLVMBuildFCmp(ctx->ac.builder,
 		pred, emit_data->args[0], emit_data->args[1], "");
 
 	emit_data->output[emit_data->chan] = LLVMBuildSelect(ctx->ac.builder,
-		cond, bld_base->base.one, bld_base->base.zero, "");
+		cond, ctx->ac.f32_1, ctx->ac.f32_0, "");
 }
 
 static void emit_fcmp(const struct lp_build_tgsi_action *action,
 		      struct lp_build_tgsi_context *bld_base,
 		      struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMRealPredicate pred;
 
 	/* Use ordered for everything but NE (which is usual for
@@ -365,23 +365,23 @@ static void emit_ssg(const struct lp_build_tgsi_action *action,
 		cmp = LLVMBuildICmp(builder, LLVMIntSGT, emit_data->args[0], ctx->i32_0, "");
 		val = LLVMBuildSelect(builder, cmp, ctx->i32_1, emit_data->args[0], "");
 		cmp = LLVMBuildICmp(builder, LLVMIntSGE, val, ctx->i32_0, "");
 		val = LLVMBuildSelect(builder, cmp, val, LLVMConstInt(ctx->i32, -1, true), "");
 	} else if (emit_data->inst->Instruction.Opcode == TGSI_OPCODE_DSSG) {
 		cmp = LLVMBuildFCmp(builder, LLVMRealOGT, emit_data->args[0], bld_base->dbl_bld.zero, "");
 		val = LLVMBuildSelect(builder, cmp, bld_base->dbl_bld.one, emit_data->args[0], "");
 		cmp = LLVMBuildFCmp(builder, LLVMRealOGE, val, bld_base->dbl_bld.zero, "");
 		val = LLVMBuildSelect(builder, cmp, val, LLVMConstReal(bld_base->dbl_bld.elem_type, -1), "");
 	} else { // float SSG
-		cmp = LLVMBuildFCmp(builder, LLVMRealOGT, emit_data->args[0], bld_base->base.zero, "");
-		val = LLVMBuildSelect(builder, cmp, bld_base->base.one, emit_data->args[0], "");
-		cmp = LLVMBuildFCmp(builder, LLVMRealOGE, val, bld_base->base.zero, "");
+		cmp = LLVMBuildFCmp(builder, LLVMRealOGT, emit_data->args[0], ctx->ac.f32_0, "");
+		val = LLVMBuildSelect(builder, cmp, ctx->ac.f32_1, emit_data->args[0], "");
+		cmp = LLVMBuildFCmp(builder, LLVMRealOGE, val, ctx->ac.f32_0, "");
 		val = LLVMBuildSelect(builder, cmp, val, LLVMConstReal(ctx->f32, -1), "");
 	}
 
 	emit_data->output[emit_data->chan] = val;
 }
 
 static void emit_ineg(const struct lp_build_tgsi_action *action,
 		      struct lp_build_tgsi_context *bld_base,
 		      struct lp_build_emit_data *emit_data)
 {
@@ -703,27 +703,29 @@ static void emit_fdiv(const struct lp_build_tgsi_action *action,
 		LLVMSetMetadata(emit_data->output[emit_data->chan],
 				ctx->fpmath_md_kind, ctx->fpmath_md_2p5_ulp);
 }
 
 /* 1/sqrt is translated to rsq for f32 if fp32 denormals are not enabled in
  * the target machine. f64 needs global unsafe math flags to get rsq. */
 static void emit_rsq(const struct lp_build_tgsi_action *action,
 		     struct lp_build_tgsi_context *bld_base,
 		     struct lp_build_emit_data *emit_data)
 {
+	struct si_shader_context *ctx = si_shader_context(bld_base);
+
 	LLVMValueRef sqrt =
 		lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_SQRT,
 					 emit_data->args[0]);
 
 	emit_data->output[emit_data->chan] =
 		lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_DIV,
-					  bld_base->base.one, sqrt);
+					  ctx->ac.f32_1, sqrt);
 }
 
 static void dfracexp_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);
 	emit_data->arg_count = 1;
 }
 
 static void dfracexp_emit(const struct lp_build_tgsi_action *action,
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
index 7c2afe3..b472b19 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
@@ -1322,21 +1322,21 @@ static void tex_fetch_args(
 						   emit_data->inst, 0,
 						   chan);
 		if (opcode == TGSI_OPCODE_TXP)
 			coords[chan] = lp_build_emit_llvm_binary(bld_base,
 								 TGSI_OPCODE_DIV,
 								 coords[chan],
 								 coords[3]);
 	}
 
 	if (opcode == TGSI_OPCODE_TXP)
-		coords[3] = bld_base->base.one;
+		coords[3] = ctx->ac.f32_1;
 
 	/* Pack offsets. */
 	if (has_offset &&
 	    opcode != TGSI_OPCODE_TXF &&
 	    opcode != TGSI_OPCODE_TXF_LZ) {
 		/* The offsets are six-bit signed integers packed like this:
 		 *   X=[5:0], Y=[13:8], and Z=[21:16].
 		 */
 		LLVMValueRef offset[3], pack;
 
@@ -1450,21 +1450,21 @@ static void tex_fetch_args(
 
 		for (param = 0; param < 2; param++) {
 			for (chan = 0; chan < num_src_deriv_channels; chan++)
 				derivs[param * num_dst_deriv_channels + chan] =
 					lp_build_emit_fetch(bld_base, inst, param+1, chan);
 
 			/* Fill in the rest with zeros. */
 			for (chan = num_src_deriv_channels;
 			     chan < num_dst_deriv_channels; chan++)
 				derivs[param * num_dst_deriv_channels + chan] =
-					bld_base->base.zero;
+					ctx->ac.f32_0;
 		}
 	}
 
 	if (target == TGSI_TEXTURE_CUBE ||
 	    target == TGSI_TEXTURE_CUBE_ARRAY ||
 	    target == TGSI_TEXTURE_SHADOWCUBE ||
 	    target == TGSI_TEXTURE_SHADOWCUBE_ARRAY) {
 		ac_prepare_cube_coords(&ctx->ac,
 				       opcode == TGSI_OPCODE_TXD,
 				       target == TGSI_TEXTURE_CUBE_ARRAY ||
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index 5c397f7..1d4696f 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -1091,21 +1091,21 @@ static void if_cond_emit(const struct lp_build_tgsi_action *action,
 
 static void if_emit(const struct lp_build_tgsi_action *action,
 		    struct lp_build_tgsi_context *bld_base,
 		    struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMValueRef cond;
 
 	cond = LLVMBuildFCmp(ctx->ac.builder, LLVMRealUNE,
 			emit_data->args[0],
-			bld_base->base.zero, "");
+			ctx->ac.f32_0, "");
 
 	if_cond_emit(action, bld_base, emit_data, cond);
 }
 
 static void uif_emit(const struct lp_build_tgsi_action *action,
 		     struct lp_build_tgsi_context *bld_base,
 		     struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMValueRef cond;
-- 
2.7.4



More information about the mesa-dev mailing list