diff options
| author | Yong He <yonghe@google.com> | 2019-01-29 11:41:54 -0800 |
|---|---|---|
| committer | Yong He <yonghe@google.com> | 2019-01-29 11:41:54 -0800 |
| commit | b7f8f7abcc3cc1dfa820ebba47a772b78d6a4cfb (patch) | |
| tree | 26d81dec1162ee9d26b811f0b7621e74ade9e06f /tests | |
| parent | f8b8ea0055ad877551198e1e295d33860b504672 (diff) | |
Add support for user defined attributes.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/diagnostics/attribute-error.slang | 34 | ||||
| -rw-r--r-- | tests/diagnostics/attribute-error.slang.expected | 8 | ||||
| -rw-r--r-- | tests/reflection/attribute.slang | 42 | ||||
| -rw-r--r-- | tests/reflection/attribute.slang.expected | 118 |
4 files changed, 202 insertions, 0 deletions
diff --git a/tests/diagnostics/attribute-error.slang b/tests/diagnostics/attribute-error.slang new file mode 100644 index 000000000..472593f3b --- /dev/null +++ b/tests/diagnostics/attribute-error.slang @@ -0,0 +1,34 @@ +// 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, "stringVal")] // attribute arg type mismatch +struct A +{ + [MyStruct(0, 10.0)] // attribute does not apply to this construct + float x; + [DefaultValue(2.0)] // attribute arg type mismatch + float y; +}; + +ParameterBlock<A> param; + +[numthreads(1, 1, 1)] +void main( + uint3 dispatchThreadID : SV_DispatchThreadID) +{ +}
\ No newline at end of file diff --git a/tests/diagnostics/attribute-error.slang.expected b/tests/diagnostics/attribute-error.slang.expected new file mode 100644 index 000000000..e372eb957 --- /dev/null +++ b/tests/diagnostics/attribute-error.slang.expected @@ -0,0 +1,8 @@ +result code = 1 +standard error = { +tests/diagnostics/attribute-error.slang(19): error 30019: expected an expression of type 'float', got 'String' +tests/diagnostics/attribute-error.slang(22): error 31002: attribute 'MyStruct' is not valid here +tests/diagnostics/attribute-error.slang(24): error 39999: expression does not evaluate to a compile-time constant +} +standard output = { +} 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<A> param; +ParameterBlock<B> 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] + } + ] +} +} |
