Merge pull request #2606 from jimblandy/avoid-reserved-words

Avoid new WGSL reserved words in wgpu examples.
This commit is contained in:
Jim Blandy
2022-04-18 08:40:29 -07:00
committed by GitHub
11 changed files with 82 additions and 82 deletions

View File

@@ -1,9 +1,9 @@
@group(0)
@binding(0)
var<storage, read_write> buffer: array<u32>;
var<storage, read_write> buf: array<u32>;
@compute
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
buffer[global_id.x] = buffer[global_id.x] + global_id.x;
buf[global_id.x] = buf[global_id.x] + global_id.x;
}

View File

@@ -34,12 +34,12 @@ fn vs_main(@builtin(vertex_index) vi: u32) -> VertexOutput {
@group(0)
@binding(1)
var texture: texture_2d<f32>;
var tex: texture_2d<f32>;
@group(0)
@binding(2)
var sam: sampler;
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color * textureSampleLevel(texture, sam, in.tex_coords, 0.0);
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
return vertex.color * textureSampleLevel(tex, sam, vertex.tex_coords, 0.0);
}

View File

@@ -7,10 +7,10 @@ struct VertexOutput {
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
let x: f32 = f32(i32(vertex_index & 1u) << 2u) - 1.0;
let y: f32 = f32(i32(vertex_index & 2u) << 1u) - 1.0;
var output: VertexOutput;
output.position = vec4<f32>(x, -y, 0.0, 1.0);
output.tex_coords = vec2<f32>(x + 1.0, y + 1.0) * 0.5;
return output;
var result: VertexOutput;
result.position = vec4<f32>(x, -y, 0.0, 1.0);
result.tex_coords = vec2<f32>(x + 1.0, y + 1.0) * 0.5;
return result;
}
@group(0)
@@ -21,6 +21,6 @@ var r_color: texture_2d<f32>;
var r_sampler: sampler;
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, vertex.tex_coords);
}

View File

@@ -15,10 +15,10 @@ fn vs_main(
@location(0) position: vec4<f32>,
@location(1) tex_coord: vec2<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coord = tex_coord;
out.position = r_locals.transform * position;
return out;
var result: VertexOutput;
result.tex_coord = tex_coord;
result.position = r_locals.transform * position;
return result;
}
@group(0)
@@ -26,8 +26,8 @@ fn vs_main(
var r_color: texture_2d<u32>;
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let tex = textureLoad(r_color, vec2<i32>(in.tex_coord * 256.0), 0);
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
let tex = textureLoad(r_color, vec2<i32>(vertex.tex_coord * 256.0), 0);
let v = f32(tex.x) / 255.0;
return vec4<f32>(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0);
}

View File

@@ -5,20 +5,20 @@ struct VertexOutput {
@vertex
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
var out: VertexOutput;
var result: VertexOutput;
let x = i32(vertex_index) / 2;
let y = i32(vertex_index) & 1;
let tc = vec2<f32>(
f32(x) * 2.0,
f32(y) * 2.0
);
out.position = vec4<f32>(
result.position = vec4<f32>(
tc.x * 2.0 - 1.0,
1.0 - tc.y * 2.0,
0.0, 1.0
);
out.tex_coords = tc;
return out;
result.tex_coords = tc;
return result;
}
@group(0)
@@ -29,6 +29,6 @@ var r_color: texture_2d<f32>;
var r_sampler: sampler;
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, vertex.tex_coords);
}

View File

@@ -16,10 +16,10 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
100.0 * (1.0 - f32(vertex_index & 2u)),
1000.0 * f32(vertex_index & 1u)
);
var out: VertexOutput;
out.tex_coords = 0.05 * pos + vec2<f32>(0.5, 0.5);
out.position = r_data.transform * vec4<f32>(pos, 0.0, 1.0);
return out;
var result: VertexOutput;
result.tex_coords = 0.05 * pos + vec2<f32>(0.5, 0.5);
result.position = r_data.transform * vec4<f32>(pos, 0.0, 1.0);
return result;
}
@group(0)
@@ -30,6 +30,6 @@ var r_color: texture_2d<f32>;
var r_sampler: sampler;
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, vertex.tex_coords);
}

View File

@@ -8,13 +8,13 @@ fn vs_main(
@location(0) position: vec2<f32>,
@location(1) color: vec4<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.position = vec4<f32>(position, 0.0, 1.0);
out.color = color;
return out;
var result: VertexOutput;
result.position = vec4<f32>(position, 0.0, 1.0);
result.color = color;
return result;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color;
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
return vertex.color;
}

View File

@@ -34,11 +34,11 @@ fn vs_main(
) -> VertexOutput {
let w = u_entity.world;
let world_pos = u_entity.world * vec4<f32>(position);
var out: VertexOutput;
out.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
out.world_position = world_pos;
out.proj_position = u_globals.view_proj * world_pos;
return out;
var result: VertexOutput;
result.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
result.world_position = world_pos;
result.proj_position = u_globals.view_proj * world_pos;
return result;
}
// fragment shader
@@ -79,16 +79,16 @@ let c_ambient: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);
let c_max_lights: u32 = 10u;
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(vertex.world_normal);
// accumulate color
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) {
let light = s_lights[i];
// project into the light space
let shadow = fetch_shadow(i, light.proj * in.world_position);
let shadow = fetch_shadow(i, light.proj * vertex.world_position);
// compute Lambertian diffuse term
let light_dir = normalize(light.pos.xyz - in.world_position.xyz);
let light_dir = normalize(light.pos.xyz - vertex.world_position.xyz);
let diffuse = max(0.0, dot(normal, light_dir));
// add light contribution
color += shadow * diffuse * light.color.xyz;
@@ -99,15 +99,15 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
// The fragment entrypoint used when storage buffers are not available for the lights
@fragment
fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
fn fs_main_without_storage(vertex: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(vertex.world_normal);
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) {
// This line is the only difference from the entrypoint above. It uses the lights
// uniform instead of the lights storage buffer
let light = u_lights[i];
let shadow = fetch_shadow(i, light.proj * in.world_position);
let light_dir = normalize(light.pos.xyz - in.world_position.xyz);
let shadow = fetch_shadow(i, light.proj * vertex.world_position);
let light_dir = normalize(light.pos.xyz - vertex.world_position.xyz);
let diffuse = max(0.0, dot(normal, light_dir));
color += shadow * diffuse * light.color.xyz;
}

View File

@@ -33,10 +33,10 @@ fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput {
let inv_model_view = transpose(mat3x3<f32>(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz));
let unprojected = r_data.proj_inv * pos;
var out: SkyOutput;
out.uv = inv_model_view * unprojected.xyz;
out.position = pos;
return out;
var result: SkyOutput;
result.uv = inv_model_view * unprojected.xyz;
result.position = pos;
return result;
}
struct EntityOutput {
@@ -50,11 +50,11 @@ fn vs_entity(
@location(0) pos: vec3<f32>,
@location(1) normal: vec3<f32>,
) -> EntityOutput {
var out: EntityOutput;
out.normal = normal;
out.view = pos - r_data.cam_pos.xyz;
out.position = r_data.proj * r_data.view * vec4<f32>(pos, 1.0);
return out;
var result: EntityOutput;
result.normal = normal;
result.view = pos - r_data.cam_pos.xyz;
result.position = r_data.proj * r_data.view * vec4<f32>(pos, 1.0);
return result;
}
@group(0)
@@ -65,14 +65,14 @@ var r_texture: texture_cube<f32>;
var r_sampler: sampler;
@fragment
fn fs_sky(in: SkyOutput) -> @location(0) vec4<f32> {
return textureSample(r_texture, r_sampler, in.uv);
fn fs_sky(vertex: SkyOutput) -> @location(0) vec4<f32> {
return textureSample(r_texture, r_sampler, vertex.uv);
}
@fragment
fn fs_entity(in: EntityOutput) -> @location(0) vec4<f32> {
let incident = normalize(in.view);
let normal = normalize(in.normal);
fn fs_entity(vertex: EntityOutput) -> @location(0) vec4<f32> {
let incident = normalize(vertex.view);
let normal = normalize(vertex.normal);
let reflected = incident - 2.0 * dot(normal, incident) * normal;
let reflected_color = textureSample(r_texture, r_sampler, reflected).rgb;

View File

@@ -24,27 +24,27 @@ fn vs_main(
@location(1) normal: vec3<f32>,
@location(2) colour: vec4<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.position = uniforms.projection_view * vec4<f32>(position, 1.0);
var result: VertexOutput;
result.position = uniforms.projection_view * vec4<f32>(position, 1.0);
// https://www.desmos.com/calculator/nqgyaf8uvo
let normalized_light_direction = normalize(position - light);
let brightness_diffuse = clamp(dot(normalized_light_direction, normal), 0.2, 1.0);
out.colour = vec4<f32>(max((brightness_diffuse + ambient) * light_colour * colour.rgb, vec3<f32>(0.0, 0.0, 0.0)), colour.a);
out.clip_dist = dot(vec4<f32>(position, 1.0), uniforms.clipping_plane);
return out;
result.colour = vec4<f32>(max((brightness_diffuse + ambient) * light_colour * colour.rgb, vec3<f32>(0.0, 0.0, 0.0)), colour.a);
result.clip_dist = dot(vec4<f32>(position, 1.0), uniforms.clipping_plane);
return result;
}
@fragment
@early_depth_test
fn fs_main(
in: VertexOutput,
vertex: VertexOutput,
) -> @location(0) vec4<f32> {
// Comment this out if using user-clipping planes:
if(in.clip_dist < 0.0) {
if(vertex.clip_dist < 0.0) {
discard;
}
return vec4<f32>(in.colour.xyz, 1.0);
return vec4<f32>(vertex.colour.xyz, 1.0);
}

View File

@@ -206,15 +206,15 @@ fn vs_main(
let eye = normalize(-water_pos);
let transformed_light = vm * vec4<f32>(light_point, 1.0);
var out: VertexOutput;
out.f_Light = light_colour * calc_specular(eye, normal, normalize(water_pos.xyz - (transformed_light.xyz * (1.0 / transformed_light.w))));
out.f_Fresnel = calc_fresnel(eye, normal);
var result: VertexOutput;
result.f_Light = light_colour * calc_specular(eye, normal, normalize(water_pos.xyz - (transformed_light.xyz * (1.0 / transformed_light.w))));
result.f_Fresnel = calc_fresnel(eye, normal);
let gridpos = uniforms.projection * vm * original_pos;
out.f_WaterScreenPos = (0.5 * gridpos.xy * (1.0 / gridpos.w)) + vec2<f32>(0.5, 0.5);
result.f_WaterScreenPos = (0.5 * gridpos.xy * (1.0 / gridpos.w)) + vec2<f32>(0.5, 0.5);
out.position = uniforms.projection * transformed_pos;
return out;
result.position = uniforms.projection * transformed_pos;
return result;
}
@@ -234,19 +234,19 @@ fn to_linear_depth(depth: f32) -> f32 {
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let reflection_colour = textureSample(reflection, colour_sampler, in.f_WaterScreenPos.xy).xyz;
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
let reflection_colour = textureSample(reflection, colour_sampler, vertex.f_WaterScreenPos.xy).xyz;
let pixel_depth = to_linear_depth(in.position.z);
let normalized_coords = in.position.xy / vec2<f32>(uniforms.time_size_width.w, uniforms.viewport_height);
let pixel_depth = to_linear_depth(vertex.position.z);
let normalized_coords = vertex.position.xy / vec2<f32>(uniforms.time_size_width.w, uniforms.viewport_height);
let terrain_depth = to_linear_depth(textureSample(terrain_depth_tex, depth_sampler, normalized_coords).r);
let dist = terrain_depth - pixel_depth;
let clamped = pow(smoothstep(0.0, 1.5, dist), 4.8);
let final_colour = in.f_Light + reflection_colour;
let final_colour = vertex.f_Light + reflection_colour;
let t = smoothstep(1.0, 5.0, dist) * 0.2; //TODO: splat for mix()?
let depth_colour = mix(final_colour, water_colour, vec3<f32>(t, t, t));
return vec4<f32>(depth_colour, clamped * (1.0 - in.f_Fresnel));
return vec4<f32>(depth_colour, clamped * (1.0 - vertex.f_Fresnel));
}