Enable wgpu_validate_locks in CI and local debug builds

Fixes #5937
This commit is contained in:
Andy Leiserson authored and mergify[bot] committed 2026-09-18 19:56:30 +00:00
1 parent b9f7ddad53
commit c8dc1509b9
8 files changed
+33 -10

No files matched your search

+5
View File
@@ -1,2 +1,7 @@
[alias]
xtask = "run -p wgpu-xtask --"
[build]
# Note that any rustflags set here will be overridden by the `RUSTFLAGS`
# environment variable, if set (e.g. in CI).
rustflags = ["--cfg", "wgpu_validate_locks_debug"]
+1 -1
View File
@@ -34,7 +34,7 @@ env:
RUST_LOG: debug,wasm_bindgen_wasm_interpreter=warn,wasm_bindgen_cli_support=warn,walrus=warn,naga=info
RUST_BACKTRACE: full
PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work
RUSTFLAGS: -D warnings
RUSTFLAGS: -D warnings --cfg wgpu_validate_locks_debug
RUSTDOCFLAGS: -D warnings
WASM_BINDGEN_TEST_TIMEOUT: 300 # 5 minutes
CACHE_SUFFIX: e # cache busting
+1 -1
View File
@@ -16,7 +16,7 @@ env:
CARGO_INCREMENTAL: false
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
RUSTFLAGS: -D warnings
RUSTFLAGS: -D warnings --cfg wgpu_validate_locks_debug
RUSTDOCFLAGS: -D warnings
#
+1 -2
View File
@@ -184,12 +184,11 @@ By @sagudev in [#10109](https://github.com/gfx-rs/wgpu/pull/10109).
- Zero-initialize padding (if any) at the end of a buffer allocation. This was application-visible in rare cases on Vulkan when a shader read beyond the valid range of a vertex buffer. By @andyleiserson in [#9791](https://github.com/gfx-rs/wgpu/pull/9791).
- Fix required immediate slots calculation and remove `naga::valid::FunctionInfo::immediate_slots_used`. By @beicause in [#9725](https://github.com/gfx-rs/wgpu/pull/9725).
- Fix a spurious assertion failure in `Device::maintain` when multiple threads race polling the same device. By @AdrianEddy in [#9958](https://github.com/gfx-rs/wgpu/pull/9958).
- Fix `PendingSubmission` releasing its lock guards out of stacking order, which tripped `--cfg wgpu_validate_locks` on any submission. By @AdrianEddy in [#9960](https://github.com/gfx-rs/wgpu/pull/9960).
- Fix `Buffer::unmap` failing with `NotMapped` when it races a `Buffer::map` running on another thread. By @AdrianEddy in [#9959](https://github.com/gfx-rs/wgpu/pull/9959).
- Fix separate depth/stencil read-only state and `SYNC-HAZARD-WRITE-AFTER-WRITE` Vulkan validation error. By @beicause in [#9763](https://github.com/gfx-rs/wgpu/pull/9763).
- In `Queue::submit`, validate all command buffers before making any updates to the init trackers. This is not expected to affect performance or behavior when handling successful submission. By @andyleiserson in [#10003](https://github.com/gfx-rs/wgpu/pull/10003).
- Fix initialization tracking for some cases of array textures, 3d textures, and depth/stencil textures with divergent usage in a render pass. By @andyleiserson in [#10002](https://github.com/gfx-rs/wgpu/pull/10002) and [#10060](https://github.com/gfx-rs/wgpu/pull/10060).
- Fixed a deadlock between `Queue::compact_blas` and `Queue::submit`, which acquired `Device::command_indices` and `Queue::pending_writes` in opposite orders. By @mstampfli in [#10118](https://github.com/gfx-rs/wgpu/pull/10118).
- Fix various deadlocks due to inconsistent ordering of lock acquisitions. `wgpu` is now tested with lock rank checking (`--cfg wgpu_validate_locks`) in CI, which should prevent many deadlocks in the future. By @AdrianEddy in [#9960](https://github.com/gfx-rs/wgpu/pull/9960), @mstampfli in [#10118](https://github.com/gfx-rs/wgpu/pull/10118), and @andyleiserson in [#9728](https://github.com/gfx-rs/wgpu/pull/9728) and [#9479](https://github.com/gfx-rs/wgpu/pull/9479).
- Fixed some cases of passing object labels to platform APIs despite `InstanceFlags::DISCARD_HAL_LABELS` being set. By @andyleiserson in [#10121](https://github.com/gfx-rs/wgpu/pull/10121) and [#10123](https://github.com/gfx-rs/wgpu/pull/10123).
- Clean up resources properly when `Device::new` fails, to avoid a leak or panic. By @andyleiserson in [#10160](https://github.com/gfx-rs/wgpu/pull/10160).
- Fix pending buffer mappings incorrectly succeeding when the device is lost before they are processed. By @jinleili in [#10301](https://github.com/gfx-rs/wgpu/pull/10301).
+4 -1
View File
@@ -30,7 +30,10 @@ ignored = ["cfg_aliases"]
[lints.rust]
missing_debug_implementations = "warn"
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wgpu_validate_locks)'] }
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(wgpu_validate_locks)',
'cfg(wgpu_validate_locks_debug)',
] }
[lib]
+10
View File
@@ -25,5 +25,15 @@ fn main() {
any(target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")
) },
metal: { all(target_vendor = "apple", feature = "metal") },
// `wgpu_validate_locks` can also be set directly, if desired.
// See `wgpu-core/src/lock/mod.rs`.
wgpu_validate_locks: {
all(
debug_assertions,
wgpu_validate_locks_debug,
not(target_family = "wasm")
)
}
}
}
+10 -5
View File
@@ -17,10 +17,14 @@
//! uninstrumented, no-overhead wrappers around the standard lock
//! types.
//!
//! If the `wgpu_validate_locks` config is set (for example, with
//! `RUSTFLAGS='--cfg wgpu_validate_locks'`), `wgpu-core` uses the
//! [`ranked`] module's locks. We hope to make this the default for
//! debug builds soon.
//! If the `wgpu_validate_locks` config is set (either directly, i.e. with
//! `RUSTFLAGS='--cfg wgpu_validate_locks'`, or via the
//! `wgpu_validate_locks_debug` `cfg` alias in `build.rs` that conditionally
//! enables it when debug assertions are also enabled), `wgpu-core` uses the
//! [`ranked`] module's locks. `.config/cargo.toml` in the `wgpu` tree specifies
//! `wgpu_validate_locks_debug`, so lock validation is active by default in
//! `wgpu` CI and `wgpu` development trees, but not in `wgpu`-using applications
//! unless specifically requested.
//!
//! If the `observe_locks` feature is enabled, `wgpu-core` uses the
//! [`observing`] module's locks.
@@ -38,6 +42,7 @@ pub mod rank;
mod ranked;
#[cfg(feature = "observe_locks")]
#[cfg_attr(wgpu_validate_locks, allow(dead_code))]
mod observing;
#[cfg_attr(any(wgpu_validate_locks, feature = "observe_locks"), allow(dead_code))]
@@ -46,7 +51,7 @@ mod vanilla;
#[cfg(wgpu_validate_locks)]
use ranked as chosen;
#[cfg(feature = "observe_locks")]
#[cfg(all(not(wgpu_validate_locks), feature = "observe_locks"))]
use observing as chosen;
#[cfg(not(any(wgpu_validate_locks, feature = "observe_locks")))]
+1
View File
@@ -289,6 +289,7 @@ pub struct RwLockReadGuard<'a, T> {
/// For details, see [the module documentation][self].
pub struct RwLockWriteGuard<'a, T> {
inner: wgpu_sync::RwLockWriteGuard<'a, T>,
#[cfg_attr(not(miri), expect(unused))] // but `Drop` has important side effects
saved: LockStateGuard,
}