swr/rast: Add Builder::GetVectorType()
authorGeorge Kyriazis <george.kyriazis@intel.com>
Tue, 1 May 2018 21:33:19 +0000 (16:33 -0500)
committerGeorge Kyriazis <george.kyriazis@intel.com>
Fri, 11 May 2018 16:25:47 +0000 (11:25 -0500)
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/jitter/builder.cpp
src/gallium/drivers/swr/rasterizer/jitter/builder.h

index 32487353f864aa8a932657d789f33b5c5f88e840..e1c5d80c8061f04e3a1a22ae2691b70107c2063c 100644 (file)
@@ -170,4 +170,48 @@ namespace SwrJit
         return (pGenIntrin->getMetadata("is_evaluate") != nullptr);
     }
 
+    //////////////////////////////////////////////////////////////////////////
+    /// @brief Packetizes the type. Assumes SOA conversion.
+    Type* Builder::GetVectorType(Type* pType)
+    {
+        if (pType->isVectorTy())
+        {
+            return pType;
+        }
+
+        // [N x float] should packetize to [N x <8 x float>]
+        if (pType->isArrayTy())
+        {
+            uint32_t arraySize = pType->getArrayNumElements();
+            Type* pArrayType = pType->getArrayElementType();
+            Type* pVecArrayType = GetVectorType(pArrayType);
+            Type* pVecType = ArrayType::get(pVecArrayType, arraySize);
+            return pVecType;
+        }
+
+        // {float,int} should packetize to {<8 x float>, <8 x int>}
+        if (pType->isAggregateType())
+        {
+            uint32_t numElems = pType->getStructNumElements();
+            SmallVector<Type*, 8> vecTypes;
+            for (uint32_t i = 0; i < numElems; ++i)
+            {
+                Type* pElemType = pType->getStructElementType(i);
+                Type* pVecElemType = GetVectorType(pElemType);
+                vecTypes.push_back(pVecElemType);
+            }
+            Type* pVecType = StructType::get(JM()->mContext, vecTypes);
+            return pVecType;
+        }
+
+        // [N x float]* should packetize to [N x <8 x float>]*
+        if (pType->isPointerTy() && pType->getPointerElementType()->isArrayTy())
+        {
+            return PointerType::get(GetVectorType(pType->getPointerElementType()), pType->getPointerAddressSpace());
+        }
+
+        // <ty> should packetize to <8 x <ty>>
+        Type* vecType = VectorType::get(pType, JM()->mVWidth);
+        return vecType;
+    }
 }
index 82c5f8cde2a868772cbcbd31651adaf2c81c488c..6ca128d38f1f77935e45988e6185ff0219ad8812 100644 (file)
@@ -123,6 +123,7 @@ namespace SwrJit
         bool IsTempAlloca(Value* inst);
         bool SetTexelMaskEvaluate(Instruction* inst);
         bool IsTexelMaskEvaluate(Instruction* inst);
+        Type* GetVectorType(Type* pType);
 
 #include "gen_builder.hpp"
 #include "gen_builder_meta.hpp"