From: James Benton Date: Wed, 30 May 2012 13:40:33 +0000 (+0100) Subject: gallivm: Changed lp_build_pad_vector to correctly handle scalar argument. X-Git-Tag: mesa-9.1-rc1~1141 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d7a8390a821e9a9e7ae5103eb50315eac8131c9c;p=platform%2Fupstream%2Fmesa.git gallivm: Changed lp_build_pad_vector to correctly handle scalar argument. Removed the lp_type argument as it was unnecessary. Reviewed-by: Jose Fonseca --- diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c index 609b9d4..24fee64 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos_array.c @@ -82,7 +82,7 @@ lp_build_fetch_rgba_aos_array(struct gallivm_state *gallivm, /* Expand to correct length */ if (src_type.length < dst_type.length) { - res = lp_build_pad_vector(gallivm, res, src_type, dst_type.length); + res = lp_build_pad_vector(gallivm, res, dst_type.length); src_type.length = dst_type.length; } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.c b/src/gallium/auxiliary/gallivm/lp_bld_pack.c index b18f784..e57d414 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_pack.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.c @@ -745,32 +745,38 @@ lp_build_resize(struct gallivm_state *gallivm, */ LLVMValueRef lp_build_pad_vector(struct gallivm_state *gallivm, - LLVMValueRef src, - struct lp_type src_type, - unsigned dst_length) + LLVMValueRef src, + unsigned dst_length) { - LLVMValueRef undef = LLVMGetUndef(lp_build_vec_type(gallivm, src_type)); LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; - unsigned i; + LLVMValueRef undef; + LLVMTypeRef type; + unsigned i, src_length; + + type = LLVMTypeOf(src); + + if (LLVMGetTypeKind(type) != LLVMVectorTypeKind) { + /* Can't use ShuffleVector on non-vector type */ + undef = LLVMGetUndef(LLVMVectorType(type, dst_length)); + return LLVMBuildInsertElement(gallivm->builder, undef, src, lp_build_const_int32(gallivm, 0), ""); + } + + undef = LLVMGetUndef(type); + src_length = LLVMGetVectorSize(type); assert(dst_length <= Elements(elems)); - assert(dst_length > src_type.length); + assert(dst_length >= src_length); - if (src_type.length == dst_length) + if (src_length == dst_length) return src; - /* If its a single scalar type, no need to reinvent the wheel */ - if (src_type.length == 1) { - return lp_build_broadcast(gallivm, LLVMVectorType(lp_build_elem_type(gallivm, src_type), dst_length), src); - } - /* All elements from src vector */ - for (i = 0; i < src_type.length; ++i) + for (i = 0; i < src_length; ++i) elems[i] = lp_build_const_int32(gallivm, i); /* Undef fill remaining space */ - for (i = src_type.length; i < dst_length; ++i) - elems[i] = lp_build_const_int32(gallivm, src_type.length); + for (i = src_length; i < dst_length; ++i) + elems[i] = lp_build_const_int32(gallivm, src_length); /* Combine the two vectors */ return LLVMBuildShuffleVector(gallivm->builder, src, undef, LLVMConstVector(elems, dst_length), ""); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.h b/src/gallium/auxiliary/gallivm/lp_bld_pack.h index 73f299c..f734c60 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_pack.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.h @@ -122,7 +122,6 @@ lp_build_resize(struct gallivm_state *gallivm, LLVMValueRef lp_build_pad_vector(struct gallivm_state *gallivm, LLVMValueRef src, - struct lp_type src_type, unsigned dst_length); #endif /* !LP_BLD_PACK_H */