summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-modifier.cpp
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2025-04-21 12:46:23 -0600
committerGitHub <noreply@github.com>2025-04-21 18:46:23 +0000
commit62baf92a524a5b57eb465100a5e47c489c049f15 (patch)
tree8f66cd150c1e0f80bf8029ffd48bb8ba6537ff9a /source/slang/slang-check-modifier.cpp
parent5d41a4dbd319c3266b21eee06bb6459adb59c2e7 (diff)
Add `vk::offset` to specify member offsets for push constants (#6797)
* Add struct member offset qualifier for SPIRV * Implement for GLSL target and add tests * clean up * fix formatting * fix typo * renamed GLSLStructOffset to VkStructOffset and added emit-spirv-via-glsl test case
Diffstat (limited to 'source/slang/slang-check-modifier.cpp')
-rw-r--r--source/slang/slang-check-modifier.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp
index d94c77d6a..e0b203fb6 100644
--- a/source/slang/slang-check-modifier.cpp
+++ b/source/slang/slang-check-modifier.cpp
@@ -1266,7 +1266,6 @@ AttributeBase* SemanticsVisitor::checkAttribute(
//
// The attribute declaration will have one or more `AttributeTargetModifier`s
// that each specify a syntax class that the attribute can be applied to.
- // If any of these match `attrTarget`, then we are good.
//
bool validTarget = false;
for (auto attrTargetMod : attrDecl->getModifiersOfType<AttributeTargetModifier>())
@@ -1277,6 +1276,18 @@ AttributeBase* SemanticsVisitor::checkAttribute(
break;
}
}
+
+ // Some attributes impose constraints on where they can be placed that cannot be captured by the
+ // only checking the syntax class. Perform more checks here.
+ switch (attr->astNodeType)
+ {
+ // Allowed only on struct fields.
+ case ASTNodeType::VkStructOffsetAttribute:
+ auto targetDecl = as<Decl>(attrTarget);
+ validTarget = validTarget && targetDecl && as<StructDecl>(getParentDecl(targetDecl));
+ break;
+ };
+
if (!validTarget)
{
getSink()->diagnose(attr, Diagnostics::attributeNotApplicable, attrName);
@@ -1327,6 +1338,7 @@ ASTNodeType getModifierConflictGroupKind(ASTNodeType modifierType)
case ASTNodeType::GLSLLayoutModifierGroupBegin:
case ASTNodeType::GLSLLayoutModifierGroupEnd:
case ASTNodeType::GLSLBufferModifier:
+ case ASTNodeType::VkStructOffsetAttribute:
case ASTNodeType::MemoryQualifierSetModifier:
case ASTNodeType::GLSLWriteOnlyModifier:
case ASTNodeType::GLSLReadOnlyModifier: