wgsl-in: Make semicolon after struct decl optional

This commit is contained in:
Pu Xingyu
2022-03-27 13:35:08 +08:00
committed by Dzmitry Malyshau
parent 54ef2e39a0
commit 3c313564ac
20 changed files with 52 additions and 53 deletions

View File

@@ -4228,7 +4228,6 @@ impl Parser {
type_span,
);
self.lookup_type.insert(name.to_owned(), ty);
lexer.expect(Token::Separator(';'))?;
}
(Token::Word("type"), _) => {
let name = lexer.next_ident()?;

View File

@@ -157,13 +157,13 @@ fn parse_type_cast() {
fn parse_struct() {
parse_str(
"
struct Foo { x: i32 };
struct Foo { x: i32 }
struct Bar {
@size(16) x: vec2<i32>,
@align(16) y: f32,
@size(32) @align(8) z: vec3<f32>,
};
struct Empty {};
struct Empty {}
var<storage,read_write> s: Foo;
",
)
@@ -443,7 +443,7 @@ fn parse_struct_instantiation() {
struct Foo {
a: f32,
b: vec3<f32>,
};
}
@stage(fragment)
fn fs_main() {
@@ -460,7 +460,7 @@ fn parse_array_length() {
"
struct Foo {
data: array<u32>
}; // this is used as both input and output for convenience
} // this is used as both input and output for convenience
@group(0) @binding(0)
var<storage> foo: Foo;

View File

@@ -2,7 +2,7 @@
struct AlignedWrapper {
@align(8) value: i32
};
}
struct Bar {
matrix: mat4x4<f32>,
@@ -10,7 +10,7 @@ struct Bar {
atom: atomic<i32>,
arr: array<vec2<u32>, 2>,
data: array<AlignedWrapper>,
};
}
@group(0) @binding(0)
var<storage,read_write> bar: Bar;

View File

@@ -3,7 +3,7 @@ let NUM_PARTICLES: u32 = 1500u;
struct Particle {
pos : vec2<f32>,
vel : vec2<f32>,
};
}
struct SimParams {
deltaT : f32,
@@ -13,11 +13,11 @@ struct SimParams {
rule1Scale : f32,
rule2Scale : f32,
rule3Scale : f32,
};
}
struct Particles {
particles : array<Particle>
};
}
@group(0) @binding(0) var<uniform> params : SimParams;
@group(0) @binding(1) var<storage> particlesSrc : Particles;

View File

@@ -5,7 +5,7 @@ struct Globals {
v: vec4<f32>,
m: mat3x4<f32>,
d: array<f32>,
};
}
@group(0) @binding(0) var<storage, read_write> globals: Globals;

View File

@@ -8,7 +8,7 @@ struct Globals {
a: atomic<u32>,
b: array<atomic<u32>, 10>,
c: array<atomic<u32>>,
};
}
@group(0) @binding(0) var<storage, read_write> globals: Globals;

View File

@@ -5,7 +5,7 @@ struct Globals {
v: vec4<f32>,
m: mat3x4<f32>,
d: array<f32>,
};
}
@group(0) @binding(0) var<storage, read_write> globals: Globals;

View File

@@ -1,6 +1,6 @@
struct PrimeIndices {
data: array<u32>
}; // this is used as both input and output for convenience
} // this is used as both input and output for convenience
@group(0) @binding(0)
var<storage,read_write> v_indices: PrimeIndices;

View File

@@ -1,13 +1,13 @@
struct PushConstants {
index: u32,
double: vec2<f64>,
};
}
var<push_constant> pc: PushConstants;
struct FragmentIn {
@location(0) color: vec4<f32>,
@builtin(primitive_index) primitive_index: u32,
};
}
@stage(fragment)
fn main(in: FragmentIn) -> @location(0) vec4<f32> {

View File

@@ -9,7 +9,7 @@ struct Foo {
v3: vec3<f32>,
// test packed vec3
v1: f32,
};
}
@group(0) @binding(1)
var<storage, read_write> alignment: Foo;

View File

@@ -3,7 +3,7 @@
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(1) varying: f32,
};
}
@stage(vertex)
fn vertex(
@@ -19,7 +19,7 @@ struct FragmentOutput {
@builtin(frag_depth) depth: f32,
@builtin(sample_mask) sample_mask: u32,
@location(0) color: f32,
};
}
@stage(fragment)
fn fragment(
@@ -48,11 +48,11 @@ fn compute(
struct Input1 {
@builtin(vertex_index) index: u32,
};
}
struct Input2 {
@builtin(instance_index) index: u32,
};
}
@stage(vertex)
fn vertex_two_structs(in1: Input1, in2: Input2) -> @builtin(position) vec4<f32> {

View File

@@ -9,7 +9,7 @@ struct FragmentInput {
@location(4) @interpolate(perspective) perspective : vec4<f32>,
@location(5) @interpolate(perspective, centroid) perspective_centroid : f32,
@location(6) @interpolate(perspective, sample) perspective_sample : f32,
};
}
@stage(vertex)
fn vert_main() -> FragmentInput {

View File

@@ -41,7 +41,7 @@ fn bool_cast(x: vec3<f32>) -> vec3<f32> {
struct Foo {
a: vec4<f32>,
b: i32,
};
}
fn constructors() -> f32 {
var foo: Foo;

View File

@@ -6,7 +6,7 @@ fn f() {
struct DynamicArray {
arr: array<u32>
};
}
@group(0) @binding(0)
var<storage, read_write> dynamic_array: DynamicArray;

View File

@@ -4,12 +4,12 @@
// Storage and Uniform storage classes
struct InStorage {
a: array<vec4<f32>, 10>
};
}
@group(0) @binding(0) var<storage> in_storage: InStorage;
struct InUniform {
a: array<vec4<f32>, 20>
};
}
@group(0) @binding(1) var<uniform> in_uniform: InUniform;
// Textures automatically land in the `handle` storage class.

View File

@@ -1,11 +1,11 @@
struct PushConstants {
multiplier: f32
};
}
var<push_constant> pc: PushConstants;
struct FragmentIn {
@location(0) color: vec4<f32>
};
}
@stage(fragment)
fn main(in: FragmentIn) -> @location(0) vec4<f32> {

View File

@@ -4,7 +4,7 @@ let c_scale: f32 = 1.2;
struct VertexOutput {
@location(0) uv : vec2<f32>,
@builtin(position) position : vec4<f32>,
};
}
@stage(vertex)
fn vert_main(

View File

@@ -1,7 +1,7 @@
struct Globals {
view_proj: mat4x4<f32>,
num_lights: vec4<u32>,
};
}
@group(0)
@binding(0)
@@ -10,7 +10,7 @@ var<uniform> u_globals: Globals;
struct Entity {
world: mat4x4<f32>,
color: vec4<f32>,
};
}
@group(1)
@binding(0)
@@ -27,7 +27,7 @@ struct VertexOutput {
@builtin(position) proj_position: vec4<f32>,
@location(0) world_normal: vec3<f32>,
@location(1) world_position: vec4<f32>,
};
}
@stage(vertex)
fn vs_main(
@@ -49,7 +49,7 @@ struct Light {
proj: mat4x4<f32>,
pos: vec4<f32>,
color: vec4<f32>,
};
}
@group(0)
@binding(1)

View File

@@ -1,12 +1,12 @@
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec3<f32>,
};
}
struct Data {
proj_inv: mat4x4<f32>,
view: mat4x4<f32>,
};
}
@group(0) @binding(0)
var<uniform> r_data: Data;

View File

@@ -377,7 +377,7 @@ fn struct_member_zero_size() {
r#"
struct Bar {
@size(0) data: array<f32>
};
}
"#,
r#"error: struct member size or alignment must not be 0
┌─ wgsl:3:23
@@ -395,7 +395,7 @@ fn struct_member_zero_align() {
r#"
struct Bar {
@align(0) data: array<f32>
};
}
"#,
r#"error: struct member size or alignment must not be 0
┌─ wgsl:3:24
@@ -641,12 +641,12 @@ fn reserved_keyword() {
// struct
check(
r#"
struct array {};
struct array {}
"#,
r###"error: name `array` is a reserved keyword
┌─ wgsl:2:20
2 │ struct array {};
2 │ struct array {}
│ ^^^^^ definition of `array`
"###,
@@ -655,12 +655,12 @@ fn reserved_keyword() {
// struct member
check(
r#"
struct Foo { sampler: f32 };
struct Foo { sampler: f32 }
"#,
r###"error: name `sampler` is a reserved keyword
┌─ wgsl:2:26
2 │ struct Foo { sampler: f32 };
2 │ struct Foo { sampler: f32 }
│ ^^^^^^^ definition of `sampler`
"###,
@@ -843,8 +843,8 @@ fn invalid_arrays() {
#[test]
fn invalid_structs() {
check_validation_error! {
"struct Bad { data: sampler };",
"struct Bad { data: texture_2d<f32> };":
"struct Bad { data: sampler }",
"struct Bad { data: texture_2d<f32> }":
Err(naga::valid::ValidationError::Type {
error: naga::valid::TypeError::InvalidData(_),
..
@@ -852,7 +852,7 @@ fn invalid_structs() {
}
check_validation_error! {
"struct Bad { data: array<f32>, other: f32, };":
"struct Bad { data: array<f32>, other: f32, }":
Err(naga::valid::ValidationError::Type {
error: naga::valid::TypeError::InvalidDynamicArray(_, _),
..
@@ -865,7 +865,7 @@ fn invalid_functions() {
check_validation_error! {
"fn unacceptable_unsized(arg: array<f32>) { }",
"
struct Unsized { data: array<f32> };
struct Unsized { data: array<f32> }
fn unacceptable_unsized(arg: Unsized) { }
":
Err(naga::valid::ValidationError::Function {
@@ -883,7 +883,7 @@ fn invalid_functions() {
check_validation_error! {
"fn unacceptable_unsized(arg: ptr<workgroup, array<f32>>) { }",
"
struct Unsized { data: array<f32> };
struct Unsized { data: array<f32> }
fn unacceptable_unsized(arg: ptr<workgroup, Unsized>) { }
":
Err(naga::valid::ValidationError::Type {
@@ -1000,7 +1000,7 @@ fn missing_bindings() {
struct VertexIn {
@location(0) pos: vec4<f32>,
uv: vec2<f32>
};
}
@stage(vertex)
fn vertex(input: VertexIn) -> @location(0) vec4<f32> {
@@ -1088,7 +1088,7 @@ fn valid_access() {
fn invalid_local_vars() {
check_validation_error! {
"
struct Unsized { data: array<f32> };
struct Unsized { data: array<f32> }
fn local_ptr_dynamic_array(okay: ptr<storage, Unsized>) {
var not_okay: ptr<storage, array<f32>> = &(*okay).data;
}
@@ -1145,12 +1145,12 @@ fn invalid_runtime_sized_arrays() {
"
struct Unsized {
arr: array<f32>
};
}
struct Outer {
legit: i32,
unsized: Unsized
};
}
@group(0) @binding(0) var<storage> outer: Outer;
@@ -1187,7 +1187,7 @@ fn select() {
}
",
"
struct S { member: i32 };
struct S { member: i32 }
fn select_structs(which: bool) -> S {
var x: S = S(1);
var y: S = S(2);
@@ -1258,7 +1258,7 @@ fn wrong_access_mode() {
"
struct Globals {
i: i32
};
}
@group(0) @binding(0)
var<storage> globals: Globals;
@@ -1270,7 +1270,7 @@ fn wrong_access_mode() {
"
struct Globals {
i: i32
};
}
@group(0) @binding(0)
var<uniform> globals: Globals;