From b820f34a1b6336af184458c5b1dfe2273c99f1ff Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 18 Aug 2020 13:08:45 -0700 Subject: Support initializing an existential value from a generic value. (#1503) * Support initializing an existential value from a generic value. * Remove trailing spaces and clean up debugging code. --- tests/compute/dynamic-dispatch-9.slang | 50 ++++++++++++++++++++++ .../compute/dynamic-dispatch-9.slang.expected.txt | 4 ++ 2 files changed, 54 insertions(+) create mode 100644 tests/compute/dynamic-dispatch-9.slang create mode 100644 tests/compute/dynamic-dispatch-9.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/dynamic-dispatch-9.slang b/tests/compute/dynamic-dispatch-9.slang new file mode 100644 index 000000000..4fb45edc9 --- /dev/null +++ b/tests/compute/dynamic-dispatch-9.slang @@ -0,0 +1,50 @@ +//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 initializing an extential value +// from a generic value. + +[anyValueSize(16)] +interface IInterface +{ + int Compute(int inVal); +}; + +int GenericCompute0(IInterface obj, int inVal) +{ + return obj.Compute(inVal); +} + +int GenericCompute1(T obj, int inVal) +{ + IInterface iobj = obj; + return iobj.Compute(inVal) + + GenericCompute0(obj, inVal) - + GenericCompute0(iobj, inVal); +} + + +struct Impl : IInterface +{ + int base; + int Compute(int inVal) { return base + inVal * inVal; } +}; + +int test(int inVal) +{ + Impl obj; + obj.base = 1; + return GenericCompute1(obj, inVal); +} + +//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer +RWStructuredBuffer 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-9.slang.expected.txt b/tests/compute/dynamic-dispatch-9.slang.expected.txt new file mode 100644 index 000000000..146ab3c8c --- /dev/null +++ b/tests/compute/dynamic-dispatch-9.slang.expected.txt @@ -0,0 +1,4 @@ +1 +2 +5 +A -- cgit v1.2.3