Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ jobs:
tier: 2
kind: no_std

# 32-bit PowerPC Linux
# Included to test support for `portable-atomic`
- name: Linux ppc32
os: ubuntu-22.04
target: powerpc-unknown-linux-gnu
tier: 2
kind: wgpu-only

name: Clippy ${{ matrix.name }}
runs-on: ${{ matrix.os }}

Expand Down
21 changes: 15 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pico-args = { version = "0.5.0", features = [
] }
png = "0.17.16"
pollster = "0.4"
portable-atomic = "1"
profiling = { version = "1", default-features = false }
raw-window-handle = { version = "0.6", default-features = false }
rayon = "1"
Expand Down
6 changes: 6 additions & 0 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ fragile-send-sync-non-atomic-wasm = [
## Enable using the `mach-dxcompiler-rs` crate to compile DX12 shaders.
static-dxc = ["wgpu-hal/static-dxc"]

## Enable portable atomics on platforms that do not support 64bit atomics.
portable-atomic = ["dep:portable-atomic", "wgpu-hal/portable-atomic"]

#! ### Target Conditional Features
# --------------------------------------------------------------------
# Look to wgpu-hal's Cargo.toml for explaination how these features and the wgpu-core
Expand Down Expand Up @@ -179,5 +182,8 @@ serde = { workspace = true, features = ["default", "derive"], optional = true }
smallvec.workspace = true
thiserror.workspace = true

[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
portable-atomic = { workspace = true, optional = true }

[build-dependencies]
cfg_aliases.workspace = true
2 changes: 2 additions & 0 deletions wgpu-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ fn main() {
all(target_vendor = "apple", feature = "vulkan-portability") // Vulkan Portability on Apple
) },
metal: { all(target_vendor = "apple", feature = "metal") },

supports_64bit_atomics: { target_has_atomic = "64" }
}
}
7 changes: 6 additions & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::{
fmt,
mem::{self, ManuallyDrop},
num::NonZeroU32,
sync::atomic::{AtomicBool, AtomicU64, Ordering},
sync::atomic::{AtomicBool, Ordering},
};
use std::sync::OnceLock;

Expand Down Expand Up @@ -57,6 +57,11 @@ use super::{
ENTRYPOINT_FAILURE_ERROR, ZERO_BUFFER_SIZE,
};

#[cfg(supports_64bit_atomics)]
use core::sync::atomic::AtomicU64;
#[cfg(not(supports_64bit_atomics))]
use portable_atomic::AtomicU64;

/// Structure describing a logical device. Some members are internally mutable,
/// stored behind mutexes.
pub struct Device {
Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ renderdoc = ["dep:libloading", "dep:renderdoc-sys", "dep:log"]
fragile-send-sync-non-atomic-wasm = [
"wgpu-types/fragile-send-sync-non-atomic-wasm",
]
portable-atomic = ["dep:portable-atomic"]

###################################
### Internal Debugging Features ###
Expand Down Expand Up @@ -300,6 +301,9 @@ 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(not(target_has_atomic = "64"))'.dependencies]
portable-atomic = { workspace = true, optional = true }

[build-dependencies]
cfg_aliases.workspace = true

Expand Down
3 changes: 2 additions & 1 deletion wgpu-hal/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn main() {
metal: { all(target_vendor = "apple", feature = "metal") },
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") },
// ⚠️ 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")) }
static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64")) },
supports_64bit_atomics: { target_has_atomic = "64" }
}
}
3 changes: 3 additions & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ 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;

/// A callback to signal that wgpu is no longer using a resource.
#[cfg(any(gles, vulkan))]
Expand Down
11 changes: 6 additions & 5 deletions wgpu-hal/src/noop/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![allow(unused_variables)]

use alloc::{string::String, vec, vec::Vec};
use core::{
ptr,
sync::atomic::{AtomicU64, Ordering},
time::Duration,
};
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 crate::TlasInstance;

Expand Down
4 changes: 4 additions & 0 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ wgpu-core = { workspace = true, features = [
"raw-window-handle",
"renderdoc",
"indirect-validation",
"portable-atomic",
] }
wgpu-hal.workspace = true

Expand Down Expand Up @@ -216,5 +217,8 @@ wgpu-hal.workspace = true

smallvec.workspace = true

[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
portable-atomic.workspace = true

[build-dependencies]
cfg_aliases.workspace = true
1 change: 1 addition & 0 deletions wgpu/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ fn main() {
naga: { any(feature = "naga-ir", feature = "spirv", feature = "glsl") },
// ⚠️ Keep in sync with target.cfg() definition in wgpu-hal/Cargo.toml and cfg_alias in `wgpu-hal` crate ⚠️
static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64")) },
supports_64bit_atomics: { target_has_atomic = "64" }
}
}
10 changes: 6 additions & 4 deletions wgpu/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
//!
//! For types (like WebGPU) that don't have such a property, we generate an identifier and use that.

use core::{
num::NonZeroU64,
sync::atomic::{AtomicU64, Ordering},
};
#[cfg(supports_64bit_atomics)]
pub use core::sync::atomic::AtomicU64;
#[cfg(not(supports_64bit_atomics))]
pub use portable_atomic::AtomicU64;

use core::{num::NonZeroU64, sync::atomic::Ordering};

static NEXT_ID: AtomicU64 = AtomicU64::new(1);

Expand Down
16 changes: 16 additions & 0 deletions xtask/src/check_feature_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ pub fn check_feature_dependencies(shell: Shell, arguments: Arguments) -> anyhow:
default_features: false,
search_terms: &[Search::Positive("glow")],
},
Requirement {
human_readable_name: "x86-64 does not depend on portable-atomic",
target: "x86_64-unknown-linux-gnu",
packages: &["wgpu"],
features: &[],
default_features: false,
search_terms: &[Search::Negative("portable-atomic")],
},
Requirement {
human_readable_name: "ppc32 does depend on portable-atomic",
target: "powerpc-unknown-linux-gnu",
packages: &["wgpu"],
features: &[],
default_features: false,
search_terms: &[Search::Positive("portable-atomic")],
},
];

let mut any_failures = false;
Expand Down
Loading