[Mesa-dev] [PATCH 63/92] ac/nir: add support for arrays-of-arrays to get_sampler_desc

Nicolai Hähnle nhaehnle at gmail.com
Mon Jun 26 14:10:42 UTC 2017


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

---
 src/amd/common/ac_nir_to_llvm.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 34cba7c..c3a885f 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -4115,31 +4115,46 @@ static LLVMValueRef radv_get_sampler_desc(struct ac_shader_abi *abi,
 
 	return ac_build_indexed_load_const(&ctx->ac, list, index);
 }
 
 static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
 				     const nir_deref_var *deref,
 				     enum ac_descriptor_type desc_type)
 {
 	LLVMValueRef index = NULL;
 	unsigned constant_index = 0;
+	const nir_deref *tail = &deref->deref;
 
-	if (deref->deref.child) {
-		const nir_deref_array *child =
-			(const nir_deref_array *)deref->deref.child;
+	while (tail->child) {
+		const nir_deref_array *child = nir_deref_as_array(tail->child);
+		unsigned array_size = glsl_get_aoa_size(tail->child->type);
+
+		if (!array_size)
+			array_size = 1;
 
 		assert(child->deref_array_type != nir_deref_array_type_wildcard);
+
 		if (child->deref_array_type == nir_deref_array_type_indirect) {
-			index = get_src(ctx, child->indirect);
+			LLVMValueRef indirect = get_src(ctx, child->indirect);
+
+			indirect = LLVMBuildMul(ctx->ac.builder, indirect,
+				LLVMConstInt(ctx->ac.i32, array_size, false), "");
+
+			if (!index)
+				index = indirect;
+			else
+				index = LLVMBuildAdd(ctx->ac.builder, index, indirect, "");
 		}
 
-		constant_index = child->base_offset;
+		constant_index += child->base_offset * array_size;
+
+		tail = &child->deref;
 	}
 
 	return ctx->abi->load_sampler_desc(ctx->abi,
 					  deref->var->data.descriptor_set,
 					  deref->var->data.binding,
 					  constant_index, index,
 					  desc_type);
 }
 
 static void set_tex_fetch_args(struct ac_llvm_context *ctx,
-- 
2.9.3



More information about the mesa-dev mailing list