Skip to content

Fixed a deadlock caused by locking the device's snatchable lock after locking the queue's pending writes #7582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
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
11 changes: 8 additions & 3 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ impl Queue {
return Ok(());
};

let snatch_guard = self.device.snatchable_lock.read();

// Platform validation requires that the staging buffer always be
// freed, even if an error occurs. All paths from here must call
// `device.pending_writes.consume`.
Expand All @@ -489,6 +491,7 @@ impl Queue {
};

let result = self.write_staging_buffer_impl(
&snatch_guard,
&mut pending_writes,
&staging_buffer,
buffer,
Expand Down Expand Up @@ -522,6 +525,7 @@ impl Queue {

let buffer = buffer.get()?;

let snatch_guard = self.device.snatchable_lock.read();
let mut pending_writes = self.pending_writes.lock();

// At this point, we have taken ownership of the staging_buffer from the
Expand All @@ -531,6 +535,7 @@ impl Queue {
let staging_buffer = staging_buffer.flush();

let result = self.write_staging_buffer_impl(
&snatch_guard,
&mut pending_writes,
&staging_buffer,
buffer,
Expand Down Expand Up @@ -583,6 +588,7 @@ impl Queue {

fn write_staging_buffer_impl(
&self,
snatch_guard: &SnatchGuard,
pending_writes: &mut PendingWrites,
staging_buffer: &FlushedStagingBuffer,
buffer: Arc<Buffer>,
Expand All @@ -595,8 +601,7 @@ impl Queue {
.set_single(&buffer, wgt::BufferUses::COPY_DST)
};

let snatch_guard = self.device.snatchable_lock.read();
let dst_raw = buffer.try_raw(&snatch_guard)?;
let dst_raw = buffer.try_raw(snatch_guard)?;

self.same_device_as(buffer.as_ref())?;

Expand All @@ -614,7 +619,7 @@ impl Queue {
to: wgt::BufferUses::COPY_SRC,
},
})
.chain(transition.map(|pending| pending.into_hal(&buffer, &snatch_guard)))
.chain(transition.map(|pending| pending.into_hal(&buffer, snatch_guard)))
.collect::<Vec<_>>();
let encoder = pending_writes.activate();
unsafe {
Expand Down
Loading