From 18b7904b8ec7718e837c79ed91092c31c3115977 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 14 Feb 2024 14:14:35 -0500 Subject: [PATCH] fix: discard cmd. enc. buf. on `wgpu_core::Global::command_encoder_drop` --- CHANGELOG.md | 1 + wgpu-core/src/command/mod.rs | 4 ++-- wgpu-core/src/device/global.rs | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 999e221f1a..034f597bda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,7 @@ Bottom level categories: - Fix panic when creating a surface while no backend is available. By @wumpf [#5166](https://github.com/gfx-rs/wgpu/pull/5166) - Correctly compute minimum buffer size for array-typed `storage` and `uniform` vars. By @jimblandy [#5222](https://github.com/gfx-rs/wgpu/pull/5222) - Fix timeout when presenting a surface where no work has been done. By @waywardmonkeys in [#5200](https://github.com/gfx-rs/wgpu/pull/5200) +- Fix an issue where command encoders weren't properly freed if an error occurred during command encoding. By @ErichDonGubler in [#5251](https://github.com/gfx-rs/wgpu/pull/5251). #### WGL diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 2d5fca200a..416c0b057e 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -75,7 +75,7 @@ impl CommandEncoder { Ok(()) } - fn discard(&mut self) { + pub(crate) fn discard(&mut self) { if self.is_open { self.is_open = false; unsafe { self.raw.discard_encoding() }; @@ -112,7 +112,7 @@ pub(crate) struct DestroyedBufferError(pub id::BufferId); pub(crate) struct DestroyedTextureError(pub id::TextureId); pub struct CommandBufferMutable { - encoder: CommandEncoder, + pub(crate) encoder: CommandEncoder, status: CommandEncoderStatus, pub(crate) trackers: Tracker, buffer_memory_init_actions: Vec>, diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 39408d2d40..fe2a5de041 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -1377,6 +1377,7 @@ impl Global { .command_buffers .unregister(command_encoder_id.transmute()) { + cmd_buf.data.lock().as_mut().unwrap().encoder.discard(); cmd_buf .device .untrack(&cmd_buf.data.lock().as_ref().unwrap().trackers);