From d85408afb2bd1c8aa464fe3e4886f67f5e231220 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Fri, 5 Dec 2025 10:44:04 -0500 Subject: [PATCH] Remove hold of snatch write lock during present (#8608) --- CHANGELOG.md | 1 + wgpu-core/src/present.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b227ccd95..2f8a663a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -203,6 +203,7 @@ By @cwfitzgerald in [#8609](https://github.com/gfx-rs/wgpu/pull/8609). - The `STORAGE_READ_ONLY` texture usage is now permitted to coexist with other read-only usages. By @andyleiserson in [#8490](https://github.com/gfx-rs/wgpu/pull/8490). - Validate that buffers are unmapped in `write_buffer` calls. By @ErichDonGubler in [#8454](https://github.com/gfx-rs/wgpu/pull/8454). - Add WGSL parsing for mesh shaders. By @inner-daemons in [#8370](https://github.com/gfx-rs/wgpu/pull/8370). +- Shorten critical section inside present such that the snatch write lock is no longer held during present, preventing other work happening on other threads. By @cwfitzgerald in [#8608](https://github.com/gfx-rs/wgpu/pull/8608). #### naga diff --git a/wgpu-core/src/present.rs b/wgpu-core/src/present.rs index 5d4e25081..0c28fb260 100644 --- a/wgpu-core/src/present.rs +++ b/wgpu-core/src/present.rs @@ -293,7 +293,11 @@ impl Surface { .take() .ok_or(SurfaceError::AlreadyAcquired)?; - let result = match texture.inner.snatch(&mut device.snatchable_lock.write()) { + let mut exclusive_snatch_guard = device.snatchable_lock.write(); + let inner = texture.inner.snatch(&mut exclusive_snatch_guard); + drop(exclusive_snatch_guard); + + let result = match inner { None => return Err(SurfaceError::TextureDestroyed), Some(resource::TextureInner::Surface { raw }) => { let raw_surface = self.raw(device.backend()).unwrap(); @@ -337,7 +341,11 @@ impl Surface { .take() .ok_or(SurfaceError::AlreadyAcquired)?; - match texture.inner.snatch(&mut device.snatchable_lock.write()) { + let mut exclusive_snatch_guard = device.snatchable_lock.write(); + let inner = texture.inner.snatch(&mut exclusive_snatch_guard); + drop(exclusive_snatch_guard); + + match inner { None => return Err(SurfaceError::TextureDestroyed), Some(resource::TextureInner::Surface { raw }) => { let raw_surface = self.raw(device.backend()).unwrap();