[Mesa-dev] [PATCH 1/3] radeonsi: reduce the number of FMASK input coordinates

Marek Olšák maraeo at gmail.com
Wed Feb 8 19:06:24 UTC 2017


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

Before:
  image_load v3, v[0:3] ...
After:
  image_load v3, v[0:1] ...
---
 src/gallium/drivers/radeonsi/si_shader.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 89229ee..f8eccdf 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -4388,51 +4388,47 @@ static void tex_fetch_args(
 	 * in FMASK), otherwise return physical sample 1.
 	 *
 	 * The sample index should be adjusted as follows:
 	 *   sample_index = (fmask >> (sample_index * 4)) & 0xF;
 	 */
 	if (target == TGSI_TEXTURE_2D_MSAA ||
 	    target == TGSI_TEXTURE_2D_ARRAY_MSAA) {
 		struct lp_build_context *uint_bld = &bld_base->uint_bld;
 		struct lp_build_emit_data txf_emit_data = *emit_data;
 		LLVMValueRef txf_address[4];
-		unsigned txf_count = count;
+		/* We only need .xy for non-arrays, and .xyz for arrays. */
+		unsigned txf_count = target == TGSI_TEXTURE_2D_MSAA ? 2 : 3;
 		struct tgsi_full_instruction inst = {};
 
 		memcpy(txf_address, address, sizeof(txf_address));
 
-		if (target == TGSI_TEXTURE_2D_MSAA) {
-			txf_address[2] = bld_base->uint_bld.zero;
-		}
-		txf_address[3] = bld_base->uint_bld.zero;
-
 		/* Read FMASK using TXF. */
 		inst.Instruction.Opcode = TGSI_OPCODE_TXF;
 		inst.Texture.Texture = target;
 		txf_emit_data.inst = &inst;
 		txf_emit_data.chan = 0;
 		set_tex_fetch_args(ctx, &txf_emit_data, TGSI_OPCODE_TXF,
 				   target, fmask_ptr, NULL,
 				   txf_address, txf_count, 0xf);
 		build_tex_intrinsic(&tex_action, bld_base, &txf_emit_data);
 
 		/* Initialize some constants. */
 		LLVMValueRef four = LLVMConstInt(ctx->i32, 4, 0);
 		LLVMValueRef F = LLVMConstInt(ctx->i32, 0xF, 0);
 
 		/* Apply the formula. */
 		LLVMValueRef fmask =
 			LLVMBuildExtractElement(gallivm->builder,
 						txf_emit_data.output[0],
 						uint_bld->zero, "");
 
-		unsigned sample_chan = target == TGSI_TEXTURE_2D_MSAA ? 2 : 3;
+		unsigned sample_chan = txf_count; /* the sample index is last */
 
 		LLVMValueRef sample_index4 =
 			LLVMBuildMul(gallivm->builder, address[sample_chan], four, "");
 
 		LLVMValueRef shifted_fmask =
 			LLVMBuildLShr(gallivm->builder, fmask, sample_index4, "");
 
 		LLVMValueRef final_sample =
 			LLVMBuildAnd(gallivm->builder, shifted_fmask, F, "");
 
-- 
2.7.4



More information about the mesa-dev mailing list