Skip to content

Commit 995efdd

Browse files
Fix portable-atomic on wgpu-hal (#7735)
1 parent e40e66d commit 995efdd

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ pico-args = { version = "0.5", features = [
159159
] }
160160
png = "0.17.6"
161161
pollster = "0.4"
162-
portable-atomic = "1.2"
162+
portable-atomic = "1.8"
163+
portable-atomic-util = "0.2.4"
163164
pp-rs = "0.2.1"
164165
profiling = { version = "1", default-features = false }
165166
quote = "1.0.38"

wgpu-hal/Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ gles = [
107107
"naga/glsl-out",
108108
"dep:arrayvec",
109109
"dep:bytemuck",
110-
"dep:cfg-if",
111110
"dep:glow",
112111
"dep:glutin_wgl_sys",
113112
"dep:hashbrown",
@@ -165,7 +164,7 @@ renderdoc = ["dep:libloading", "dep:renderdoc-sys", "dep:log"]
165164
fragile-send-sync-non-atomic-wasm = [
166165
"wgpu-types/fragile-send-sync-non-atomic-wasm",
167166
]
168-
portable-atomic = ["dep:portable-atomic"]
167+
portable-atomic = ["dep:portable-atomic", "dep:portable-atomic-util"]
169168

170169
###################################
171170
### Internal Debugging Features ###
@@ -207,6 +206,7 @@ wgpu-types = { workspace = true, default-features = false }
207206

208207
# Dependencies in the lib and empty backend
209208
bitflags.workspace = true
209+
cfg-if.workspace = true
210210
raw-window-handle.workspace = true
211211
parking_lot = { workspace = true, optional = true }
212212
thiserror.workspace = true
@@ -216,14 +216,12 @@ arrayvec = { workspace = true, optional = true }
216216
bytemuck = { workspace = true, optional = true, features = ["derive"] }
217217
hashbrown = { workspace = true, optional = true }
218218
log = { workspace = true, optional = true }
219-
once_cell = { workspace = true, optional = true }
220219
ordered-float = { workspace = true, optional = true }
221220
profiling = { workspace = true, optional = true, default-features = false }
222221
rustc-hash = { workspace = true, optional = true }
223222

224223
# Backend: GLES
225224
glow = { workspace = true, optional = true }
226-
cfg-if = { workspace = true, optional = true }
227225

228226
########################
229227
### Platform: Native ###
@@ -318,14 +316,18 @@ khronos-egl = { workspace = true, optional = true, features = [
318316
# Note: it's unused by emscripten, but we keep it to have single code base in egl.rs
319317
libloading = { workspace = true, optional = true }
320318

321-
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
319+
[target.'cfg(any(not(target_has_atomic = "64"), not(target_has_atomic = "ptr")))'.dependencies]
322320
portable-atomic = { workspace = true, optional = true }
323321

322+
[target.'cfg(not(target_has_atomic = "ptr"))'.dependencies]
323+
portable-atomic-util = { workspace = true, features = [
324+
"alloc",
325+
], optional = true }
326+
324327
[build-dependencies]
325328
cfg_aliases.workspace = true
326329

327330
[dev-dependencies]
328-
cfg-if.workspace = true
329331
env_logger.workspace = true
330332
glam.workspace = true # for ray-traced-triangle example
331333
naga = { workspace = true, features = ["wgsl-in", "termcolor"] }

wgpu-hal/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn main() {
2525
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") },
2626
// ⚠️ Keep in sync with target.cfg() definition in Cargo.toml and cfg_alias in `wgpu` crate ⚠️
2727
static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64")) },
28-
supports_64bit_atomics: { target_has_atomic = "64" }
28+
supports_64bit_atomics: { target_has_atomic = "64" },
29+
supports_ptr_atomics: { target_has_atomic = "ptr" }
2930
}
3031
}

wgpu-hal/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ pub use dynamic::{
292292

293293
#[allow(unused)]
294294
use alloc::boxed::Box;
295-
use alloc::{borrow::Cow, string::String, sync::Arc, vec::Vec};
295+
use alloc::{borrow::Cow, string::String, vec::Vec};
296296
use core::{
297297
borrow::Borrow,
298298
error::Error,
@@ -306,6 +306,14 @@ use bitflags::bitflags;
306306
use thiserror::Error;
307307
use wgt::WasmNotSendSync;
308308

309+
cfg_if::cfg_if! {
310+
if #[cfg(supports_ptr_atomics)] {
311+
use alloc::sync::Arc;
312+
} else if #[cfg(feature = "portable-atomic")] {
313+
use portable_atomic_util::Arc;
314+
}
315+
}
316+
309317
// - Vertex + Fragment
310318
// - Compute
311319
// Task + Mesh + Fragment
@@ -450,9 +458,18 @@ impl InstanceError {
450458
}
451459
#[allow(dead_code)] // may be unused on some platforms
452460
pub(crate) fn with_source(message: String, source: impl Error + Send + Sync + 'static) -> Self {
461+
cfg_if::cfg_if! {
462+
if #[cfg(supports_ptr_atomics)] {
463+
let source = Arc::new(source);
464+
} else {
465+
// TODO(https://github.com/rust-lang/rust/issues/18598): avoid indirection via Box once arbitrary types support unsized coercion
466+
let source: Box<dyn Error + Send + Sync + 'static> = Box::new(source);
467+
let source = Arc::from(source);
468+
}
469+
}
453470
Self {
454471
message,
455-
source: Some(Arc::new(source)),
472+
source: Some(source),
456473
}
457474
}
458475
}

wgpu-hal/src/noop/buffer.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
use alloc::{sync::Arc, vec::Vec};
1+
use alloc::vec::Vec;
22
use core::{cell::UnsafeCell, ops::Range, ptr};
33

4+
cfg_if::cfg_if! {
5+
if #[cfg(supports_ptr_atomics)] {
6+
use alloc::sync::Arc;
7+
} else if #[cfg(feature = "portable-atomic")] {
8+
use portable_atomic_util::Arc;
9+
}
10+
}
11+
412
#[derive(Clone, Debug)]
513
pub struct Buffer {
614
/// This data is potentially accessed mutably in arbitrary non-overlapping slices,

0 commit comments

Comments
 (0)