diff options
| author | Yong He <yonghe@outlook.com> | 2020-06-19 13:16:22 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-19 13:16:22 -0700 |
| commit | b595dd0cd984bcb4db980693363798dd2b490da4 (patch) | |
| tree | c00d6cf873d2ee1dfb50eeae782b082d2f72770a /tests/language-feature/inheritance/struct-inheritance.slang | |
| parent | 110d15b61ac5d76da001d412eaa4be07f3cd8f4d (diff) | |
| parent | 19880116635a4a76af55d876b82ec966c90deafb (diff) | |
Merge pull request #1403 from tfoleyNV/struct-inheritance-and-interfaces
Work on struct inheritance and interfaces
Diffstat (limited to 'tests/language-feature/inheritance/struct-inheritance.slang')
| -rw-r--r-- | tests/language-feature/inheritance/struct-inheritance.slang | 58 |
1 files changed, 58 insertions, 0 deletions
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; +} |
