summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir.cpp')
-rw-r--r--source/slang/slang-ir.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 8d36c2e86..181970632 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -3771,6 +3771,32 @@ namespace Slang
}
if (targetVectorType->getElementCount() != sourceVectorType->getElementCount())
{
+ auto fromCount = as<IRIntLit>(sourceVectorType->getElementCount());
+ auto toCount = as<IRIntLit>(targetVectorType->getElementCount());
+ if (fromCount && toCount)
+ {
+ if (toCount->getValue() < fromCount->getValue())
+ {
+ List<UInt> indices;
+ for (UInt i = 0; i < (UInt)toCount->getValue(); i++)
+ indices.add(i);
+ return emitSwizzle(targetVectorType, value, (UInt)indices.getCount(), indices.getBuffer());
+ }
+ else if (toCount->getValue() > fromCount->getValue())
+ {
+ List<IRInst*> args;
+ for (UInt i = 0; i < (UInt)fromCount->getValue(); i++)
+ {
+ auto element = emitSwizzle(sourceVectorType->getElementType(), value , 1, &i);
+ args.add(element);
+ }
+ for (IRIntegerValue i = fromCount->getValue(); i < toCount->getValue(); i++)
+ {
+ args.add(emitDefaultConstruct(targetVectorType->getElementType()));
+ }
+ return emitMakeVector(targetVectorType, args);
+ }
+ }
auto reshape = emitIntrinsicInst(
getVectorType(
sourceVectorType->getElementType(), targetVectorType->getElementCount()),