Skip to content

Commit

Permalink
d3d12: Propagate errors when closing command lists (#5125)
Browse files Browse the repository at this point in the history
Before this commit, command lists that we failed to close were used anyway during submit, causing device loss.
  • Loading branch information
nical authored Jan 23, 2024
1 parent ac8756c commit 60a5739
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
14 changes: 7 additions & 7 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,18 @@ impl<A: HalApi> PendingWrites<A> {
.push(TempResource::StagingBuffer(buffer));
}

#[must_use]
fn pre_submit(&mut self) -> Option<&A::CommandBuffer> {
fn pre_submit(&mut self) -> Result<Option<&A::CommandBuffer>, DeviceError> {
self.dst_buffers.clear();
self.dst_textures.clear();
if self.is_active {
let cmd_buf = unsafe { self.command_encoder.end_encoding().unwrap() };
let cmd_buf = unsafe { self.command_encoder.end_encoding()? };
self.is_active = false;
self.executing_command_buffers.push(cmd_buf);
self.executing_command_buffers.last()
} else {
None

return Ok(self.executing_command_buffers.last());
}

Ok(None)
}

#[must_use]
Expand Down Expand Up @@ -1463,7 +1463,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

let refs = pending_writes
.pre_submit()
.pre_submit()?
.into_iter()
.chain(
active_executions
Expand Down
9 changes: 4 additions & 5 deletions wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,13 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
}
unsafe fn end_encoding(&mut self) -> Result<super::CommandBuffer, crate::DeviceError> {
let raw = self.list.take().unwrap();
let closed = raw.close().into_result().is_ok();
Ok(super::CommandBuffer { raw, closed })
raw.close()
.into_device_result("GraphicsCommandList::close")?;
Ok(super::CommandBuffer { raw })
}
unsafe fn reset_all<I: Iterator<Item = super::CommandBuffer>>(&mut self, command_buffers: I) {
for cmd_buf in command_buffers {
if cmd_buf.closed {
self.free_lists.push(cmd_buf.raw);
}
self.free_lists.push(cmd_buf.raw);
}
self.allocator.reset();
}
Expand Down
1 change: 0 additions & 1 deletion wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ impl fmt::Debug for CommandEncoder {
#[derive(Debug)]
pub struct CommandBuffer {
raw: d3d12::GraphicsCommandList,
closed: bool,
}

unsafe impl Send for CommandBuffer {}
Expand Down

0 comments on commit 60a5739

Please sign in to comment.