summaryrefslogtreecommitdiff
path: root/source/slang/slang-lower-to-ir.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-01-18 00:01:58 -0500
committerGitHub <noreply@github.com>2023-01-17 21:01:58 -0800
commita0994a8da142e54362e9ec1fdb5e5abc708ec3d2 (patch)
tree363e75df065338fdb1da29286d932733fdb6b3c4 /source/slang/slang-lower-to-ir.cpp
parent1a486813ef0bc7f7a2eb6eaeec2921fd71a2bd05 (diff)
Add `set` to spirv_instruction (#2597)
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
-rw-r--r--source/slang/slang-lower-to-ir.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index 383067363..ec51c7bfa 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -7894,21 +7894,19 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
}
}
- IRIntLit* _getIntLitFromAttribute(IRBuilder* builder, Attribute* attrib)
+ IRIntLit* _getIntLitFromAttribute(IRBuilder* builder, Attribute* attrib, Index index = 0)
{
- attrib->args.getCount();
- SLANG_ASSERT(attrib->args.getCount() ==1);
- Expr* expr = attrib->args[0];
+ SLANG_ASSERT(attrib->args.getCount() > index);
+ Expr* expr = attrib->args[index];
auto intLitExpr = as<IntegerLiteralExpr>(expr);
SLANG_ASSERT(intLitExpr);
return as<IRIntLit>(builder->getIntValue(builder->getIntType(), intLitExpr->value));
}
- IRStringLit* _getStringLitFromAttribute(IRBuilder* builder, Attribute* attrib)
+ IRStringLit* _getStringLitFromAttribute(IRBuilder* builder, Attribute* attrib, Index index = 0)
{
- attrib->args.getCount();
- SLANG_ASSERT(attrib->args.getCount() == 1);
- Expr* expr = attrib->args[0];
+ SLANG_ASSERT(attrib->args.getCount() > index);
+ Expr* expr = attrib->args[index];
auto stringLitExpr = as<StringLiteralExpr>(expr);
SLANG_ASSERT(stringLitExpr);
@@ -8332,8 +8330,28 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
if (auto attr = decl->findModifier<SPIRVInstructionOpAttribute>())
{
- IRIntLit* intLit = _getIntLitFromAttribute(getBuilder(), attr);
- getBuilder()->addDecoration(irFunc, kIROp_SPIRVOpDecoration, intLit);
+ auto builder = getBuilder();
+ IRIntLit* intLit = _getIntLitFromAttribute(builder, attr, 0);
+
+ IRStringLit* setStringLit = nullptr;
+ if (attr->args.getCount() > 1)
+ {
+ IRStringLit* checkSetStringLit = _getStringLitFromAttribute(builder, attr, 1);
+ if (checkSetStringLit && checkSetStringLit->getStringSlice().getLength() > 0)
+ {
+ setStringLit = checkSetStringLit;
+ }
+ }
+
+ // If it has a `set` defined, set it on the decoration
+ if (setStringLit)
+ {
+ builder->addDecoration(irFunc, kIROp_SPIRVOpDecoration, intLit, setStringLit);
+ }
+ else
+ {
+ builder->addDecoration(irFunc, kIROp_SPIRVOpDecoration, intLit);
+ }
}
if (decl->findModifier<UnsafeForceInlineEarlyAttribute>())