From aa3e6bdbe024355b07f6a61806024b248528fe4b Mon Sep 17 00:00:00 2001 From: Darren Wihandi <65404740+fairywreath@users.noreply.github.com> Date: Fri, 30 May 2025 01:04:27 -0400 Subject: 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 --- source/slang/slang-check-expr.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-check-expr.cpp') 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()) && 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( - declRef.substitute(m_astBuilder, declRef.getDecl()->getType()), + declRef.substitute(m_astBuilder, decl->getType()), declRef); } -- cgit v1.2.3