summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ast-modifier.h108
-rw-r--r--source/slang/slang-ast-print.cpp2
-rw-r--r--source/slang/slang-check-modifier.cpp81
-rw-r--r--source/slang/slang-lower-to-ir.cpp6
-rw-r--r--source/slang/slang-parameter-binding.cpp2
-rw-r--r--source/slang/slang-parser.cpp96
6 files changed, 163 insertions, 132 deletions
diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h
index 6d11f0953..f5dd86df1 100644
--- a/source/slang/slang-ast-modifier.h
+++ b/source/slang/slang-ast-modifier.h
@@ -263,29 +263,6 @@ class SharedModifiers : public Modifier
SLANG_AST_CLASS(SharedModifiers)
};
-
-// A GLSL `layout` modifier
-//
-// We use a distinct modifier for each key that
-// appears within the `layout(...)` construct,
-// and each key might have an optional value token.
-//
-// TODO: We probably want a notion of "modifier groups"
-// so that we can recover good source location info
-// for modifiers that were part of the same vs.
-// different constructs.
-class GLSLLayoutModifier : public Modifier
-{
- SLANG_ABSTRACT_AST_CLASS(GLSLLayoutModifier)
-
-
- // The token used to introduce the modifier is stored
- // as the `nameToken` field.
-
- // TODO: may want to accept a full expression here
- Token valToken;
-};
-
// AST nodes to represent the begin/end of a `layout` modifier group
class GLSLLayoutModifierGroupMarker : public Modifier
{
@@ -302,29 +279,12 @@ class GLSLLayoutModifierGroupEnd : public GLSLLayoutModifierGroupMarker
SLANG_AST_CLASS(GLSLLayoutModifierGroupEnd)
};
-
-// We divide GLSL `layout` modifiers into those we have parsed
-// (in the sense of having some notion of their semantics), and
-// those we have not.
-class GLSLParsedLayoutModifier : public GLSLLayoutModifier
-{
- SLANG_ABSTRACT_AST_CLASS(GLSLParsedLayoutModifier)
-};
-
-class GLSLUnparsedLayoutModifier : public GLSLLayoutModifier
+class GLSLUnparsedLayoutModifier : public Modifier
{
SLANG_AST_CLASS(GLSLUnparsedLayoutModifier)
};
-
-// Specific cases for known GLSL `layout` modifiers that we need to work with
-
-class GLSLLocationLayoutModifier : public GLSLParsedLayoutModifier
-{
- SLANG_AST_CLASS(GLSLLocationLayoutModifier)
-};
-
-class GLSLBufferDataLayoutModifier : public GLSLParsedLayoutModifier
+class GLSLBufferDataLayoutModifier : public Modifier
{
SLANG_AST_CLASS(GLSLBufferDataLayoutModifier)
};
@@ -725,6 +685,70 @@ class UncheckedGLSLOffsetLayoutAttribute : public UncheckedGLSLLayoutAttribute
SLANG_UNREFLECTED
};
+class UncheckedGLSLInputAttachmentIndexLayoutAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLInputAttachmentIndexLayoutAttribute)
+
+ SLANG_UNREFLECTED
+};
+
+class UncheckedGLSLLocationLayoutAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLLocationLayoutAttribute)
+
+ SLANG_UNREFLECTED
+};
+
+class UncheckedGLSLIndexLayoutAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLIndexLayoutAttribute)
+
+ SLANG_UNREFLECTED
+};
+
+class UncheckedGLSLConstantIdAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLConstantIdAttribute)
+
+ SLANG_UNREFLECTED
+};
+
+class UncheckedGLSLRayPayloadAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLRayPayloadAttribute)
+
+ SLANG_UNREFLECTED
+};
+
+class UncheckedGLSLRayPayloadInAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLRayPayloadInAttribute)
+
+ SLANG_UNREFLECTED
+};
+
+
+class UncheckedGLSLHitObjectAttributesAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLHitObjectAttributesAttribute)
+
+ SLANG_UNREFLECTED
+};
+
+class UncheckedGLSLCallablePayloadAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLCallablePayloadAttribute)
+
+ SLANG_UNREFLECTED
+};
+
+class UncheckedGLSLCallablePayloadInAttribute : public UncheckedGLSLLayoutAttribute
+{
+ SLANG_AST_CLASS(UncheckedGLSLCallablePayloadInAttribute)
+
+ SLANG_UNREFLECTED
+};
+
// A `[name(arg0, ...)]` style attribute that has been validated.
class Attribute : public AttributeBase
{
diff --git a/source/slang/slang-ast-print.cpp b/source/slang/slang-ast-print.cpp
index 3e3d333c3..22a5ec8d1 100644
--- a/source/slang/slang-ast-print.cpp
+++ b/source/slang/slang-ast-print.cpp
@@ -434,8 +434,6 @@ void ASTPrinter::addDeclKindPrefix(Decl* decl)
continue;
if (as<RequiredGLSLExtensionModifier>(modifier))
continue;
- if (as<GLSLLayoutModifier>(modifier))
- continue;
if (as<GLSLLayoutModifierGroupMarker>(modifier))
continue;
if (as<HLSLLayoutSemantic>(modifier))
diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp
index 05eb978bc..3723c98f8 100644
--- a/source/slang/slang-check-modifier.cpp
+++ b/source/slang/slang-check-modifier.cpp
@@ -513,6 +513,17 @@ Modifier* SemanticsVisitor::validateAttribute(
inputAttachmentIndexLayoutAttribute->location = location->getValue();
}
+ else if (auto locationLayoutAttr = as<GLSLLocationAttribute>(attr))
+ {
+ if (attr->args.getCount() != 1)
+ return nullptr;
+
+ auto location = checkConstantIntVal(attr->args[0]);
+ if (!location)
+ return nullptr;
+
+ locationLayoutAttr->value = int32_t(location->getValue());
+ }
else if (auto bindingAttr = as<GLSLBindingAttribute>(attr))
{
// This must be vk::binding or gl::binding (as specified in core.meta.slang under
@@ -1242,12 +1253,22 @@ ASTNodeType getModifierConflictGroupKind(ASTNodeType modifierType)
return ASTNodeType::OutModifier;
// Modifiers that are their own exclusive group.
- case ASTNodeType::GLSLLayoutModifier:
- case ASTNodeType::GLSLParsedLayoutModifier:
- case ASTNodeType::GLSLLocationLayoutModifier:
case ASTNodeType::GLSLInputAttachmentIndexLayoutAttribute:
case ASTNodeType::GLSLOffsetLayoutAttribute:
case ASTNodeType::GLSLUnparsedLayoutModifier:
+ case ASTNodeType::UncheckedGLSLBindingLayoutAttribute:
+ case ASTNodeType::UncheckedGLSLSetLayoutAttribute:
+ case ASTNodeType::UncheckedGLSLOffsetLayoutAttribute:
+ case ASTNodeType::UncheckedGLSLInputAttachmentIndexLayoutAttribute:
+ case ASTNodeType::UncheckedGLSLLocationLayoutAttribute:
+ case ASTNodeType::UncheckedGLSLIndexLayoutAttribute:
+ case ASTNodeType::UncheckedGLSLConstantIdAttribute:
+ case ASTNodeType::UncheckedGLSLRayPayloadAttribute:
+ case ASTNodeType::UncheckedGLSLRayPayloadInAttribute:
+ case ASTNodeType::UncheckedGLSLHitObjectAttributesAttribute:
+ case ASTNodeType::UncheckedGLSLCallablePayloadAttribute:
+ case ASTNodeType::UncheckedGLSLCallablePayloadInAttribute:
+ case ASTNodeType::GLSLBufferDataLayoutModifier:
case ASTNodeType::GLSLLayoutModifierGroupMarker:
case ASTNodeType::GLSLLayoutModifierGroupBegin:
case ASTNodeType::GLSLLayoutModifierGroupEnd:
@@ -1321,12 +1342,10 @@ bool isModifierAllowedOnDecl(bool isGLSLInput, ASTNodeType modifierType, Decl* d
case ASTNodeType::InModifier:
case ASTNodeType::InOutModifier:
case ASTNodeType::OutModifier:
- case ASTNodeType::GLSLLayoutModifier:
- case ASTNodeType::GLSLParsedLayoutModifier:
- case ASTNodeType::GLSLLocationLayoutModifier:
case ASTNodeType::GLSLInputAttachmentIndexLayoutAttribute:
case ASTNodeType::GLSLOffsetLayoutAttribute:
case ASTNodeType::GLSLUnparsedLayoutModifier:
+ case ASTNodeType::UncheckedGLSLLayoutAttribute:
case ASTNodeType::GLSLLayoutModifierGroupMarker:
case ASTNodeType::GLSLLayoutModifierGroupBegin:
case ASTNodeType::GLSLLayoutModifierGroupEnd:
@@ -1502,14 +1521,28 @@ AttributeBase* SemanticsVisitor::checkGLSLLayoutAttribute(
SLANG_ASSERT(uncheckedAttr->args.getCount() == 2);
}
- else if (as<UncheckedGLSLOffsetLayoutAttribute>(uncheckedAttr))
- {
- attr = m_astBuilder->create<GLSLOffsetLayoutAttribute>();
+
+#define CASE(UncheckedType, CheckedType) \
+ else if (as<UncheckedType>(uncheckedAttr)) \
+ { \
+ attr = m_astBuilder->create<CheckedType>(); \
}
+
+ CASE(UncheckedGLSLOffsetLayoutAttribute, GLSLOffsetLayoutAttribute)
+ CASE(UncheckedGLSLInputAttachmentIndexLayoutAttribute, GLSLInputAttachmentIndexLayoutAttribute)
+ CASE(UncheckedGLSLLocationLayoutAttribute, GLSLLocationAttribute)
+ CASE(UncheckedGLSLIndexLayoutAttribute, GLSLIndexAttribute)
+ CASE(UncheckedGLSLConstantIdAttribute, VkConstantIdAttribute)
+ CASE(UncheckedGLSLRayPayloadAttribute, VulkanRayPayloadAttribute)
+ CASE(UncheckedGLSLRayPayloadInAttribute, VulkanRayPayloadInAttribute)
+ CASE(UncheckedGLSLHitObjectAttributesAttribute, VulkanHitObjectAttributesAttribute)
+ CASE(UncheckedGLSLCallablePayloadAttribute, VulkanCallablePayloadAttribute)
+ CASE(UncheckedGLSLCallablePayloadInAttribute, VulkanCallablePayloadInAttribute)
else
{
getSink()->diagnose(uncheckedAttr, Diagnostics::unrecognizedGLSLLayoutQualifier);
}
+#undef CASE
if (attr)
{
@@ -1559,21 +1592,6 @@ Modifier* SemanticsVisitor::checkModifier(
return checkedAttr;
}
- if (auto glslLayoutAttribute = as<UncheckedGLSLLayoutAttribute>(m))
- {
- return checkGLSLLayoutAttribute(glslLayoutAttribute, syntaxNode);
- }
-
- if (const auto glslImplicitOffsetAttribute = as<GLSLImplicitOffsetLayoutAttribute>(m))
- {
- auto offsetAttr = m_astBuilder->create<GLSLOffsetLayoutAttribute>();
- offsetAttr->loc = glslImplicitOffsetAttribute->loc;
-
- // Offset constant folding computation is deferred until all other modifiers are checked to
- // ensure bindinig is checked first.
- return offsetAttr;
- }
-
if (auto decl = as<Decl>(syntaxNode))
{
auto moduleDecl = getModuleDecl(decl);
@@ -1591,6 +1609,21 @@ Modifier* SemanticsVisitor::checkModifier(
}
}
+ if (auto glslLayoutAttribute = as<UncheckedGLSLLayoutAttribute>(m))
+ {
+ return checkGLSLLayoutAttribute(glslLayoutAttribute, syntaxNode);
+ }
+
+ if (const auto glslImplicitOffsetAttribute = as<GLSLImplicitOffsetLayoutAttribute>(m))
+ {
+ auto offsetAttr = m_astBuilder->create<GLSLOffsetLayoutAttribute>();
+ offsetAttr->loc = glslImplicitOffsetAttribute->loc;
+
+ // Offset constant folding computation is deferred until all other modifiers are checked to
+ // ensure bindinig is checked first.
+ return offsetAttr;
+ }
+
MemoryQualifierSetModifier::Flags::MemoryQualifiersBit memoryQualifierBit =
MemoryQualifierSetModifier::Flags::kNone;
if (as<GloballyCoherentModifier>(m))
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index ce6f8cb42..6ff270dc6 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -2290,14 +2290,12 @@ void addVarDecorations(IRGenContext* context, IRInst* inst, Decl* decl)
{
builder->addSimpleDecoration<IRGlobalInputDecoration>(inst);
}
- else if (auto glslLocationMod = as<GLSLLocationLayoutModifier>(mod))
+ else if (auto glslLocationMod = as<GLSLLocationAttribute>(mod))
{
builder->addDecoration(
inst,
kIROp_GLSLLocationDecoration,
- builder->getIntValue(
- builder->getIntType(),
- stringToInt(glslLocationMod->valToken.getContent())));
+ builder->getIntValue(builder->getIntType(), glslLocationMod->value));
}
else if (auto glslOffsetMod = as<GLSLOffsetLayoutAttribute>(mod))
{
diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp
index 1303a59f1..c232d0aee 100644
--- a/source/slang/slang-parameter-binding.cpp
+++ b/source/slang/slang-parameter-binding.cpp
@@ -4250,7 +4250,7 @@ RefPtr<ProgramLayout> generateParameterBindings(TargetProgram* targetProgram, Di
{
needDefaultConstantBuffer = true;
if (varLayout->varDecl.getDecl()->hasModifier<GLSLBindingAttribute>() ||
- varLayout->varDecl.getDecl()->hasModifier<GLSLLocationLayoutModifier>())
+ varLayout->varDecl.getDecl()->hasModifier<GLSLLocationAttribute>())
sink->diagnose(
varLayout->varDecl,
Diagnostics::explicitUniformLocation,
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 2fb44921d..5554724a7 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -1025,26 +1025,24 @@ static Modifier* parseUncheckedGLSLLayoutAttribute(Parser* parser, NameLoc& name
UncheckedGLSLLayoutAttribute* attr;
- if (nameLoc.name->text == "binding")
- {
- // An explicit type for binding is used so that it can be looked up quickly
- // through the list builder when implicitly injecting an offset qualifier.
- attr = parser->astBuilder->create<UncheckedGLSLBindingLayoutAttribute>();
- }
- else if (nameLoc.name->text == "offset")
- {
- // An explicit type for offset is used so that it can be looked up quickly
- // through the list builder when implicitly injecting an offset qualifier.
- attr = parser->astBuilder->create<UncheckedGLSLOffsetLayoutAttribute>();
- }
- else if (nameLoc.name->text == "set")
- {
- attr = parser->astBuilder->create<UncheckedGLSLSetLayoutAttribute>();
- }
+#define CASE(key, ResultType) \
+ if (nameLoc.name->text == #key) \
+ { \
+ attr = parser->astBuilder->create<ResultType>(); \
+ } \
else
+
+ CASE(binding, UncheckedGLSLBindingLayoutAttribute)
+ CASE(set, UncheckedGLSLSetLayoutAttribute)
+ CASE(offset, UncheckedGLSLOffsetLayoutAttribute)
+ CASE(input_attachment_index, UncheckedGLSLInputAttachmentIndexLayoutAttribute)
+ CASE(location, UncheckedGLSLLocationLayoutAttribute)
+ CASE(index, UncheckedGLSLIndexLayoutAttribute)
+ CASE(constant_id, UncheckedGLSLConstantIdAttribute)
{
attr = parser->astBuilder->create<UncheckedGLSLLayoutAttribute>();
}
+#undef CASE
attr->keywordName = nameLoc.name;
attr->loc = nameLoc.loc;
@@ -8456,17 +8454,6 @@ static NodeBase* parseLayoutModifier(Parser* parser, void* /*userData*/)
derivativeGroupLinearAttrib =
parser->astBuilder->create<GLSLLayoutDerivativeGroupLinearAttribute>();
}
- else if (nameText == "input_attachment_index")
- {
- inputAttachmentIndexLayoutAttribute =
- parser->astBuilder->create<GLSLInputAttachmentIndexLayoutAttribute>();
- if (AdvanceIf(parser, TokenType::OpAssign))
- {
- auto token = parser->ReadToken(TokenType::IntegerLiteral);
- auto intVal = getIntegerLiteralValue(token);
- inputAttachmentIndexLayoutAttribute->location = intVal;
- }
- }
else if (findImageFormatByName(nameText.getUnownedSlice(), &format))
{
auto attr = parser->astBuilder->create<FormatAttribute>();
@@ -8486,11 +8473,9 @@ static NodeBase* parseLayoutModifier(Parser* parser, void* /*userData*/)
CASE(push_constant, PushConstantAttribute)
CASE(shaderRecordNV, ShaderRecordAttribute)
CASE(shaderRecordEXT, ShaderRecordAttribute)
- CASE(constant_id, VkConstantIdAttribute)
CASE(std140, GLSLStd140Modifier)
CASE(std430, GLSLStd430Modifier)
CASE(scalar, GLSLScalarModifier)
- CASE(location, GLSLLocationLayoutModifier)
{
modifier = parseUncheckedGLSLLayoutAttribute(parser, nameAndLoc);
}
@@ -8500,21 +8485,6 @@ static NodeBase* parseLayoutModifier(Parser* parser, void* /*userData*/)
modifier->keywordName = nameAndLoc.name;
modifier->loc = nameAndLoc.loc;
-
- // Special handling for GLSLLayoutModifier
- if (auto glslModifier = as<GLSLLayoutModifier>(modifier))
- {
- // not all GLSLLayoutModifier subtypes have an OpAssign after
- if (AdvanceIf(parser, TokenType::OpAssign))
- glslModifier->valToken = parser->ReadToken(TokenType::IntegerLiteral);
- }
- else if (auto specConstAttr = as<VkConstantIdAttribute>(modifier))
- {
- parser->ReadToken(TokenType::OpAssign);
- specConstAttr->location =
- (int)getIntegerLiteralValue(parser->ReadToken(TokenType::IntegerLiteral));
- }
-
if (as<GLSLUnparsedLayoutModifier>(modifier))
{
parser->diagnose(
@@ -8530,23 +8500,31 @@ static NodeBase* parseLayoutModifier(Parser* parser, void* /*userData*/)
parser->ReadToken(TokenType::Comma);
}
-#define CASE(key, type) \
- if (AdvanceIf(parser, #key)) \
- { \
- auto modifier = parser->astBuilder->create<type>(); \
- modifier->location = \
- int(getIntegerLiteralValue(listBuilder.find<GLSLLayoutModifier>()->valToken)); \
- listBuilder.add(modifier); \
- } \
+#define CASE(key, type) \
+ if (AdvanceIf(parser, #key)) \
+ { \
+ auto modifier = parser->astBuilder->create<type>(); \
+ if (const auto locationExpr = listBuilder.find<UncheckedGLSLLocationLayoutAttribute>()) \
+ { \
+ modifier->args.add(locationExpr->args[0]); \
+ } \
+ else \
+ { \
+ auto defaultLocationExpr = parser->astBuilder->create<IntegerLiteralExpr>(); \
+ defaultLocationExpr->value = 0; \
+ modifier->args.add(defaultLocationExpr); \
+ } \
+ listBuilder.add(modifier); \
+ } \
else
- CASE(rayPayloadEXT, VulkanRayPayloadAttribute)
- CASE(rayPayloadNV, VulkanRayPayloadAttribute)
- CASE(rayPayloadInEXT, VulkanRayPayloadInAttribute)
- CASE(rayPayloadInNV, VulkanRayPayloadInAttribute)
- CASE(hitObjectAttributeNV, VulkanHitObjectAttributesAttribute)
- CASE(callableDataEXT, VulkanCallablePayloadAttribute)
- CASE(callableDataInEXT, VulkanCallablePayloadInAttribute) {}
+ CASE(rayPayloadEXT, UncheckedGLSLRayPayloadAttribute)
+ CASE(rayPayloadNV, UncheckedGLSLRayPayloadAttribute)
+ CASE(rayPayloadInEXT, UncheckedGLSLRayPayloadInAttribute)
+ CASE(rayPayloadInNV, UncheckedGLSLRayPayloadInAttribute)
+ CASE(hitObjectAttributeNV, UncheckedGLSLHitObjectAttributesAttribute)
+ CASE(callableDataEXT, UncheckedGLSLCallablePayloadAttribute)
+ CASE(callableDataInEXT, UncheckedGLSLCallablePayloadAttribute) {}
#undef CASE