diff --git a/src/front/wgsl/lexer.rs b/src/front/wgsl/lexer.rs index 4d8e057ecf..fed5214c78 100644 --- a/src/front/wgsl/lexer.rs +++ b/src/front/wgsl/lexer.rs @@ -102,6 +102,15 @@ fn consume_token(mut input: &str) -> (Token<'_>, &str) { (Token::UnterminatedString, quote_content) } } + '/' if chars.as_str().starts_with('/') => { + match chars.position(|c| c == '\n' || c == '\r') { + Some(_) => { + input = chars.as_str(); + continue; + } + None => (Token::End, chars.as_str()), + } + } '-' => { let og_chars = chars.as_str(); match chars.next() { @@ -129,13 +138,6 @@ fn consume_token(mut input: &str) -> (Token<'_>, &str) { (Token::Operation(cur), input) } } - '#' => match chars.position(|c| c == '\n' || c == '\r') { - Some(_) => { - input = chars.as_str(); - continue; - } - None => (Token::End, chars.as_str()), - }, _ => (Token::Unknown(cur), chars.as_str()), }; } diff --git a/src/front/wgsl/tests.rs b/src/front/wgsl/tests.rs index c8b812497a..439a14f8bb 100644 --- a/src/front/wgsl/tests.rs +++ b/src/front/wgsl/tests.rs @@ -3,12 +3,12 @@ use super::parse_str; #[test] fn parse_comment() { parse_str( - "# - ## - ######################################################### asda - #################### dad ########## # - ##################################################################################################### - # + "// + //// + ///////////////////////////////////////////////////////// asda + //////////////////// dad ////////// / + ///////////////////////////////////////////////////////////////////////////////////////////////////// + // ", ) .unwrap(); diff --git a/test-data/simple/x.wgsl b/test-data/simple/x.wgsl index b35b83b426..563cf1645f 100644 --- a/test-data/simple/x.wgsl +++ b/test-data/simple/x.wgsl @@ -1,4 +1,4 @@ -# vertex +// vertex [[location(0)]] var a_pos : vec2; [[location(0)]] var o_pos : vec4; diff --git a/tests/snapshots/in/boids.wgsl b/tests/snapshots/in/boids.wgsl index 3d60518671..ec87eeab28 100644 --- a/tests/snapshots/in/boids.wgsl +++ b/tests/snapshots/in/boids.wgsl @@ -1,18 +1,18 @@ -# Copyright 2020 The Tint Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +// Copyright 2020 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. -# vertex shader +// vertex shader [[location(0)]] var a_particlePos : vec2; [[location(1)]] var a_particleVel : vec2; @@ -28,7 +28,7 @@ fn main() { gl_Position = vec4(pos + a_particlePos, 0.0, 1.0); } -# fragment shader +// fragment shader [[location(0)]] var fragColor : vec4; [[stage(fragment)]] @@ -36,7 +36,7 @@ fn main() { fragColor = vec4(1.0, 1.0, 1.0, 1.0); } -# compute shader +// compute shader [[block]] struct Particle { [[span(8)]] pos : vec2; @@ -65,7 +65,7 @@ struct Particles { [[builtin(global_invocation_id)]] var gl_GlobalInvocationID : vec3; -# https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp +// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp [[stage(compute), workgroup_size(1)]] fn main() { const index : u32 = gl_GlobalInvocationID.x; @@ -122,13 +122,13 @@ fn main() { vVel = vVel + (cMass * params.rule1Scale) + (colVel * params.rule2Scale) + (cVel * params.rule3Scale); - # clamp velocity for a more pleasing simulation + // clamp velocity for a more pleasing simulation vVel = normalize(vVel) * clamp(length(vVel), 0.0, 0.1); - # kinematic update + // kinematic update vPos = vPos + (vVel * params.deltaT); - # Wrap around boundary + // Wrap around boundary if (vPos.x < -1.0) { vPos.x = 1.0; } @@ -142,7 +142,7 @@ fn main() { vPos.y = -1.0; } - # Write back + // Write back particlesB.particles[index].pos = vPos; particlesB.particles[index].vel = vVel; } diff --git a/tests/snapshots/in/quad.wgsl b/tests/snapshots/in/quad.wgsl index d7b45f22df..bc619d5fc3 100644 --- a/tests/snapshots/in/quad.wgsl +++ b/tests/snapshots/in/quad.wgsl @@ -1,4 +1,4 @@ -# vertex +// vertex const c_scale: f32 = 1.2; [[location(0)]] var a_pos : vec2; [[location(1)]] var a_uv : vec2; @@ -11,7 +11,7 @@ fn main() { o_position = vec4(c_scale * a_pos, 0.0, 1.0); } -# fragment +// fragment [[location(0)]] var v_uv : vec2; [[group(0), binding(0)]] var u_texture : texture_2d; [[group(0), binding(1)]] var u_sampler : sampler; diff --git a/tests/snapshots/in/simple.wgsl b/tests/snapshots/in/simple.wgsl index ec43564123..54d4923569 100644 --- a/tests/snapshots/in/simple.wgsl +++ b/tests/snapshots/in/simple.wgsl @@ -1,4 +1,4 @@ -# vertex +// vertex [[builtin(position)]] var o_position : vec4; [[stage(vertex)]] diff --git a/tests/snapshots/in/skybox.wgsl b/tests/snapshots/in/skybox.wgsl index 42436f13b8..4cd8381339 100644 --- a/tests/snapshots/in/skybox.wgsl +++ b/tests/snapshots/in/skybox.wgsl @@ -3,7 +3,7 @@ var out_position: vec4; [[location(0)]] var out_uv: vec3; [[builtin(vertex_index)]] var in_vertex_index: u32; -#[[block]] +//[[block]] struct Data { proj_inv: mat4x4; view: mat4x4; @@ -13,7 +13,7 @@ var r_data: Data; [[stage(vertex)]] fn vs_main() { - # hacky way to draw a large triangle + // hacky way to draw a large triangle var tmp1: i32 = i32(in_vertex_index) / 2; var tmp2: i32 = i32(in_vertex_index) & 1; const pos: vec4 = vec4( @@ -24,7 +24,7 @@ fn vs_main() { ); const inv_model_view: mat3x3 = transpose(mat3x3(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz)); - var unprojected: vec4 = r_data.proj_inv * pos; #TODO: const + var unprojected: vec4 = r_data.proj_inv * pos; //TODO: const out_uv = inv_model_view * unprojected.xyz; out_position = pos; }