wgsl: validate struct parsing
- [x]
struct a {}-- invalid (empty struct) - [ ]
struct { a: i32, }-- invalid no name - [ ] invalid duplicate struct name
struct a { a: i32, };
struct a { b: i32, };
- [ ]
struct a { a : i32, a: f32 }-- invalid duplicate member name - [ ]
struct a b: i32}-- invalid missing{ - [ ]
struct a { b: i32-- invalid missing} - [ ]
struct 123 { a: i32}--invalid name - [ ]
struct a { a: i32; b:i32;}-- invalid;instead of, - [ ]
struct a { a: i32 b: i32}-- invalid missing, - [x]
struct a { a: i32, b: i32,}-- valid trailing, - [x]
struct a { a: i32,}-- single element valid - [ ] valid substructure
struct a { b: f32 };
struct b { c: a };
- [ ]
struct a { b: i32}; var a = 1;-- invalid usage ofashadows struct name - [ ]
struct a { b i32}-- invalid declaration inside struct decl - [x]
struct a { b: array<f32> }-- valid runtime array - [x]
struct a { b: array<f32>, c: i32}-- invalid runtime array must be last - [x]
struct a { b: texture_3d}-- invalid - [x]
struct a { b: sampler }-- invalid - [x] all types -- valid
struct B {
a: i32
};
struct a {
a: i32,
b: f32,
c: u32,
d: mat2x3<f32>,
e: vec3<f32>,
f: atomic<i32>,
g: array<B, 4>,
h: B,
i: array<f32>
}
-
[x]
struct B { a: array<i32>}; struct a { b: B }-- invalid as runtime array must be in outer struct -
[ ]
struct/*comment*/B\n\n{\na/*comment*/: i32}-- valid -
[x]
struct a { b: ptr<workgroup, i32>}-- invalid no pointers -
[ ]
type a = i32; struct b { c: a}-- valid -
[ ]
struct a { @builtin(position) @location(1) a : vec4<f32>}--invalid only one of -
[ ]
struct a { @builtin(position) a : vec4<f32> }-- valid -
[ ]
struct a { @location(0) b: f32}-- valid -
[ ]
struct a { @location(0) @interpolate(flat) b: f32}-- valid -
[ ]
struct a { @interpolate(perspective, centroid) @location(2) b: f32}-- valid -
[ ]
struct a { @builtin(position) @invariant a : vec4<f32>}-- valid -
[ ]
struct a { @invariant @builtin(position) a : vec4<f32>}-- valid -
[ ]
struct a { @binding(0) b: f32}-- invalid -
[ ]
struct a { @group(1) b: f32}-- invalid -
[ ]
struct a { @id(1) b: f32}-- invalid -
[ ]
struct a { @interpolate(flat) @builtin(position) b: vec4<f32>}-- invalid -
[ ]
struct a { @invariant @location(0) b: f32}-- invalid -
[ ]
struct a { @workgroup_size(1) b: f32}-- invalid -
[ ] multiple builtins (test each of the builtins for each of the valid and invalid stages
Align and size rules for storage class
- [x]
struct a { @align(32) b: vec3<f32>}-- valid - [x]
struct a { @align(0) b: f32 }--invalid - [x]
struct a { @align(7) b: f32 }-- invalid not power of 2 - [ ]
struct a { @align(2) b: i32}-- invalid align must be at least 4 - [ ]
struct a { @align(4) @size(4) b: atomic<i32>}-- valid - [ ]
struct a { @size(4) @align(4) b: atomic<i32>}-- valid - [ ]
struct a { @align(8) @size(7) b: i32, @align(256) @size(1025) c: f32}-- valid - [x]
struct a { @align(32) @align(16) b: f32}-- invalid - [x]
struct a { @size(32) @size(16) b: f32}-- invalid
Align and size rules for uniform class
- [ ]
struct a { b : array<f32, 7> }-- invalid stride must be 16 and not 4 - [ ]
struct a { @size(16) b: array<f32, 7>}-- valid - [ ]
struct b { c: i32}; struct a { d: b}-- invalid as size of b must be 16 and not 4
- Size tests https://github.com/gpuweb/cts/blob/main/src/webgpu/shader/validation/shader_io/size.spec.ts
- Align tests https://github.com/gpuweb/cts/blob/main/src/webgpu/shader/validation/parse/align.spec.ts
- Struct tests https://github.com/gpuweb/cts/blob/main/src/webgpu/shader/validation/types/struct.spec.ts