HLSL: Additional attribute support: [[]], namespace, parameters:
- support C++11 style brackets [[...]]
- support namespaces [[vk::...]]
- support these on parameter declarations in functions
- support location, binding/set, input attachments
diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp
index 6f023de..74afb03 100755
--- a/hlsl/hlslParseHelper.cpp
+++ b/hlsl/hlslParseHelper.cpp
@@ -1666,7 +1666,6 @@
return paramNodes;
}
-
// Handle all [attrib] attribute for the shader entry point
void HlslParseContext::handleEntryPointAttributes(const TSourceLoc& loc, const TAttributeMap& attributes)
{
@@ -1815,6 +1814,44 @@
}
}
+// Update the given type with any type-like attribute information in the
+// attributes.
+void HlslParseContext::transferTypeAttributes(const TAttributeMap& attributes, TType& type)
+{
+ // extract integers out of attribute arguments stored in attribute aggregate
+ const auto getInt = [&](TAttributeType attr, int argNum, int& value) -> bool {
+ const TIntermAggregate* attrAgg = attributes[attr];
+ if (attrAgg == nullptr)
+ return false;
+ if (argNum >= attrAgg->getSequence().size())
+ return false;
+ const TConstUnion& intConst = attrAgg->getSequence()[argNum]->getAsConstantUnion()->getConstArray()[0];
+ if (intConst == nullptr)
+ return false;
+ value = intConst.getIConst();
+ return true;
+ };
+
+ // location
+ int value;
+ if (getInt(EatLocation, 0, value))
+ type.getQualifier().layoutLocation = value;
+
+ // binding
+ if (getInt(EatBinding, 0, value)) {
+ type.getQualifier().layoutBinding = value;
+ type.getQualifier().layoutSet = 0;
+ }
+
+ // set
+ if (getInt(EatBinding, 1, value))
+ type.getQualifier().layoutSet = value;
+
+ // input attachment
+ if (getInt(EatInputAttachment, 0, value))
+ type.getQualifier().layoutAttachment = value;
+}
+
//
// Do all special handling for the entry point, including wrapping
// the shader's entry point with the official entry point that will call it.