[Mesa-dev] [PATCH 13/16] gallium/radeon: use tgsi_scan_arrays for temp arrays

Nicolai Hähnle nhaehnle at gmail.com
Wed Aug 10 19:23:38 UTC 2016


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

---
 src/gallium/drivers/radeon/radeon_llvm.h            | 3 ++-
 src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c | 9 ++++++---
 src/gallium/drivers/radeonsi/si_shader.c            | 3 ++-
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/radeon/radeon_llvm.h b/src/gallium/drivers/radeon/radeon_llvm.h
index 6086dd6..4ed2c97 100644
--- a/src/gallium/drivers/radeon/radeon_llvm.h
+++ b/src/gallium/drivers/radeon/radeon_llvm.h
@@ -114,21 +114,22 @@ LLVMTypeRef tgsi2llvmtype(struct lp_build_tgsi_context *bld_base,
 LLVMValueRef bitcast(struct lp_build_tgsi_context *bld_base,
 		     enum tgsi_opcode_type type, LLVMValueRef value);
 
 void radeon_llvm_emit_prepare_cube_coords(struct lp_build_tgsi_context *bld_base,
 					  struct lp_build_emit_data *emit_data,
 					  LLVMValueRef *coords_arg,
 					  LLVMValueRef *derivs_arg);
 
 void radeon_llvm_context_init(struct radeon_llvm_context *ctx,
                               const char *triple,
-			      const struct tgsi_shader_info *info);
+			      const struct tgsi_shader_info *info,
+			      const struct tgsi_token *tokens);
 
 void radeon_llvm_create_func(struct radeon_llvm_context *ctx,
 			     LLVMTypeRef *return_types, unsigned num_return_elems,
 			     LLVMTypeRef *ParamTypes, unsigned ParamCount);
 
 void radeon_llvm_dispose(struct radeon_llvm_context *ctx);
 
 unsigned radeon_llvm_reg_index_soa(unsigned index, unsigned chan);
 
 void radeon_llvm_finalize_module(struct radeon_llvm_context *ctx);
diff --git a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
index 2521023..dac0594 100644
--- a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
+++ b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
@@ -478,22 +478,20 @@ static void emit_declaration(struct lp_build_tgsi_context *bld_base,
 	{
 		char name[16] = "";
 		LLVMValueRef array_alloca = NULL;
 		unsigned decl_size;
 		first = decl->Range.First;
 		last = decl->Range.Last;
 		decl_size = 4 * ((last - first) + 1);
 		if (decl->Declaration.Array) {
 			unsigned id = decl->Array.ArrayID - 1;
 
-			ctx->temp_arrays[id].range = decl->Range;
-
 			/* If the array has more than 16 elements, store it
 			 * in memory using an alloca that spans the entire
 			 * array.
 			 *
 			 * Otherwise, store each array element individually.
 			 * We will then generate vectors (per-channel, up to
 			 * <4 x float>) for indirect addressing.
 			 *
 			 * Note that 16 is the number of vector elements that
 			 * LLVM will store in a register, so theoretically an
@@ -1723,21 +1721,22 @@ static void emit_rsq(const struct lp_build_tgsi_action *action,
 	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);
 }
 
 void radeon_llvm_context_init(struct radeon_llvm_context *ctx, const char *triple,
-			      const struct tgsi_shader_info *info)
+			      const struct tgsi_shader_info *info,
+			      const struct tgsi_token *tokens)
 {
 	struct lp_type type;
 
 	/* Initialize the gallivm object:
 	 * We are only using the module, context, and builder fields of this struct.
 	 * This should be enough for us to be able to pass our gallivm struct to the
 	 * helper functions in the gallivm module.
 	 */
 	memset(&ctx->gallivm, 0, sizeof (ctx->gallivm));
 	memset(&ctx->soa, 0, sizeof(ctx->soa));
@@ -1749,20 +1748,24 @@ void radeon_llvm_context_init(struct radeon_llvm_context *ctx, const char *tripl
 
 	struct lp_build_tgsi_context *bld_base = &ctx->soa.bld_base;
 
 	bld_base->info = info;
 
 	if (info && info->array_max[TGSI_FILE_TEMPORARY] > 0) {
 		int size = info->array_max[TGSI_FILE_TEMPORARY];
 
 		ctx->temp_arrays = CALLOC(size, sizeof(ctx->temp_arrays[0]));
 		ctx->temp_array_allocas = CALLOC(size, sizeof(ctx->temp_array_allocas[0]));
+
+		if (tokens)
+			tgsi_scan_arrays(tokens, TGSI_FILE_TEMPORARY, size,
+					 ctx->temp_arrays);
 	}
 
 	type.floating = true;
 	type.fixed = false;
 	type.sign = true;
 	type.norm = false;
 	type.width = 32;
 	type.length = 1;
 
 	lp_build_context_init(&bld_base->base, &ctx->gallivm, type);
diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index c595ee0..06b5c9c 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -6517,21 +6517,22 @@ static void si_init_shader_ctx(struct si_shader_context *ctx,
 			       struct si_screen *sscreen,
 			       struct si_shader *shader,
 			       LLVMTargetMachineRef tm)
 {
 	struct lp_build_tgsi_context *bld_base;
 	struct lp_build_tgsi_action tmpl = {};
 
 	memset(ctx, 0, sizeof(*ctx));
 	radeon_llvm_context_init(
 		&ctx->radeon_bld, "amdgcn--",
-		(shader && shader->selector) ? &shader->selector->info : NULL);
+		(shader && shader->selector) ? &shader->selector->info : NULL,
+		(shader && shader->selector) ? shader->selector->tokens : NULL);
 	ctx->tm = tm;
 	ctx->screen = sscreen;
 	if (shader && shader->selector)
 		ctx->type = shader->selector->info.processor;
 	else
 		ctx->type = -1;
 	ctx->shader = shader;
 
 	ctx->voidt = LLVMVoidTypeInContext(ctx->radeon_bld.gallivm.context);
 	ctx->i1 = LLVMInt1TypeInContext(ctx->radeon_bld.gallivm.context);
-- 
2.7.4



More information about the mesa-dev mailing list