mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 16:31:11 +01:00
[wgpu-core]: Switch to wgpu-sync for locking primitives
This commit is contained in:
1 parent
8573e7a44e
commit
34f7efb7d4
9 files changed
+50
-52
No files matched your search
Generated
+1
-1
@@ -4795,7 +4795,6 @@ dependencies = [
|
||||
"naga",
|
||||
"naga-types",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"portable-atomic",
|
||||
"profiling",
|
||||
"proptest",
|
||||
@@ -4812,6 +4811,7 @@ dependencies = [
|
||||
"wgpu-core-deps-windows",
|
||||
"wgpu-hal",
|
||||
"wgpu-naga-bridge",
|
||||
"wgpu-sync",
|
||||
"wgpu-types",
|
||||
]
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ serde = [
|
||||
trace = ["serde", "std", "dep:ron", "naga/serialize", "wgpu-types/trace"]
|
||||
|
||||
## Enable API replaying
|
||||
replay = ["serde", "naga/deserialize"]
|
||||
replay = ["serde", "naga/deserialize", "std"]
|
||||
|
||||
#! ### Shading Language Support
|
||||
# --------------------------------------------------------------------
|
||||
@@ -111,7 +111,7 @@ fragile-send-sync-non-atomic-wasm = [
|
||||
|
||||
## Enable certain items to be `Send` and `Sync` when they would not otherwise be.
|
||||
## Also enables backtraces in some error cases when also under cfg(debug_assertions).
|
||||
std = []
|
||||
std = ["wgpu-sync/std"]
|
||||
|
||||
#! ### External libraries
|
||||
# --------------------------------------------------------------------
|
||||
@@ -186,6 +186,7 @@ naga.workspace = true
|
||||
naga-types.workspace = true
|
||||
wgpu-naga-bridge.workspace = true
|
||||
wgpu-hal.workspace = true
|
||||
wgpu-sync = { workspace = true, default-features = false }
|
||||
wgpu-types.workspace = true
|
||||
|
||||
arrayvec.workspace = true
|
||||
@@ -199,7 +200,6 @@ indexmap.workspace = true
|
||||
log.workspace = true
|
||||
macro_rules_attribute = { workspace = true, optional = true }
|
||||
once_cell = { workspace = true, features = ["std"] }
|
||||
parking_lot.workspace = true
|
||||
profiling = { workspace = true, default-features = false }
|
||||
raw-window-handle.workspace = true
|
||||
ron = { workspace = true, optional = true }
|
||||
|
||||
@@ -205,13 +205,11 @@ impl ExternalTextureParams {
|
||||
|
||||
/// Because all operations are push/swap (no longlived lock),
|
||||
/// we can have mutex without lock rank
|
||||
pub(crate) struct DeferredBufferMapPendingClosures(
|
||||
parking_lot::Mutex<Vec<BufferMapPendingClosure>>,
|
||||
);
|
||||
pub(crate) struct DeferredBufferMapPendingClosures(wgpu_sync::Mutex<Vec<BufferMapPendingClosure>>);
|
||||
|
||||
impl DeferredBufferMapPendingClosures {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self(parking_lot::Mutex::new(Vec::new()))
|
||||
Self(wgpu_sync::Mutex::new(Vec::new()))
|
||||
}
|
||||
|
||||
pub(crate) fn push(&self, closure: BufferMapPendingClosure) {
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
//!
|
||||
//! Otherwise, `wgpu-core` uses the [`vanilla`] module's locks.
|
||||
//!
|
||||
//! [`Mutex`]: parking_lot::Mutex
|
||||
//! [`RwLock`]: parking_lot::RwLock
|
||||
//! [`Mutex`]: wgpu_sync::Mutex
|
||||
//! [`RwLock`]: wgpu_sync::RwLock
|
||||
//! [`SnatchLock`]: crate::snatch::SnatchLock
|
||||
|
||||
pub mod rank;
|
||||
|
||||
@@ -42,30 +42,30 @@ pub type RankData = Option<HeldLock>;
|
||||
|
||||
/// A `Mutex` instrumented for lock acquisition order observation.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::Mutex`], along with
|
||||
/// This is just a wrapper around a [`wgpu_sync::Mutex`], along with
|
||||
/// its rank in the `wgpu_core` lock ordering.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct Mutex<T> {
|
||||
inner: parking_lot::Mutex<T>,
|
||||
inner: wgpu_sync::Mutex<T>,
|
||||
rank: LockRank,
|
||||
}
|
||||
|
||||
/// A guard produced by locking [`Mutex`].
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::MutexGuard`], along
|
||||
/// This is just a wrapper around a [`wgpu_sync::MutexGuard`], along
|
||||
/// with the state needed to track lock acquisition.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct MutexGuard<'a, T> {
|
||||
inner: parking_lot::MutexGuard<'a, T>,
|
||||
inner: wgpu_sync::MutexGuard<'a, T>,
|
||||
_state: LockStateGuard,
|
||||
}
|
||||
|
||||
impl<T> Mutex<T> {
|
||||
pub fn new(rank: LockRank, value: T) -> Mutex<T> {
|
||||
Mutex {
|
||||
inner: parking_lot::Mutex::new(value),
|
||||
inner: wgpu_sync::Mutex::new(value),
|
||||
rank,
|
||||
}
|
||||
}
|
||||
@@ -110,41 +110,41 @@ impl<T: core::fmt::Debug> core::fmt::Debug for Mutex<T> {
|
||||
|
||||
/// An `RwLock` instrumented for lock acquisition order observation.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::RwLock`], along with
|
||||
/// This is just a wrapper around a [`wgpu_sync::RwLock`], along with
|
||||
/// its rank in the `wgpu_core` lock ordering.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct RwLock<T> {
|
||||
inner: parking_lot::RwLock<T>,
|
||||
inner: wgpu_sync::RwLock<T>,
|
||||
rank: LockRank,
|
||||
}
|
||||
|
||||
/// A read guard produced by locking [`RwLock`] for reading.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::RwLockReadGuard`], along with
|
||||
/// This is just a wrapper around a [`wgpu_sync::RwLockReadGuard`], along with
|
||||
/// the state needed to track lock acquisition.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct RwLockReadGuard<'a, T> {
|
||||
inner: parking_lot::RwLockReadGuard<'a, T>,
|
||||
inner: wgpu_sync::RwLockReadGuard<'a, T>,
|
||||
_state: LockStateGuard,
|
||||
}
|
||||
|
||||
/// A write guard produced by locking [`RwLock`] for writing.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::RwLockWriteGuard`], along
|
||||
/// This is just a wrapper around a [`wgpu_sync::RwLockWriteGuard`], along
|
||||
/// with the state needed to track lock acquisition.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct RwLockWriteGuard<'a, T> {
|
||||
inner: parking_lot::RwLockWriteGuard<'a, T>,
|
||||
inner: wgpu_sync::RwLockWriteGuard<'a, T>,
|
||||
_state: LockStateGuard,
|
||||
}
|
||||
|
||||
impl<T> RwLock<T> {
|
||||
pub fn new(rank: LockRank, value: T) -> RwLock<T> {
|
||||
RwLock {
|
||||
inner: parking_lot::RwLock::new(value),
|
||||
inner: wgpu_sync::RwLock::new(value),
|
||||
rank,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
/// TODO(<https://github.com/gfx-rs/wgpu/issues/5572>): Resolve invalid
|
||||
/// acquisitions of DEVICE_COMMAND_INDICES followed by COMMAND_BUFFER_DATA.
|
||||
///
|
||||
/// [`Mutex`]: parking_lot::Mutex
|
||||
/// [`RwLock`]: parking_lot::RwLock
|
||||
/// [`Mutex`]: wgpu_sync::Mutex
|
||||
/// [`RwLock`]: wgpu_sync::RwLock
|
||||
/// [`SnatchLock`]: crate::snatch::SnatchLock
|
||||
/// [`CommandBuffer::data`]: crate::command::CommandBuffer::data
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
||||
@@ -63,23 +63,23 @@ pub use LockState as RankData;
|
||||
|
||||
/// A `Mutex` instrumented for deadlock prevention.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::Mutex`], along with
|
||||
/// This is just a wrapper around a [`wgpu_sync::Mutex`], along with
|
||||
/// its rank in the `wgpu_core` lock ordering.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct Mutex<T> {
|
||||
inner: parking_lot::Mutex<T>,
|
||||
inner: wgpu_sync::Mutex<T>,
|
||||
rank: LockRank,
|
||||
}
|
||||
|
||||
/// A guard produced by locking [`Mutex`].
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::MutexGuard`], along
|
||||
/// This is just a wrapper around a [`wgpu_sync::MutexGuard`], along
|
||||
/// with the state needed to track lock acquisition.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct MutexGuard<'a, T> {
|
||||
inner: parking_lot::MutexGuard<'a, T>,
|
||||
inner: wgpu_sync::MutexGuard<'a, T>,
|
||||
#[cfg_attr(not(miri), expect(unused))] // but `Drop` has important side effects
|
||||
saved: LockStateGuard,
|
||||
}
|
||||
@@ -216,7 +216,7 @@ fn release(saved: LockState) {
|
||||
impl<T> Mutex<T> {
|
||||
pub fn new(rank: LockRank, value: T) -> Mutex<T> {
|
||||
Mutex {
|
||||
inner: parking_lot::Mutex::new(value),
|
||||
inner: wgpu_sync::Mutex::new(value),
|
||||
rank,
|
||||
}
|
||||
}
|
||||
@@ -261,41 +261,41 @@ impl<T: fmt::Debug> fmt::Debug for Mutex<T> {
|
||||
|
||||
/// An `RwLock` instrumented for deadlock prevention.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::RwLock`], along with
|
||||
/// This is just a wrapper around a [`wgpu_sync::RwLock`], along with
|
||||
/// its rank in the `wgpu_core` lock ordering.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct RwLock<T> {
|
||||
inner: parking_lot::RwLock<T>,
|
||||
inner: wgpu_sync::RwLock<T>,
|
||||
rank: LockRank,
|
||||
}
|
||||
|
||||
/// A read guard produced by locking [`RwLock`] for reading.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::RwLockReadGuard`], along with
|
||||
/// This is just a wrapper around a [`wgpu_sync::RwLockReadGuard`], along with
|
||||
/// the state needed to track lock acquisition.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct RwLockReadGuard<'a, T> {
|
||||
inner: parking_lot::RwLockReadGuard<'a, T>,
|
||||
inner: wgpu_sync::RwLockReadGuard<'a, T>,
|
||||
saved: LockStateGuard,
|
||||
}
|
||||
|
||||
/// A write guard produced by locking [`RwLock`] for writing.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::RwLockWriteGuard`], along
|
||||
/// This is just a wrapper around a [`wgpu_sync::RwLockWriteGuard`], along
|
||||
/// with the state needed to track lock acquisition.
|
||||
///
|
||||
/// For details, see [the module documentation][self].
|
||||
pub struct RwLockWriteGuard<'a, T> {
|
||||
inner: parking_lot::RwLockWriteGuard<'a, T>,
|
||||
inner: wgpu_sync::RwLockWriteGuard<'a, T>,
|
||||
saved: LockStateGuard,
|
||||
}
|
||||
|
||||
impl<T> RwLock<T> {
|
||||
pub fn new(rank: LockRank, value: T) -> RwLock<T> {
|
||||
RwLock {
|
||||
inner: parking_lot::RwLock::new(value),
|
||||
inner: wgpu_sync::RwLock::new(value),
|
||||
rank,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Plain, uninstrumented wrappers around [`parking_lot`] lock types.
|
||||
//! Plain, uninstrumented wrappers around [`wgpu_sync`] lock types.
|
||||
//!
|
||||
//! These definitions are used when no particular lock instrumentation
|
||||
//! Cargo feature is selected.
|
||||
@@ -9,9 +9,9 @@ use crate::lock::rank::LockRank;
|
||||
|
||||
pub struct RankData;
|
||||
|
||||
/// A plain wrapper around [`parking_lot::Mutex`].
|
||||
/// A plain wrapper around [`wgpu_sync::Mutex`].
|
||||
///
|
||||
/// This is just like [`parking_lot::Mutex`], except that our [`new`]
|
||||
/// This is just like [`wgpu_sync::Mutex`], except that our [`new`]
|
||||
/// method takes a rank, indicating where the new mutex should sit in
|
||||
/// `wgpu-core`'s lock ordering. The rank is ignored.
|
||||
///
|
||||
@@ -19,16 +19,16 @@ pub struct RankData;
|
||||
///
|
||||
/// [`new`]: Mutex::new
|
||||
/// [`lock`]: crate::lock
|
||||
pub struct Mutex<T>(parking_lot::Mutex<T>);
|
||||
pub struct Mutex<T>(wgpu_sync::Mutex<T>);
|
||||
|
||||
/// A guard produced by locking [`Mutex`].
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::MutexGuard`].
|
||||
pub struct MutexGuard<'a, T>(parking_lot::MutexGuard<'a, T>);
|
||||
/// This is just a wrapper around a [`wgpu_sync::MutexGuard`].
|
||||
pub struct MutexGuard<'a, T>(wgpu_sync::MutexGuard<'a, T>);
|
||||
|
||||
impl<T> Mutex<T> {
|
||||
pub fn new(_rank: LockRank, value: T) -> Mutex<T> {
|
||||
Mutex(parking_lot::Mutex::new(value))
|
||||
Mutex(wgpu_sync::Mutex::new(value))
|
||||
}
|
||||
|
||||
pub fn lock(&self) -> MutexGuard<'_, T> {
|
||||
@@ -64,9 +64,9 @@ impl<T: fmt::Debug> fmt::Debug for Mutex<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A plain wrapper around [`parking_lot::RwLock`].
|
||||
/// A plain wrapper around [`wgpu_sync::RwLock`].
|
||||
///
|
||||
/// This is just like [`parking_lot::RwLock`], except that our [`new`]
|
||||
/// This is just like [`wgpu_sync::RwLock`], except that our [`new`]
|
||||
/// method takes a rank, indicating where the new mutex should sit in
|
||||
/// `wgpu-core`'s lock ordering. The rank is ignored.
|
||||
///
|
||||
@@ -74,21 +74,21 @@ impl<T: fmt::Debug> fmt::Debug for Mutex<T> {
|
||||
///
|
||||
/// [`new`]: RwLock::new
|
||||
/// [`lock`]: crate::lock
|
||||
pub struct RwLock<T>(parking_lot::RwLock<T>);
|
||||
pub struct RwLock<T>(wgpu_sync::RwLock<T>);
|
||||
|
||||
/// A read guard produced by locking [`RwLock`] as a reader.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::RwLockReadGuard`].
|
||||
pub struct RwLockReadGuard<'a, T>(parking_lot::RwLockReadGuard<'a, T>);
|
||||
/// This is just a wrapper around a [`wgpu_sync::RwLockReadGuard`].
|
||||
pub struct RwLockReadGuard<'a, T>(wgpu_sync::RwLockReadGuard<'a, T>);
|
||||
|
||||
/// A write guard produced by locking [`RwLock`] as a writer.
|
||||
///
|
||||
/// This is just a wrapper around a [`parking_lot::RwLockWriteGuard`].
|
||||
pub struct RwLockWriteGuard<'a, T>(parking_lot::RwLockWriteGuard<'a, T>);
|
||||
/// This is just a wrapper around a [`wgpu_sync::RwLockWriteGuard`].
|
||||
pub struct RwLockWriteGuard<'a, T>(wgpu_sync::RwLockWriteGuard<'a, T>);
|
||||
|
||||
impl<T> RwLock<T> {
|
||||
pub fn new(_rank: LockRank, value: T) -> RwLock<T> {
|
||||
RwLock(parking_lot::RwLock::new(value))
|
||||
RwLock(wgpu_sync::RwLock::new(value))
|
||||
}
|
||||
|
||||
pub fn read(&self) -> RwLockReadGuard<'_, T> {
|
||||
|
||||
@@ -2,7 +2,7 @@ use alloc::sync::Arc;
|
||||
|
||||
use crate::id::Marker;
|
||||
use crate::resource::ResourceType;
|
||||
use parking_lot::Mutex;
|
||||
use wgpu_sync::Mutex;
|
||||
|
||||
/// Not a public API. For use only by `player`.
|
||||
#[doc(hidden)]
|
||||
|
||||
Reference in new issue
Block a user