[Mesa-dev] [PATCH 19/31] radeonsi: extract si_build_tcs_epilog_function

Nicolai Hähnle nhaehnle at gmail.com
Mon Oct 31 22:11:06 UTC 2016


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

---
 src/gallium/drivers/radeonsi/si_shader.c | 79 +++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 33 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 628b8c3..b33f54a 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -7709,73 +7709,86 @@ static bool si_shader_select_tes_parts(struct si_screen *sscreen,
 {
 	if (shader->key.tes.as_es)
 		return true;
 
 	/* TES compiled as VS. */
 	return si_get_vs_epilog(sscreen, tm, shader, debug,
 				&shader->key.tes.epilog);
 }
 
 /**
+ * Compile the TCS epilog function. This writes tesselation factors to memory
+ * based on the output primitive type of the tesselator (determined by TES).
+ */
+static void si_build_tcs_epilog_function(struct si_shader_context *ctx,
+					 union si_shader_part_key *key)
+{
+	struct gallivm_state *gallivm = &ctx->gallivm;
+	struct lp_build_tgsi_context *bld_base = &ctx->soa.bld_base;
+	LLVMTypeRef params[16];
+	LLVMValueRef func;
+	int last_sgpr, num_params;
+
+	/* Declare inputs. Only RW_BUFFERS and TESS_FACTOR_OFFSET are used. */
+	params[SI_PARAM_RW_BUFFERS] = const_array(ctx->v16i8, SI_NUM_RW_BUFFERS);
+	params[SI_PARAM_CONST_BUFFERS] = ctx->i64;
+	params[SI_PARAM_SAMPLERS] = ctx->i64;
+	params[SI_PARAM_IMAGES] = ctx->i64;
+	params[SI_PARAM_SHADER_BUFFERS] = ctx->i64;
+	params[SI_PARAM_TCS_OFFCHIP_LAYOUT] = ctx->i32;
+	params[SI_PARAM_TCS_OUT_OFFSETS] = ctx->i32;
+	params[SI_PARAM_TCS_OUT_LAYOUT] = ctx->i32;
+	params[SI_PARAM_TCS_IN_LAYOUT] = ctx->i32;
+	params[ctx->param_oc_lds = SI_PARAM_TCS_OC_LDS] = ctx->i32;
+	params[SI_PARAM_TESS_FACTOR_OFFSET] = ctx->i32;
+	last_sgpr = SI_PARAM_TESS_FACTOR_OFFSET;
+	num_params = last_sgpr + 1;
+
+	params[num_params++] = ctx->i32; /* patch index within the wave (REL_PATCH_ID) */
+	params[num_params++] = ctx->i32; /* invocation ID within the patch */
+	params[num_params++] = ctx->i32; /* LDS offset where tess factors should be loaded from */
+
+	/* Create the function. */
+	si_create_function(ctx, "tcs_epilog", NULL, 0, params, num_params, last_sgpr);
+	declare_tess_lds(ctx);
+	func = ctx->main_fn;
+
+	si_write_tess_factors(bld_base,
+			      LLVMGetParam(func, last_sgpr + 1),
+			      LLVMGetParam(func, last_sgpr + 2),
+			      LLVMGetParam(func, last_sgpr + 3));
+
+	LLVMBuildRetVoid(gallivm->builder);
+}
+
+/**
  * Compile the TCS epilog. This writes tesselation factors to memory based on
  * the output primitive type of the tesselator (determined by TES).
  */
 static bool si_compile_tcs_epilog(struct si_screen *sscreen,
 				  LLVMTargetMachineRef tm,
 				  struct pipe_debug_callback *debug,
 				  struct si_shader_part *out)
 {
 	union si_shader_part_key *key = &out->key;
 	struct si_shader shader = {};
 	struct si_shader_context ctx;
 	struct gallivm_state *gallivm = &ctx.gallivm;
-	struct lp_build_tgsi_context *bld_base = &ctx.soa.bld_base;
-	LLVMTypeRef params[16];
-	LLVMValueRef func;
-	int last_sgpr, num_params;
 	bool status = true;
 
 	si_init_shader_ctx(&ctx, sscreen, &shader, tm);
 	ctx.type = PIPE_SHADER_TESS_CTRL;
 	shader.key.tcs.epilog = key->tcs_epilog.states;
 
-	/* Declare inputs. Only RW_BUFFERS and TESS_FACTOR_OFFSET are used. */
-	params[SI_PARAM_RW_BUFFERS] = const_array(ctx.v16i8, SI_NUM_RW_BUFFERS);
-	params[SI_PARAM_CONST_BUFFERS] = ctx.i64;
-	params[SI_PARAM_SAMPLERS] = ctx.i64;
-	params[SI_PARAM_IMAGES] = ctx.i64;
-	params[SI_PARAM_SHADER_BUFFERS] = ctx.i64;
-	params[SI_PARAM_TCS_OFFCHIP_LAYOUT] = ctx.i32;
-	params[SI_PARAM_TCS_OUT_OFFSETS] = ctx.i32;
-	params[SI_PARAM_TCS_OUT_LAYOUT] = ctx.i32;
-	params[SI_PARAM_TCS_IN_LAYOUT] = ctx.i32;
-	params[ctx.param_oc_lds = SI_PARAM_TCS_OC_LDS] = ctx.i32;
-	params[SI_PARAM_TESS_FACTOR_OFFSET] = ctx.i32;
-	last_sgpr = SI_PARAM_TESS_FACTOR_OFFSET;
-	num_params = last_sgpr + 1;
-
-	params[num_params++] = ctx.i32; /* patch index within the wave (REL_PATCH_ID) */
-	params[num_params++] = ctx.i32; /* invocation ID within the patch */
-	params[num_params++] = ctx.i32; /* LDS offset where tess factors should be loaded from */
-
-	/* Create the function. */
-	si_create_function(&ctx, "tcs_epilog", NULL, 0, params, num_params, last_sgpr);
-	declare_tess_lds(&ctx);
-	func = ctx.main_fn;
-
-	si_write_tess_factors(bld_base,
-			      LLVMGetParam(func, last_sgpr + 1),
-			      LLVMGetParam(func, last_sgpr + 2),
-			      LLVMGetParam(func, last_sgpr + 3));
+	si_build_tcs_epilog_function(&ctx, key);
 
 	/* Compile. */
-	LLVMBuildRetVoid(gallivm->builder);
 	si_llvm_finalize_module(&ctx,
 		r600_extra_shader_checks(&sscreen->b, PIPE_SHADER_TESS_CTRL));
 
 	if (si_compile_llvm(sscreen, &out->binary, &out->config, tm,
 			    gallivm->module, debug, ctx.type,
 			    "Tessellation Control Shader Epilog"))
 		status = false;
 
 	si_llvm_dispose(&ctx);
 	return status;
-- 
2.7.4



More information about the mesa-dev mailing list