Merge pull request #2182 from hannobraun/wgpu

Upgrade to wgpu 0.19
This commit is contained in:
Hanno Braun 2024-01-29 14:06:33 +01:00 committed by GitHub
commit a4a5f2cbb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 103 additions and 94 deletions

4
.cargo/config.toml Normal file
View File

@ -0,0 +1,4 @@
[build]
# As of wgpu 0.19.1, these are necessary to build for WebGPU.
rustflags = ["--cfg=web_sys_unstable_apis"]
rustdocflags = ["--cfg=web_sys_unstable_apis"]

133
Cargo.lock generated
View File

@ -587,10 +587,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]] [[package]]
name = "com-rs" name = "com"
version = "0.2.1" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf43edc576402991846b093a7ca18a3477e0ef9c588cde84964b5d3e43016642" checksum = "7e17887fd17353b65b1b2ef1c526c83e26cd72e74f598a8dc1bee13a48f3d9f6"
dependencies = [
"com_macros",
]
[[package]]
name = "com_macros"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d375883580a668c7481ea6631fc1a8863e33cc335bf56bfad8d7e6d4b04b13a5"
dependencies = [
"com_macros_support",
"proc-macro2",
"syn 1.0.109",
]
[[package]]
name = "com_macros_support"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad899a1087a9296d5644792d7cb72b8e34c1bec8e7d4fbc002230169a6e8710c"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "combine" name = "combine"
@ -688,12 +713,12 @@ checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991"
[[package]] [[package]]
name = "d3d12" name = "d3d12"
version = "0.7.0" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e16e44ab292b1dddfdaf7be62cfd8877df52f2f3fde5858d95bab606be259f20" checksum = "3e3d747f100290a1ca24b752186f61f6637e1deffe3bf6320de6fcb29510a307"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"libloading 0.8.1", "libloading 0.7.4",
"winapi", "winapi",
] ]
@ -927,7 +952,7 @@ dependencies = [
"getrandom", "getrandom",
"image", "image",
"nalgebra", "nalgebra",
"raw-window-handle 0.5.2", "raw-window-handle",
"thiserror", "thiserror",
"tobj", "tobj",
"tracing", "tracing",
@ -956,18 +981,6 @@ dependencies = [
"miniz_oxide", "miniz_oxide",
] ]
[[package]]
name = "flume"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181"
dependencies = [
"futures-core",
"futures-sink",
"nanorand",
"spin",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -1196,11 +1209,10 @@ dependencies = [
[[package]] [[package]]
name = "gpu-allocator" name = "gpu-allocator"
version = "0.23.0" version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40fe17c8a05d60c38c0a4e5a3c802f2f1ceb66b76c67d96ffb34bef0475a7fad" checksum = "6f56f6318968d03c18e1bcf4857ff88c61157e9da8e47c5f29055d60e1228884"
dependencies = [ dependencies = [
"backtrace",
"log", "log",
"presser", "presser",
"thiserror", "thiserror",
@ -1259,14 +1271,14 @@ dependencies = [
[[package]] [[package]]
name = "hassle-rs" name = "hassle-rs"
version = "0.10.0" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1397650ee315e8891a0df210707f0fc61771b0cc518c3023896064c5407cb3b0" checksum = "af2a7e73e1f34c48da31fb668a907f250794837e08faa144fd24f0b8b741e890"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 2.4.2",
"com-rs", "com",
"libc", "libc",
"libloading 0.7.4", "libloading 0.8.1",
"thiserror", "thiserror",
"widestring", "widestring",
"winapi", "winapi",
@ -1767,9 +1779,9 @@ dependencies = [
[[package]] [[package]]
name = "naga" name = "naga"
version = "0.14.2" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae585df4b6514cf8842ac0f1ab4992edc975892704835b549cf818dc0191249e" checksum = "8878eb410fc90853da3908aebfe61d73d26d4437ef850b70050461f939509899"
dependencies = [ dependencies = [
"bit-set", "bit-set",
"bitflags 2.4.2", "bitflags 2.4.2",
@ -1812,15 +1824,6 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "nanorand"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "native-tls" name = "native-tls"
version = "0.2.11" version = "0.2.11"
@ -1850,8 +1853,7 @@ dependencies = [
"log", "log",
"ndk-sys", "ndk-sys",
"num_enum", "num_enum",
"raw-window-handle 0.5.2", "raw-window-handle",
"raw-window-handle 0.6.0",
"thiserror", "thiserror",
] ]
@ -2400,12 +2402,6 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab" checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab"
[[package]]
name = "raw-window-handle"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
[[package]] [[package]]
name = "raw-window-handle" name = "raw-window-handle"
version = "0.6.0" version = "0.6.0"
@ -2966,18 +2962,14 @@ name = "spin"
version = "0.9.8" version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
[[package]] [[package]]
name = "spirv" name = "spirv"
version = "0.2.0+1.5.4" version = "0.3.0+sdk-1.3.268.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830" checksum = "eda41003dc44290527a59b13432d4a0379379fa074b70174882adfbdfd917844"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 2.4.2",
"num-traits",
] ]
[[package]] [[package]]
@ -3733,9 +3725,9 @@ dependencies = [
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.64" version = "0.3.67"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -3753,19 +3745,19 @@ dependencies = [
[[package]] [[package]]
name = "wgpu" name = "wgpu"
version = "0.18.0" version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30e7d227c9f961f2061c26f4cb0fbd4df0ef37e056edd0931783599d6c94ef24" checksum = "0bfe9a310dcf2e6b85f00c46059aaeaf4184caa8e29a1ecd4b7a704c3482332d"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"cfg-if", "cfg-if",
"flume", "cfg_aliases",
"js-sys", "js-sys",
"log", "log",
"naga", "naga",
"parking_lot", "parking_lot",
"profiling", "profiling",
"raw-window-handle 0.5.2", "raw-window-handle",
"smallvec", "smallvec",
"static_assertions", "static_assertions",
"wasm-bindgen", "wasm-bindgen",
@ -3778,19 +3770,22 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-core" name = "wgpu-core"
version = "0.18.1" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef91c1d62d1e9e81c79e600131a258edf75c9531cbdbde09c44a011a47312726" checksum = "6b15e451d4060ada0d99a64df44e4d590213496da7c4f245572d51071e8e30ed"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"bit-vec", "bit-vec",
"bitflags 2.4.2", "bitflags 2.4.2",
"cfg_aliases",
"codespan-reporting", "codespan-reporting",
"indexmap",
"log", "log",
"naga", "naga",
"once_cell",
"parking_lot", "parking_lot",
"profiling", "profiling",
"raw-window-handle 0.5.2", "raw-window-handle",
"rustc-hash", "rustc-hash",
"smallvec", "smallvec",
"thiserror", "thiserror",
@ -3801,9 +3796,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-hal" name = "wgpu-hal"
version = "0.18.1" version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b84ecc802da3eb67b4cf3dd9ea6fe45bbb47ef13e6c49c5c3240868a9cc6cdd9" checksum = "e3bb47856236bfafc0bc591a925eb036ac19cd987624a447ff353e7a7e7e6f72"
dependencies = [ dependencies = [
"android_system_properties", "android_system_properties",
"arrayvec", "arrayvec",
@ -3811,6 +3806,7 @@ dependencies = [
"bit-set", "bit-set",
"bitflags 2.4.2", "bitflags 2.4.2",
"block", "block",
"cfg_aliases",
"core-graphics-types", "core-graphics-types",
"d3d12", "d3d12",
"glow", "glow",
@ -3831,7 +3827,7 @@ dependencies = [
"parking_lot", "parking_lot",
"profiling", "profiling",
"range-alloc", "range-alloc",
"raw-window-handle 0.5.2", "raw-window-handle",
"renderdoc-sys", "renderdoc-sys",
"rustc-hash", "rustc-hash",
"smallvec", "smallvec",
@ -3844,9 +3840,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-types" name = "wgpu-types"
version = "0.18.0" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d5ed5f0edf0de351fe311c53304986315ce866f394a2e6df0c4b3c70774bcdd" checksum = "895fcbeb772bfb049eb80b2d6e47f6c9af235284e9703c96fc0218a42ffd5af2"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"js-sys", "js-sys",
@ -4153,8 +4149,7 @@ dependencies = [
"once_cell", "once_cell",
"orbclient", "orbclient",
"percent-encoding", "percent-encoding",
"raw-window-handle 0.5.2", "raw-window-handle",
"raw-window-handle 0.6.0",
"redox_syscall 0.3.5", "redox_syscall 0.3.5",
"rustix", "rustix",
"sctk-adwaita", "sctk-adwaita",

View File

@ -19,7 +19,7 @@ fj-interop.workspace = true
fj-math.workspace = true fj-math.workspace = true
nalgebra = "0.32.3" nalgebra = "0.32.3"
tobj = "4.0.1" tobj = "4.0.1"
raw-window-handle = "0.5.2" raw-window-handle = "0.6.0"
thiserror = "1.0.53" thiserror = "1.0.53"
tracing = "0.1.40" tracing = "0.1.40"
@ -33,7 +33,7 @@ default-features = false
features = ["png", "jpeg"] features = ["png", "jpeg"]
[dependencies.wgpu] [dependencies.wgpu]
version = "0.18.0" version = "0.19.1"
features = ["webgl"] features = ["webgl"]
# We don't depend on `getrandom` directly, but we need this to enable the `js` # We don't depend on `getrandom` directly, but we need this to enable the `js`

View File

@ -9,7 +9,7 @@ pub struct Device {
impl Device { impl Device {
pub async fn from_preferred_adapter( pub async fn from_preferred_adapter(
instance: &wgpu::Instance, instance: &wgpu::Instance,
surface: &wgpu::Surface, surface: &wgpu::Surface<'_>,
) -> Result<(Self, wgpu::Adapter, wgpu::Features), DeviceError> { ) -> Result<(Self, wgpu::Adapter, wgpu::Features), DeviceError> {
let adapter = instance let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions { .request_adapter(&wgpu::RequestAdapterOptions {
@ -30,8 +30,9 @@ impl Device {
pub async fn try_from_all_adapters( pub async fn try_from_all_adapters(
instance: &wgpu::Instance, instance: &wgpu::Instance,
) -> Result<(Self, wgpu::Adapter, wgpu::Features), DeviceError> { ) -> Result<(Self, wgpu::Adapter, wgpu::Features), DeviceError> {
let mut all_adapters = let mut all_adapters = instance
instance.enumerate_adapters(wgpu::Backends::all()); .enumerate_adapters(wgpu::Backends::all())
.into_iter();
let result = loop { let result = loop {
let Some(adapter) = all_adapters.next() else { let Some(adapter) = all_adapters.next() else {
@ -67,7 +68,7 @@ impl Device {
pub async fn new( pub async fn new(
adapter: &wgpu::Adapter, adapter: &wgpu::Adapter,
) -> Result<(Self, wgpu::Features), DeviceError> { ) -> Result<(Self, wgpu::Features), DeviceError> {
let features = { let required_features = {
let desired_features = wgpu::Features::POLYGON_MODE_LINE; let desired_features = wgpu::Features::POLYGON_MODE_LINE;
let available_features = adapter.features(); let available_features = adapter.features();
@ -82,7 +83,7 @@ impl Device {
desired_features.intersection(available_features) desired_features.intersection(available_features)
}; };
let limits = { let required_limits = {
// This is the lowest of the available defaults. It should guarantee // This is the lowest of the available defaults. It should guarantee
// that we can run pretty much everywhere. // that we can run pretty much everywhere.
let lowest_limits = wgpu::Limits::downlevel_webgl2_defaults(); let lowest_limits = wgpu::Limits::downlevel_webgl2_defaults();
@ -98,14 +99,14 @@ impl Device {
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
label: None, label: None,
features, required_features,
limits, required_limits,
}, },
None, None,
) )
.await?; .await?;
Ok((Device { device, queue }, features)) Ok((Device { device, queue }, required_features))
} }
} }

View File

@ -19,7 +19,7 @@ use super::{
/// Graphics rendering state and target abstraction /// Graphics rendering state and target abstraction
#[derive(Debug)] #[derive(Debug)]
pub struct Renderer { pub struct Renderer {
surface: wgpu::Surface, surface: wgpu::Surface<'static>,
device: Device, device: Device,
surface_config: wgpu::SurfaceConfiguration, surface_config: wgpu::SurfaceConfiguration,
@ -44,7 +44,7 @@ impl Renderer {
}); });
// This is sound, as `window` is an object to create a surface upon. // This is sound, as `window` is an object to create a surface upon.
let surface = unsafe { instance.create_surface(screen.window()) }?; let surface = instance.create_surface(screen.window())?;
for adapter in instance.enumerate_adapters(wgpu::Backends::all()) { for adapter in instance.enumerate_adapters(wgpu::Backends::all()) {
debug!("Available adapter: {:?}", adapter.get_info()); debug!("Available adapter: {:?}", adapter.get_info());
@ -106,6 +106,7 @@ impl Renderer {
width, width,
height, height,
present_mode: wgpu::PresentMode::AutoVsync, present_mode: wgpu::PresentMode::AutoVsync,
desired_maximum_frame_latency: 2,
// I don't understand what this option does. It was introduced with // I don't understand what this option does. It was introduced with
// wgpu 0.14, but we had already been using premultiplied alpha // wgpu 0.14, but we had already been using premultiplied alpha
// blending before that. See the `BlendState` configuration of the // blending before that. See the `BlendState` configuration of the

View File

@ -1,17 +1,19 @@
//! Types that describe aspects of the screen //! Types that describe aspects of the screen
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; use std::sync::Arc;
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
/// Needs to be implemented by types that can serve as a screen to render to /// Needs to be implemented by types that can serve as a screen to render to
pub trait Screen { pub trait Screen {
/// The window /// The window
type Window: HasRawDisplayHandle + HasRawWindowHandle; type Window: HasDisplayHandle + HasWindowHandle + Send + Sync + 'static;
/// Access the size of the screen /// Access the size of the screen
fn size(&self) -> ScreenSize; fn size(&self) -> ScreenSize;
/// Access the window /// Access the window
fn window(&self) -> &Self::Window; fn window(&self) -> Arc<Self::Window>;
} }
/// Cursor position in normalized coordinates (-1 to +1) /// Cursor position in normalized coordinates (-1 to +1)

View File

@ -20,7 +20,4 @@ fj-math.workspace = true
fj-viewer.workspace = true fj-viewer.workspace = true
futures = "0.3.30" futures = "0.3.30"
thiserror = "1.0.53" thiserror = "1.0.53"
winit = "0.29.2"
[dependencies.winit]
version = "0.29.2"
features = ["rwh_05"]

View File

@ -1,8 +1,12 @@
use std::sync::Arc;
use fj_viewer::{Screen, ScreenSize}; use fj_viewer::{Screen, ScreenSize};
use winit::{event_loop::EventLoop, window::WindowBuilder}; use winit::{event_loop::EventLoop, window::WindowBuilder};
/// A window that can be used with `fj-viewer` /// A window that can be used with `fj-viewer`
pub struct Window(winit::window::Window); pub struct Window {
inner: Arc<winit::window::Window>,
}
impl Window { impl Window {
/// Create an instance of `Window` from the given `EventLoop` /// Create an instance of `Window` from the given `EventLoop`
@ -33,7 +37,9 @@ impl Window {
.with_transparent(false) .with_transparent(false)
.build(event_loop)?; .build(event_loop)?;
Ok(Self(window)) Ok(Self {
inner: Arc::new(window),
})
} }
} }
@ -41,7 +47,7 @@ impl Screen for Window {
type Window = winit::window::Window; type Window = winit::window::Window;
fn size(&self) -> ScreenSize { fn size(&self) -> ScreenSize {
let size = self.0.inner_size(); let size = self.inner.inner_size();
ScreenSize { ScreenSize {
width: size.width, width: size.width,
@ -49,8 +55,8 @@ impl Screen for Window {
} }
} }
fn window(&self) -> &winit::window::Window { fn window(&self) -> Arc<Self::Window> {
&self.0 self.inner.clone()
} }
} }

View File

@ -39,7 +39,10 @@ fn main() -> anyhow::Result<()> {
.arg("--all-features") .arg("--all-features")
.args(["--target", target.triple]) .args(["--target", target.triple])
.args(["-p", crate_]) .args(["-p", crate_])
.env("RUSTFLAGS", "-D warnings"); // Wee need to recreate that `web_sys` cfg here. It's already
// specified in `.cargo/config`, but the use of `RUSTFLAGS` here
// overwrites that.
.env("RUSTFLAGS", "-D warnings --cfg=web_sys_unstable_apis");
println!("Running {command:?}"); println!("Running {command:?}");
let status = command.status()?; let status = command.status()?;