Skip to content

Commit ffa1fc0

Browse files
committed
update wgpu to 0.13 (#5168)
# Objective - Update wgpu to 0.13 - ~~Wait, is wgpu 0.13 released? No, but I had most of the changes already ready since playing with webgpu~~ well it has been released now - Also update parking_lot to 0.12 and naga to 0.9 ## Solution - Update syntax for wgsl shaders https://github.com/gfx-rs/wgpu/blob/master/CHANGELOG.md#wgsl-syntax - Add a few options, remove some references: https://github.com/gfx-rs/wgpu/blob/master/CHANGELOG.md#other-breaking-changes - fragment inputs should now exactly match vertex outputs for locations, so I added exports for those to be able to reuse them gfx-rs/wgpu#2704
1 parent c43295a commit ffa1fc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+664
-773
lines changed

.github/bors.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ status = [
1616
"miri",
1717
"check-compiles",
1818
"build-and-install-on-iOS",
19-
"run-examples-on-windows",
19+
"run-examples-on-windows-dx12",
2020
]
2121

2222
use_squash_merge = true

.github/workflows/validation-jobs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Build APK
6262
run: cargo apk build --example android_example
6363

64-
run-examples-on-windows:
64+
run-examples-on-windows-dx12:
6565
runs-on: windows-latest
6666
timeout-minutes: 30
6767
steps:
@@ -91,7 +91,7 @@ jobs:
9191
for example in .github/example-run/*.ron; do
9292
example_name=`basename $example .ron`
9393
echo "running $example_name - "`date`
94-
time CI_TESTING_CONFIG=$example cargo run --example $example_name --features "bevy_ci_testing"
94+
time WGPU_BACKEND=dx12 CI_TESTING_CONFIG=$example cargo run --example $example_name --features "bevy_ci_testing"
9595
sleep 10
9696
done
9797

assets/shaders/animate_shader.wgsl

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#import bevy_pbr::mesh_types
22
#import bevy_pbr::mesh_view_bindings
33

4-
[[group(1), binding(0)]]
4+
@group(1) @binding(0)
55
var<uniform> mesh: Mesh;
66

77
// NOTE: Bindings must come before functions that use them!
88
#import bevy_pbr::mesh_functions
99

1010
struct Vertex {
11-
[[location(0)]] position: vec3<f32>;
12-
[[location(1)]] normal: vec3<f32>;
13-
[[location(2)]] uv: vec2<f32>;
11+
@location(0) position: vec3<f32>,
12+
@location(1) normal: vec3<f32>,
13+
@location(2) uv: vec2<f32>,
1414
};
1515

1616
struct VertexOutput {
17-
[[builtin(position)]] clip_position: vec4<f32>;
18-
[[location(0)]] uv: vec2<f32>;
17+
@builtin(position) clip_position: vec4<f32>,
18+
@location(0) uv: vec2<f32>,
1919
};
2020

21-
[[stage(vertex)]]
21+
@vertex
2222
fn vertex(vertex: Vertex) -> VertexOutput {
2323
var out: VertexOutput;
2424
out.clip_position = mesh_position_local_to_clip(mesh.model, vec4<f32>(vertex.position, 1.0));
@@ -28,9 +28,9 @@ fn vertex(vertex: Vertex) -> VertexOutput {
2828

2929

3030
struct Time {
31-
time_since_startup: f32;
31+
time_since_startup: f32,
3232
};
33-
[[group(2), binding(0)]]
33+
@group(2) @binding(0)
3434
var<uniform> time: Time;
3535

3636

@@ -54,8 +54,8 @@ fn oklab_to_linear_srgb(c: vec3<f32>) -> vec3<f32> {
5454
);
5555
}
5656

57-
[[stage(fragment)]]
58-
fn fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> {
57+
@fragment
58+
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
5959
let speed = 2.0;
6060
let t_1 = sin(time.time_since_startup * speed) * 0.5 + 0.5;
6161
let t_2 = cos(time.time_since_startup * speed);

assets/shaders/array_texture.wgsl

+7-15
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,19 @@
88
#import bevy_pbr::shadows
99
#import bevy_pbr::pbr_functions
1010

11-
[[group(1), binding(0)]]
11+
@group(1) @binding(0)
1212
var my_array_texture: texture_2d_array<f32>;
13-
[[group(1), binding(1)]]
13+
@group(1) @binding(1)
1414
var my_array_texture_sampler: sampler;
1515

1616
struct FragmentInput {
17-
[[builtin(front_facing)]] is_front: bool;
18-
[[builtin(position)]] frag_coord: vec4<f32>;
19-
[[location(0)]] world_position: vec4<f32>;
20-
[[location(1)]] world_normal: vec3<f32>;
21-
[[location(2)]] uv: vec2<f32>;
22-
#ifdef VERTEX_TANGENTS
23-
[[location(3)]] world_tangent: vec4<f32>;
24-
#endif
25-
#ifdef VERTEX_COLORS
26-
[[location(4)]] color: vec4<f32>;
27-
#endif
17+
@builtin(front_facing) is_front: bool,
18+
@builtin(position) frag_coord: vec4<f32>,
19+
#import bevy_pbr::mesh_vertex_output
2820
};
2921

30-
[[stage(fragment)]]
31-
fn fragment(in: FragmentInput) -> [[location(0)]] vec4<f32> {
22+
@fragment
23+
fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
3224
let layer = i32(in.world_position.x) & 0x3;
3325

3426
// Prepare a 'processed' StandardMaterial by sampling all textures to resolve

assets/shaders/custom_material.wgsl

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
struct CustomMaterial {
2-
color: vec4<f32>;
2+
color: vec4<f32>,
33
};
44

5-
[[group(1), binding(0)]]
5+
@group(1) @binding(0)
66
var<uniform> material: CustomMaterial;
7-
[[group(1), binding(1)]]
7+
@group(1) @binding(1)
88
var base_color_texture: texture_2d<f32>;
9-
[[group(1), binding(2)]]
9+
@group(1) @binding(2)
1010
var base_color_sampler: sampler;
1111

12-
[[stage(fragment)]]
13-
fn fragment([[location(2)]] uv: vec2<f32>) -> [[location(0)]] vec4<f32> {
12+
@fragment
13+
fn fragment(
14+
#import bevy_pbr::mesh_vertex_output
15+
) -> @location(0) vec4<f32> {
1416
return material.color * textureSample(base_color_texture, base_color_sampler, uv);
1517
}

assets/shaders/custom_material_chromatic_aberration.wgsl

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#import bevy_pbr::mesh_view_bindings
22

3-
[[group(1), binding(0)]]
3+
@group(1) @binding(0)
44
var texture: texture_2d<f32>;
55

6-
[[group(1), binding(1)]]
6+
@group(1) @binding(1)
77
var our_sampler: sampler;
88

9-
10-
[[stage(fragment)]]
11-
fn fragment([[builtin(position)]] position: vec4<f32>) -> [[location(0)]] vec4<f32> {
9+
@fragment
10+
fn fragment(
11+
@builtin(position) position: vec4<f32>,
12+
#import bevy_sprite::mesh2d_vertex_output
13+
) -> @location(0) vec4<f32> {
1214
// Get screen position with coordinates from 0 to 1
1315
let uv = position.xy / vec2<f32>(view.width, view.height);
1416
let offset_strength = 0.02;

assets/shaders/custom_material_screenspace_texture.wgsl

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#import bevy_pbr::mesh_view_bindings
22

3-
[[group(1), binding(0)]]
3+
@group(1) @binding(0)
44
var texture: texture_2d<f32>;
5-
[[group(1), binding(1)]]
5+
@group(1) @binding(1)
66
var texture_sampler: sampler;
77

8-
[[stage(fragment)]]
9-
fn fragment([[builtin(position)]] position: vec4<f32>) -> [[location(0)]] vec4<f32> {
8+
@fragment
9+
fn fragment(
10+
@builtin(position) position: vec4<f32>,
11+
#import bevy_pbr::mesh_vertex_output
12+
) -> @location(0) vec4<f32> {
1013
let uv = position.xy / vec2<f32>(view.width, view.height);
1114
let color = textureSample(texture, texture_sampler, uv);
1215
return color;

assets/shaders/custom_vertex_attribute.wgsl

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
#import bevy_pbr::mesh_bindings
33

44
struct CustomMaterial {
5-
color: vec4<f32>;
5+
color: vec4<f32>,
66
};
7-
[[group(1), binding(0)]]
7+
@group(1) @binding(0)
88
var<uniform> material: CustomMaterial;
99

1010
// NOTE: Bindings must come before functions that use them!
1111
#import bevy_pbr::mesh_functions
1212

1313
struct Vertex {
14-
[[location(0)]] position: vec3<f32>;
15-
[[location(1)]] blend_color: vec4<f32>;
14+
@location(0) position: vec3<f32>,
15+
@location(1) blend_color: vec4<f32>,
1616
};
1717

1818
struct VertexOutput {
19-
[[builtin(position)]] clip_position: vec4<f32>;
20-
[[location(0)]] blend_color: vec4<f32>;
19+
@builtin(position) clip_position: vec4<f32>,
20+
@location(0) blend_color: vec4<f32>,
2121
};
2222

23-
[[stage(vertex)]]
23+
@vertex
2424
fn vertex(vertex: Vertex) -> VertexOutput {
2525
var out: VertexOutput;
2626
out.clip_position = mesh_position_local_to_clip(mesh.model, vec4<f32>(vertex.position, 1.0));
@@ -29,10 +29,10 @@ fn vertex(vertex: Vertex) -> VertexOutput {
2929
}
3030

3131
struct FragmentInput {
32-
[[location(0)]] blend_color: vec4<f32>;
32+
@location(0) blend_color: vec4<f32>,
3333
};
3434

35-
[[stage(fragment)]]
36-
fn fragment(input: FragmentInput) -> [[location(0)]] vec4<f32> {
35+
@fragment
36+
fn fragment(input: FragmentInput) -> @location(0) vec4<f32> {
3737
return material.color * input.blend_color;
3838
}

assets/shaders/game_of_life.wgsl

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[[group(0), binding(0)]]
1+
@group(0) @binding(0)
22
var texture: texture_storage_2d<rgba8unorm, read_write>;
33

44
fn hash(value: u32) -> u32 {
@@ -15,8 +15,8 @@ fn randomFloat(value: u32) -> f32 {
1515
return f32(hash(value)) / 4294967295.0;
1616
}
1717

18-
[[stage(compute), workgroup_size(8, 8, 1)]]
19-
fn init([[builtin(global_invocation_id)]] invocation_id: vec3<u32>, [[builtin(num_workgroups)]] num_workgroups: vec3<u32>) {
18+
@compute @workgroup_size(8, 8, 1)
19+
fn init(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_workgroups) num_workgroups: vec3<u32>) {
2020
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
2121
let location_f32 = vec2<f32>(f32(invocation_id.x), f32(invocation_id.y));
2222

@@ -28,24 +28,24 @@ fn init([[builtin(global_invocation_id)]] invocation_id: vec3<u32>, [[builtin(nu
2828
}
2929

3030

31-
fn get(location: vec2<i32>, offset_x: i32, offset_y: i32) -> i32 {
31+
fn is_alive(location: vec2<i32>, offset_x: i32, offset_y: i32) -> i32 {
3232
let value: vec4<f32> = textureLoad(texture, location + vec2<i32>(offset_x, offset_y));
3333
return i32(value.x);
3434
}
3535

3636
fn count_alive(location: vec2<i32>) -> i32 {
37-
return get(location, -1, -1) +
38-
get(location, -1, 0) +
39-
get(location, -1, 1) +
40-
get(location, 0, -1) +
41-
get(location, 0, 1) +
42-
get(location, 1, -1) +
43-
get(location, 1, 0) +
44-
get(location, 1, 1);
37+
return is_alive(location, -1, -1) +
38+
is_alive(location, -1, 0) +
39+
is_alive(location, -1, 1) +
40+
is_alive(location, 0, -1) +
41+
is_alive(location, 0, 1) +
42+
is_alive(location, 1, -1) +
43+
is_alive(location, 1, 0) +
44+
is_alive(location, 1, 1);
4545
}
4646

47-
[[stage(compute), workgroup_size(8, 8, 1)]]
48-
fn update([[builtin(global_invocation_id)]] invocation_id: vec3<u32>) {
47+
@compute @workgroup_size(8, 8, 1)
48+
fn update(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
4949
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
5050

5151
let n_alive = count_alive(location);
@@ -55,7 +55,7 @@ fn update([[builtin(global_invocation_id)]] invocation_id: vec3<u32>) {
5555
if (n_alive == 3) {
5656
alive = true;
5757
} else if (n_alive == 2) {
58-
let currently_alive = get(location, 0, 0);
58+
let currently_alive = is_alive(location, 0, 0);
5959
alive = bool(currently_alive);
6060
} else {
6161
alive = false;

assets/shaders/instancing.wgsl

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
#import bevy_pbr::mesh_types
22
#import bevy_pbr::mesh_view_bindings
33

4-
[[group(1), binding(0)]]
4+
@group(1) @binding(0)
55
var<uniform> mesh: Mesh;
66

77
// NOTE: Bindings must come before functions that use them!
88
#import bevy_pbr::mesh_functions
99

1010
struct Vertex {
11-
[[location(0)]] position: vec3<f32>;
12-
[[location(1)]] normal: vec3<f32>;
13-
[[location(2)]] uv: vec2<f32>;
11+
@location(0) position: vec3<f32>,
12+
@location(1) normal: vec3<f32>,
13+
@location(2) uv: vec2<f32>,
1414

15-
[[location(3)]] i_pos_scale: vec4<f32>;
16-
[[location(4)]] i_color: vec4<f32>;
15+
@location(3) i_pos_scale: vec4<f32>,
16+
@location(4) i_color: vec4<f32>,
1717
};
1818

1919
struct VertexOutput {
20-
[[builtin(position)]] clip_position: vec4<f32>;
21-
[[location(0)]] color: vec4<f32>;
20+
@builtin(position) clip_position: vec4<f32>,
21+
@location(0) color: vec4<f32>,
2222
};
2323

24-
[[stage(vertex)]]
24+
@vertex
2525
fn vertex(vertex: Vertex) -> VertexOutput {
2626
let position = vertex.position * vertex.i_pos_scale.w + vertex.i_pos_scale.xyz;
2727
var out: VertexOutput;
@@ -30,7 +30,7 @@ fn vertex(vertex: Vertex) -> VertexOutput {
3030
return out;
3131
}
3232

33-
[[stage(fragment)]]
34-
fn fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> {
33+
@fragment
34+
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
3535
return in.color;
3636
}

assets/shaders/shader_defs.wgsl

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
struct CustomMaterial {
2-
color: vec4<f32>;
2+
color: vec4<f32>,
33
};
44

5-
[[group(1), binding(0)]]
5+
@group(1) @binding(0)
66
var<uniform> material: CustomMaterial;
77

8-
[[stage(fragment)]]
9-
fn fragment() -> [[location(0)]] vec4<f32> {
8+
@fragment
9+
fn fragment(
10+
#import bevy_pbr::mesh_vertex_output
11+
) -> @location(0) vec4<f32> {
1012
#ifdef IS_RED
1113
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
1214
#else

crates/bevy_asset/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ thiserror = "1.0"
3131
downcast-rs = "1.2.0"
3232
fastrand = "1.7.0"
3333
notify = { version = "=5.0.0-pre.11", optional = true }
34-
parking_lot = "0.11.0"
34+
parking_lot = "0.12.1"
3535

3636
[target.'cfg(target_arch = "wasm32")'.dependencies]
3737
wasm-bindgen = { version = "0.2" }

crates/bevy_audio/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }
1919
# other
2020
anyhow = "1.0.4"
2121
rodio = { version = "0.15", default-features = false }
22-
parking_lot = "0.11.0"
22+
parking_lot = "0.12.1"
2323

2424
[target.'cfg(target_arch = "wasm32")'.dependencies]
2525
rodio = { version = "0.15", default-features = false, features = ["wasm-bindgen"] }

0 commit comments

Comments
 (0)