summaryrefslogtreecommitdiffstats
path: root/tests/compute/dynamic-dispatch-2.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-06-19 11:19:51 -0700
committerGitHub <noreply@github.com>2020-06-19 11:19:51 -0700
commit110d15b61ac5d76da001d412eaa4be07f3cd8f4d (patch)
tree6d2cef5dab495b484844b4d54c312751af62091e /tests/compute/dynamic-dispatch-2.slang
parent5fbb9ff7e1516bd787695d2c9d80b696f0a9ca9a (diff)
Dynamic dispatch for static member functions of associatedtypes. (#1404)
Diffstat (limited to 'tests/compute/dynamic-dispatch-2.slang')
-rw-r--r--tests/compute/dynamic-dispatch-2.slang53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-2.slang b/tests/compute/dynamic-dispatch-2.slang
new file mode 100644
index 000000000..ade8aeb84
--- /dev/null
+++ b/tests/compute/dynamic-dispatch-2.slang
@@ -0,0 +1,53 @@
+//TEST(compute):COMPARE_COMPUTE:-cpu -xslang -allow-dynamic-code
+
+// Test dynamic dispatch code gen for static member functions
+// of associated type.
+
+interface IAssoc
+{
+ int get();
+ static int getBase();
+}
+interface IInterface
+{
+ associatedtype Assoc : IAssoc;
+ int Compute(int inVal);
+ Assoc getAssoc();
+};
+
+int GenericCompute<T:IInterface>(T obj, int inVal)
+{
+ return obj.Compute(inVal) + T.Assoc.getBase();
+}
+
+struct Impl : IInterface
+{
+ struct Assoc : IAssoc
+ {
+ int val;
+ int get() { return val; }
+ static int getBase() { return -1; }
+ };
+ int base;
+ int Compute(int inVal) { return base + inVal * inVal; }
+ Assoc getAssoc() { Assoc rs; rs.val = 1; return rs; }
+};
+
+int test(int inVal)
+{
+ Impl obj;
+ obj.base = 1;
+ return GenericCompute<Impl>(obj, inVal);
+}
+
+//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 inVal = outputBuffer[tid];
+ int outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+}