From ca7bf79df3a3f5f4494912cb0572c36662755b9d Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 12 Apr 2023 22:58:22 -0700 Subject: Combine lookupWitness lowering with specialization. (#2794) --- tests/ir/dynamic-generic-method-specialize.slang | 65 ++++++++++++++++++++++ ...ic-generic-method-specialize.slang.expected.txt | 2 + 2 files changed, 67 insertions(+) create mode 100644 tests/ir/dynamic-generic-method-specialize.slang create mode 100644 tests/ir/dynamic-generic-method-specialize.slang.expected.txt (limited to 'tests/ir') 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(float arr[N]); +} + +struct Add : IInterface +{ + float base; + typealias V = SimpleVal; + V run(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(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 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(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 -- cgit v1.2.3