From dc991f7cb6b7f9f7271f4e557cfdd3e59804d1d3 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 21 Oct 2021 16:27:40 -0700 Subject: Passing associated type arguments to existential parameters + packing for `bool`. (#1987) * Passing associated type arguments to existential parameters + packing for `bool`. * fix typo Co-authored-by: Yong He --- tests/compute/dynamic-dispatch-18.slang | 53 ++++++++++++++++++++++ .../compute/dynamic-dispatch-18.slang.expected.txt | 2 + 2 files changed, 55 insertions(+) create mode 100644 tests/compute/dynamic-dispatch-18.slang create mode 100644 tests/compute/dynamic-dispatch-18.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/dynamic-dispatch-18.slang b/tests/compute/dynamic-dispatch-18.slang new file mode 100644 index 000000000..23cdabbbd --- /dev/null +++ b/tests/compute/dynamic-dispatch-18.slang @@ -0,0 +1,53 @@ +// Test using generic interface methods with dynamic dispatch. + +//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 + +[anyValueSize(12)] +interface IReturnsZero +{ + float get(); +} + +[anyValueSize(16)] +interface IInterface +{ + associatedtype Getter : IReturnsZero; + Getter createGetter(); +} + +struct Impl : IInterface +{ + int data; + struct Getter : IReturnsZero + { + bool data; + float get() { if (data) return 0.0; else return 1.0;} + } + Getter createGetter() { Getter g; g.data = true; return g; } +}; + + +float test(IReturnsZero r) +{ + return r.get(); +} + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer gOutputBuffer; + +//TEST_INPUT: set gObj = new StructuredBuffer[new Impl{1}]; +RWStructuredBuffer gObj; + +//TEST_INPUT: type_conformance Impl:IInterface = 3 + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + float result = 0.0; + let i = createDynamicObject(3, 0); + IReturnsZero iobj = i.createGetter(); + result = test(iobj); + gOutputBuffer[0] = result; +} diff --git a/tests/compute/dynamic-dispatch-18.slang.expected.txt b/tests/compute/dynamic-dispatch-18.slang.expected.txt new file mode 100644 index 000000000..4b1f4c0d9 --- /dev/null +++ b/tests/compute/dynamic-dispatch-18.slang.expected.txt @@ -0,0 +1,2 @@ +type: float +0.000000 -- cgit v1.2.3