mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
WGSL // comments
- Update parser to match the latest spec: https://github.com/gpuweb/gpuweb/pull/1326
This commit is contained in:
committed by
Dzmitry Malyshau
parent
6710f5954e
commit
3bf7f41068
@@ -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()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ use super::parse_str;
|
||||
#[test]
|
||||
fn parse_comment() {
|
||||
parse_str(
|
||||
"#
|
||||
##
|
||||
######################################################### asda
|
||||
#################### dad ########## #
|
||||
#####################################################################################################
|
||||
#
|
||||
"//
|
||||
////
|
||||
///////////////////////////////////////////////////////// asda
|
||||
//////////////////// dad ////////// /
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# vertex
|
||||
// vertex
|
||||
[[location(0)]] var<in> a_pos : vec2<f32>;
|
||||
[[location(0)]] var<out> o_pos : vec4<f32>;
|
||||
|
||||
|
||||
@@ -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<in> a_particlePos : vec2<f32>;
|
||||
[[location(1)]] var<in> a_particleVel : vec2<f32>;
|
||||
@@ -28,7 +28,7 @@ fn main() {
|
||||
gl_Position = vec4<f32>(pos + a_particlePos, 0.0, 1.0);
|
||||
}
|
||||
|
||||
# fragment shader
|
||||
// fragment shader
|
||||
[[location(0)]] var<out> fragColor : vec4<f32>;
|
||||
|
||||
[[stage(fragment)]]
|
||||
@@ -36,7 +36,7 @@ fn main() {
|
||||
fragColor = vec4<f32>(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
# compute shader
|
||||
// compute shader
|
||||
[[block]]
|
||||
struct Particle {
|
||||
[[span(8)]] pos : vec2<f32>;
|
||||
@@ -65,7 +65,7 @@ struct Particles {
|
||||
|
||||
[[builtin(global_invocation_id)]] var gl_GlobalInvocationID : vec3<u32>;
|
||||
|
||||
# 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;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# vertex
|
||||
// vertex
|
||||
const c_scale: f32 = 1.2;
|
||||
[[location(0)]] var<in> a_pos : vec2<f32>;
|
||||
[[location(1)]] var<in> a_uv : vec2<f32>;
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
o_position = vec4<f32>(c_scale * a_pos, 0.0, 1.0);
|
||||
}
|
||||
|
||||
# fragment
|
||||
// fragment
|
||||
[[location(0)]] var<in> v_uv : vec2<f32>;
|
||||
[[group(0), binding(0)]] var u_texture : texture_2d<f32>;
|
||||
[[group(0), binding(1)]] var u_sampler : sampler;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# vertex
|
||||
// vertex
|
||||
[[builtin(position)]] var<out> o_position : vec4<f32>;
|
||||
|
||||
[[stage(vertex)]]
|
||||
|
||||
@@ -3,7 +3,7 @@ var<out> out_position: vec4<f32>;
|
||||
[[location(0)]] var<out> out_uv: vec3<f32>;
|
||||
[[builtin(vertex_index)]] var<in> in_vertex_index: u32;
|
||||
|
||||
#[[block]]
|
||||
//[[block]]
|
||||
struct Data {
|
||||
proj_inv: mat4x4<f32>;
|
||||
view: mat4x4<f32>;
|
||||
@@ -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<f32> = vec4<f32>(
|
||||
@@ -24,7 +24,7 @@ fn vs_main() {
|
||||
);
|
||||
|
||||
const inv_model_view: mat3x3<f32> = transpose(mat3x3<f32>(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz));
|
||||
var unprojected: vec4<f32> = r_data.proj_inv * pos; #TODO: const
|
||||
var unprojected: vec4<f32> = r_data.proj_inv * pos; //TODO: const
|
||||
out_uv = inv_model_view * unprojected.xyz;
|
||||
out_position = pos;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user