ac/nir: add support for arrays-of-arrays to get_sampler_desc
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 9 Jun 2017 13:16:51 +0000 (15:16 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 31 Jul 2017 12:55:38 +0000 (14:55 +0200)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_nir_to_llvm.c

index 6bf0845fee4cf8c2094c4613ff4ba5de11e673cc..e6a4504418aef36a4507d0b927b5c5f56ee6234d 100644 (file)
@@ -4224,17 +4224,32 @@ static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
 {
        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,