Skip to content

Commit a26171b

Browse files
Fix compilation for targets that don't have AtomicU64. (#7118)
Co-authored-by: Connor Fitzgerald <[email protected]>
1 parent 37419a3 commit a26171b

File tree

14 files changed

+80
-17
lines changed

14 files changed

+80
-17
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ jobs:
181181
tier: 2
182182
kind: no_std
183183

184+
# 32-bit PowerPC Linux
185+
# Included to test support for `portable-atomic`
186+
- name: Linux ppc32
187+
os: ubuntu-22.04
188+
target: powerpc-unknown-linux-gnu
189+
tier: 2
190+
kind: wgpu-only
191+
184192
name: Clippy ${{ matrix.name }}
185193
runs-on: ${{ matrix.os }}
186194

Cargo.lock

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ pico-args = { version = "0.5.0", features = [
135135
] }
136136
png = "0.17.16"
137137
pollster = "0.4"
138+
portable-atomic = "1"
138139
profiling = { version = "1", default-features = false }
139140
raw-window-handle = { version = "0.6", default-features = false }
140141
rayon = "1"

wgpu-core/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ fragile-send-sync-non-atomic-wasm = [
114114
## Enable using the `mach-dxcompiler-rs` crate to compile DX12 shaders.
115115
static-dxc = ["wgpu-hal/static-dxc"]
116116

117+
## Enable portable atomics on platforms that do not support 64bit atomics.
118+
portable-atomic = ["dep:portable-atomic", "wgpu-hal/portable-atomic"]
119+
117120
#! ### Target Conditional Features
118121
# --------------------------------------------------------------------
119122
# Look to wgpu-hal's Cargo.toml for explaination how these features and the wgpu-core
@@ -179,5 +182,8 @@ serde = { workspace = true, features = ["default", "derive"], optional = true }
179182
smallvec.workspace = true
180183
thiserror.workspace = true
181184

185+
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
186+
portable-atomic = { workspace = true, optional = true }
187+
182188
[build-dependencies]
183189
cfg_aliases.workspace = true

wgpu-core/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ fn main() {
1818
all(target_vendor = "apple", feature = "vulkan-portability") // Vulkan Portability on Apple
1919
) },
2020
metal: { all(target_vendor = "apple", feature = "metal") },
21+
22+
supports_64bit_atomics: { target_has_atomic = "64" }
2123
}
2224
}

wgpu-core/src/device/resource.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::{
99
fmt,
1010
mem::{self, ManuallyDrop},
1111
num::NonZeroU32,
12-
sync::atomic::{AtomicBool, AtomicU64, Ordering},
12+
sync::atomic::{AtomicBool, Ordering},
1313
};
1414
use std::sync::OnceLock;
1515

@@ -57,6 +57,11 @@ use super::{
5757
ENTRYPOINT_FAILURE_ERROR, ZERO_BUFFER_SIZE,
5858
};
5959

60+
#[cfg(supports_64bit_atomics)]
61+
use core::sync::atomic::AtomicU64;
62+
#[cfg(not(supports_64bit_atomics))]
63+
use portable_atomic::AtomicU64;
64+
6065
/// Structure describing a logical device. Some members are internally mutable,
6166
/// stored behind mutexes.
6267
pub struct Device {

wgpu-hal/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ renderdoc = ["dep:libloading", "dep:renderdoc-sys", "dep:log"]
155155
fragile-send-sync-non-atomic-wasm = [
156156
"wgpu-types/fragile-send-sync-non-atomic-wasm",
157157
]
158+
portable-atomic = ["dep:portable-atomic"]
158159

159160
###################################
160161
### Internal Debugging Features ###
@@ -300,6 +301,9 @@ khronos-egl = { workspace = true, optional = true, features = [
300301
# Note: it's unused by emscripten, but we keep it to have single code base in egl.rs
301302
libloading = { workspace = true, optional = true }
302303

304+
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
305+
portable-atomic = { workspace = true, optional = true }
306+
303307
[build-dependencies]
304308
cfg_aliases.workspace = true
305309

wgpu-hal/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn main() {
1212
metal: { all(target_vendor = "apple", feature = "metal") },
1313
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") },
1414
// ⚠️ Keep in sync with target.cfg() definition in Cargo.toml and cfg_alias in `wgpu` crate ⚠️
15-
static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64")) }
15+
static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64")) },
16+
supports_64bit_atomics: { target_has_atomic = "64" }
1617
}
1718
}

wgpu-hal/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ pub const QUERY_SIZE: wgt::BufferAddress = 8;
317317
pub type Label<'a> = Option<&'a str>;
318318
pub type MemoryRange = Range<wgt::BufferAddress>;
319319
pub type FenceValue = u64;
320+
#[cfg(supports_64bit_atomics)]
320321
pub type AtomicFenceValue = core::sync::atomic::AtomicU64;
322+
#[cfg(not(supports_64bit_atomics))]
323+
pub type AtomicFenceValue = portable_atomic::AtomicU64;
321324

322325
/// A callback to signal that wgpu is no longer using a resource.
323326
#[cfg(any(gles, vulkan))]

wgpu-hal/src/noop/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#![allow(unused_variables)]
22

33
use alloc::{string::String, vec, vec::Vec};
4-
use core::{
5-
ptr,
6-
sync::atomic::{AtomicU64, Ordering},
7-
time::Duration,
8-
};
4+
use core::{ptr, sync::atomic::Ordering, time::Duration};
5+
6+
#[cfg(supports_64bit_atomics)]
7+
use core::sync::atomic::AtomicU64;
8+
#[cfg(not(supports_64bit_atomics))]
9+
use portable_atomic::AtomicU64;
910

1011
use crate::TlasInstance;
1112

0 commit comments

Comments
 (0)