From ec119b16884c7eeab80817f2c1ed5f91bb050921 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Thu, 31 Mar 2022 16:57:28 -0700 Subject: [PATCH 1/2] Add logging to LifetimeTracker::triage_suspected. This adds `log::debug` lines reporting the decision to actually free something, for all resource types. --- wgpu-core/src/device/life.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index 21efcb4256..5669e89e1b 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -445,6 +445,7 @@ impl LifetimeTracker { while let Some(id) = self.suspected_resources.render_bundles.pop() { if trackers.bundles.remove_abandoned(id) { + log::debug!("Bundle {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyRenderBundle(id.0)); @@ -463,6 +464,7 @@ impl LifetimeTracker { while let Some(id) = self.suspected_resources.bind_groups.pop() { if trackers.bind_groups.remove_abandoned(id) { + log::debug!("Bind group {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyBindGroup(id.0)); @@ -494,6 +496,7 @@ impl LifetimeTracker { let mut list = mem::take(&mut self.suspected_resources.texture_views); for id in list.drain(..) { if trackers.views.remove_abandoned(id) { + log::debug!("Texture view {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyTextureView(id.0)); @@ -520,6 +523,7 @@ impl LifetimeTracker { for id in self.suspected_resources.textures.drain(..) { if trackers.textures.remove_abandoned(id) { + log::debug!("Texture {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyTexture(id.0)); @@ -556,6 +560,7 @@ impl LifetimeTracker { for id in self.suspected_resources.samplers.drain(..) { if trackers.samplers.remove_abandoned(id) { + log::debug!("Sampler {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroySampler(id.0)); @@ -580,11 +585,11 @@ impl LifetimeTracker { for id in self.suspected_resources.buffers.drain(..) { if trackers.buffers.remove_abandoned(id) { + log::debug!("Buffer {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyBuffer(id.0)); } - log::debug!("Buffer {:?} is detached", id); if let Some(res) = hub.buffers.unregister_locked(id.0, &mut *guard) { let submit_index = res.life_guard.life_count(); @@ -608,6 +613,7 @@ impl LifetimeTracker { for id in self.suspected_resources.compute_pipelines.drain(..) { if trackers.compute_pipes.remove_abandoned(id) { + log::debug!("Compute pipeline {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyComputePipeline(id.0)); @@ -632,6 +638,7 @@ impl LifetimeTracker { for id in self.suspected_resources.render_pipelines.drain(..) { if trackers.render_pipes.remove_abandoned(id) { + log::debug!("Render pipeline {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyRenderPipeline(id.0)); @@ -660,6 +667,7 @@ impl LifetimeTracker { { //Note: this has to happen after all the suspected pipelines are destroyed if ref_count.load() == 1 { + log::debug!("Pipeline layout {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyPipelineLayout(id.0)); @@ -684,6 +692,7 @@ impl LifetimeTracker { //Note: same BGL can appear multiple times in the list, but only the last // encounter could drop the refcount to 0. if guard[id].multi_ref_count.dec_and_check_empty() { + log::debug!("Bind group layout {:?} will be destroyed", id); #[cfg(feature = "trace")] if let Some(t) = trace { t.lock().add(trace::Action::DestroyBindGroupLayout(id.0)); @@ -701,6 +710,7 @@ impl LifetimeTracker { for id in self.suspected_resources.query_sets.drain(..) { if trackers.query_sets.remove_abandoned(id) { + log::debug!("Query set {:?} will be destroyed", id); // #[cfg(feature = "trace")] // trace.map(|t| t.lock().add(trace::Action::DestroyComputePipeline(id.0))); if let Some(res) = hub.query_sets.unregister_locked(id.0, &mut *guard) { From 126bed782185a84aa62b563ebd40625a25ecaf78 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Thu, 31 Mar 2022 17:13:56 -0700 Subject: [PATCH 2/2] Add logging to Global::X_drop methods. This adds `log::debug` lines reporting calls to the `wgpu-core` entry points for dropping resources. --- wgpu-core/src/device/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index b52dcfc96e..83d38b8a9d 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -3320,11 +3320,11 @@ impl Global { pub fn buffer_drop(&self, buffer_id: id::BufferId, wait: bool) { profiling::scope!("drop", "Buffer"); + log::debug!("buffer {:?} is dropped", buffer_id); let hub = A::hub(self); let mut token = Token::root(); - log::info!("Buffer {:?} is dropped", buffer_id); let (ref_count, last_submit_index, device_id) = { let (mut buffer_guard, _) = hub.buffers.write(&mut token); match buffer_guard.get_mut(buffer_id) { @@ -3562,6 +3562,7 @@ impl Global { pub fn texture_drop(&self, texture_id: id::TextureId, wait: bool) { profiling::scope!("drop", "Texture"); + log::debug!("texture {:?} is dropped", texture_id); let hub = A::hub(self); let mut token = Token::root(); @@ -3667,6 +3668,7 @@ impl Global { wait: bool, ) -> Result<(), resource::TextureViewDestroyError> { profiling::scope!("drop", "TextureView"); + log::debug!("texture view {:?} is dropped", texture_view_id); let hub = A::hub(self); let mut token = Token::root(); @@ -3760,6 +3762,7 @@ impl Global { pub fn sampler_drop(&self, sampler_id: id::SamplerId) { profiling::scope!("drop", "Sampler"); + log::debug!("sampler {:?} is dropped", sampler_id); let hub = A::hub(self); let mut token = Token::root(); @@ -3859,6 +3862,7 @@ impl Global { pub fn bind_group_layout_drop(&self, bind_group_layout_id: id::BindGroupLayoutId) { profiling::scope!("drop", "BindGroupLayout"); + log::debug!("bind group layout {:?} is dropped", bind_group_layout_id); let hub = A::hub(self); let mut token = Token::root(); @@ -3932,6 +3936,7 @@ impl Global { pub fn pipeline_layout_drop(&self, pipeline_layout_id: id::PipelineLayoutId) { profiling::scope!("drop", "PipelineLayout"); + log::debug!("pipeline layout {:?} is dropped", pipeline_layout_id); let hub = A::hub(self); let mut token = Token::root(); @@ -4026,6 +4031,7 @@ impl Global { pub fn bind_group_drop(&self, bind_group_id: id::BindGroupId) { profiling::scope!("drop", "BindGroup"); + log::debug!("bind group {:?} is dropped", bind_group_id); let hub = A::hub(self); let mut token = Token::root(); @@ -4166,6 +4172,7 @@ impl Global { pub fn shader_module_drop(&self, shader_module_id: id::ShaderModuleId) { profiling::scope!("drop", "ShaderModule"); + log::debug!("shader module {:?} is dropped", shader_module_id); let hub = A::hub(self); let mut token = Token::root(); @@ -4240,6 +4247,7 @@ impl Global { pub fn command_encoder_drop(&self, command_encoder_id: id::CommandEncoderId) { profiling::scope!("drop", "CommandEncoder"); + log::debug!("command encoder {:?} is dropped", command_encoder_id); let hub = A::hub(self); let mut token = Token::root(); @@ -4256,6 +4264,7 @@ impl Global { pub fn command_buffer_drop(&self, command_buffer_id: id::CommandBufferId) { profiling::scope!("drop", "CommandBuffer"); + log::debug!("command buffer {:?} is dropped", command_buffer_id); self.command_encoder_drop::(command_buffer_id) } @@ -4334,6 +4343,7 @@ impl Global { pub fn render_bundle_drop(&self, render_bundle_id: id::RenderBundleId) { profiling::scope!("drop", "RenderBundle"); + log::debug!("render bundle {:?} is dropped", render_bundle_id); let hub = A::hub(self); let mut token = Token::root(); @@ -4410,6 +4420,7 @@ impl Global { pub fn query_set_drop(&self, query_set_id: id::QuerySetId) { profiling::scope!("drop", "QuerySet"); + log::debug!("query set {:?} is dropped", query_set_id); let hub = A::hub(self); let mut token = Token::root(); @@ -4542,6 +4553,7 @@ impl Global { pub fn render_pipeline_drop(&self, render_pipeline_id: id::RenderPipelineId) { profiling::scope!("drop", "RenderPipeline"); + log::debug!("render pipeline {:?} is dropped", render_pipeline_id); let hub = A::hub(self); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -4673,6 +4685,7 @@ impl Global { pub fn compute_pipeline_drop(&self, compute_pipeline_id: id::ComputePipelineId) { profiling::scope!("drop", "ComputePipeline"); + log::debug!("compute pipeline {:?} is dropped", compute_pipeline_id); let hub = A::hub(self); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -4967,6 +4980,7 @@ impl Global { pub fn device_drop(&self, device_id: id::DeviceId) { profiling::scope!("drop", "Device"); + log::debug!("device {:?} is dropped", device_id); let hub = A::hub(self); let mut token = Token::root();