Skip to content

Commit

Permalink
Drop texture clear_views in surface_texture_discard (#4057)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajveermalviya authored Aug 30, 2023
1 parent e47dc2a commit 625afc3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ By @Valaphee in [#3402](https://github.com/gfx-rs/wgpu/pull/3402)

- Derive storage bindings via `naga::StorageAccess` instead of `naga::GlobalUse`. By @teoxoy in [#3985](https://github.com/gfx-rs/wgpu/pull/3985).
- `Queue::on_submitted_work_done` callbacks will now always be called after all previous `BufferSlice::map_async` callbacks, even when there are no active submissions. By @cwfitzgerald in [#4036](https://github.com/gfx-rs/wgpu/pull/4036).
- Fix `clear` texture views being leaked when `wgpu::SurfaceTexture` is dropped before it is presented. By @rajveermalviya in [#4057](https://github.com/gfx-rs/wgpu/pull/4057).

#### Vulkan
- Fix enabling `wgpu::Features::PARTIALLY_BOUND_BINDING_ARRAY` not being actually enabled in vulkan backend. By @39ali in[#3772](https://github.com/gfx-rs/wgpu/pull/3772).
Expand Down
16 changes: 7 additions & 9 deletions wgpu-core/src/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let (texture, _) = hub.textures.unregister(texture_id.value.0, &mut token);
if let Some(texture) = texture {
if let resource::TextureClearMode::RenderPass { clear_views, .. } =
texture.clear_mode
{
for clear_view in clear_views {
unsafe {
hal::Device::destroy_texture_view(&device.raw, clear_view);
}
}
}
texture.clear_mode.destroy_clear_views(&device.raw);

let suf = A::get_surface_mut(surface);
match texture.inner {
Expand Down Expand Up @@ -386,10 +378,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

// The texture ID got added to the device tracker by `submit()`,
// and now we are moving it away.
log::debug!(
"Removing swapchain texture {:?} from the device tracker",
texture_id.value
);
device.trackers.lock().textures.remove(texture_id.value);

let (texture, _) = hub.textures.unregister(texture_id.value.0, &mut token);
if let Some(texture) = texture {
texture.clear_mode.destroy_clear_views(&device.raw);

let suf = A::get_surface_mut(surface);
match texture.inner {
resource::TextureInner::Surface {
Expand Down
12 changes: 12 additions & 0 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ pub enum TextureClearMode<A: hal::Api> {
None,
}

impl<A: hal::Api> TextureClearMode<A> {
pub(crate) fn destroy_clear_views(self, device: &A::Device) {
if let TextureClearMode::RenderPass { clear_views, .. } = self {
for clear_view in clear_views {
unsafe {
hal::Device::destroy_texture_view(device, clear_view);
}
}
}
}
}

#[derive(Debug)]
pub struct Texture<A: hal::Api> {
pub(crate) inner: TextureInner<A>,
Expand Down

0 comments on commit 625afc3

Please sign in to comment.