From 0642c98f27052246ee4da7db7696bd64d1850f5f Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Thu, 6 Aug 2026 10:42:16 +1000 Subject: [PATCH] [wgpu]: Switch to `wgpu-sync` for locking primitives --- Cargo.lock | 2 +- wgpu/Cargo.toml | 12 ++------- wgpu/src/util/mod.rs | 3 +-- wgpu/src/util/mutex.rs | 60 ------------------------------------------ 4 files changed, 4 insertions(+), 73 deletions(-) delete mode 100644 wgpu/src/util/mutex.rs diff --git a/Cargo.lock b/Cargo.lock index 44aa1d4b8..73813b959 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4722,7 +4722,6 @@ dependencies = [ "js-sys", "log", "naga", - "parking_lot", "portable-atomic", "profiling", "raw-window-handle", @@ -4733,6 +4732,7 @@ dependencies = [ "web-sys", "wgpu-core", "wgpu-hal", + "wgpu-sync", "wgpu-types", ] diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 2eaf54d94..e6411e01f 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -35,7 +35,6 @@ ignored = ["cfg_aliases"] [features] default = [ "std", - "parking_lot", "dx12", "metal", "gles", @@ -179,6 +178,7 @@ web = ["dep:wasm-bindgen", "dep:js-sys", "dep:web-sys", "wgpu-types/web"] ## support. std = [ "raw-window-handle/std", + "wgpu-sync/std", "wgpu-types/std", "wgpu-core?/std", "js-sys?/std", @@ -187,14 +187,6 @@ std = [ "wasm-bindgen-futures?/std", ] -## Uses `parking_lot` as the implementation for locking primitives. -## -## This is a recommended feature for most users and should only be disabled when -## required, e.g., for `no_std` support. -## If disabled, either `std::sync::Mutex` or `core::cell::RefCell` will be used, -## based on whether `std` is enabled or not. -parking_lot = ["dep:parking_lot"] - ## Enables `exhaust` method for `TextureFormat` of `wgpu-types`. ## ## This is relevant for `wgpu-info`. @@ -207,6 +199,7 @@ exhaust = ["wgpu-types/exhaust"] [dependencies] naga = { workspace = true, optional = true, features = ["termcolor"] } wgpu-core = { workspace = true, optional = true } +wgpu-sync = { workspace = true, default-features = false } wgpu-types.workspace = true # Needed for both wgpu-core and webgpu @@ -217,7 +210,6 @@ cfg-if.workspace = true document-features.workspace = true log.workspace = true hashbrown.workspace = true -parking_lot = { workspace = true, optional = true } profiling.workspace = true raw-window-handle = { workspace = true, features = ["alloc"] } static_assertions.workspace = true diff --git a/wgpu/src/util/mod.rs b/wgpu/src/util/mod.rs index 1b9574d3e..f806dcf64 100644 --- a/wgpu/src/util/mod.rs +++ b/wgpu/src/util/mod.rs @@ -10,7 +10,6 @@ mod belt; mod device; mod encoder; mod init; -mod mutex; mod panicking; mod spirv; mod texture_blitter; @@ -29,8 +28,8 @@ pub use wgt::{ math::*, DispatchIndirectArgs, DrawIndexedIndirectArgs, DrawIndirectArgs, TextureDataOrder, }; -pub(crate) use mutex::Mutex; pub(crate) use panicking::is_panicking; +pub(crate) use wgpu_sync::Mutex; use crate::BufferUsages; diff --git a/wgpu/src/util/mutex.rs b/wgpu/src/util/mutex.rs deleted file mode 100644 index 86dff533d..000000000 --- a/wgpu/src/util/mutex.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! Provides a [`Mutex`] for internal use based on what features are available. - -cfg_if::cfg_if! { - if #[cfg(feature = "parking_lot")] { - use parking_lot::Mutex as MutexInner; - } else if #[cfg(std)] { - use std::sync::Mutex as MutexInner; - } else { - use core::cell::RefCell as MutexInner; - } -} - -pub(crate) struct Mutex { - inner: MutexInner, -} - -impl core::fmt::Debug for Mutex -where - MutexInner: core::fmt::Debug, -{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - as core::fmt::Debug>::fmt(&self.inner, f) - } -} - -impl Default for Mutex { - fn default() -> Self { - Self::new(::default()) - } -} - -impl Mutex { - pub const fn new(value: T) -> Self { - Self { - inner: MutexInner::new(value), - } - } -} - -impl Mutex { - pub fn lock(&self) -> impl core::ops::DerefMut + '_ { - cfg_if::cfg_if! { - if #[cfg(feature = "parking_lot")] { - self.inner.lock() - } else if #[cfg(std)] { - self.inner.lock().unwrap_or_else(std::sync::PoisonError::into_inner) - } else { - loop { - let Ok(lock) = self.inner.try_borrow_mut() else { - // Without `std` all we can do is spin until the current lock is released - core::hint::spin_loop(); - continue; - }; - - break lock; - } - } - } - } -}