summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-05-02 13:05:18 -0700
committerGitHub <noreply@github.com>2024-05-02 13:05:18 -0700
commite5d49cf21db7a398afe6cfdb76f6b4a028e9eecb (patch)
treecbf120740771f332b1b8f61eacee01b85628465c
parentf7d54af67e026feb2546af1deaf2513a36f8516e (diff)
Allow multiple _AttributeTargets for attribute declaration (#4087)
The syntax like: [__AttributeUsage(_AttributeTargets.Var)] [__AttributeUsage(_AttributeTargets.Param)] struct DefaultValueAttribute { int iParam; }; is allowed. For user-defined attribute, we can specify more attribute targets on the attribute declaration. So one attribute can be used in more than one situations.
-rw-r--r--source/slang/slang-check-modifier.cpp12
-rw-r--r--tests/reflection/attribute.slang30
-rw-r--r--tests/reflection/attribute.slang.expected58
3 files changed, 88 insertions, 12 deletions
diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp
index 56d905063..b8ff1a116 100644
--- a/source/slang/slang-check-modifier.cpp
+++ b/source/slang/slang-check-modifier.cpp
@@ -212,10 +212,14 @@ namespace Slang
attrDecl->nameAndLoc.loc = structDecl->nameAndLoc.loc;
attrDecl->loc = structDecl->loc;
- AttributeTargetModifier* targetModifier = m_astBuilder->create<AttributeTargetModifier>();
- targetModifier->syntaxClass = attrUsageAttr->targetSyntaxClass;
- targetModifier->loc = attrUsageAttr->loc;
- addModifier(attrDecl, targetModifier);
+ while(attrUsageAttr)
+ {
+ AttributeTargetModifier* targetModifier = m_astBuilder->create<AttributeTargetModifier>();
+ targetModifier->syntaxClass = attrUsageAttr->targetSyntaxClass;
+ targetModifier->loc = attrUsageAttr->loc;
+ addModifier(attrDecl, targetModifier);
+ attrUsageAttr = as<AttributeUsageAttribute>(attrUsageAttr->next);
+ }
// Every attribute declaration is associated with the type
// of syntax nodes it constructs (via reflection/RTTI).
diff --git a/tests/reflection/attribute.slang b/tests/reflection/attribute.slang
index 864aa5896..e0739643c 100644
--- a/tests/reflection/attribute.slang
+++ b/tests/reflection/attribute.slang
@@ -10,14 +10,10 @@ struct MyStructAttribute
int iParam;
float fParam;
};
-[__AttributeUsage(_AttributeTargets.Var)]
-struct DefaultValueAttribute
-{
- int iParam;
-};
+[__AttributeUsage(_AttributeTargets.Var)]
[__AttributeUsage(_AttributeTargets.Param)]
-struct DefaultFuncParamAttribute
+struct DefaultValueAttribute
{
int iParam;
};
@@ -43,9 +39,29 @@ ParameterBlock<B> param2;
[DefaultValue(2)] int globalInt;
+[__AttributeUsage(_AttributeTargets.Struct)]
+[__AttributeUsage(_AttributeTargets.Var)]
+[__AttributeUsage(_AttributeTargets.Param)]
+struct StructVarParamAttribute
+{
+ int iParam;
+};
+
+[StructVarParam(0)]
+struct D
+{
+ int a;
+};
+
+D param3;
+
+[StructVarParam(1)] int globalInt2;
+
+
[numthreads(1, 1, 1)]
void main(
uint3 dispatchThreadID : SV_DispatchThreadID,
- [DefaultFuncParam(3)] float a)
+ [DefaultValue(3)] float a,
+ [StructVarParam(2)] float b)
{
}
diff --git a/tests/reflection/attribute.slang.expected b/tests/reflection/attribute.slang.expected
index 94018c19c..9b51aae32 100644
--- a/tests/reflection/attribute.slang.expected
+++ b/tests/reflection/attribute.slang.expected
@@ -220,6 +220,46 @@ standard output = {
"kind": "scalar",
"scalarType": "int32"
}
+ },
+ {
+ "name": "param3",
+ "binding": {"kind": "uniform", "offset": 16, "size": 4},
+ "type": {
+ "kind": "struct",
+ "name": "D",
+ "fields": [
+ {
+ "name": "a",
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ },
+ "binding": {"kind": "uniform", "offset": 0, "size": 4}
+ }
+ ],
+ "userAttribs": [{
+ "name": "StructVarParam",
+ "arguments": [
+ 0
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "name": "globalInt2",
+ "userAttribs": [{
+ "name": "StructVarParam",
+ "arguments": [
+ 1
+ ]
+ }
+ ],
+ "binding": {"kind": "uniform", "offset": 20, "size": 4},
+ "type": {
+ "kind": "scalar",
+ "scalarType": "int32"
+ }
}
],
"entryPoints": [
@@ -242,7 +282,7 @@ standard output = {
{
"name": "a",
"userAttribs": [{
- "name": "DefaultFuncParam",
+ "name": "DefaultValue",
"arguments": [
3
]
@@ -254,6 +294,22 @@ standard output = {
"kind": "scalar",
"scalarType": "float32"
}
+ },
+ {
+ "name": "b",
+ "userAttribs": [{
+ "name": "StructVarParam",
+ "arguments": [
+ 2
+ ]
+ }
+ ],
+ "stage": "compute",
+ "binding": {"kind": "varyingInput", "index": 1},
+ "type": {
+ "kind": "scalar",
+ "scalarType": "float32"
+ }
}
],
"threadGroupSize": [1, 1, 1]