From 0470ea05a42d6c3f35d81a433fefdd440500cdbd Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 24 Aug 2023 16:32:33 -0700 Subject: Misc. SPIRV Fixes, Part 2. (#3147) * Misc. SPIRV Fixes, Part 2. * Fix up. * Fix. * Add system smenatic values. * 16 bit int and floats, matrix/vector reshape, bool ops. * Fix. * Fix. * Allow push constant entry point params. * entrypoint params. * swizzleSet and swizzledStore. * packoffset. * string hash. * Fix. * Matrix arithmetics. --------- Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source/slang/slang-ir.cpp') 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(sourceVectorType->getElementCount()); + auto toCount = as(targetVectorType->getElementCount()); + if (fromCount && toCount) + { + if (toCount->getValue() < fromCount->getValue()) + { + List 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 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()), -- cgit v1.2.3