[Mesa-dev] [PATCH 6/8] radeonsi: use si_shader_context instead of lp_build_context in more places

Nicolai Hähnle nhaehnle at gmail.com
Tue Nov 21 15:03:26 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/gallium/drivers/radeonsi/si_shader.c | 50 +++++++++++++++-----------------
 1 file changed, 23 insertions(+), 27 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index e6b14f92056..61adb6b1dcc 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -2074,27 +2074,26 @@ static LLVMValueRef si_llvm_pack_two_int32_as_int16(struct si_shader_context *ct
 {
 	LLVMValueRef v[2] = {
 		LLVMBuildAnd(ctx->ac.builder, val[0],
 			     LLVMConstInt(ctx->i32, 0xffff, 0), ""),
 		val[1],
 	};
 	return si_llvm_pack_two_int16(ctx, v);
 }
 
 /* Initialize arguments for the shader export intrinsic */
-static void si_llvm_init_export_args(struct lp_build_tgsi_context *bld_base,
+static void si_llvm_init_export_args(struct si_shader_context *ctx,
 				     LLVMValueRef *values,
 				     unsigned target,
 				     struct ac_export_args *args)
 {
-	struct si_shader_context *ctx = si_shader_context(bld_base);
-	struct lp_build_context *base = &bld_base->base;
+	LLVMValueRef f32undef = LLVMGetUndef(ctx->ac.f32);
 	LLVMBuilderRef builder = ctx->ac.builder;
 	LLVMValueRef val[4];
 	unsigned spi_shader_col_format = V_028714_SPI_SHADER_32_ABGR;
 	unsigned chan;
 	bool is_int8, is_int10;
 
 	/* Default is 0xf. Adjusted below depending on the format. */
 	args->enabled_channels = 0xf; /* writemask */
 
 	/* Specify whether the EXEC mask represents the valid mask */
@@ -2111,24 +2110,24 @@ static void si_llvm_init_export_args(struct lp_build_tgsi_context *bld_base,
 		unsigned col_formats = key->part.ps.epilog.spi_shader_col_format;
 		int cbuf = target - V_008DFC_SQ_EXP_MRT;
 
 		assert(cbuf >= 0 && cbuf < 8);
 		spi_shader_col_format = (col_formats >> (cbuf * 4)) & 0xf;
 		is_int8 = (key->part.ps.epilog.color_is_int8 >> cbuf) & 0x1;
 		is_int10 = (key->part.ps.epilog.color_is_int10 >> cbuf) & 0x1;
 	}
 
 	args->compr = false;
-	args->out[0] = base->undef;
-	args->out[1] = base->undef;
-	args->out[2] = base->undef;
-	args->out[3] = base->undef;
+	args->out[0] = f32undef;
+	args->out[1] = f32undef;
+	args->out[2] = f32undef;
+	args->out[3] = f32undef;
 
 	switch (spi_shader_col_format) {
 	case V_028714_SPI_SHADER_ZERO:
 		args->enabled_channels = 0; /* writemask */
 		args->target = V_008DFC_SQ_EXP_NULL;
 		break;
 
 	case V_028714_SPI_SHADER_32_R:
 		args->enabled_channels = 1; /* writemask */
 		args->out[0] = values[0];
@@ -2173,24 +2172,24 @@ static void si_llvm_init_export_args(struct lp_build_tgsi_context *bld_base,
 		}
 
 		args->compr = 1; /* COMPR flag */
 		args->out[0] = ac_to_float(&ctx->ac, si_llvm_pack_two_int16(ctx, val));
 		args->out[1] = ac_to_float(&ctx->ac, si_llvm_pack_two_int16(ctx, val+2));
 		break;
 
 	case V_028714_SPI_SHADER_SNORM16_ABGR:
 		for (chan = 0; chan < 4; chan++) {
 			/* Clamp between [-1, 1]. */
-			val[chan] = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MIN,
+			val[chan] = lp_build_emit_llvm_binary(&ctx->bld_base, TGSI_OPCODE_MIN,
 							      values[chan],
 							      LLVMConstReal(ctx->f32, 1));
-			val[chan] = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_MAX,
+			val[chan] = lp_build_emit_llvm_binary(&ctx->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], ctx->ac.f32_0, ""),
@@ -2206,21 +2205,21 @@ static void si_llvm_init_export_args(struct lp_build_tgsi_context *bld_base,
 
 	case V_028714_SPI_SHADER_UINT16_ABGR: {
 		LLVMValueRef max_rgb = LLVMConstInt(ctx->i32,
 			is_int8 ? 255 : is_int10 ? 1023 : 65535, 0);
 		LLVMValueRef max_alpha =
 			!is_int10 ? max_rgb : LLVMConstInt(ctx->i32, 3, 0);
 
 		/* Clamp. */
 		for (chan = 0; chan < 4; chan++) {
 			val[chan] = ac_to_integer(&ctx->ac, values[chan]);
-			val[chan] = lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_UMIN,
+			val[chan] = lp_build_emit_llvm_binary(&ctx->bld_base, TGSI_OPCODE_UMIN,
 					val[chan],
 					chan == 3 ? max_alpha : max_rgb);
 		}
 
 		args->compr = 1; /* COMPR flag */
 		args->out[0] = ac_to_float(&ctx->ac, si_llvm_pack_two_int16(ctx, val));
 		args->out[1] = ac_to_float(&ctx->ac, si_llvm_pack_two_int16(ctx, val+2));
 		break;
 	}
 
@@ -2230,24 +2229,24 @@ static void si_llvm_init_export_args(struct lp_build_tgsi_context *bld_base,
 		LLVMValueRef min_rgb = LLVMConstInt(ctx->i32,
 			is_int8 ? -128 : is_int10 ? -512 : -32768, 0);
 		LLVMValueRef max_alpha =
 			!is_int10 ? max_rgb : ctx->i32_1;
 		LLVMValueRef min_alpha =
 			!is_int10 ? min_rgb : LLVMConstInt(ctx->i32, -2, 0);
 
 		/* Clamp. */
 		for (chan = 0; chan < 4; chan++) {
 			val[chan] = ac_to_integer(&ctx->ac, values[chan]);
-			val[chan] = lp_build_emit_llvm_binary(bld_base,
+			val[chan] = lp_build_emit_llvm_binary(&ctx->bld_base,
 					TGSI_OPCODE_IMIN,
 					val[chan], chan == 3 ? max_alpha : max_rgb);
-			val[chan] = lp_build_emit_llvm_binary(bld_base,
+			val[chan] = lp_build_emit_llvm_binary(&ctx->bld_base,
 					TGSI_OPCODE_IMAX,
 					val[chan], chan == 3 ? min_alpha : min_rgb);
 		}
 
 		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;
 	}
 
@@ -2303,25 +2302,23 @@ static LLVMValueRef si_scale_alpha_by_sample_mask(struct lp_build_tgsi_context *
 	coverage = LLVMBuildUIToFP(ctx->ac.builder, coverage,
 				   ctx->f32, "");
 
 	coverage = LLVMBuildFMul(ctx->ac.builder, coverage,
 				 LLVMConstReal(ctx->f32,
 					1.0 / SI_NUM_SMOOTH_AA_SAMPLES), "");
 
 	return LLVMBuildFMul(ctx->ac.builder, alpha, coverage, "");
 }
 
-static void si_llvm_emit_clipvertex(struct lp_build_tgsi_context *bld_base,
+static void si_llvm_emit_clipvertex(struct si_shader_context *ctx,
 				    struct ac_export_args *pos, LLVMValueRef *out_elts)
 {
-	struct si_shader_context *ctx = si_shader_context(bld_base);
-	struct lp_build_context *base = &bld_base->base;
 	unsigned reg_index;
 	unsigned chan;
 	unsigned const_chan;
 	LLVMValueRef base_elt;
 	LLVMValueRef ptr = LLVMGetParam(ctx->main_fn, ctx->param_rw_buffers);
 	LLVMValueRef constbuf_index = LLVMConstInt(ctx->i32,
 						   SI_VS_CONST_CLIP_PLANES, 0);
 	LLVMValueRef const_resource = ac_build_load_to_sgpr(&ctx->ac, ptr, constbuf_index);
 
 	for (reg_index = 0; reg_index < 2; reg_index ++) {
@@ -2334,22 +2331,22 @@ static void si_llvm_emit_clipvertex(struct lp_build_tgsi_context *bld_base,
 
 		/* Compute dot products of position and user clip plane vectors */
 		for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
 			for (const_chan = 0; const_chan < TGSI_NUM_CHANNELS; const_chan++) {
 				LLVMValueRef addr =
 					LLVMConstInt(ctx->i32, ((reg_index * 4 + chan) * 4 +
 								const_chan) * 4, 0);
 				base_elt = buffer_load_const(ctx, const_resource,
 							     addr);
 				args->out[chan] =
-					lp_build_add(base, args->out[chan],
-						     lp_build_mul(base, base_elt,
+					lp_build_add(&ctx->bld_base.base, args->out[chan],
+						     lp_build_mul(&ctx->bld_base.base, base_elt,
 								  out_elts[const_chan]));
 			}
 		}
 
 		args->enabled_channels = 0xf;
 		args->valid_mask = 0;
 		args->done = 0;
 		args->target = V_008DFC_SQ_EXP_POS + 2 + reg_index;
 		args->compr = 0;
 	}
@@ -2505,21 +2502,21 @@ static void si_llvm_emit_streamout(struct si_shader_context *ctx,
 		}
 	}
 	lp_build_endif(&if_ctx);
 }
 
 static void si_export_param(struct si_shader_context *ctx, unsigned index,
 			    LLVMValueRef *values)
 {
 	struct ac_export_args args;
 
-	si_llvm_init_export_args(&ctx->bld_base, values,
+	si_llvm_init_export_args(ctx, values,
 				 V_008DFC_SQ_EXP_PARAM + index, &args);
 	ac_build_export(&ctx->ac, &args);
 }
 
 static void si_build_param_exports(struct si_shader_context *ctx,
 				   struct si_shader_output_values *outputs,
 			           unsigned noutput)
 {
 	struct si_shader *shader = ctx->shader;
 	unsigned param_count = 0;
@@ -2558,61 +2555,60 @@ static void si_build_param_exports(struct si_shader_context *ctx,
 		si_export_param(ctx, param_count, outputs[i].values);
 
 		assert(i < ARRAY_SIZE(shader->info.vs_output_param_offset));
 		shader->info.vs_output_param_offset[i] = param_count++;
 	}
 
 	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,
+static void si_llvm_export_vs(struct si_shader_context *ctx,
 			      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 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,
+			si_llvm_init_export_args(ctx, outputs[i].values,
 						 V_008DFC_SQ_EXP_POS, &pos_args[0]);
 			break;
 		case TGSI_SEMANTIC_PSIZE:
 			psize_value = outputs[i].values[0];
 			break;
 		case TGSI_SEMANTIC_LAYER:
 			layer_value = outputs[i].values[0];
 			break;
 		case TGSI_SEMANTIC_VIEWPORT_INDEX:
 			viewport_index_value = outputs[i].values[0];
 			break;
 		case TGSI_SEMANTIC_EDGEFLAG:
 			edgeflag_value = outputs[i].values[0];
 			break;
 		case TGSI_SEMANTIC_CLIPDIST:
 			if (!shader->key.opt.clip_disable) {
 				unsigned index = 2 + outputs[i].semantic_index;
-				si_llvm_init_export_args(bld_base, outputs[i].values,
+				si_llvm_init_export_args(ctx, outputs[i].values,
 							 V_008DFC_SQ_EXP_POS + index,
 							 &pos_args[index]);
 			}
 			break;
 		case TGSI_SEMANTIC_CLIPVERTEX:
 			if (!shader->key.opt.clip_disable) {
-				si_llvm_emit_clipvertex(bld_base, pos_args,
+				si_llvm_emit_clipvertex(ctx, pos_args,
 							outputs[i].values);
 			}
 			break;
 		}
 	}
 
 	/* 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 */
@@ -3332,21 +3328,21 @@ static void si_llvm_emit_vs_epilogue(struct ac_shader_abi *abi,
 		outputs[i].semantic_index = 0;
 		outputs[i].values[0] = ac_to_float(&ctx->ac, get_primitive_id(ctx, 0));
 		for (j = 1; j < 4; j++)
 			outputs[i].values[j] = LLVMConstReal(ctx->f32, 0);
 
 		memset(outputs[i].vertex_stream, 0,
 		       sizeof(outputs[i].vertex_stream));
 		i++;
 	}
 
-	si_llvm_export_vs(&ctx->bld_base, outputs, i);
+	si_llvm_export_vs(ctx, outputs, i);
 	FREE(outputs);
 }
 
 static void si_tgsi_emit_epilogue(struct lp_build_tgsi_context *bld_base)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 
 	ctx->abi.emit_outputs(&ctx->abi, RADEON_LLVM_MAX_OUTPUTS,
 			      &ctx->outputs[0][0]);
 }
@@ -3473,41 +3469,41 @@ static void si_export_mrt_color(struct lp_build_tgsi_context *bld_base,
 		color[3] = si_scale_alpha_by_sample_mask(bld_base, color[3],
 							 samplemask_param);
 
 	/* If last_cbuf > 0, FS_COLOR0_WRITES_ALL_CBUFS is true. */
 	if (ctx->shader->key.part.ps.epilog.last_cbuf > 0) {
 		struct ac_export_args args[8];
 		int c, last = -1;
 
 		/* Get the export arguments, also find out what the last one is. */
 		for (c = 0; c <= ctx->shader->key.part.ps.epilog.last_cbuf; c++) {
-			si_llvm_init_export_args(bld_base, color,
+			si_llvm_init_export_args(ctx, color,
 						 V_008DFC_SQ_EXP_MRT + c, &args[c]);
 			if (args[c].enabled_channels)
 				last = c;
 		}
 
 		/* Emit all exports. */
 		for (c = 0; c <= ctx->shader->key.part.ps.epilog.last_cbuf; c++) {
 			if (is_last && last == c) {
 				args[c].valid_mask = 1; /* whether the EXEC mask is valid */
 				args[c].done = 1; /* DONE bit */
 			} else if (!args[c].enabled_channels)
 				continue; /* unnecessary NULL export */
 
 			memcpy(&exp->args[exp->num++], &args[c], sizeof(args[c]));
 		}
 	} else {
 		struct ac_export_args args;
 
 		/* Export */
-		si_llvm_init_export_args(bld_base, color, V_008DFC_SQ_EXP_MRT + index,
+		si_llvm_init_export_args(ctx, color, V_008DFC_SQ_EXP_MRT + index,
 					 &args);
 		if (is_last) {
 			args.valid_mask = 1; /* whether the EXEC mask is valid */
 			args.done = 1; /* DONE bit */
 		} else if (!args.enabled_channels)
 			return; /* unnecessary NULL export */
 
 		memcpy(&exp->args[exp->num++], &args, sizeof(args));
 	}
 }
@@ -5474,21 +5470,21 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
 		}
 
 		/* Streamout and exports. */
 		if (gs_selector->so.num_outputs) {
 			si_llvm_emit_streamout(&ctx, outputs,
 					       gsinfo->num_outputs,
 					       stream);
 		}
 
 		if (stream == 0)
-			si_llvm_export_vs(bld_base, outputs, gsinfo->num_outputs);
+			si_llvm_export_vs(&ctx, outputs, gsinfo->num_outputs);
 
 		LLVMBuildBr(builder, end_bb);
 	}
 
 	LLVMPositionBuilderAtEnd(builder, end_bb);
 
 	LLVMBuildRetVoid(ctx.ac.builder);
 
 	ctx.type = PIPE_SHADER_GEOMETRY; /* override for shader dumping */
 	si_llvm_optimize_module(&ctx);
-- 
2.11.0



More information about the mesa-dev mailing list