From c92dbae57ee255a59e3dc1f8259f492970f9afc2 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 8 Oct 2020 23:12:31 -0400 Subject: [PATCH] [rs] Immediate resource destruction --- wgpu/src/backend/direct.rs | 16 ++++++++++++---- wgpu/src/backend/web.rs | 12 +++++++++--- wgpu/src/lib.rs | 15 ++++++++++++++- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index b73db414c1..319732b7e9 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -1206,6 +1206,18 @@ impl crate::Context for Context { ) } + fn buffer_destroy(&self, buffer: &Self::BufferId) { + let global = &self.0; + wgc::gfx_select!(buffer.id => global.buffer_destroy(buffer.id)).unwrap_pretty() + } + fn buffer_drop(&self, buffer: &Self::BufferId) { + let global = &self.0; + wgc::gfx_select!(buffer.id => global.buffer_drop(buffer.id, false)) + } + fn texture_destroy(&self, texture: &Self::TextureId) { + let global = &self.0; + wgc::gfx_select!(texture.id => global.texture_destroy(texture.id)).unwrap_pretty() + } fn texture_drop(&self, texture: &Self::TextureId) { let global = &self.0; wgc::gfx_select!(texture.id => global.texture_drop(texture.id, false)) @@ -1218,10 +1230,6 @@ impl crate::Context for Context { let global = &self.0; wgc::gfx_select!(*sampler => global.sampler_drop(*sampler)) } - fn buffer_drop(&self, buffer: &Self::BufferId) { - let global = &self.0; - wgc::gfx_select!(buffer.id => global.buffer_drop(buffer.id, false)) - } fn bind_group_drop(&self, bind_group: &Self::BindGroupId) { let global = &self.0; wgc::gfx_select!(*bind_group => global.bind_group_drop(*bind_group)) diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index c149c02cac..d0dce39506 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1267,6 +1267,15 @@ impl crate::Context for Context { Sendable(texture.0.create_view_with_descriptor(&mapped)) } + fn buffer_destroy(&self, _buffer: &Self::BufferId) { + // TODO + } + fn buffer_drop(&self, _buffer: &Self::BufferId) { + // Dropped automatically + } + fn texture_destroy(&self, _texture: &Self::TextureId) { + // TODO + } fn texture_drop(&self, _texture: &Self::TextureId) { // Dropped automatically } @@ -1276,9 +1285,6 @@ impl crate::Context for Context { fn sampler_drop(&self, _sampler: &Self::SamplerId) { // Dropped automatically } - fn buffer_drop(&self, _buffer: &Self::BufferId) { - // Dropped automatically - } fn bind_group_drop(&self, _bind_group: &Self::BindGroupId) { // Dropped automatically } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 63d2ae3458..e08dff11c6 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -301,10 +301,13 @@ trait Context: Debug + Send + Sized + Sync { texture: &Self::TextureId, desc: &TextureViewDescriptor, ) -> Self::TextureViewId; + + fn buffer_destroy(&self, buffer: &Self::BufferId); + fn buffer_drop(&self, buffer: &Self::BufferId); + fn texture_destroy(&self, buffer: &Self::TextureId); fn texture_drop(&self, texture: &Self::TextureId); fn texture_view_drop(&self, texture_view: &Self::TextureViewId); fn sampler_drop(&self, sampler: &Self::SamplerId); - fn buffer_drop(&self, buffer: &Self::BufferId); fn bind_group_drop(&self, bind_group: &Self::BindGroupId); fn bind_group_layout_drop(&self, bind_group_layout: &Self::BindGroupLayoutId); fn pipeline_layout_drop(&self, pipeline_layout: &Self::PipelineLayoutId); @@ -1716,6 +1719,11 @@ impl Buffer { self.map_context.lock().reset(); Context::buffer_unmap(&*self.context, &self.id); } + + /// Destroy the associated native resources as soon as possible. + pub fn destroy(&self) { + Context::buffer_destroy(&*self.context, &self.id); + } } impl<'a> BufferSlice<'a> { @@ -1802,6 +1810,11 @@ impl Texture { owned: true, } } + + /// Destroy the associated native resources as soon as possible. + pub fn destroy(&self) { + Context::texture_destroy(&*self.context, &self.id); + } } impl Drop for Texture {