summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-02-20 14:48:51 -0800
committerGitHub <noreply@github.com>2025-02-20 14:48:51 -0800
commit19867ffca6dca7995c799354081219c9e76f13d1 (patch)
treeb9153428fc8b7b6f3069931cf816ad374a2e7c52 /source/slang/slang-ir.cpp
parent9580e311e0cefb0f8e11afc316783a67201654eb (diff)
Simplify implicit cast ctors for vector & matrix. (#6408)
* Simplify implicit cast ctors for vector & matrix. * Fix formatting. * Fix tests. * Fix Falcor test. * Mark __builtin_cast as internal.
Diffstat (limited to 'source/slang/slang-ir.cpp')
-rw-r--r--source/slang/slang-ir.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index cdabb1ac2..f28f61ffc 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -3995,7 +3995,7 @@ static TypeCastStyle _getTypeStyleId(IRType* type)
}
}
-IRInst* IRBuilder::emitCast(IRType* type, IRInst* value)
+IRInst* IRBuilder::emitCast(IRType* type, IRInst* value, bool fallbackToBuiltinCast)
{
if (isTypeEqual(type, value->getDataType()))
return value;
@@ -4009,8 +4009,17 @@ IRInst* IRBuilder::emitCast(IRType* type, IRInst* value)
SLANG_UNREACHABLE("cast from void type");
}
- SLANG_RELEASE_ASSERT(toStyle != TypeCastStyle::Unknown);
- SLANG_RELEASE_ASSERT(fromStyle != TypeCastStyle::Unknown);
+ if (toStyle == TypeCastStyle::Unknown || fromStyle == TypeCastStyle::Unknown)
+ {
+ if (fallbackToBuiltinCast)
+ {
+ return emitIntrinsicInst(type, kIROp_BuiltinCast, 1, &value);
+ }
+ else
+ {
+ return nullptr;
+ }
+ }
struct OpSeq
{
@@ -4057,7 +4066,18 @@ IRInst* IRBuilder::emitCast(IRType* type, IRInst* value)
auto t = type;
if (op.op1 != kIROp_Nop)
{
- t = getUInt64Type();
+ if (toStyle == TypeCastStyle::Bool)
+ t = getIntType();
+ else
+ t = getUInt64Type();
+ if (auto vecType = as<IRVectorType>(type))
+ t = getVectorType(t, vecType->getElementCount());
+ else if (auto matType = as<IRMatrixType>(type))
+ t = getMatrixType(
+ t,
+ matType->getRowCount(),
+ matType->getColumnCount(),
+ matType->getLayout());
}
auto result = emitIntrinsicInst(t, op.op0, 1, &value);
if (op.op1 != kIROp_Nop)
@@ -8293,6 +8313,7 @@ bool IRInst::mightHaveSideEffects(SideEffectAnalysisOptions options)
case kIROp_ExtractExistentialValue:
case kIROp_ExtractExistentialWitnessTable:
case kIROp_WrapExistential:
+ case kIROp_BuiltinCast:
case kIROp_BitCast:
case kIROp_CastFloatToInt:
case kIROp_CastIntToFloat: