From 62baf92a524a5b57eb465100a5e47c489c049f15 Mon Sep 17 00:00:00 2001 From: Darren Wihandi <65404740+fairywreath@users.noreply.github.com> Date: Mon, 21 Apr 2025 12:46:23 -0600 Subject: 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 --- source/slang/slang-check-modifier.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-check-modifier.cpp') 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()) @@ -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(attrTarget); + validTarget = validTarget && targetDecl && as(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: -- cgit v1.2.3