mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-28 00:59:12 +01:00
[wgpu]: Switch to wgpu-sync for locking primitives
This commit is contained in:
1 parent
34f7efb7d4
commit
0642c98f27
4 files changed
+4
-73
No files matched your search
Generated
+1
-1
@@ -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",
|
||||
]
|
||||
|
||||
|
||||
+2
-10
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<T: ?Sized> {
|
||||
inner: MutexInner<T>,
|
||||
}
|
||||
|
||||
impl<T: ?Sized> core::fmt::Debug for Mutex<T>
|
||||
where
|
||||
MutexInner<T>: core::fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
<MutexInner<T> as core::fmt::Debug>::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Default> Default for Mutex<T> {
|
||||
fn default() -> Self {
|
||||
Self::new(<T as Default>::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Mutex<T> {
|
||||
pub const fn new(value: T) -> Self {
|
||||
Self {
|
||||
inner: MutexInner::new(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> Mutex<T> {
|
||||
pub fn lock(&self) -> impl core::ops::DerefMut<Target = T> + '_ {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user