[Mesa-dev] [FLAG-DAY-PREP 3/9] amd: use nir_intrinsic_var() accessor

Rob Clark robdclark at gmail.com
Thu Mar 15 14:28:02 UTC 2018


---
 src/amd/common/ac_nir_to_llvm.c              | 70 +++++++++++++++-------------
 src/amd/vulkan/radv_shader_info.c            | 11 ++---
 src/gallium/drivers/radeonsi/si_shader_nir.c |  4 +-
 3 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index b0c0d76b470..8df00fc3c8c 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -1634,10 +1634,11 @@ static LLVMValueRef load_tess_varyings(struct ac_nir_context *ctx,
 	LLVMValueRef vertex_index = NULL;
 	LLVMValueRef indir_index = NULL;
 	unsigned const_index = 0;
-	unsigned location = instr->variables[0]->var->data.location;
-	unsigned driver_location = instr->variables[0]->var->data.driver_location;
-	const bool is_patch =  instr->variables[0]->var->data.patch;
-	const bool is_compact = instr->variables[0]->var->data.compact;
+	const nir_variable *var = nir_intrinsic_var(instr, 0);
+	unsigned location = var->data.location;
+	unsigned driver_location = var->data.driver_location;
+	const bool is_patch =  var->data.patch;
+	const bool is_compact = var->data.compact;
 
 	get_deref_offset(ctx, instr->variables[0],
 			 false, NULL, is_patch ? NULL : &vertex_index,
@@ -1654,7 +1655,7 @@ static LLVMValueRef load_tess_varyings(struct ac_nir_context *ctx,
 	result = ctx->abi->load_tess_varyings(ctx->abi, src_component_type,
 					      vertex_index, indir_index,
 					      const_index, location, driver_location,
-					      instr->variables[0]->var->data.location_frac,
+					      var->data.location_frac,
 					      instr->num_components,
 					      is_patch, is_compact, load_inputs);
 	return LLVMBuildBitCast(ctx->ac.builder, result, dest_type, "");
@@ -1664,22 +1665,23 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx,
 				   nir_intrinsic_instr *instr)
 {
 	LLVMValueRef values[8];
-	int idx = instr->variables[0]->var->data.driver_location;
+	nir_variable *var = nir_intrinsic_var(instr, 0);
+	int idx = var->data.driver_location;
 	int ve = instr->dest.ssa.num_components;
-	unsigned comp = instr->variables[0]->var->data.location_frac;
+	unsigned comp = var->data.location_frac;
 	LLVMValueRef indir_index;
 	LLVMValueRef ret;
 	unsigned const_index;
-	unsigned stride = instr->variables[0]->var->data.compact ? 1 : 4;
+	unsigned stride = var->data.compact ? 1 : 4;
 	bool vs_in = ctx->stage == MESA_SHADER_VERTEX &&
-	             instr->variables[0]->var->data.mode == nir_var_shader_in;
+	             var->data.mode == nir_var_shader_in;
 	get_deref_offset(ctx, instr->variables[0], vs_in, NULL, NULL,
 				      &const_index, &indir_index);
 
 	if (instr->dest.ssa.bit_size == 64)
 		ve *= 2;
 
-	switch (instr->variables[0]->var->data.mode) {
+	switch (var->data.mode) {
 	case nir_var_shader_in:
 		if (ctx->stage == MESA_SHADER_TESS_CTRL ||
 		    ctx->stage == MESA_SHADER_TESS_EVAL) {
@@ -1694,16 +1696,16 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx,
 					 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,
+			return ctx->abi->load_inputs(ctx->abi, var->data.location,
+						     var->data.driver_location,
+						     var->data.location_frac,
 						     instr->num_components, vertex_index, const_index, type);
 		}
 
 		for (unsigned chan = comp; chan < ve + comp; chan++) {
 			if (indir_index) {
 				unsigned count = glsl_count_attribute_slots(
-						instr->variables[0]->var->type,
+						var->type,
 						ctx->stage == MESA_SHADER_VERTEX);
 				count -= chan / 4;
 				LLVMValueRef tmp_vec = ac_build_gather_values_extended(
@@ -1721,7 +1723,7 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx,
 		for (unsigned chan = 0; chan < ve; chan++) {
 			if (indir_index) {
 				unsigned count = glsl_count_attribute_slots(
-					instr->variables[0]->var->type, false);
+					var->type, false);
 				count -= chan / 4;
 				LLVMValueRef tmp_vec = ac_build_gather_values_extended(
 						&ctx->ac, ctx->locals + idx + chan, count,
@@ -1751,7 +1753,7 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx,
 		for (unsigned chan = comp; chan < ve + comp; chan++) {
 			if (indir_index) {
 				unsigned count = glsl_count_attribute_slots(
-						instr->variables[0]->var->type, false);
+						var->type, false);
 				count -= chan / 4;
 				LLVMValueRef tmp_vec = ac_build_gather_values_extended(
 						&ctx->ac, ctx->abi->outputs + idx + chan, count,
@@ -1779,8 +1781,9 @@ visit_store_var(struct ac_nir_context *ctx,
 		nir_intrinsic_instr *instr)
 {
 	LLVMValueRef temp_ptr, value;
-	int idx = instr->variables[0]->var->data.driver_location;
-	unsigned comp = instr->variables[0]->var->data.location_frac;
+	const nir_variable *var = nir_intrinsic_var(instr, 0);
+	int idx = var->data.driver_location;
+	unsigned comp = var->data.location_frac;
 	LLVMValueRef src = ac_to_float(&ctx->ac, get_src(ctx, instr->src[0]));
 	int writemask = instr->const_index[0] << comp;
 	LLVMValueRef indir_index;
@@ -1797,20 +1800,20 @@ visit_store_var(struct ac_nir_context *ctx,
 		writemask = widen_mask(writemask, 2);
 	}
 
-	switch (instr->variables[0]->var->data.mode) {
+	switch (var->data.mode) {
 	case nir_var_shader_out:
 
 		if (ctx->stage == MESA_SHADER_TESS_CTRL) {
 			LLVMValueRef vertex_index = NULL;
 			LLVMValueRef indir_index = NULL;
 			unsigned const_index = 0;
-			const bool is_patch = instr->variables[0]->var->data.patch;
+			const bool is_patch = var->data.patch;
 
 			get_deref_offset(ctx, instr->variables[0],
 					 false, NULL, is_patch ? NULL : &vertex_index,
 					 &const_index, &indir_index);
 
-			ctx->abi->store_tcs_outputs(ctx->abi, instr->variables[0]->var,
+			ctx->abi->store_tcs_outputs(ctx->abi, var,
 						    vertex_index, indir_index,
 						    const_index, src, writemask);
 			return;
@@ -1823,11 +1826,11 @@ visit_store_var(struct ac_nir_context *ctx,
 
 			value = ac_llvm_extract_elem(&ctx->ac, src, chan - comp);
 
-			if (instr->variables[0]->var->data.compact)
+			if (var->data.compact)
 				stride = 1;
 			if (indir_index) {
 				unsigned count = glsl_count_attribute_slots(
-						instr->variables[0]->var->type, false);
+						var->type, false);
 				count -= chan / 4;
 				LLVMValueRef tmp_vec = ac_build_gather_values_extended(
 						&ctx->ac, ctx->abi->outputs + idx + chan, count,
@@ -1853,7 +1856,7 @@ visit_store_var(struct ac_nir_context *ctx,
 			value = ac_llvm_extract_elem(&ctx->ac, src, chan);
 			if (indir_index) {
 				unsigned count = glsl_count_attribute_slots(
-					instr->variables[0]->var->type, false);
+					var->type, false);
 				count -= chan / 4;
 				LLVMValueRef tmp_vec = ac_build_gather_values_extended(
 					&ctx->ac, ctx->locals + idx + chan, count,
@@ -2025,7 +2028,7 @@ static LLVMValueRef adjust_sample_index_using_fmask(struct ac_llvm_context *ctx,
 static LLVMValueRef get_image_coords(struct ac_nir_context *ctx,
 				     const nir_intrinsic_instr *instr)
 {
-	const struct glsl_type *type = glsl_without_array(instr->variables[0]->var->type);
+	const struct glsl_type *type = glsl_without_array(nir_intrinsic_var(instr, 0)->type);
 
 	LLVMValueRef src0 = get_src(ctx, instr->src[0]);
 	LLVMValueRef coords[4];
@@ -2120,7 +2123,7 @@ static LLVMValueRef visit_image_load(struct ac_nir_context *ctx,
 	LLVMValueRef params[7];
 	LLVMValueRef res;
 	char intrinsic_name[64];
-	const nir_variable *var = instr->variables[0]->var;
+	const nir_variable *var = nir_intrinsic_var(instr, 0);
 	const struct glsl_type *type = var->type;
 
 	if(instr->variables[0]->deref.child)
@@ -2176,7 +2179,7 @@ static void visit_image_store(struct ac_nir_context *ctx,
 {
 	LLVMValueRef params[8];
 	char intrinsic_name[64];
-	const nir_variable *var = instr->variables[0]->var;
+	const nir_variable *var = nir_intrinsic_var(instr, 0);
 	const struct glsl_type *type = glsl_without_array(var->type);
 	const enum glsl_sampler_dim dim = glsl_get_sampler_dim(type);
 	LLVMValueRef glc = ctx->ac.i1false;
@@ -2225,7 +2228,7 @@ static LLVMValueRef visit_image_atomic(struct ac_nir_context *ctx,
 {
 	LLVMValueRef params[7];
 	int param_count = 0;
-	const nir_variable *var = instr->variables[0]->var;
+	const nir_variable *var = nir_intrinsic_var(instr, 0);
 
 	const char *atomic_name;
 	char intrinsic_name[41];
@@ -2301,7 +2304,7 @@ static LLVMValueRef visit_image_atomic(struct ac_nir_context *ctx,
 static LLVMValueRef visit_image_samples(struct ac_nir_context *ctx,
 					const nir_intrinsic_instr *instr)
 {
-	const nir_variable *var = instr->variables[0]->var;
+	const nir_variable *var = nir_intrinsic_var(instr, 0);
 	const struct glsl_type *type = glsl_without_array(var->type);
 
 	struct ac_image_args args = { 0 };
@@ -2319,7 +2322,7 @@ static LLVMValueRef visit_image_size(struct ac_nir_context *ctx,
 				     const nir_intrinsic_instr *instr)
 {
 	LLVMValueRef res;
-	const nir_variable *var = instr->variables[0]->var;
+	const nir_variable *var = nir_intrinsic_var(instr, 0);
 	const struct glsl_type *type = glsl_without_array(var->type);
 
 	if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_BUF)
@@ -2607,7 +2610,8 @@ static LLVMValueRef visit_interp(struct ac_nir_context *ctx,
 	LLVMValueRef src_c0 = NULL;
 	LLVMValueRef src_c1 = NULL;
 	LLVMValueRef src0 = NULL;
-	int input_index = instr->variables[0]->var->data.location - VARYING_SLOT_VAR0;
+	const nir_variable *var = nir_intrinsic_var(instr, 0);
+	int input_index = var->data.location - VARYING_SLOT_VAR0;
 	switch (instr->intrinsic) {
 	case nir_intrinsic_interp_var_at_centroid:
 		location = INTERP_CENTROID;
@@ -2636,7 +2640,7 @@ static LLVMValueRef visit_interp(struct ac_nir_context *ctx,
 		src_c1 = LLVMBuildExtractElement(ctx->ac.builder, sample_position, ctx->ac.i32_1, "");
 		src_c1 = LLVMBuildFSub(ctx->ac.builder, src_c1, halfval, "");
 	}
-	interp_param = ctx->abi->lookup_interp_param(ctx->abi, instr->variables[0]->var->data.interpolation, location);
+	interp_param = ctx->abi->lookup_interp_param(ctx->abi, var->data.interpolation, location);
 	attr_number = LLVMConstInt(ctx->ac.i32, input_index, false);
 
 	if (location == INTERP_CENTER) {
@@ -2700,7 +2704,7 @@ static LLVMValueRef visit_interp(struct ac_nir_context *ctx,
 		}
 	}
 	return ac_build_varying_gather_values(&ctx->ac, result, instr->num_components,
-					      instr->variables[0]->var->data.location_frac);
+					      var->data.location_frac);
 }
 
 static void visit_intrinsic(struct ac_nir_context *ctx,
diff --git a/src/amd/vulkan/radv_shader_info.c b/src/amd/vulkan/radv_shader_info.c
index 3cce0c2f6e4..dea89fa0a9f 100644
--- a/src/amd/vulkan/radv_shader_info.c
+++ b/src/amd/vulkan/radv_shader_info.c
@@ -97,7 +97,8 @@ gather_intrinsic_info(const nir_shader *nir, const nir_intrinsic_instr *instr,
 	case nir_intrinsic_image_atomic_exchange:
 	case nir_intrinsic_image_atomic_comp_swap:
 	case nir_intrinsic_image_size: {
-		const struct glsl_type *type = instr->variables[0]->var->type;
+		nir_variable *var = nir_intrinsic_var(instr, 0);
+		const struct glsl_type *type = var->type;
 		if(instr->variables[0]->deref.child)
 			type = instr->variables[0]->deref.child->type;
 
@@ -105,7 +106,7 @@ gather_intrinsic_info(const nir_shader *nir, const nir_intrinsic_instr *instr,
 		if (dim == GLSL_SAMPLER_DIM_SUBPASS ||
 		    dim == GLSL_SAMPLER_DIM_SUBPASS_MS)
 			info->ps.uses_input_attachments = true;
-		mark_sampler_desc(instr->variables[0]->var, info);
+		mark_sampler_desc(var, info);
 
 		if (nir_intrinsic_image_store ||
 		    nir_intrinsic_image_atomic_add ||
@@ -137,8 +138,7 @@ gather_intrinsic_info(const nir_shader *nir, const nir_intrinsic_instr *instr,
 		break;
 	case nir_intrinsic_load_var:
 		if (nir->info.stage == MESA_SHADER_VERTEX) {
-			nir_deref_var *dvar = instr->variables[0];
-			nir_variable *var = dvar->var;
+			nir_variable *var = nir_intrinsic_var(instr, 0);
 
 			if (var->data.mode == nir_var_shader_in) {
 				unsigned idx = var->data.location;
@@ -149,8 +149,7 @@ gather_intrinsic_info(const nir_shader *nir, const nir_intrinsic_instr *instr,
 		}
 		break;
 	case nir_intrinsic_store_var: {
-		nir_deref_var *dvar = instr->variables[0];
-		nir_variable *var = dvar->var;
+		nir_variable *var = nir_intrinsic_var(instr, 0);
 
 		if (var->data.mode == nir_var_shader_out) {
 			unsigned idx = var->data.location;
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c
index acb796b331c..6332c198b59 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -149,7 +149,7 @@ static void scan_instruction(struct tgsi_shader_info *info,
 			info->writes_memory = true;
 			break;
 		case nir_intrinsic_load_var: {
-			nir_variable *var = intr->variables[0]->var;
+			nir_variable *var = nir_intrinsic_var(intr, 0);
 			nir_variable_mode mode = var->data.mode;
 			enum glsl_base_type base_type =
 				glsl_get_base_type(glsl_without_array(var->type));
@@ -186,7 +186,7 @@ static void scan_instruction(struct tgsi_shader_info *info,
 		case nir_intrinsic_interp_var_at_sample:
 		case nir_intrinsic_interp_var_at_offset: {
 			enum glsl_interp_mode interp =
-				intr->variables[0]->var->data.interpolation;
+					nir_intrinsic_var(intr, 0)->data.interpolation;
 			switch (interp) {
 			case INTERP_MODE_SMOOTH:
 			case INTERP_MODE_NONE:
-- 
2.14.3



More information about the mesa-dev mailing list