diff options
| author | Yong He <yonghe@outlook.com> | 2017-12-27 20:17:36 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-27 20:17:36 -0500 |
| commit | e370fe2984e7e260dc2d78d67b087e542d0102b0 (patch) | |
| tree | dd441836025e802f79e74646f8f280c7515cbaec /tests | |
| parent | 69242398be1ba76898c0d6541eec3b7ca0ec1ab4 (diff) | |
| parent | d55b56bc804f25d8390f1dc6b09ff9116ffcaf29 (diff) | |
Merge pull request #335 from csyonghe/master
Support nested generic types (e.g. L<T<S>>)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/generic-list.slang | 48 | ||||
| -rw-r--r-- | tests/compute/generic-list.slang.expected.txt | 1 | ||||
| -rw-r--r-- | tests/compute/generic-struct-with-constraint.slang | 44 | ||||
| -rw-r--r-- | tests/compute/generic-struct-with-constraint.slang.expected.txt | 1 |
4 files changed, 94 insertions, 0 deletions
diff --git a/tests/compute/generic-list.slang b/tests/compute/generic-list.slang new file mode 100644 index 000000000..256e02d33 --- /dev/null +++ b/tests/compute/generic-list.slang @@ -0,0 +1,48 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +// Confirm that generics syntax can be used in user +// code and generates valid output. + +RWStructuredBuffer<float4> outputBuffer; + +interface IElement +{ + float4 getValue(); +}; + +struct SingleElement : IElement +{ + float4 value; + float4 getValue() + { + return value; + } +}; + +struct ListElement<THead : IElement, TTail : IElement> : IElement +{ + THead head; + TTail tail; + float4 getValue() + { + return head.getValue() + tail.getValue(); + } +}; + +float4 test<T : IElement>(T val) +{ + return val.getValue(); +} + + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + ListElement<SingleElement, ListElement<SingleElement, ListElement<SingleElement, SingleElement> > > list; + list.head.value = float4(1.0); + list.tail.head.value = float4(2.0); + list.tail.tail.head.value = float4(3.0); + list.tail.tail.tail.value = float4(4.0); + float4 outVal = test(list); + outputBuffer[0] = outVal; +}
\ No newline at end of file diff --git a/tests/compute/generic-list.slang.expected.txt b/tests/compute/generic-list.slang.expected.txt new file mode 100644 index 000000000..040178fa9 --- /dev/null +++ b/tests/compute/generic-list.slang.expected.txt @@ -0,0 +1 @@ +41200000
\ No newline at end of file diff --git a/tests/compute/generic-struct-with-constraint.slang b/tests/compute/generic-struct-with-constraint.slang new file mode 100644 index 000000000..0c81ad176 --- /dev/null +++ b/tests/compute/generic-struct-with-constraint.slang @@ -0,0 +1,44 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +// Confirm that generics syntax can be used in user +// code and generates valid output. + +RWStructuredBuffer<float4> outputBuffer; + +interface IElement +{ + float4 getValue(); +}; + +struct SingleElement : IElement +{ + float4 value; + float4 getValue() + { + return value; + } +}; + +struct ListElement<THead : IElement> : IElement +{ + THead head; + float4 getValue() + { + return head.getValue(); + } +}; + +float4 test<T : IElement>(T val) +{ + return val.getValue(); +} + + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + ListElement<SingleElement> list; + list.head.value = float4(1.0); + float4 outVal = test<ListElement<SingleElement> >(list); + outputBuffer[0] = outVal; +}
\ No newline at end of file diff --git a/tests/compute/generic-struct-with-constraint.slang.expected.txt b/tests/compute/generic-struct-with-constraint.slang.expected.txt new file mode 100644 index 000000000..47b9ba0c8 --- /dev/null +++ b/tests/compute/generic-struct-with-constraint.slang.expected.txt @@ -0,0 +1 @@ +3F800000
\ No newline at end of file |
