summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/language-feature/inheritance/struct-inherit-interface-requirement.slang69
-rw-r--r--tests/language-feature/inheritance/struct-inherit-interface-requirement.slang.expected.txt0
-rw-r--r--tests/language-feature/inheritance/struct-inheritance.slang58
-rw-r--r--tests/language-feature/inheritance/struct-inheritance.slang.expected.txt4
4 files changed, 131 insertions, 0 deletions
diff --git a/tests/language-feature/inheritance/struct-inherit-interface-requirement.slang b/tests/language-feature/inheritance/struct-inherit-interface-requirement.slang
new file mode 100644
index 000000000..e18695737
--- /dev/null
+++ b/tests/language-feature/inheritance/struct-inherit-interface-requirement.slang
@@ -0,0 +1,69 @@
+// struct-inherit-interface-requirement.slang
+
+//TEST(compute):COMPARE_COMPUTE:
+
+// Test that a `struct` type can use an inherited
+// member to satisfy an interface requirement.
+
+interface ITweak
+{
+ int tweak(int val);
+ int twiddle(int val);
+}
+
+// Note: `Base` intentionally doesn't inherit from `ITweak`,
+// but it *does* provide a method that could satisfy one
+// of the interface requirements.
+//
+struct Base
+{
+ int a;
+
+ int tweak(int val) { return val ^ a; }
+}
+
+struct Derived : Base, ITweak
+{
+ // Note: it is important for this type to have an additional
+ // field beyond the one in `Base`, because it ensures that
+ // the two types `Base` and `Derived` aren't structurally
+ // equivalent when compiled through HLSL (which silently allows
+ // certain type mismatches so long as there is a memberwise
+ // structural match).
+ int b;
+
+ int twiddle(int val)
+ {
+ return val + b;
+ }
+}
+
+int tweakAndTwiddle<T : ITweak>(T tweaker, int val)
+{
+ int tmp = val;
+ tmp = tweaker.tweak(val);
+ tmp = tweaker.twiddle(val);
+ return val;
+}
+
+
+int test(int val)
+{
+ Derived d;
+ d.a = 0xFF;
+ d.b = 1;
+
+ return tweakAndTwiddle(d, val);
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ int inVal = tid;
+ int outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/language-feature/inheritance/struct-inherit-interface-requirement.slang.expected.txt b/tests/language-feature/inheritance/struct-inherit-interface-requirement.slang.expected.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/language-feature/inheritance/struct-inherit-interface-requirement.slang.expected.txt
diff --git a/tests/language-feature/inheritance/struct-inheritance.slang b/tests/language-feature/inheritance/struct-inheritance.slang
new file mode 100644
index 000000000..e2cfaf25b
--- /dev/null
+++ b/tests/language-feature/inheritance/struct-inheritance.slang
@@ -0,0 +1,58 @@
+// struct-inheritance.slang
+
+//TEST(compute):COMPARE_COMPUTE:
+
+// Test that we can define a `struct` type
+// that inherits from another `struct`.
+
+struct Base
+{
+ int a;
+
+ int tweakBase(int val) { return val ^ a; }
+}
+
+struct Derived : Base
+{
+ int b;
+
+ int tweakDerived(int val) { return tweakBase(val) + b; }
+}
+
+int tweak(Base b, int v)
+{
+ return b.tweakBase(v);
+}
+
+//TEST_INPUT:cbuffer(data=[1 2]):name=C
+cbuffer C
+{
+ int x;
+ int y;
+}
+
+int test(int val)
+{
+ Derived d;// = { x, y };
+ d.a = x;
+ d.b = y;
+
+ int result = 0;
+ result = result*16 + d.a;
+ result = result*16 + d.tweakBase(val);
+ result = result*16 + tweak(d, val);
+ result = result*16 + d.tweakDerived(val);
+ return result;
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ int inVal = tid;
+ int outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/language-feature/inheritance/struct-inheritance.slang.expected.txt b/tests/language-feature/inheritance/struct-inheritance.slang.expected.txt
new file mode 100644
index 000000000..a17826230
--- /dev/null
+++ b/tests/language-feature/inheritance/struct-inheritance.slang.expected.txt
@@ -0,0 +1,4 @@
+1113
+1002
+1335
+1224