summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/expression/call/builtin/arrayLength.spec.ts
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
commita90a5cba08fdf6c0ceb95101c275108a152a3aed (patch)
tree532507288f3defd7f4dcf1af49698bcb76034855 /dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/expression/call/builtin/arrayLength.spec.ts
parentAdding debian version 126.0.1-1. (diff)
downloadfirefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz
firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/expression/call/builtin/arrayLength.spec.ts')
-rw-r--r--dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/expression/call/builtin/arrayLength.spec.ts109
1 files changed, 109 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/expression/call/builtin/arrayLength.spec.ts b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/expression/call/builtin/arrayLength.spec.ts
new file mode 100644
index 0000000000..27d8814b14
--- /dev/null
+++ b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/expression/call/builtin/arrayLength.spec.ts
@@ -0,0 +1,109 @@
+export const description = `
+Validation tests for arrayLength builtins.
+`;
+
+import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
+import { ShaderValidationTest } from '../../../shader_validation_test.js';
+
+export const g = makeTestGroup(ShaderValidationTest);
+
+g.test('bool_type')
+ .specURL('https://www.w3.org/TR/WGSL/#arrayLength-builtin')
+ .desc(
+ `
+arrayLength accepts only runtime-sized arrays
+`
+ )
+ .fn(t => {
+ const code = `
+@compute @workgroup_size(1)
+fn main() {
+ var b = true;
+ _ = arrayLength(&b);
+}`;
+
+ t.expectCompileResult(false, code);
+ });
+
+const atomic_types = ['u32', 'i32'].map(j => `atomic<${j}>`);
+const vec_types = [2, 3, 4]
+ .map(i => ['i32', 'u32', 'f32', 'f16'].map(j => `vec${i}<${j}>`))
+ .reduce((a, c) => a.concat(c), []);
+const f32_matrix_types = [2, 3, 4]
+ .map(i => [2, 3, 4].map(j => `mat${i}x${j}f`))
+ .reduce((a, c) => a.concat(c), []);
+const f16_matrix_types = [2, 3, 4]
+ .map(i => [2, 3, 4].map(j => `mat${i}x${j}<f16>`))
+ .reduce((a, c) => a.concat(c), []);
+
+g.test('type')
+ .specURL('https://www.w3.org/TR/WGSL/#arrayLength-builtin')
+ .desc(
+ `
+arrayLength accepts only runtime-sized arrays
+`
+ )
+ .params(u =>
+ u.combine('type', [
+ 'i32',
+ 'u32',
+ 'f32',
+ 'f16',
+ ...f32_matrix_types,
+ ...f16_matrix_types,
+ ...vec_types,
+ ...atomic_types,
+ 'T',
+ 'array<i32, 2>',
+ 'array<i32>',
+ ])
+ )
+ .beforeAllSubcases(t => {
+ if (t.params.type.includes('f16')) {
+ t.selectDeviceOrSkipTestCase('shader-f16');
+ }
+ })
+ .fn(t => {
+ const code = `
+struct T {
+ b: i32,
+}
+struct S {
+ ary: ${t.params.type}
+}
+
+@group(0) @binding(0) var<storage, read_write> items: S;
+
+@compute @workgroup_size(1)
+fn main() {
+ _ = arrayLength(&items.ary);
+}`;
+
+ t.expectCompileResult(t.params.type === 'array<i32>', code);
+ });
+
+// Note, the `write` case actually fails because you can't declare a storage buffer of
+// access_mode `write`.
+g.test('access_mode')
+ .specURL('https://www.w3.org/TR/WGSL/#arrayLength-builtin')
+ .desc(
+ `
+arrayLength runtime-sized array must have an access_mode of read or read_write
+`
+ )
+ .params(u => u.combine('mode', ['read', 'read_write', 'write']))
+ .fn(t => {
+ const code = `
+struct S {
+ ary: array<i32>,
+}
+
+@group(0) @binding(0) var<storage, ${t.params.mode}> items: S;
+
+@compute @workgroup_size(1)
+fn main() {
+ _ = arrayLength(&items.ary);
+}`;
+
+ t.expectCompileResult(t.params.mode !== 'write', code);
+ });