diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/dynamic-dispatch-2.slang | 2 | ||||
| -rw-r--r-- | tests/compute/dynamic-dispatch-3.slang | 60 | ||||
| -rw-r--r-- | tests/compute/dynamic-dispatch-3.slang.expected.txt | 4 |
3 files changed, 64 insertions, 2 deletions
diff --git a/tests/compute/dynamic-dispatch-2.slang b/tests/compute/dynamic-dispatch-2.slang index ade8aeb84..6b8b0e633 100644 --- a/tests/compute/dynamic-dispatch-2.slang +++ b/tests/compute/dynamic-dispatch-2.slang @@ -12,7 +12,6 @@ interface IInterface { associatedtype Assoc : IAssoc; int Compute(int inVal); - Assoc getAssoc(); }; int GenericCompute<T:IInterface>(T obj, int inVal) @@ -30,7 +29,6 @@ struct Impl : IInterface }; int base; int Compute(int inVal) { return base + inVal * inVal; } - Assoc getAssoc() { Assoc rs; rs.val = 1; return rs; } }; int test(int inVal) 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; +} diff --git a/tests/compute/dynamic-dispatch-3.slang.expected.txt b/tests/compute/dynamic-dispatch-3.slang.expected.txt new file mode 100644 index 000000000..a6bafb7ca --- /dev/null +++ b/tests/compute/dynamic-dispatch-3.slang.expected.txt @@ -0,0 +1,4 @@ +2 +3 +6 +B |
