From 447b7e0e2be031409b1421b49c81f020353bf7c5 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 21 Dec 2021 16:35:34 -0500 Subject: Language experiments (#2068) * #include an absolute path didn't work - because paths were taken to always be relative. * Moved to experiments. Added some more tests. * More tests around associated types. * Return interface tests. * More tests. --- .../experiments/interface/return-interface-2.slang | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/experiments/interface/return-interface-2.slang (limited to 'tests/experiments/interface/return-interface-2.slang') diff --git a/tests/experiments/interface/return-interface-2.slang b/tests/experiments/interface/return-interface-2.slang new file mode 100644 index 000000000..1aa6fc5e3 --- /dev/null +++ b/tests/experiments/interface/return-interface-2.slang @@ -0,0 +1,55 @@ +//TEST_TEST:SIMPLE:-target dxil -entry computeMain -profile cs_6_2 + +/* +Testing returning an interface type. + +Fails with: + +.slang(6): error 41011: type 'SomeType' does not fit in the size required by its conforming interface. +struct SomeType : IGetValue +^~~~~~ + +That's understandable in so far as dynamic dispatch appears to assume anyValue(16) by default. On the other hand, the compiler will know all conforming types (well at linkage anyway), and so potentially could work out an appropriate size. +*/ + +interface IGetValue +{ + int getValue(int index); +}; + +struct SomeType : IGetValue +{ + __init(int inOffset) { offset = inOffset; another = float4(inOffset); } + int getValue(int index) { return index + offset; } + int offset; + float4 another; +}; + +interface IInterface +{ + IGetValue get(int offset); +}; + +struct InterfaceImpl : IInterface +{ + IGetValue get(int offset) + { + return SomeType(offset); + }; +}; + +RWStructuredBuffer outputBuffer; + +[numthreads(4, 4, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int x = dispatchThreadID.x; + + InterfaceImpl impl; + + IInterface intf = impl; + + var r = intf.get(16); + + outputBuffer[dispatchThreadID.x] = x + r.getValue(x); +} \ No newline at end of file -- cgit v1.2.3