From 60a5739df2806b6435ce6875354bf2ba9ba02709 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 23 Jan 2024 14:30:08 +0100 Subject: [PATCH] d3d12: Propagate errors when closing command lists (#5125) Before this commit, command lists that we failed to close were used anyway during submit, causing device loss. --- wgpu-core/src/device/queue.rs | 14 +++++++------- wgpu-hal/src/dx12/command.rs | 9 ++++----- wgpu-hal/src/dx12/mod.rs | 1 - 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 43a2d1d98..4e56350d8 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -228,18 +228,18 @@ impl PendingWrites { .push(TempResource::StagingBuffer(buffer)); } - #[must_use] - fn pre_submit(&mut self) -> Option<&A::CommandBuffer> { + fn pre_submit(&mut self) -> Result, 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] @@ -1463,7 +1463,7 @@ impl Global { } let refs = pending_writes - .pre_submit() + .pre_submit()? .into_iter() .chain( active_executions diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index 3d05813ed..f527898d9 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -289,14 +289,13 @@ impl crate::CommandEncoder for super::CommandEncoder { } unsafe fn end_encoding(&mut self) -> Result { 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>(&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(); } diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 038bb8ca1..3c786f9e4 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -386,7 +386,6 @@ impl fmt::Debug for CommandEncoder { #[derive(Debug)] pub struct CommandBuffer { raw: d3d12::GraphicsCommandList, - closed: bool, } unsafe impl Send for CommandBuffer {}