summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-09-18 13:46:20 -0700
committerGitHub <noreply@github.com>2024-09-18 13:46:20 -0700
commit2d83875f4b376f047c4541a6f6c13d36e5aa228b (patch)
treeba41c6faa6e97b6821ac8ea635f2ae52ca8d1f4c /tests
parent85b996a75683b5364456d731a9cb4aee5c3fada2 (diff)
Add `IRWArray` interface, and make StructuredBuffer conform to them. (#5097)
* Add `IRWArray` interface, and make StructuredBuffer conform to them. * Update user guide. * Fix. * Fixes.
Diffstat (limited to 'tests')
-rw-r--r--tests/diagnostics/inout-never-written.slang74
-rw-r--r--tests/language-feature/generics/irwarray.slang34
2 files changed, 34 insertions, 74 deletions
diff --git a/tests/diagnostics/inout-never-written.slang b/tests/diagnostics/inout-never-written.slang
deleted file mode 100644
index f4d4bce7e..000000000
--- a/tests/diagnostics/inout-never-written.slang
+++ /dev/null
@@ -1,74 +0,0 @@
-//TEST:SIMPLE(filecheck=CHK): -target spirv
-
-struct State
-{
- float3 v;
- float3 n;
- int rnd;
-};
-
-//CHK-DAG: ([[# @LINE + 1]]): warning 41022: inout parameter 'x' is never written to
-void int_never_assigned(inout int x) {}
-
-//CHK-DAG: ([[# @LINE + 1]]): warning 41022: inout parameter 'state' is never written to
-void state_never_assigned(inout State state, inout float v)
-{
- v = state.v.x;
-}
-
-void state_assigned(inout State state)
-{
- state.rnd = (int) dot(state.v, state.n);
-}
-
-struct A
-{
- int state;
-
- //CHK-DAG: ([[# @LINE + 1]]): warning 41023: method marked `[mutable]` but never modifies `this`
- [mutating] int next() { return state; }
-
- [mutating] int progress()
- {
- unmodified(state);
- return state;
- }
-};
-
-__generic <T>
-struct B
-{
- int state;
-
- //CHK-DAG: ([[# @LINE + 1]]): warning 41023: method marked `[mutable]` but never modifies `this`
- [mutating] int next() { return state; }
-};
-
-// Sometimes an inOutImplicitCast is done,
-// this needs to be tracked as an alias;
-// none of the following functions should
-// generate warnings
-uint lcg(inout uint prev)
-{
- const uint LCG_A = 1664525u;
- const uint LCG_C = 1013904223u;
- prev = (LCG_A * prev + LCG_C);
- return prev & 0x00FFFFFF;
-}
-
-float rnd(inout uint prev)
-{
- return ((float) lcg(prev) / (float) 0x01000000);
-}
-
-float3 sample(inout int seed)
-{
- float3 xi;
- xi.x = rnd(seed);
- xi.y = rnd(seed);
- xi.z = rnd(seed);
- return xi.z;
-}
-
-//CHK-NOT: warning 41022
-//CHK-NOT: warning 41023
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<U, T : IRWArray<U>>(inout T array, int index, U value) { array[index] = value; }
+void writeToBuffer<U, T : IRWArray<U>>(T array, int index, U value) { array[index] = value; }
+U readFromArray<U, T:IArray<U>>(T array, int index) { return array[index]; }
+
+//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);
+
+ // 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));
+}