summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-spirv.cpp
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-07-08 21:34:51 -0700
committerGitHub <noreply@github.com>2024-07-08 21:34:51 -0700
commit5a174dfab4ae0852cb96df5f48bae474949cc017 (patch)
tree10f6fdaf9e272d8979609d161d1caad4094f5067 /source/slang/slang-emit-spirv.cpp
parenta453fadfb373499f08779dd7df8f2347d292fd91 (diff)
Fix the issue in emitFloatCast (#4559)
* Fix the issue in emitFloatCast In emitFloatCast function, we only considered the input type is float scalar or float vector, so if the input type is a float matrix type, it will crash. We should also handle the float matrix type. Also, we add some diagnose info to point out the source location where there is error happened, so in the future it's easier to tell us what happens. * Add a unit test * Disable the test for metal Metal doesn't support 'double'. " metal 32023.35: /tmp/unknown-YgHAsJ.metal(15): error : 'double' is not supported in Metal matrix<double,int(3),int(4)> b_0 = matrix<double,int(3),int(4)> (a_0); "
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
-rw-r--r--source/slang/slang-emit-spirv.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 1a4d80ae1..f7d807190 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -2403,7 +2403,7 @@ struct SPIRVEmitContext
// For now we aren't handling function declarations;
// we expect to deal only with fully linked modules.
//
- SLANG_UNUSED(irFunc);
+ m_sink->diagnose(irFunc, Diagnostics::internalCompilerError);
SLANG_UNEXPECTED("function declaration in SPIR-V emit");
UNREACHABLE_RETURN(nullptr);
}
@@ -5194,9 +5194,36 @@ struct SPIRVEmitContext
{
const auto fromTypeV = inst->getOperand(0)->getDataType();
const auto toTypeV = inst->getDataType();
- SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV));
- const auto fromType = getVectorElementType(fromTypeV);
- const auto toType = getVectorElementType(toTypeV);
+
+ IRType* fromType = nullptr;
+ IRType* toType = nullptr;
+
+ if (as<IRVectorType>(fromTypeV) || as<IRVectorType>(toTypeV))
+ {
+ fromType = getVectorElementType(fromTypeV);
+ toType = getVectorElementType(toTypeV);
+ }
+ else if (as<IRMatrixType>(fromTypeV) || as<IRMatrixType>(toTypeV))
+ {
+ fromType = getMatrixElementType(fromTypeV);
+ toType = getMatrixElementType(toTypeV);
+ }
+ else
+ {
+ fromType = fromTypeV;
+ toType = toTypeV;
+ }
+
+ // We'd better give some diagnostics to at least point out which line in the shader is wrong, so
+ // it can help the user or developers to locate the issue easier.
+ if (!isFloatingType(fromType)) {
+ m_sink->diagnose(inst, Diagnostics::internalCompilerError);
+ }
+
+ if (!isFloatingType(toType)) {
+ m_sink->diagnose(inst, Diagnostics::internalCompilerError);
+ }
+
SLANG_ASSERT(isFloatingType(fromType));
SLANG_ASSERT(isFloatingType(toType));
SLANG_ASSERT(!isTypeEqual(fromType, toType));