Mesa (master): ac: add si_nir_load_input_gs() to the abi

Timothy Arceri tarceri at kemper.freedesktop.org
Mon Dec 4 01:54:05 UTC 2017


Module: Mesa
Branch: master
Commit: ccd1810bbaf38ee31bd973f903bc9871cc8b1171
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ccd1810bbaf38ee31bd973f903bc9871cc8b1171

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Wed Nov  8 14:20:23 2017 +1100

ac: add si_nir_load_input_gs() to the abi

V2: make use of driver_location and don't expose NIR to the ABI.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>

---

 src/amd/common/ac_nir_to_llvm.c                   | 39 +++++++++++++++--------
 src/amd/common/ac_shader_abi.h                    |  9 ++++++
 src/gallium/drivers/radeonsi/si_shader.c          |  1 +
 src/gallium/drivers/radeonsi/si_shader_internal.h |  9 ++++++
 src/gallium/drivers/radeonsi/si_shader_nir.c      | 20 ++++++++++++
 5 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index db1936b311..96ba289a81 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -2894,27 +2894,29 @@ load_tes_input(struct nir_to_llvm_context *ctx,
 }
 
 static LLVMValueRef
-load_gs_input(struct nir_to_llvm_context *ctx,
-	      nir_intrinsic_instr *instr)
+load_gs_input(struct ac_shader_abi *abi,
+	      unsigned location,
+	      unsigned driver_location,
+	      unsigned component,
+	      unsigned num_components,
+	      unsigned vertex_index,
+	      unsigned const_index,
+	      LLVMTypeRef type)
 {
-	LLVMValueRef indir_index, vtx_offset;
-	unsigned const_index;
+	struct nir_to_llvm_context *ctx = nir_to_llvm_context_from_abi(abi);
+	LLVMValueRef vtx_offset;
 	LLVMValueRef args[9];
 	unsigned param, vtx_offset_param;
 	LLVMValueRef value[4], result;
-	unsigned vertex_index;
-	get_deref_offset(ctx->nir, instr->variables[0],
-			 false, &vertex_index, NULL,
-			 &const_index, &indir_index);
+
 	vtx_offset_param = vertex_index;
 	assert(vtx_offset_param < 6);
 	vtx_offset = LLVMBuildMul(ctx->builder, ctx->gs_vtx_offset[vtx_offset_param],
 				  LLVMConstInt(ctx->ac.i32, 4, false), "");
 
-	param = shader_io_get_unique_index(instr->variables[0]->var->data.location);
+	param = shader_io_get_unique_index(location);
 
-	unsigned comp = instr->variables[0]->var->data.location_frac;
-	for (unsigned i = comp; i < instr->num_components + comp; i++) {
+	for (unsigned i = component; i < num_components + component; i++) {
 		if (ctx->ac.chip_class >= GFX9) {
 			LLVMValueRef dw_addr = ctx->gs_vtx_offset[vtx_offset_param];
 			dw_addr = LLVMBuildAdd(ctx->ac.builder, dw_addr,
@@ -2937,7 +2939,7 @@ load_gs_input(struct nir_to_llvm_context *ctx,
 			                              AC_FUNC_ATTR_LEGACY);
 		}
 	}
-	result = ac_build_varying_gather_values(&ctx->ac, value, instr->num_components, comp);
+	result = ac_build_varying_gather_values(&ctx->ac, value, num_components, component);
 
 	return result;
 }
@@ -3006,7 +3008,16 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx,
 		if (ctx->stage == MESA_SHADER_TESS_EVAL)
 			return load_tes_input(ctx->nctx, instr);
 		if (ctx->stage == MESA_SHADER_GEOMETRY) {
-			return load_gs_input(ctx->nctx, instr);
+				LLVMValueRef indir_index;
+				unsigned const_index, vertex_index;
+				get_deref_offset(ctx, instr->variables[0],
+						 false, &vertex_index, NULL,
+						 &const_index, &indir_index);
+			return ctx->abi->load_inputs(ctx->abi, instr->variables[0]->var->data.location,
+						     instr->variables[0]->var->data.driver_location,
+						     instr->variables[0]->var->data.location_frac, ve,
+						     vertex_index, const_index,
+						     nir2llvmtype(ctx, instr->variables[0]->var->type));
 		}
 
 		for (unsigned chan = comp; chan < ve + comp; chan++) {
@@ -6560,8 +6571,8 @@ LLVMModuleRef ac_translate_nir_to_llvm(LLVMTargetMachineRef tm,
 
 		if (shaders[i]->info.stage == MESA_SHADER_GEOMETRY) {
 			ctx.gs_next_vertex = ac_build_alloca(&ctx.ac, ctx.ac.i32, "gs_next_vertex");
-
 			ctx.gs_max_out_vertices = shaders[i]->info.gs.vertices_out;
+			ctx.abi.load_inputs = load_gs_input;
 		} else if (shaders[i]->info.stage == MESA_SHADER_TESS_CTRL) {
 			ctx.tcs_outputs_read = shaders[i]->info.outputs_read;
 			ctx.tcs_patch_outputs_read = shaders[i]->info.patch_outputs_read;
diff --git a/src/amd/common/ac_shader_abi.h b/src/amd/common/ac_shader_abi.h
index 56209bd917..68fc431d42 100644
--- a/src/amd/common/ac_shader_abi.h
+++ b/src/amd/common/ac_shader_abi.h
@@ -64,6 +64,15 @@ struct ac_shader_abi {
 			    unsigned stream,
 			    LLVMValueRef *addrs);
 
+	LLVMValueRef (*load_inputs)(struct ac_shader_abi *abi,
+				    unsigned location,
+				    unsigned driver_location,
+				    unsigned component,
+				    unsigned num_components,
+				    unsigned vertex_index,
+				    unsigned const_index,
+				    LLVMTypeRef type);
+
 	LLVMValueRef (*load_ubo)(struct ac_shader_abi *abi, LLVMValueRef index);
 
 	/**
diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 950207b303..a94c2af870 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -5800,6 +5800,7 @@ static bool si_compile_tgsi_main(struct si_shader_context *ctx,
 		break;
 	case PIPE_SHADER_GEOMETRY:
 		bld_base->emit_fetch_funcs[TGSI_FILE_INPUT] = fetch_input_gs;
+		ctx->abi.load_inputs = si_nir_load_input_gs;
 		ctx->abi.emit_vertex = si_llvm_emit_vertex;
 		ctx->abi.emit_outputs = si_llvm_emit_gs_epilogue;
 		bld_base->emit_epilogue = si_tgsi_emit_gs_epilogue;
diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h b/src/gallium/drivers/radeonsi/si_shader_internal.h
index a548cf11f0..f50a022db8 100644
--- a/src/gallium/drivers/radeonsi/si_shader_internal.h
+++ b/src/gallium/drivers/radeonsi/si_shader_internal.h
@@ -332,4 +332,13 @@ void si_llvm_load_input_fs(
 
 bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir);
 
+LLVMValueRef si_nir_load_input_gs(struct ac_shader_abi *abi,
+				  unsigned location,
+				  unsigned driver_location,
+				  unsigned component,
+				  unsigned num_components,
+				  unsigned vertex_index,
+				  unsigned const_index,
+				  LLVMTypeRef type);
+
 #endif
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c
index 979361a74e..1b502b33e9 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -488,6 +488,26 @@ static void declare_nir_input_fs(struct si_shader_context *ctx,
 	si_llvm_load_input_fs(ctx, input_index, out);
 }
 
+LLVMValueRef si_nir_load_input_gs(struct ac_shader_abi *abi,
+				  unsigned location,
+				  unsigned driver_location,
+				  unsigned component,
+				  unsigned num_components,
+				  unsigned vertex_index,
+				  unsigned const_index,
+				  LLVMTypeRef type)
+{
+	struct si_shader_context *ctx = si_shader_context_from_abi(abi);
+
+	LLVMValueRef value[4];
+	for (unsigned i = component; i < num_components + component; i++) {
+		value[i] = si_llvm_load_input_gs(&ctx->abi, driver_location  / 4,
+						 vertex_index, type, i);
+	}
+
+	return ac_build_varying_gather_values(&ctx->ac, value, num_components, component);
+}
+
 static LLVMValueRef
 si_nir_load_sampler_desc(struct ac_shader_abi *abi,
 		         unsigned descriptor_set, unsigned base_index,




More information about the mesa-commit mailing list