Skip to content

Commit

Permalink
update wgpu to 0.13 (bevyengine#5168)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
mockersf authored and ItsDoot committed Feb 1, 2023
1 parent 3017418 commit 3c4afc0
Show file tree
Hide file tree
Showing 70 changed files with 665 additions and 774 deletions.
2 changes: 1 addition & 1 deletion .github/bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ status = [
"miri",
"check-compiles",
"build-and-install-on-iOS",
"run-examples-on-windows",
"run-examples-on-windows-dx12",
]

use_squash_merge = true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validation-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ jobs:
- name: Build APK
run: cargo apk build --example android_example

run-examples-on-windows:
run-examples-on-windows-dx12:
runs-on: windows-latest
timeout-minutes: 30
timeout-minutes: 60
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
for example in .github/example-run/*.ron; do
example_name=`basename $example .ron`
echo "running $example_name - "`date`
time CI_TESTING_CONFIG=$example cargo run --example $example_name --features "bevy_ci_testing"
time WGPU_BACKEND=dx12 CI_TESTING_CONFIG=$example cargo run --example $example_name --features "bevy_ci_testing"
sleep 10
done
Expand Down
22 changes: 11 additions & 11 deletions assets/shaders/animate_shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#import bevy_pbr::mesh_types
#import bevy_pbr::mesh_view_bindings

[[group(1), binding(0)]]
@group(1) @binding(0)
var<uniform> mesh: Mesh;

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

struct Vertex {
[[location(0)]] position: vec3<f32>;
[[location(1)]] normal: vec3<f32>;
[[location(2)]] uv: vec2<f32>;
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) uv: vec2<f32>,
};

struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] uv: vec2<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) uv: vec2<f32>,
};

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


struct Time {
time_since_startup: f32;
time_since_startup: f32,
};
[[group(2), binding(0)]]
@group(2) @binding(0)
var<uniform> time: Time;


Expand All @@ -54,8 +54,8 @@ fn oklab_to_linear_srgb(c: vec3<f32>) -> vec3<f32> {
);
}

[[stage(fragment)]]
fn fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
let speed = 2.0;
let t_1 = sin(time.time_since_startup * speed) * 0.5 + 0.5;
let t_2 = cos(time.time_since_startup * speed);
Expand Down
22 changes: 7 additions & 15 deletions assets/shaders/array_texture.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,19 @@
#import bevy_pbr::shadows
#import bevy_pbr::pbr_functions

[[group(1), binding(0)]]
@group(1) @binding(0)
var my_array_texture: texture_2d_array<f32>;
[[group(1), binding(1)]]
@group(1) @binding(1)
var my_array_texture_sampler: sampler;

struct FragmentInput {
[[builtin(front_facing)]] is_front: bool;
[[builtin(position)]] frag_coord: vec4<f32>;
[[location(0)]] world_position: vec4<f32>;
[[location(1)]] world_normal: vec3<f32>;
[[location(2)]] uv: vec2<f32>;
#ifdef VERTEX_TANGENTS
[[location(3)]] world_tangent: vec4<f32>;
#endif
#ifdef VERTEX_COLORS
[[location(4)]] color: vec4<f32>;
#endif
@builtin(front_facing) is_front: bool,
@builtin(position) frag_coord: vec4<f32>,
#import bevy_pbr::mesh_vertex_output
};

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

// Prepare a 'processed' StandardMaterial by sampling all textures to resolve
Expand Down
14 changes: 8 additions & 6 deletions assets/shaders/custom_material.wgsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
struct CustomMaterial {
color: vec4<f32>;
color: vec4<f32>,
};

[[group(1), binding(0)]]
@group(1) @binding(0)
var<uniform> material: CustomMaterial;
[[group(1), binding(1)]]
@group(1) @binding(1)
var base_color_texture: texture_2d<f32>;
[[group(1), binding(2)]]
@group(1) @binding(2)
var base_color_sampler: sampler;

[[stage(fragment)]]
fn fragment([[location(2)]] uv: vec2<f32>) -> [[location(0)]] vec4<f32> {
@fragment
fn fragment(
#import bevy_pbr::mesh_vertex_output
) -> @location(0) vec4<f32> {
return material.color * textureSample(base_color_texture, base_color_sampler, uv);
}
12 changes: 7 additions & 5 deletions assets/shaders/custom_material_chromatic_aberration.wgsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#import bevy_pbr::mesh_view_bindings

[[group(1), binding(0)]]
@group(1) @binding(0)
var texture: texture_2d<f32>;

[[group(1), binding(1)]]
@group(1) @binding(1)
var our_sampler: sampler;


[[stage(fragment)]]
fn fragment([[builtin(position)]] position: vec4<f32>) -> [[location(0)]] vec4<f32> {
@fragment
fn fragment(
@builtin(position) position: vec4<f32>,
#import bevy_sprite::mesh2d_vertex_output
) -> @location(0) vec4<f32> {
// Get screen position with coordinates from 0 to 1
let uv = position.xy / vec2<f32>(view.width, view.height);
let offset_strength = 0.02;
Expand Down
11 changes: 7 additions & 4 deletions assets/shaders/custom_material_screenspace_texture.wgsl
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#import bevy_pbr::mesh_view_bindings

[[group(1), binding(0)]]
@group(1) @binding(0)
var texture: texture_2d<f32>;
[[group(1), binding(1)]]
@group(1) @binding(1)
var texture_sampler: sampler;

[[stage(fragment)]]
fn fragment([[builtin(position)]] position: vec4<f32>) -> [[location(0)]] vec4<f32> {
@fragment
fn fragment(
@builtin(position) position: vec4<f32>,
#import bevy_pbr::mesh_vertex_output
) -> @location(0) vec4<f32> {
let uv = position.xy / vec2<f32>(view.width, view.height);
let color = textureSample(texture, texture_sampler, uv);
return color;
Expand Down
20 changes: 10 additions & 10 deletions assets/shaders/custom_vertex_attribute.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
#import bevy_pbr::mesh_bindings

struct CustomMaterial {
color: vec4<f32>;
color: vec4<f32>,
};
[[group(1), binding(0)]]
@group(1) @binding(0)
var<uniform> material: CustomMaterial;

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

struct Vertex {
[[location(0)]] position: vec3<f32>;
[[location(1)]] blend_color: vec4<f32>;
@location(0) position: vec3<f32>,
@location(1) blend_color: vec4<f32>,
};

struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] blend_color: vec4<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) blend_color: vec4<f32>,
};

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

struct FragmentInput {
[[location(0)]] blend_color: vec4<f32>;
@location(0) blend_color: vec4<f32>,
};

[[stage(fragment)]]
fn fragment(input: FragmentInput) -> [[location(0)]] vec4<f32> {
@fragment
fn fragment(input: FragmentInput) -> @location(0) vec4<f32> {
return material.color * input.blend_color;
}
30 changes: 15 additions & 15 deletions assets/shaders/game_of_life.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[group(0), binding(0)]]
@group(0) @binding(0)
var texture: texture_storage_2d<rgba8unorm, read_write>;

fn hash(value: u32) -> u32 {
Expand All @@ -15,8 +15,8 @@ fn randomFloat(value: u32) -> f32 {
return f32(hash(value)) / 4294967295.0;
}

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

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


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

fn count_alive(location: vec2<i32>) -> i32 {
return get(location, -1, -1) +
get(location, -1, 0) +
get(location, -1, 1) +
get(location, 0, -1) +
get(location, 0, 1) +
get(location, 1, -1) +
get(location, 1, 0) +
get(location, 1, 1);
return is_alive(location, -1, -1) +
is_alive(location, -1, 0) +
is_alive(location, -1, 1) +
is_alive(location, 0, -1) +
is_alive(location, 0, 1) +
is_alive(location, 1, -1) +
is_alive(location, 1, 0) +
is_alive(location, 1, 1);
}

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

let n_alive = count_alive(location);
Expand All @@ -55,7 +55,7 @@ fn update([[builtin(global_invocation_id)]] invocation_id: vec3<u32>) {
if (n_alive == 3) {
alive = true;
} else if (n_alive == 2) {
let currently_alive = get(location, 0, 0);
let currently_alive = is_alive(location, 0, 0);
alive = bool(currently_alive);
} else {
alive = false;
Expand Down
22 changes: 11 additions & 11 deletions assets/shaders/instancing.wgsl
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#import bevy_pbr::mesh_types
#import bevy_pbr::mesh_view_bindings

[[group(1), binding(0)]]
@group(1) @binding(0)
var<uniform> mesh: Mesh;

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

struct Vertex {
[[location(0)]] position: vec3<f32>;
[[location(1)]] normal: vec3<f32>;
[[location(2)]] uv: vec2<f32>;
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) uv: vec2<f32>,

[[location(3)]] i_pos_scale: vec4<f32>;
[[location(4)]] i_color: vec4<f32>;
@location(3) i_pos_scale: vec4<f32>,
@location(4) i_color: vec4<f32>,
};

struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec4<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec4<f32>,
};

[[stage(vertex)]]
@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
let position = vertex.position * vertex.i_pos_scale.w + vertex.i_pos_scale.xyz;
var out: VertexOutput;
Expand All @@ -30,7 +30,7 @@ fn vertex(vertex: Vertex) -> VertexOutput {
return out;
}

[[stage(fragment)]]
fn fragment(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color;
}
10 changes: 6 additions & 4 deletions assets/shaders/shader_defs.wgsl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
struct CustomMaterial {
color: vec4<f32>;
color: vec4<f32>,
};

[[group(1), binding(0)]]
@group(1) @binding(0)
var<uniform> material: CustomMaterial;

[[stage(fragment)]]
fn fragment() -> [[location(0)]] vec4<f32> {
@fragment
fn fragment(
#import bevy_pbr::mesh_vertex_output
) -> @location(0) vec4<f32> {
#ifdef IS_RED
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
#else
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ thiserror = "1.0"
downcast-rs = "1.2.0"
fastrand = "1.7.0"
notify = { version = "=5.0.0-pre.11", optional = true }
parking_lot = "0.11.0"
parking_lot = "0.12.1"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2" }
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }
# other
anyhow = "1.0.4"
rodio = { version = "0.15", default-features = false }
parking_lot = "0.11.0"
parking_lot = "0.12.1"

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

0 comments on commit 3c4afc0

Please sign in to comment.