summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-11-01 13:16:26 -0400
committerYong He <yonghe@outlook.com>2017-11-01 13:16:26 -0400
commit134354c68768c0e3530c02678e12cb02f5646e8a (patch)
tree20a9ae10db6790ddc5032315b85efd94fc672cff /tests
parentb623864fe609e6912cdd2e350aa70cf7e441e1d3 (diff)
Adding support for associated types.
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/assoctype-complex.slang44
-rw-r--r--tests/compute/assoctype-simple.slang2
-rw-r--r--tests/compute/assoctype-simple.slang.expected.txt4
3 files changed, 49 insertions, 1 deletions
diff --git a/tests/compute/assoctype-complex.slang b/tests/compute/assoctype-complex.slang
new file mode 100644
index 000000000..3e590b2e0
--- /dev/null
+++ b/tests/compute/assoctype-complex.slang
@@ -0,0 +1,44 @@
+RWStructuredBuffer<float> outputBuffer;
+interface IBase
+{
+ associatedtype V;
+ V sub(V a0, V a1);
+}
+interface ISimple
+{
+ associatedtype U : IBase;
+ U.V add(U v0, U v1);
+}
+
+struct Val : IBase
+{
+ typedef int V;
+ V sub(V a0, V a1)
+ {
+ return a0-a1;
+ }
+};
+
+struct Simple : ISimple
+{
+ typedef Val U;
+ Val.V add(U v0, U v1)
+ {
+ return v0.sub(4, v1.sub(1,2));
+ }
+};
+
+__generic<T:ISimple>
+T.U.V test(T simple, T.U v0, T.U v1)
+{
+ return simple.add(v0, v1);
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ Simple s;
+ Val v0, v1;
+ float outVal = test<Simple>(s, v0, v1); // == 1.0
+ outputBuffer[0] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/assoctype-simple.slang b/tests/compute/assoctype-simple.slang
index e03bb4e54..0f160c9c0 100644
--- a/tests/compute/assoctype-simple.slang
+++ b/tests/compute/assoctype-simple.slang
@@ -31,5 +31,5 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
Simple s;
float outVal = test<Simple>(s, 2.0, 1.0); // == 3.0
- outputBuffer[tid] = outVal;
+ outputBuffer[dispatchThreadID.x] = outVal;
} \ No newline at end of file
diff --git a/tests/compute/assoctype-simple.slang.expected.txt b/tests/compute/assoctype-simple.slang.expected.txt
new file mode 100644
index 000000000..e54af3bc8
--- /dev/null
+++ b/tests/compute/assoctype-simple.slang.expected.txt
@@ -0,0 +1,4 @@
+40400000
+40400000
+40400000
+40400000