Skip to content

Commit 4adb750

Browse files
authored
wgsl: Add validation tests for override-sized arrays (#4470)
Make sure they can only be declared in the workgroup address space, and that they cannot be nested in other types or directly constructed.
1 parent 277ef80 commit 4adb750

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/webgpu/listing_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,7 @@
20022002
"webgpu:shader,validation,decl,let:initializer:*": { "subcaseMS": 0.706 },
20032003
"webgpu:shader,validation,decl,let:module_scope:*": { "subcaseMS": 0.619 },
20042004
"webgpu:shader,validation,decl,let:type:*": { "subcaseMS": 122.199 },
2005+
"webgpu:shader,validation,decl,override:array_size:*": { "subcaseMS": 44.868 },
20052006
"webgpu:shader,validation,decl,override:function_scope:*": { "subcaseMS": 1.003 },
20062007
"webgpu:shader,validation,decl,override:id:*": { "subcaseMS": 69.432 },
20072008
"webgpu:shader,validation,decl,override:initializer:*": { "subcaseMS": 4.810 },

src/webgpu/shader/validation/decl/override.spec.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,70 @@ g.test('function_scope')
239239
const code = `fn foo() { override x : u32; }`;
240240
t.expectCompileResult(false, code);
241241
});
242+
243+
const kArrayCases = {
244+
workgroup_var: {
245+
code: `var<workgroup> a: array<u32, size>;`,
246+
valid_with_override_size: true,
247+
},
248+
private_var: {
249+
code: `var<private> a: array<u32, size>;`,
250+
valid_with_override_size: false,
251+
},
252+
uniform_var: {
253+
code: `@group(0) @binding(0) var<uniform> a: array<vec4u, size>;`,
254+
valid_with_override_size: false,
255+
},
256+
storage_var: {
257+
code: `@group(0) @binding(0) var<storage> a: array<u32, size>;`,
258+
valid_with_override_size: false,
259+
},
260+
function_var: {
261+
code: `fn f() { var a: array<u32, size>; }`,
262+
valid_with_override_size: false,
263+
},
264+
workgroup_ptr_param: {
265+
code: `fn f(a: ptr<workgroup, array<u32, size>>) {}`,
266+
valid_with_override_size: true,
267+
},
268+
private_ptr_param: {
269+
code: `fn f(a: ptr<private, array<u32, size>>) {}`,
270+
valid_with_override_size: false,
271+
},
272+
workgroup_ptr_let: {
273+
code: `var<workgroup> a: array<u32, size>; fn f() { let a = &a; }`,
274+
valid_with_override_size: true,
275+
},
276+
private_ptr_let: {
277+
code: `var<private> a: array<u32, size>; fn f() { let a = &a; }`,
278+
valid_with_override_size: false,
279+
},
280+
array_in_struct: {
281+
code: `struct S { a: array<u32, size> };`,
282+
valid_with_override_size: false,
283+
},
284+
array_in_array: {
285+
code: `var<workgroup> a: array<array<u32, size>, 4>;`,
286+
valid_with_override_size: false,
287+
},
288+
construct_array: {
289+
code: `fn a() -> u32 { return array<u32, size>()[0]; }`,
290+
valid_with_override_size: false,
291+
},
292+
};
293+
294+
g.test('array_size')
295+
.desc(
296+
'Test that override-sized arrays are only allowed in the workgroup address space, and cannot be nested in other types or constructed.'
297+
)
298+
.params(u => u.combine('case', keysOf(kArrayCases)).combine('stage', ['const', 'override']))
299+
.fn(t => {
300+
const testcase = kArrayCases[t.params.case];
301+
const wgsl = `
302+
${t.params.stage} size = 1;
303+
${testcase.code}
304+
`;
305+
306+
// Using a `const` size is the control case that should always pass.
307+
t.expectCompileResult(t.params.stage === 'const' || testcase.valid_with_override_size, wgsl);
308+
});

0 commit comments

Comments
 (0)