+static LLVMValueRef
+get_soa_array_offsets(struct lp_build_context *uint_bld,
+ LLVMValueRef indirect_index,
+ unsigned chan_index,
+ boolean need_perelement_offset)
+{
+ struct gallivm_state *gallivm = uint_bld->gallivm;
+ LLVMValueRef chan_vec =
+ lp_build_const_int_vec(uint_bld->gallivm, uint_bld->type, chan_index);
+ LLVMValueRef length_vec =
+ lp_build_const_int_vec(gallivm, uint_bld->type, uint_bld->type.length);
+ LLVMValueRef index_vec;
+
+ /* index_vec = (indirect_index * 4 + chan_index) * length + offsets */
+ index_vec = lp_build_shl_imm(uint_bld, indirect_index, 2);
+ index_vec = lp_build_add(uint_bld, index_vec, chan_vec);
+ index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
+
+ if (need_perelement_offset) {
+ LLVMValueRef pixel_offsets;
+ int i;
+ /* build pixel offset vector: {0, 1, 2, 3, ...} */
+ pixel_offsets = uint_bld->undef;
+ for (i = 0; i < uint_bld->type.length; i++) {
+ LLVMValueRef ii = lp_build_const_int32(gallivm, i);
+ pixel_offsets = LLVMBuildInsertElement(gallivm->builder, pixel_offsets,
+ ii, ii, "");
+ }
+ index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets);
+ }
+ return index_vec;
+}
+