diff options
| author | Yong He <yonghe@outlook.com> | 2020-06-26 11:59:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-26 11:59:33 -0700 |
| commit | 3e8bdb60afb5b0c0a53ce06d1dbbc429988f5885 (patch) | |
| tree | 03f379d064f5e4df3423824140fad897b8a688e7 /tests/compute/dynamic-dispatch-3.slang | |
| parent | d084f632a136354dd12952183994240b459240ee (diff) | |
| parent | 4e443984065552cc2f648ae2fae9e49a4ef21107 (diff) | |
Merge pull request #1408 from csyonghe/dyndispatch2
Dynamic dispatch for generic interface requirements and `associatedtype`
Diffstat (limited to 'tests/compute/dynamic-dispatch-3.slang')
| -rw-r--r-- | tests/compute/dynamic-dispatch-3.slang | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/compute/dynamic-dispatch-3.slang b/tests/compute/dynamic-dispatch-3.slang new file mode 100644 index 000000000..7011a2f4e --- /dev/null +++ b/tests/compute/dynamic-dispatch-3.slang @@ -0,0 +1,60 @@ +//TEST(compute):COMPARE_COMPUTE:-cpu -xslang -allow-dynamic-code + +// Test dynamic dispatch code gen for static member functions +// of associated type. +interface IGetter +{ + int getVal(); +}; +interface IAssoc +{ + int get(); + static int getBase<T:IGetter>(T getter); +} +interface IInterface +{ + associatedtype Assoc : IAssoc; + int Compute(int inVal); +}; + +struct GetterImpl : IGetter +{ + int getVal() { return 1; } +}; + +int GenericCompute<T:IInterface>(T obj, int inVal) +{ + GetterImpl getter; + return obj.Compute(inVal) + T.Assoc.getBase(getter); +} + +struct Impl : IInterface +{ + struct Assoc : IAssoc + { + int val; + int get() { return val; } + static int getBase<T:IGetter>(T t) { return t.getVal(); } + }; + 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; +} |
