summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-07-13 15:16:09 -0700
committerGitHub <noreply@github.com>2020-07-13 15:16:09 -0700
commit48f26ef082fa3b0c2a02dc57585f7e43210bbb63 (patch)
treee3e13e8034c0f2efe1454a51b4df0290056dae9f /tests
parent249f48dbb5e240c713661be969a6939ec57561e5 (diff)
Dynamic code gen for functions returning generic types. (#1439)
* Dynamic code gen for functions returning generic types. * Add expected test result.
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/dynamic-dispatch-6.slang55
-rw-r--r--tests/compute/dynamic-dispatch-6.slang.expected.txt4
2 files changed, 59 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-6.slang b/tests/compute/dynamic-dispatch-6.slang
new file mode 100644
index 000000000..f9631713d
--- /dev/null
+++ b/tests/compute/dynamic-dispatch-6.slang
@@ -0,0 +1,55 @@
+//TEST(compute):COMPARE_COMPUTE:-cpu -xslang -allow-dynamic-code
+//DISABLE_TEST(compute):COMPARE_COMPUTE:-cuda -xslang -allow-dynamic-code
+
+// Test dynamic dispatch code gen for generic-typed return values.
+
+interface IInterface
+{
+ [mutating]
+ void SetVal(int inVal);
+ int Compute();
+};
+
+T CreateT_Inner<T:IInterface>(int inVal)
+{
+ T obj;
+ obj.SetVal(inVal);
+ return obj;
+}
+
+T CreateT<T:IInterface>(int inVal)
+{
+ return CreateT_Inner<T>(inVal);
+}
+
+struct Impl : IInterface
+{
+ int base;
+ [mutating]
+ void SetVal(int inVal)
+ {
+ base = inVal;
+ }
+ int Compute()
+ {
+ return base;
+ }
+};
+
+int test()
+{
+ var obj = CreateT<Impl>(3);
+ var obj2 = CreateT_Inner<Impl>(1);
+ return obj.Compute() + obj2.Compute();
+}
+
+//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer : register(u0);
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ int outVal = test();
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/compute/dynamic-dispatch-6.slang.expected.txt b/tests/compute/dynamic-dispatch-6.slang.expected.txt
new file mode 100644
index 000000000..e785149d2
--- /dev/null
+++ b/tests/compute/dynamic-dispatch-6.slang.expected.txt
@@ -0,0 +1,4 @@
+4
+4
+4
+4