From b7f8f7abcc3cc1dfa820ebba47a772b78d6a4cfb Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 29 Jan 2019 11:41:54 -0800 Subject: Add support for user defined attributes. --- tests/reflection/attribute.slang | 42 +++++++++++ tests/reflection/attribute.slang.expected | 118 ++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tests/reflection/attribute.slang create mode 100644 tests/reflection/attribute.slang.expected (limited to 'tests/reflection') diff --git a/tests/reflection/attribute.slang b/tests/reflection/attribute.slang new file mode 100644 index 000000000..a3cda4f4b --- /dev/null +++ b/tests/reflection/attribute.slang @@ -0,0 +1,42 @@ +// attribute.slang + +// Tests reflection of user defined attributes. + +//TEST:REFLECTION:-stage compute -entry main -target hlsl + +[AttributeUsage(AttributeTargets.Struct)] +struct MyStructAttribute +{ + int iParam; + float fParam; +}; +[AttributeUsage(AttributeTargets.Var)] +struct DefaultValueAttribute +{ + int iParam; +}; + +[MyStruct(0, 1.0)] +struct A +{ + float x; + [DefaultValue(1)] + float y; +}; + +[MyStruct(0, 2.0)] +struct B +{ + float x; + [DefaultValue(1+1)] + float z; +}; + +ParameterBlock param; +ParameterBlock param2; + +[numthreads(1, 1, 1)] +void main( + uint3 dispatchThreadID : SV_DispatchThreadID) +{ +} \ No newline at end of file diff --git a/tests/reflection/attribute.slang.expected b/tests/reflection/attribute.slang.expected new file mode 100644 index 000000000..4348b898f --- /dev/null +++ b/tests/reflection/attribute.slang.expected @@ -0,0 +1,118 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "param", + "binding": {"kind": "constantBuffer", "index": 0}, + "type": { + "kind": "parameterBlock", + "elementType": { + "kind": "struct", + "name": "A", + "fields": [ + { + "name": "x", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + }, + { + "name": "y", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 4, "size": 4}, + "userAttribs": [{ + "name": "DefaultValue", + "arguments": [ + 1 + ] + } + ] + } + ], + "userAttribs": [{ + "name": "MyStruct", + "arguments": [ + 0, + 1.000000 + ] + } + ] + } + } + }, + { + "name": "param2", + "binding": {"kind": "constantBuffer", "index": 1}, + "type": { + "kind": "parameterBlock", + "elementType": { + "kind": "struct", + "name": "B", + "fields": [ + { + "name": "x", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + }, + { + "name": "z", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 4, "size": 4}, + "userAttribs": [{ + "name": "DefaultValue", + "arguments": [ + 2 + ] + } + ] + } + ], + "userAttribs": [{ + "name": "MyStruct", + "arguments": [ + 0, + 2.000000 + ] + } + ] + } + } + } + ], + "entryPoints": [ + { + "name": "main", + "stage:": "compute", + "parameters": [ + { + "name": "dispatchThreadID", + "semanticName": "SV_DISPATCHTHREADID", + "type": { + "kind": "vector", + "elementCount": 3, + "elementType": { + "kind": "scalar", + "scalarType": "uint32" + } + } + } + ], + "threadGroupSize": [1, 1, 1] + } + ] +} +} -- cgit v1.2.3 From c1761283e7bb6b5cfcedf910e76fd4f939395b1d Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 29 Jan 2019 13:35:23 -0800 Subject: Add underscores to `AttributeUsage` to signal its preview state. --- source/slang/core.meta.slang | 4 ++-- source/slang/core.meta.slang.h | 4 ++-- tests/diagnostics/attribute-error.slang | 4 ++-- tests/reflection/attribute.slang | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/reflection') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 54dfc6127..bd01d679a 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -1287,11 +1287,11 @@ attribute_syntax [mutating] : MutatingAttribute; __attributeTarget(FunctionDeclBase) attribute_syntax [__readNone] : ReadNoneAttribute; -enum AttributeTargets +enum _AttributeTargets { Struct = $( (int) UserDefinedAttributeTargets::Struct), Var = $( (int) UserDefinedAttributeTargets::Var), Function = $( (int) UserDefinedAttributeTargets::Function), }; __attributeTarget(StructDecl) -attribute_syntax [AttributeUsage(target : AttributeTargets)] : AttributeUsageAttribute; \ No newline at end of file +attribute_syntax [__AttributeUsage(target : _AttributeTargets)] : AttributeUsageAttribute; \ No newline at end of file diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index f0671396d..448fdb058 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -1305,7 +1305,7 @@ SLANG_RAW(" /// This is equivalent to the LLVM `readnone` function attribute. SLANG_RAW("__attributeTarget(FunctionDeclBase)\n") SLANG_RAW("attribute_syntax [__readNone] : ReadNoneAttribute;\n") SLANG_RAW("\n") -SLANG_RAW("enum AttributeTargets\n") +SLANG_RAW("enum _AttributeTargets\n") SLANG_RAW("{\n") SLANG_RAW(" Struct = ") SLANG_SPLICE( (int) UserDefinedAttributeTargets::Struct @@ -1321,4 +1321,4 @@ SLANG_SPLICE( (int) UserDefinedAttributeTargets::Function SLANG_RAW(",\n") SLANG_RAW("};\n") SLANG_RAW("__attributeTarget(StructDecl)\n") -SLANG_RAW("attribute_syntax [AttributeUsage(target : AttributeTargets)] : AttributeUsageAttribute;") +SLANG_RAW("attribute_syntax [__AttributeUsage(target : _AttributeTargets)] : AttributeUsageAttribute;") diff --git a/tests/diagnostics/attribute-error.slang b/tests/diagnostics/attribute-error.slang index 472593f3b..b913d3d4a 100644 --- a/tests/diagnostics/attribute-error.slang +++ b/tests/diagnostics/attribute-error.slang @@ -4,13 +4,13 @@ //TEST:REFLECTION:-stage compute -entry main -target hlsl -[AttributeUsage(AttributeTargets.Struct)] +[__AttributeUsage(_AttributeTargets.Struct)] struct MyStructAttribute { int iParam; float fParam; }; -[AttributeUsage(AttributeTargets.Var)] +[__AttributeUsage(_AttributeTargets.Var)] struct DefaultValueAttribute { int iParam; diff --git a/tests/reflection/attribute.slang b/tests/reflection/attribute.slang index a3cda4f4b..687148add 100644 --- a/tests/reflection/attribute.slang +++ b/tests/reflection/attribute.slang @@ -4,13 +4,13 @@ //TEST:REFLECTION:-stage compute -entry main -target hlsl -[AttributeUsage(AttributeTargets.Struct)] +[__AttributeUsage(_AttributeTargets.Struct)] struct MyStructAttribute { int iParam; float fParam; }; -[AttributeUsage(AttributeTargets.Var)] +[__AttributeUsage(_AttributeTargets.Var)] struct DefaultValueAttribute { int iParam; -- cgit v1.2.3