diff options
| author | Yong He <yonghe@outlook.com> | 2020-11-06 10:26:27 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-06 10:26:27 -0800 |
| commit | 444ff4d8fdeb721b94a9424d03c162f43fb217c9 (patch) | |
| tree | 7896e00e223d9b1a66a8479f510e60136c5713c3 /tests | |
| parent | 94861d5d8afdf216c0a507af24fdbe9fda4b66d7 (diff) | |
Specialize witness table lookups. (#1596)
* Specialize witness table lookups.
* Remove generated files from vcxproj
* Fix call to generic interface methods.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/dynamic-dispatch-14.slang | 75 | ||||
| -rw-r--r-- | tests/compute/dynamic-dispatch-14.slang.expected.txt | 4 |
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-14.slang b/tests/compute/dynamic-dispatch-14.slang new file mode 100644 index 000000000..5d84a3ee6 --- /dev/null +++ b/tests/compute/dynamic-dispatch-14.slang @@ -0,0 +1,75 @@ +// Test using interface typed shader parameters with associated types. + +//TEST(compute):COMPARE_COMPUTE:-cpu +//TEST(compute):COMPARE_COMPUTE:-cuda + +[anyValueSize(8)] +interface IAssoc +{ + int eval(); +} + +[anyValueSize(8)] +interface IInterface +{ + associatedtype TAssoc : IAssoc; + TAssoc run(int input); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer<int> gOutputBuffer; + +//TEST_INPUT:ubuffer(data=[rtti(MyImpl) witness(MyImpl, IInterface) 1 0], stride=4):name=gCb +StructuredBuffer<IInterface> gCb; + +//TEST_INPUT:ubuffer(data=[rtti(MyImpl) witness(MyImpl, IInterface) 1 0], stride=4):name=gCb1 +StructuredBuffer<IInterface> gCb1; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + let tid = dispatchThreadID.x; + + let inputVal : int = tid; + IInterface v0 = gCb.Load(0); + IInterface v1 = gCb1[0]; + let outputVal = v0.run(inputVal).eval() + v1.run(inputVal).eval(); + + gOutputBuffer[tid] = outputVal; +} + +// Specialize gCb1, but not gCb2 +//TEST_INPUT: globalExistentialType MyImpl +//TEST_INPUT: globalExistentialType __Dynamic +// Type must be marked `public` to ensure it is visible in the generated DLL. +public struct MyImpl : IInterface +{ + int val; + public struct TAssoc : IAssoc + { + int val; + int eval() { return val; } + } + TAssoc run(int input) + { + TAssoc rs; + rs.val = input + val; + return rs; + } +}; + +public struct MyImpl2 : IInterface +{ + int val; + public struct TAssoc : IAssoc + { + int val; + int eval() { return val; } + } + TAssoc run(int input) + { + TAssoc rs; + rs.val = input - val; + return rs; + } +};
\ No newline at end of file diff --git a/tests/compute/dynamic-dispatch-14.slang.expected.txt b/tests/compute/dynamic-dispatch-14.slang.expected.txt new file mode 100644 index 000000000..628d2a8fd --- /dev/null +++ b/tests/compute/dynamic-dispatch-14.slang.expected.txt @@ -0,0 +1,4 @@ +2 +4 +6 +8 |
