summaryrefslogtreecommitdiffstats
path: root/tests/ir
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-04-12 22:58:22 -0700
committerGitHub <noreply@github.com>2023-04-12 22:58:22 -0700
commitca7bf79df3a3f5f4494912cb0572c36662755b9d (patch)
tree64b14034326be8285c0265e74ad3ed11e29ff062 /tests/ir
parent12ec9b832fc74faba7162e54e04f7f48878ea88e (diff)
Combine lookupWitness lowering with specialization. (#2794)
Diffstat (limited to 'tests/ir')
-rw-r--r--tests/ir/dynamic-generic-method-specialize.slang65
-rw-r--r--tests/ir/dynamic-generic-method-specialize.slang.expected.txt2
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/ir/dynamic-generic-method-specialize.slang b/tests/ir/dynamic-generic-method-specialize.slang
new file mode 100644
index 000000000..92ce8158e
--- /dev/null
+++ b/tests/ir/dynamic-generic-method-specialize.slang
@@ -0,0 +1,65 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -profile sm_5_0 -output-using-type
+
+// Test that we can specialize a generic method called through a dynamic interface.
+
+interface IValue
+{
+ float getVal();
+}
+
+struct SimpleVal : IValue
+{
+ float val;
+ float getVal() { return val; }
+}
+
+[anyValueSize(16)]
+interface IInterface
+{
+ associatedtype V : IValue;
+ V run<let N : int>(float arr[N]);
+}
+
+struct Add : IInterface
+{
+ float base;
+ typealias V = SimpleVal;
+ V run<let N : int>(float arr[N])
+ {
+ float sum = base;
+ for (int i = 0; i < N; i++)
+ sum += arr[i];
+ V rs;
+ rs.val = sum;
+ return rs;
+ }
+}
+
+struct Mul : IInterface
+{
+ float base;
+ typealias V = SimpleVal;
+ V run<let N : int>(float arr[N])
+ {
+ float sum = base;
+ for (int i = 0; i < N; i++)
+ sum *= arr[i];
+ V rs;
+ rs.val = sum;
+ return rs;
+ }
+}
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
+RWStructuredBuffer<float> gOutputBuffer;
+
+//TEST_INPUT:type_conformance Add:IInterface=1
+//TEST_INPUT:type_conformance Mul:IInterface=2
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ var obj = createDynamicObject<IInterface>(1, 1.0); // Add.
+ float arr[3] = { 2, 3, 4 };
+ gOutputBuffer[0] = obj.run(arr).getVal();
+} \ No newline at end of file
diff --git a/tests/ir/dynamic-generic-method-specialize.slang.expected.txt b/tests/ir/dynamic-generic-method-specialize.slang.expected.txt
new file mode 100644
index 000000000..0bc25648a
--- /dev/null
+++ b/tests/ir/dynamic-generic-method-specialize.slang.expected.txt
@@ -0,0 +1,2 @@
+type: float
+10.0 \ No newline at end of file