Mesa (master): gallivm: Changed lp_build_pad_vector to correctly handle scalar argument.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed Nov 28 19:14:54 UTC 2012


Module: Mesa
Branch: master
Commit: d7a8390a821e9a9e7ae5103eb50315eac8131c9c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d7a8390a821e9a9e7ae5103eb50315eac8131c9c

Author: James Benton <jbenton at vmware.com>
Date:   Wed May 30 14:40:33 2012 +0100

gallivm: Changed lp_build_pad_vector to correctly handle scalar argument.

Removed the lp_type argument as it was unnecessary.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

---

 .../auxiliary/gallivm/lp_bld_format_aos_array.c    |    2 +-
 src/gallium/auxiliary/gallivm/lp_bld_pack.c        |   36 +++++++++++--------
 src/gallium/auxiliary/gallivm/lp_bld_pack.h        |    1 -
 3 files changed, 22 insertions(+), 17 deletions(-)

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 */




More information about the mesa-commit mailing list