summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-expr.cpp
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2025-05-30 01:04:27 -0400
committerGitHub <noreply@github.com>2025-05-29 22:04:27 -0700
commitaa3e6bdbe024355b07f6a61806024b248528fe4b (patch)
tree3f11539df4dfd0dfcb7df2b4e7ce877ab9b84179 /source/slang/slang-check-expr.cpp
parent61f66c116ab10fdfd37492056aab7dfa4276a0b7 (diff)
Fix SPIRV `OpSpecConstantOp` emit (#7158)
* Fix SPIRV specialization constant with floating-point operations * Improve test * WIP * Restrict `OpSpecConstantOp` allowed operations based on SPIRV specifications * Fix typo on floating type check * Emit error on float to int spec cosnt int val casts
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
-rw-r--r--source/slang/slang-check-expr.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index 205575a81..9472138c3 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -1980,8 +1980,21 @@ IntVal* SemanticsVisitor::tryConstantFoldDeclRef(
decl->hasModifier<VkConstantIdAttribute>()) &&
kind == ConstantFoldingKind::SpecializationConstant)
{
+ // Float-to-inst casts cannot be`OpSpecConstOp` operations in SPIR-V,
+ // which means they need to be local instructions can cannot be hoisted to the
+ // global scope. Deduplication logic is run for `IntVal`s however and without hoisting
+ // instructions using this `IntVal` will trigger error. Hence we emit error here
+ // to not allow such cases.
+ //
+ // Note that float-to-inst casts for non-`IntVal`s are allowed.
+ if (!isScalarIntegerType(decl->getType()))
+ {
+ getSink()->diagnose(declRef, Diagnostics::intValFromNonIntSpecConstEncountered);
+ return nullptr;
+ }
+
return m_astBuilder->getOrCreate<DeclRefIntVal>(
- declRef.substitute(m_astBuilder, declRef.getDecl()->getType()),
+ declRef.substitute(m_astBuilder, decl->getType()),
declRef);
}