[Mesa-dev] [PATCH 05/11] radeonsi: use si_get_indirect_index for TEMP indexing

Marek Olšák maraeo at gmail.com
Fri Sep 29 12:25:28 UTC 2017


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

---
 .../drivers/radeonsi/si_shader_tgsi_setup.c        | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index 109ec1b..d6529f2 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -324,34 +324,20 @@ get_array_range(struct lp_build_tgsi_context *bld_base,
 		unsigned array_id = get_temp_array_id(bld_base, reg_index, reg);
 		if (array_id)
 			return ctx->temp_arrays[array_id - 1].range;
 	}
 
 	range.First = 0;
 	range.Last = bld_base->info->file_max[File];
 	return range;
 }
 
-static LLVMValueRef
-emit_array_index(struct si_shader_context *ctx,
-		 const struct tgsi_ind_register *reg,
-		 unsigned offset)
-{
-	struct gallivm_state *gallivm = &ctx->gallivm;
-
-	if (!reg) {
-		return LLVMConstInt(ctx->i32, offset, 0);
-	}
-	LLVMValueRef addr = LLVMBuildLoad(gallivm->builder, ctx->addrs[reg->Index][reg->Swizzle], "");
-	return LLVMBuildAdd(gallivm->builder, addr, LLVMConstInt(ctx->i32, offset, 0), "");
-}
-
 /**
  * For indirect registers, construct a pointer directly to the requested
  * element using getelementptr if possible.
  *
  * Returns NULL if the insertelement/extractelement fallback for array access
  * must be used.
  */
 static LLVMValueRef
 get_pointer_into_array(struct si_shader_context *ctx,
 		       unsigned file,
@@ -376,22 +362,22 @@ get_pointer_into_array(struct si_shader_context *ctx,
 
 	alloca = ctx->temp_array_allocas[array_id - 1];
 	if (!alloca)
 		return NULL;
 
 	array = &ctx->temp_arrays[array_id - 1];
 
 	if (!(array->writemask & (1 << swizzle)))
 		return ctx->undef_alloca;
 
-	index = emit_array_index(ctx, reg_indirect,
-				 reg_index - ctx->temp_arrays[array_id - 1].range.First);
+	index = si_get_indirect_index(ctx, reg_indirect, 1,
+				      reg_index - ctx->temp_arrays[array_id - 1].range.First);
 
 	/* Ensure that the index is within a valid range, to guard against
 	 * VM faults and overwriting critical data (e.g. spilled resource
 	 * descriptors).
 	 *
 	 * TODO It should be possible to avoid the additional instructions
 	 * if LLVM is changed so that it guarantuees:
 	 * 1. the scratch space descriptor isolates the current wave (this
 	 *    could even save the scratch offset SGPR at the cost of an
 	 *    additional SALU instruction)
@@ -483,21 +469,21 @@ load_value_from_array(struct lp_build_tgsi_context *bld_base,
 			ptr_hi = LLVMBuildGEP(builder, ptr, &ctx->i32_1, 1, "");
 			val_hi = LLVMBuildLoad(builder, ptr_hi, "");
 			val = si_llvm_emit_fetch_64bit(bld_base, type, val, val_hi);
 		}
 
 		return val;
 	} else {
 		struct tgsi_declaration_range range =
 			get_array_range(bld_base, file, reg_index, reg_indirect);
 		LLVMValueRef index =
-			emit_array_index(ctx, reg_indirect, reg_index - range.First);
+			si_get_indirect_index(ctx, reg_indirect, 1, reg_index - range.First);
 		LLVMValueRef array =
 			emit_array_fetch(bld_base, file, type, range, swizzle);
 		return LLVMBuildExtractElement(builder, array, index, "");
 	}
 }
 
 static void
 store_value_to_array(struct lp_build_tgsi_context *bld_base,
 		     LLVMValueRef value,
 		     unsigned file,
@@ -509,21 +495,21 @@ store_value_to_array(struct lp_build_tgsi_context *bld_base,
 	struct gallivm_state *gallivm = &ctx->gallivm;
 	LLVMBuilderRef builder = gallivm->builder;
 	LLVMValueRef ptr;
 
 	ptr = get_pointer_into_array(ctx, file, chan_index, reg_index, reg_indirect);
 	if (ptr) {
 		LLVMBuildStore(builder, value, ptr);
 	} else {
 		unsigned i, size;
 		struct tgsi_declaration_range range = get_array_range(bld_base, file, reg_index, reg_indirect);
-		LLVMValueRef index = emit_array_index(ctx, reg_indirect, reg_index - range.First);
+		LLVMValueRef index = si_get_indirect_index(ctx, reg_indirect, 1, reg_index - range.First);
 		LLVMValueRef array =
 			emit_array_fetch(bld_base, file, TGSI_TYPE_FLOAT, range, chan_index);
 		LLVMValueRef temp_ptr;
 
 		array = LLVMBuildInsertElement(builder, array, value, index, "");
 
 		size = range.Last - range.First + 1;
 		for (i = 0; i < size; ++i) {
 			switch(file) {
 			case TGSI_FILE_OUTPUT:
-- 
2.7.4



More information about the mesa-dev mailing list