diff options
| author | Yong He <yonghe@outlook.com> | 2020-06-18 15:05:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-18 15:05:58 -0700 |
| commit | aa6aca498cd1f7fbbdb143e72dd48b1d714c8fbb (patch) | |
| tree | a2361c042e6a03ff957bd4a921f73efbb89dc1b7 /tests/compute/dynamic-dispatch-1.slang | |
| parent | 5952e3b3d7f505a7e6d71ecd0793911224f5bac3 (diff) | |
| parent | 82ba914db9c3823ad7a0834d46b7fccedfe0acee (diff) | |
Merge pull request #1400 from csyonghe/dyndispatch
Dynamic dispatch non-static functions.
Diffstat (limited to 'tests/compute/dynamic-dispatch-1.slang')
| -rw-r--r-- | tests/compute/dynamic-dispatch-1.slang | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-1.slang b/tests/compute/dynamic-dispatch-1.slang new file mode 100644 index 000000000..9e63ee124 --- /dev/null +++ b/tests/compute/dynamic-dispatch-1.slang @@ -0,0 +1,38 @@ +//TEST(compute):COMPARE_COMPUTE:-cpu -xslang -allow-dynamic-code + +// Test dynamic dispatch code gen for non-static member functions. + +interface IInterface +{ + int Compute(int inVal); +}; + +int GenericCompute<T:IInterface>(T obj, int inVal) +{ + return obj.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 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; +} |
