summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/generic-list.slang48
-rw-r--r--tests/compute/generic-list.slang.expected.txt1
-rw-r--r--tests/compute/generic-struct-with-constraint.slang44
-rw-r--r--tests/compute/generic-struct-with-constraint.slang.expected.txt1
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