From 62d16a23b0ecd72dc624abd7e10b373c40adaa90 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 25 Jun 2022 13:05:35 -0700 Subject: Specialize generic/existential calls within generic functions. (#2294) * Expose internals of dce and use it to implement call graph walk. * Specialize calls in generic functions. * Fix clang error. Co-authored-by: Yong He --- tests/compute/dynamic-dispatch-19.slang | 65 ++++++++++++++++++++++ .../compute/dynamic-dispatch-19.slang.expected.txt | 2 + 2 files changed, 67 insertions(+) create mode 100644 tests/compute/dynamic-dispatch-19.slang create mode 100644 tests/compute/dynamic-dispatch-19.slang.expected.txt (limited to 'tests/compute') diff --git a/tests/compute/dynamic-dispatch-19.slang b/tests/compute/dynamic-dispatch-19.slang new file mode 100644 index 000000000..573cade82 --- /dev/null +++ b/tests/compute/dynamic-dispatch-19.slang @@ -0,0 +1,65 @@ +// Test use of unrelated generics in a dynamically dispatched generic function can be specialized. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -use-dxil -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0 -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type + +interface IValueGetter +{ + float get(); +} + +struct MyWrapper +{ + T getter; + float getVal() + { + return getter.get(); + } +} + +interface IFoo +{ + int getIntVal(int x); +} + +[anyValueSize(16)] +interface IInterface +{ + float callGetter(T foo); +} + +struct Impl : IInterface +{ + int data; + struct GetterImpl : IValueGetter { float val; float get(){return val;} } + float callGetter(T foo) + { + // We should be able to specialize `wrapper` even if it is + // used in this dynamically dispatched method. + MyWrapper wrapper; + wrapper.getter.val = 2.0f; + return wrapper.getVal() * foo.getIntVal(1); + } +}; + +struct IdentityFoo : IFoo { int getIntVal(int x) { return x; } } + +float test() +{ + IInterface obj = createDynamicObject(3, uint4(1,2,3,4)); + IdentityFoo foo; + // Call via dynamic dispatch + return obj.callGetter(foo); +} + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer gOutputBuffer; + +//TEST_INPUT: type_conformance Impl:IInterface = 3 + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + gOutputBuffer[0] = test(); +} diff --git a/tests/compute/dynamic-dispatch-19.slang.expected.txt b/tests/compute/dynamic-dispatch-19.slang.expected.txt new file mode 100644 index 000000000..395c7d3be --- /dev/null +++ b/tests/compute/dynamic-dispatch-19.slang.expected.txt @@ -0,0 +1,2 @@ +type: float +2.0 -- cgit v1.2.3