Skip to content

Commit d85408a

Browse files
authored
Remove hold of snatch write lock during present (#8608)
1 parent 655441c commit d85408a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ By @cwfitzgerald in [#8609](https://github.com/gfx-rs/wgpu/pull/8609).
203203
- 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).
204204
- Validate that buffers are unmapped in `write_buffer` calls. By @ErichDonGubler in [#8454](https://github.com/gfx-rs/wgpu/pull/8454).
205205
- Add WGSL parsing for mesh shaders. By @inner-daemons in [#8370](https://github.com/gfx-rs/wgpu/pull/8370).
206+
- 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).
206207

207208
#### naga
208209

wgpu-core/src/present.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ impl Surface {
293293
.take()
294294
.ok_or(SurfaceError::AlreadyAcquired)?;
295295

296-
let result = match texture.inner.snatch(&mut device.snatchable_lock.write()) {
296+
let mut exclusive_snatch_guard = device.snatchable_lock.write();
297+
let inner = texture.inner.snatch(&mut exclusive_snatch_guard);
298+
drop(exclusive_snatch_guard);
299+
300+
let result = match inner {
297301
None => return Err(SurfaceError::TextureDestroyed),
298302
Some(resource::TextureInner::Surface { raw }) => {
299303
let raw_surface = self.raw(device.backend()).unwrap();
@@ -337,7 +341,11 @@ impl Surface {
337341
.take()
338342
.ok_or(SurfaceError::AlreadyAcquired)?;
339343

340-
match texture.inner.snatch(&mut device.snatchable_lock.write()) {
344+
let mut exclusive_snatch_guard = device.snatchable_lock.write();
345+
let inner = texture.inner.snatch(&mut exclusive_snatch_guard);
346+
drop(exclusive_snatch_guard);
347+
348+
match inner {
341349
None => return Err(SurfaceError::TextureDestroyed),
342350
Some(resource::TextureInner::Surface { raw }) => {
343351
let raw_surface = self.raw(device.backend()).unwrap();

0 commit comments

Comments
 (0)