diff options
| author | Yong He <yonghe@outlook.com> | 2022-09-01 10:01:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 10:01:36 -0700 |
| commit | 1f3130055956dbe441f7fc6849b189624a05f7df (patch) | |
| tree | 8b07682fbae53b0cf17af7ad76812111719e76f4 /tests | |
| parent | 4a94473eb34376dd8474f8ca3f2834b5c1daac14 (diff) | |
Public interface for arithmetic types in stdlib. (#2389)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/language-feature/generics/arithmetic-ops.slang | 44 | ||||
| -rw-r--r-- | tests/language-feature/generics/arithmetic-ops.slang.expected.txt | 5 |
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/language-feature/generics/arithmetic-ops.slang b/tests/language-feature/generics/arithmetic-ops.slang new file mode 100644 index 000000000..d2f1af47f --- /dev/null +++ b/tests/language-feature/generics/arithmetic-ops.slang @@ -0,0 +1,44 @@ +//TEST(compute):COMPARE_COMPUTE: -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj -output-using-type +T simpleTest<T : IArithmetic>(T v0, T v1) +{ + if (v0 > T(0)) + { + return v0 + v1; + } + else + { + return -v0 * v1; + } +} + +interface IMyInterface : IArithmetic +{ + int myMethod(); +} + +extension float : IMyInterface +{ + int myMethod() { return 4; } +} + +extension double : IMyInterface +{ + int myMethod() { return 8; } +} + +int genTest<T : IMyInterface>(T v0, T v1) +{ + vector<T, 2> v = vector<T, 2>(v0, v1); + return (v.x + v.y).myMethod(); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + outputBuffer[tid] = int(simpleTest<float>(1.0f, 2.0f)) + genTest<float>(1.0f, 2.0f); +} diff --git a/tests/language-feature/generics/arithmetic-ops.slang.expected.txt b/tests/language-feature/generics/arithmetic-ops.slang.expected.txt new file mode 100644 index 000000000..5c4343b55 --- /dev/null +++ b/tests/language-feature/generics/arithmetic-ops.slang.expected.txt @@ -0,0 +1,5 @@ +type: int32_t +7 +7 +7 +7 |
