diff options
Diffstat (limited to 'tests/language-feature/generics')
| -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 +} |
