1
0
Fork 0

[WGPU] Migrate to 0.13

This commit is contained in:
Florian RICHER 2022-07-02 15:21:22 +02:00
parent 131123842c
commit af551ebc2a
7 changed files with 98 additions and 77 deletions

57
Cargo.lock generated
View file

@ -34,6 +34,15 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "android_system_properties"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a20ae67ce26261f218e2b3f2f0d01887a9818283ca6fb260fa7c67e253d61c92"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.58" version = "1.0.58"
@ -57,9 +66,9 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]] [[package]]
name = "ash" name = "ash"
version = "0.34.0+1.2.203" version = "0.37.0+1.3.209"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0f780da53d0063880d45554306489f09dd8d1bda47688b4a57bc579119356df" checksum = "006ca68e0f2b03f22d6fa9f2860f85aed430d257fec20f8879b2145e7c7ae1a6"
dependencies = [ dependencies = [
"libloading", "libloading",
] ]
@ -558,9 +567,9 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
[[package]] [[package]]
name = "d3d12" name = "d3d12"
version = "0.4.1" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c" checksum = "827914e1f53b1e0e025ecd3d967a7836b7bcb54520f90e21ef8df7b4d88a2759"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"libloading", "libloading",
@ -1089,6 +1098,7 @@ checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3"
dependencies = [ dependencies = [
"libc", "libc",
"libloading", "libloading",
"pkg-config",
] ]
[[package]] [[package]]
@ -1183,9 +1193,9 @@ dependencies = [
[[package]] [[package]]
name = "metal" name = "metal"
version = "0.23.1" version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0514f491f4cc03632ab399ee01e2c1c1b12d3e1cf2d667c1ff5f87d6dcd2084" checksum = "de11355d1f6781482d027a3b4d4de7825dcedb197bf573e0596d00008402d060"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"block", "block",
@ -1230,9 +1240,9 @@ dependencies = [
[[package]] [[package]]
name = "naga" name = "naga"
version = "0.8.5" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3012f2dbcc79e8e0b5825a4836a7106a75dd9b2fe42c528163be0f572538c705" checksum = "5f50357e1167a3ab92d6b3c7f4bf5f7fd13fde3f4b28bf0d5ea07b5100fdb6c0"
dependencies = [ dependencies = [
"bit-set", "bit-set",
"bitflags", "bitflags",
@ -1243,7 +1253,9 @@ dependencies = [
"num-traits", "num-traits",
"rustc-hash", "rustc-hash",
"spirv", "spirv",
"termcolor",
"thiserror", "thiserror",
"unicode-xid",
] ]
[[package]] [[package]]
@ -2085,6 +2097,12 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
[[package]] [[package]]
name = "url" name = "url"
version = "2.2.2" version = "2.2.2"
@ -2282,9 +2300,9 @@ dependencies = [
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.57" version = "0.3.58"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -2301,9 +2319,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu" name = "wgpu"
version = "0.12.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97cd781ff044d6d697b632a2e212032c2e957d1afaa21dbf58069cbb8f78567" checksum = "fd28e7c69ffd19c02e609322e4170738ac3340e699d8adfa16f5745625e4aa8c"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"js-sys", "js-sys",
@ -2322,11 +2340,12 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-core" name = "wgpu-core"
version = "0.12.2" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4688c000eb841ca55f7b35db659b78d6e1cd77d7caf8fb929f4e181f754047d" checksum = "0bb155661d02bf104303589fbf9206fa971c80dbb6d4763e66879253bd0a072c"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"bit-vec",
"bitflags", "bitflags",
"cfg_aliases", "cfg_aliases",
"codespan-reporting", "codespan-reporting",
@ -2339,16 +2358,18 @@ dependencies = [
"raw-window-handle", "raw-window-handle",
"smallvec", "smallvec",
"thiserror", "thiserror",
"web-sys",
"wgpu-hal", "wgpu-hal",
"wgpu-types", "wgpu-types",
] ]
[[package]] [[package]]
name = "wgpu-hal" name = "wgpu-hal"
version = "0.12.5" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d684ea6a34974a2fc19f1dfd183d11a62e22d75c4f187a574bb1224df8e056c2" checksum = "a9f9cb367209e2ad214afa8d823348334994dc1579f4a521d53a3bc4d0848e73"
dependencies = [ dependencies = [
"android_system_properties",
"arrayvec", "arrayvec",
"ash", "ash",
"bit-set", "bit-set",
@ -2383,9 +2404,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-types" name = "wgpu-types"
version = "0.12.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "549533d9e1cdd4b4cda7718d33ff500fc4c34b5467b71d76b547ae0324f3b2a2" checksum = "f48d691b733b9d50ea8cb18f377fd1ed927c90c55ad1ec5b90f68885471977f7"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]

View file

@ -17,7 +17,7 @@ pollster = "0.2"
log = "0.4" log = "0.4"
rayon = "1.4" rayon = "1.4"
tobj = { version = "3.2", features = ["async"]} tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.12"} wgpu = { version = "0.13"}
winit = "0.26" winit = "0.26"
instant = "0.1" instant = "0.1"
async-std = "1" async-std = "1"
@ -31,7 +31,7 @@ features = ["png", "jpeg"]
reqwest = { version = "0.11" } reqwest = { version = "0.11" }
console_error_panic_hook = "0.1" console_error_panic_hook = "0.1"
console_log = "0.2" console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]} wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4" wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [ web-sys = { version = "0.3", features = [

View file

@ -1,29 +1,29 @@
// Vertex shader // Vertex shader
struct Camera { struct Camera {
view_pos: vec4<f32>; view_pos: vec4<f32>,
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>,
}; }
[[group(0), binding(0)]] @group(0) @binding(0)
var<uniform> camera: Camera; var<uniform> camera: Camera;
struct Light { struct Light {
position: vec3<f32>; position: vec3<f32>,
color: vec3<f32>; color: vec3<f32>,
}; }
[[group(1), binding(0)]] @group(1) @binding(0)
var<uniform> light: Light; var<uniform> light: Light;
struct VertexInput { struct VertexInput {
[[location(0)]] position: vec3<f32>; @location(0) position: vec3<f32>,
}; }
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>; @builtin(position) clip_position: vec4<f32>,
[[location(0)]] color: vec3<f32>; @location(0) color: vec3<f32>,
}; }
[[stage(vertex)]] @vertex
fn vs_main( fn vs_main(
model: VertexInput, model: VertexInput,
) -> VertexOutput { ) -> VertexOutput {
@ -36,7 +36,7 @@ fn vs_main(
// Fragment shader // Fragment shader
[[stage(fragment)]] @fragment
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> { fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0); return vec4<f32>(in.color, 1.0);
} }

View file

@ -1,45 +1,45 @@
// Vertex shader // Vertex shader
struct Camera { struct Camera {
view_pos: vec4<f32>; view_pos: vec4<f32>,
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>,
}; }
[[group(1), binding(0)]] @group(1) @binding(0)
var<uniform> camera: Camera; var<uniform> camera: Camera;
struct Light { struct Light {
position: vec3<f32>; position: vec3<f32>,
color: vec3<f32>; color: vec3<f32>,
}; }
[[group(2), binding(0)]] @group(2) @binding(0)
var<uniform> light: Light; var<uniform> light: Light;
struct VertexInput { struct VertexInput {
[[location(0)]] position: vec3<f32>; @location(0) position: vec3<f32>,
[[location(1)]] tex_coords: vec2<f32>; @location(1) tex_coords: vec2<f32>,
[[location(2)]] normal: vec3<f32>; @location(2) normal: vec3<f32>,
[[location(3)]] tangent: vec3<f32>; @location(3) tangent: vec3<f32>,
[[location(4)]] bitangent: vec3<f32>; @location(4) bitangent: vec3<f32>,
}; }
struct InstanceInput { struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>; @location(5) model_matrix_0: vec4<f32>,
[[location(6)]] model_matrix_1: vec4<f32>; @location(6) model_matrix_1: vec4<f32>,
[[location(7)]] model_matrix_2: vec4<f32>; @location(7) model_matrix_2: vec4<f32>,
[[location(8)]] model_matrix_3: vec4<f32>; @location(8) model_matrix_3: vec4<f32>,
[[location(9)]] normal_matrix_0: vec3<f32>; @location(9) normal_matrix_0: vec3<f32>,
[[location(10)]] normal_matrix_1: vec3<f32>; @location(10) normal_matrix_1: vec3<f32>,
[[location(11)]] normal_matrix_2: vec3<f32>; @location(11) normal_matrix_2: vec3<f32>,
}; }
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>; @builtin(position) clip_position: vec4<f32>,
[[location(0)]] tex_coords: vec2<f32>; @location(0) tex_coords: vec2<f32>,
[[location(1)]] tangent_position: vec3<f32>; @location(1) tangent_position: vec3<f32>,
[[location(2)]] tangent_light_position: vec3<f32>; @location(2) tangent_light_position: vec3<f32>,
[[location(3)]] tangent_view_position: vec3<f32>; @location(3) tangent_view_position: vec3<f32>,
}; }
[[stage(vertex)]] @vertex
fn vs_main( fn vs_main(
model: VertexInput, model: VertexInput,
instance: InstanceInput, instance: InstanceInput,
@ -79,17 +79,17 @@ fn vs_main(
// Fragment shader // Fragment shader
[[group(0), binding(0)]] @group(0) @binding(0)
var t_diffuse: texture_2d<f32>; var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]] @group(0) @binding(1)
var s_diffuse: sampler; var s_diffuse: sampler;
[[group(0), binding(2)]] @group(0) @binding(2)
var t_normal: texture_2d<f32>; var t_normal: texture_2d<f32>;
[[group(0), binding(3)]] @group(0) @binding(3)
var s_normal: sampler; var s_normal: sampler;
[[stage(fragment)]] @fragment
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> { fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords); let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords);
let object_normal: vec4<f32> = textureSample(t_normal, s_normal, in.tex_coords); let object_normal: vec4<f32> = textureSample(t_normal, s_normal, in.tex_coords);

View file

@ -6,7 +6,7 @@ pub fn create_render_pipeline(
vertex_layouts: &[wgpu::VertexBufferLayout], vertex_layouts: &[wgpu::VertexBufferLayout],
shader: wgpu::ShaderModuleDescriptor, shader: wgpu::ShaderModuleDescriptor,
) -> wgpu::RenderPipeline { ) -> wgpu::RenderPipeline {
let shader = device.create_shader_module(&shader); let shader = device.create_shader_module(shader);
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some(&format!("{:?}", shader)), label: Some(&format!("{:?}", shader)),
@ -19,14 +19,14 @@ pub fn create_render_pipeline(
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &shader, module: &shader,
entry_point: "fs_main", entry_point: "fs_main",
targets: &[wgpu::ColorTargetState { targets: &[Some(wgpu::ColorTargetState {
format: color_format, format: color_format,
blend: Some(wgpu::BlendState { blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE,
}), }),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}], })],
}), }),
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,

View file

@ -289,7 +289,7 @@ impl super::State for DefaultState {
) -> Result<(), wgpu::SurfaceError> { ) -> Result<(), wgpu::SurfaceError> {
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"), label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view, view: &view,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
@ -301,7 +301,7 @@ impl super::State for DefaultState {
}), }),
store: true, store: true,
}, },
}], })],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view, view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations { depth_ops: Some(wgpu::Operations {

View file

@ -49,7 +49,7 @@ impl Renderer {
let config = wgpu::SurfaceConfiguration { let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT, usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(), format: surface.get_supported_formats(&adapter)[0],
width: size.width, width: size.width,
height: size.height, height: size.height,
present_mode: wgpu::PresentMode::Fifo, present_mode: wgpu::PresentMode::Fifo,