diff options
| author | Yong He <yonghe@outlook.com> | 2020-08-21 01:10:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-21 01:10:45 -0700 |
| commit | a8bc5983eae60ca37e853041e989a654c1247876 (patch) | |
| tree | 330cae10c2c24ba14ca726b61c576d9f362f5b8e /tests/compute/dynamic-dispatch-10.slang | |
| parent | 11748a75e66c2bd3fa7ef7635fd35363465f599c (diff) | |
Allow calling a generic function with an existential value (dynamic dispatch) (#1508)
* Allow calling a generic function with an existential value (dynamic dispatch).
* Fixes per review comments.
* Clean up implementation by having `openExistential` return `ExtractExistentialType` instead of a DeclRef to the interface with a `ThisTypeSubstitution`.
* More cleanups
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/compute/dynamic-dispatch-10.slang')
| -rw-r--r-- | tests/compute/dynamic-dispatch-10.slang | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-10.slang b/tests/compute/dynamic-dispatch-10.slang new file mode 100644 index 000000000..3e1848186 --- /dev/null +++ b/tests/compute/dynamic-dispatch-10.slang @@ -0,0 +1,47 @@ +//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 specializing a generic with +// an existential value. + +[anyValueSize(16)] +interface IInterface +{ + int Compute(int inVal); +}; + +int GenericCompute0(IInterface obj, int inVal) +{ + return GenericCompute1(obj, obj, inVal); +} + +int GenericCompute1<T:IInterface>(T obj, IInterface obj2, int inVal) +{ + return obj.Compute(inVal) + obj2.Compute(inVal); +} + + +struct Impl : IInterface +{ + int base; + int Compute(int inVal) { return base + inVal * inVal; } +}; + +int test(int inVal) +{ + Impl obj; + obj.base = 1; + return GenericCompute0(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; +} |
