summaryrefslogtreecommitdiffstats
path: root/tests/experiments/interface/return-interface-2.slang
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-12-21 16:35:34 -0500
committerGitHub <noreply@github.com>2021-12-21 16:35:34 -0500
commit447b7e0e2be031409b1421b49c81f020353bf7c5 (patch)
tree721a1e892b4dc0bcc8c62d7b7e3f9dbb843bf958 /tests/experiments/interface/return-interface-2.slang
parentd7ed829c3f85514fc08a12a5701d64390b31040c (diff)
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.
Diffstat (limited to 'tests/experiments/interface/return-interface-2.slang')
-rw-r--r--tests/experiments/interface/return-interface-2.slang55
1 files changed, 55 insertions, 0 deletions
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<int> 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