diff options
| author | Yong He <yonghe@outlook.com> | 2023-10-25 07:50:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-25 22:50:14 +0800 |
| commit | 5dc3c2f57963de93ad03724a01ea48b8585dc15a (patch) | |
| tree | 072748b952eb03da7950110ed3a8f87da9b5e72f /tests | |
| parent | f8bf75cf1ae0aeee155996a917c2925bc500f3e2 (diff) | |
Add `IArray`. (#3281)
* Initial support for generic interfaces.
* Cleanup.
* Add generic syntax for interfaces.
* Add `IArray`.
* Fix.
* Fix.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/language-feature/generics/iarray.slang | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/language-feature/generics/iarray.slang b/tests/language-feature/generics/iarray.slang new file mode 100644 index 000000000..c2314f106 --- /dev/null +++ b/tests/language-feature/generics/iarray.slang @@ -0,0 +1,37 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type + +T sum<T:__BuiltinArithmeticType>(IArray<T> array) +{ + T result = T(0); + for (int i = 0; i < array.getCount(); i++) + { + result = result + array[i]; + } + return result; +} +vector<T,N> sum<T:__BuiltinArithmeticType, let N:int>(IArray<vector<T,N>> array) +{ + vector<T,N> result = vector<T,N>(T(0)); + for (int i = 0; i < array.getCount(); i++) + { + result = result + array[i]; + } + return result; +} +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + float arr[3] = { 1.0, 2.0, 3.0 }; + float4 v = float4(1.0, 2.0, 3.0, 4.0); + float2x2 m = float2x2(1.0, 2.0, 3.0, 4.0); + outputBuffer[0] = sum(arr); + outputBuffer[1] = sum(v); + outputBuffer[2] = sum(sum(m)); + // CHECK: 6.0 + // CHECK: 10.0 + // CHECK: 10.0 +} |
