mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 23:41:01 +01:00
wgpu-hal: use wgpu-sync for atomics
This commit is contained in:
1 parent
35b46f3297
commit
aa9d8af9f5
14 files changed
+23
-60
No files matched your search
Generated
-2
@@ -4984,8 +4984,6 @@ dependencies = [
|
||||
"objc2-metal 0.3.2",
|
||||
"objc2-quartz-core 0.3.2",
|
||||
"ordered-float",
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"profiling",
|
||||
"range-alloc",
|
||||
"raw-window-handle",
|
||||
|
||||
+2
-15
@@ -87,7 +87,6 @@ metal = [
|
||||
"dep:profiling",
|
||||
"dep:smallvec",
|
||||
"dep:raw-window-metal",
|
||||
"dep:wgpu-sync",
|
||||
]
|
||||
vulkan = [
|
||||
"naga/spv-out",
|
||||
@@ -102,7 +101,6 @@ vulkan = [
|
||||
"dep:profiling",
|
||||
"dep:raw-window-metal",
|
||||
"dep:smallvec",
|
||||
"dep:wgpu-sync",
|
||||
"dep:windows",
|
||||
"dep:windows-core",
|
||||
"gpu-allocator/vulkan",
|
||||
@@ -127,7 +125,6 @@ gles = [
|
||||
"dep:wasm-bindgen",
|
||||
"dep:wayland-sys",
|
||||
"dep:web-sys",
|
||||
"dep:wgpu-sync",
|
||||
"dep:windows-result",
|
||||
"naga/glsl-out",
|
||||
"wgpu-sync/std", # Required for send/sync
|
||||
@@ -148,7 +145,6 @@ dx12 = [
|
||||
"dep:ordered-float",
|
||||
"dep:profiling",
|
||||
"dep:range-alloc",
|
||||
"dep:wgpu-sync",
|
||||
"dep:windows-core",
|
||||
"gpu-allocator/d3d12",
|
||||
"naga/hlsl-out",
|
||||
@@ -179,7 +175,7 @@ renderdoc = ["dep:libloading", "dep:renderdoc-sys"]
|
||||
fragile-send-sync-non-atomic-wasm = [
|
||||
"wgpu-types/fragile-send-sync-non-atomic-wasm",
|
||||
]
|
||||
portable-atomic = ["dep:portable-atomic", "dep:portable-atomic-util"]
|
||||
portable-atomic = ["wgpu-sync/portable-atomic"]
|
||||
|
||||
###################################
|
||||
### Internal Debugging Features ###
|
||||
@@ -196,7 +192,6 @@ device_lost_panic = []
|
||||
internal_error_panic = []
|
||||
# Tracks validation errors in a `VALIDATION_CANARY` static.
|
||||
validation_canary = [
|
||||
"dep:wgpu-sync",
|
||||
"wgpu-sync/std", # Required for send/sync
|
||||
]
|
||||
|
||||
@@ -215,7 +210,7 @@ required-features = ["gles"]
|
||||
naga.workspace = true
|
||||
wgpu-naga-bridge.workspace = true
|
||||
naga-types = { workspace = true }
|
||||
wgpu-sync = { workspace = true, default-features = false, optional = true }
|
||||
wgpu-sync = { workspace = true, default-features = false }
|
||||
wgpu-types = { workspace = true, default-features = false }
|
||||
|
||||
# Dependencies in the lib and empty backend
|
||||
@@ -348,14 +343,6 @@ khronos-egl = { workspace = true, optional = true, features = [
|
||||
# Note: it's unused by emscripten, but we keep it to have single code base in egl.rs
|
||||
libloading = { workspace = true, optional = true }
|
||||
|
||||
[target.'cfg(any(not(target_has_atomic = "64"), not(target_has_atomic = "ptr")))'.dependencies]
|
||||
portable-atomic = { workspace = true, optional = true }
|
||||
|
||||
[target.'cfg(not(target_has_atomic = "ptr"))'.dependencies]
|
||||
portable-atomic-util = { workspace = true, features = [
|
||||
"alloc",
|
||||
], optional = true }
|
||||
|
||||
### Platform: Windows + MacOS + Linux for "raw-gles" example ###
|
||||
[target.'cfg(not(any(target_family = "wasm", target_os = "ios", target_os = "visionos", target_env = "ohos")))'.dev-dependencies]
|
||||
glutin-winit = { workspace = true, features = ["egl", "wgl", "wayland", "x11"] }
|
||||
|
||||
@@ -30,7 +30,5 @@ fn main() {
|
||||
any_backend: { any(dx12, metal, vulkan, gles) },
|
||||
// ⚠️ Keep in sync with target.cfg() definition in Cargo.toml and cfg_alias in `wgpu` crate ⚠️
|
||||
static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64"), target_env = "msvc") },
|
||||
supports_64bit_atomics: { target_has_atomic = "64" },
|
||||
supports_ptr_atomics: { target_has_atomic = "ptr" }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
use alloc::{string::String, sync::Arc, vec::Vec};
|
||||
use core::{ptr, sync::atomic::AtomicU64};
|
||||
use core::ptr;
|
||||
use std::thread;
|
||||
|
||||
use wgpu_sync::Mutex;
|
||||
use wgpu_sync::{atomic::AtomicU64, Mutex};
|
||||
use windows::{
|
||||
core::Interface as _,
|
||||
Win32::{
|
||||
|
||||
@@ -93,11 +93,12 @@ mod types;
|
||||
mod view;
|
||||
|
||||
use alloc::{borrow::ToOwned as _, string::String, sync::Arc, vec::Vec};
|
||||
use core::{ffi, fmt, mem, ops::Deref, sync::atomic::AtomicU64};
|
||||
use core::{ffi, fmt, mem, ops::Deref};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use hashbrown::HashMap;
|
||||
use suballocation::Allocator;
|
||||
use wgpu_sync::atomic::AtomicU64;
|
||||
use wgpu_sync::{Mutex, RwLock};
|
||||
use windows::{
|
||||
core::{Free as _, Interface},
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use alloc::{borrow::ToOwned as _, format, string::String, sync::Arc, vec, vec::Vec};
|
||||
use core::sync::atomic::AtomicU8;
|
||||
|
||||
use glow::HasContext;
|
||||
use wgpu_sync::Mutex;
|
||||
use wgpu_sync::{atomic::AtomicU8, Mutex};
|
||||
use wgt::AstcChannel;
|
||||
|
||||
use crate::auxil::db;
|
||||
|
||||
@@ -110,12 +110,11 @@ pub use self::wgl::{AdapterContext, AdapterContextLock, Instance, Surface};
|
||||
pub use fence::Fence;
|
||||
|
||||
use alloc::{boxed::Box, string::String, string::ToString as _, sync::Arc, vec::Vec};
|
||||
use core::{
|
||||
fmt,
|
||||
ops::Range,
|
||||
sync::atomic::{AtomicU32, AtomicU8},
|
||||
use core::{fmt, ops::Range};
|
||||
use wgpu_sync::{
|
||||
atomic::{AtomicU32, AtomicU8},
|
||||
Mutex,
|
||||
};
|
||||
use wgpu_sync::Mutex;
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use glow::HasContext;
|
||||
|
||||
+3
-13
@@ -308,16 +308,9 @@ use core::{
|
||||
use bitflags::bitflags;
|
||||
use raw_window_handle::DisplayHandle;
|
||||
use thiserror::Error;
|
||||
use wgpu_sync::Arc;
|
||||
use wgt::WasmNotSendSync;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(supports_ptr_atomics)] {
|
||||
use alloc::sync::Arc;
|
||||
} else if #[cfg(feature = "portable-atomic")] {
|
||||
use portable_atomic_util::Arc;
|
||||
}
|
||||
}
|
||||
|
||||
// - Vertex + Fragment
|
||||
// - Compute
|
||||
// Task + Mesh + Fragment
|
||||
@@ -334,10 +327,7 @@ pub const QUERY_SIZE: wgt::BufferAddress = 8;
|
||||
pub type Label<'a> = Option<&'a str>;
|
||||
pub type MemoryRange = Range<wgt::BufferAddress>;
|
||||
pub type FenceValue = u64;
|
||||
#[cfg(supports_64bit_atomics)]
|
||||
pub type AtomicFenceValue = core::sync::atomic::AtomicU64;
|
||||
#[cfg(not(supports_64bit_atomics))]
|
||||
pub type AtomicFenceValue = portable_atomic::AtomicU64;
|
||||
pub type AtomicFenceValue = wgpu_sync::atomic::AtomicU64;
|
||||
|
||||
/// A callback to signal that wgpu is no longer using a resource.
|
||||
#[cfg(all(any(gles, vulkan, metal), not(webgl)))]
|
||||
@@ -597,7 +587,7 @@ impl InstanceError {
|
||||
#[allow(dead_code, reason = "may be unused on some platforms")]
|
||||
pub(crate) fn with_source(message: String, source: impl Error + Send + Sync + 'static) -> Self {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(supports_ptr_atomics)] {
|
||||
if #[cfg(target_has_atomic = "ptr")] {
|
||||
let source = Arc::new(source);
|
||||
} else {
|
||||
// TODO(https://github.com/rust-lang/rust/issues/18598): avoid indirection via Box once arbitrary types support unsized coercion
|
||||
|
||||
@@ -10,8 +10,7 @@ use objc2_metal::{
|
||||
use wgt::{AstcBlock, AstcChannel};
|
||||
|
||||
use alloc::{string::ToString as _, sync::Arc, vec::Vec};
|
||||
use core::sync::atomic;
|
||||
use wgpu_sync::{Mutex, OnceCell};
|
||||
use wgpu_sync::{atomic, Mutex, OnceCell};
|
||||
|
||||
use crate::metal::QueueShared;
|
||||
|
||||
|
||||
@@ -23,8 +23,9 @@ use alloc::{
|
||||
sync::Arc,
|
||||
vec::Vec,
|
||||
};
|
||||
use core::{ops::Range, ptr::NonNull, sync::atomic};
|
||||
use core::{ops::Range, ptr::NonNull};
|
||||
use smallvec::SmallVec;
|
||||
use wgpu_sync::atomic;
|
||||
|
||||
// has to match `Temp::binding_sizes`
|
||||
const WORD_SIZE: usize = 4;
|
||||
|
||||
@@ -33,7 +33,7 @@ use alloc::{
|
||||
sync::Arc,
|
||||
vec::Vec,
|
||||
};
|
||||
use core::{fmt, iter, ops, ptr::NonNull, sync::atomic};
|
||||
use core::{fmt, iter, ops, ptr::NonNull};
|
||||
|
||||
use bitflags::bitflags;
|
||||
use hashbrown::HashMap;
|
||||
@@ -55,7 +55,7 @@ use objc2_metal::{
|
||||
MTLTriangleFillMode, MTLWinding,
|
||||
};
|
||||
use objc2_quartz_core::CAMetalLayer;
|
||||
use wgpu_sync::{Condvar, Mutex, OnceCell, RwLock};
|
||||
use wgpu_sync::{atomic, Condvar, Mutex, OnceCell, RwLock};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Api;
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::{cell::UnsafeCell, ops::Range, ptr};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(supports_ptr_atomics)] {
|
||||
use alloc::sync::Arc;
|
||||
} else if #[cfg(feature = "portable-atomic")] {
|
||||
use portable_atomic_util::Arc;
|
||||
}
|
||||
}
|
||||
use wgpu_sync::Arc;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Buffer {
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
use alloc::{string::String, sync::Arc, vec, vec::Vec};
|
||||
use core::{ptr, sync::atomic::Ordering, time::Duration};
|
||||
|
||||
#[cfg(supports_64bit_atomics)]
|
||||
use core::sync::atomic::AtomicU64;
|
||||
#[cfg(not(supports_64bit_atomics))]
|
||||
use portable_atomic::AtomicU64;
|
||||
use wgpu_sync::atomic::AtomicU64;
|
||||
|
||||
use crate::TlasInstance;
|
||||
|
||||
|
||||
@@ -1009,7 +1009,7 @@ struct ResourceIdentityFactory<T> {
|
||||
#[cfg(not(target_has_atomic = "64"))]
|
||||
next_id: Mutex<u64>,
|
||||
#[cfg(target_has_atomic = "64")]
|
||||
next_id: core::sync::atomic::AtomicU64,
|
||||
next_id: wgpu_sync::atomic::AtomicU64,
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
@@ -1019,7 +1019,7 @@ impl<T> ResourceIdentityFactory<T> {
|
||||
#[cfg(not(target_has_atomic = "64"))]
|
||||
next_id: Mutex::new(0),
|
||||
#[cfg(target_has_atomic = "64")]
|
||||
next_id: core::sync::atomic::AtomicU64::new(0),
|
||||
next_id: wgpu_sync::atomic::AtomicU64::new(0),
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user