From 2d83875f4b376f047c4541a6f6c13d36e5aa228b Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 18 Sep 2024 13:46:20 -0700 Subject: Add `IRWArray` interface, and make StructuredBuffer conform to them. (#5097) * Add `IRWArray` interface, and make StructuredBuffer conform to them. * Update user guide. * Fix. * Fixes. --- tests/language-feature/generics/irwarray.slang | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/language-feature/generics/irwarray.slang (limited to 'tests/language-feature') diff --git a/tests/language-feature/generics/irwarray.slang b/tests/language-feature/generics/irwarray.slang new file mode 100644 index 000000000..47109f7b0 --- /dev/null +++ b/tests/language-feature/generics/irwarray.slang @@ -0,0 +1,34 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type + +void writeToArray>(inout T array, int index, U value) { array[index] = value; } +void writeToBuffer>(T array, int index, U value) { array[index] = value; } +U readFromArray>(T array, int index) { return array[index]; } + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer 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); + + // CHECK: 1.0 + writeToBuffer(outputBuffer, 0, 1.0f); + + // CHECK: 4.0 + writeToArray(arr, 0, 4.0f); + outputBuffer[1] = readFromArray(arr, 0); + + // CHECK: 3.0 + writeToArray(v, 3, 3.0f); + outputBuffer[2] = readFromArray(v, 3); + + // CHECK: 30.0 + writeToArray(m, 1, float2(10.0f, 20.0f)); + outputBuffer[3] = readFromArray(m, 1).x + readFromArray(m, 1).y; + + writeToBuffer(outputBuffer, 0, readFromArray(outputBuffer, 0)); +} -- cgit v1.2.3