Skip to content

Commit

Permalink
Move the trace recording of destroy events out of triage_resources (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nical authored Jan 11, 2024
1 parent 2512b2d commit c90f43b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 203 deletions.
19 changes: 19 additions & 0 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(feature = "trace")]
use crate::device::trace;
use crate::{
device::{
bgl, Device, DeviceError, MissingDownlevelFlags, MissingFeatures, SHADER_STAGE_COUNT,
Expand Down Expand Up @@ -469,6 +471,11 @@ impl<A: HalApi> Drop for BindGroupLayout<A> {
self.device.bgl_pool.remove(&self.entries);
}
if let Some(raw) = self.raw.take() {
#[cfg(feature = "trace")]
if let Some(t) = self.device.trace.lock().as_mut() {
t.add(trace::Action::DestroyBindGroupLayout(self.info.id()));
}

resource_log!("Destroy raw BindGroupLayout {:?}", self.info.label());
unsafe {
use hal::Device;
Expand Down Expand Up @@ -608,6 +615,12 @@ impl<A: HalApi> Drop for PipelineLayout<A> {
fn drop(&mut self) {
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw PipelineLayout {:?}", self.info.label());

#[cfg(feature = "trace")]
if let Some(t) = self.device.trace.lock().as_mut() {
t.add(trace::Action::DestroyPipelineLayout(self.info.id()));
}

unsafe {
use hal::Device;
self.device.raw().destroy_pipeline_layout(raw);
Expand Down Expand Up @@ -837,6 +850,12 @@ impl<A: HalApi> Drop for BindGroup<A> {
fn drop(&mut self) {
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw BindGroup {:?}", self.info.label());

#[cfg(feature = "trace")]
if let Some(t) = self.device.trace.lock().as_mut() {
t.add(trace::Action::DestroyBindGroup(self.info.id()));
}

unsafe {
use hal::Device;
self.device.raw().destroy_bind_group(raw);
Expand Down
14 changes: 14 additions & 0 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ index format changes.

#![allow(clippy::reversed_empty_ranges)]

#[cfg(feature = "trace")]
use crate::device::trace;
use crate::{
binding_model::{buffer_binding_type_alignment, BindGroup, BindGroupLayout, PipelineLayout},
command::{
Expand All @@ -96,6 +98,7 @@ use crate::{
init_tracker::{BufferInitTrackerAction, MemoryInitKind, TextureInitTrackerAction},
pipeline::{self, PipelineFlags, RenderPipeline},
resource::{Resource, ResourceInfo, ResourceType},
resource_log,
track::RenderBundleScope,
validation::check_buffer_usage,
Label, LabelHelpers,
Expand Down Expand Up @@ -763,6 +766,17 @@ pub struct RenderBundle<A: HalApi> {
discard_hal_labels: bool,
}

impl<A: HalApi> Drop for RenderBundle<A> {
fn drop(&mut self) {
resource_log!("Destroy raw RenderBundle {:?}", self.info.label());

#[cfg(feature = "trace")]
if let Some(t) = self.device.trace.lock().as_mut() {
t.add(trace::Action::DestroyRenderBundle(self.info.id()));
}
}
}

#[cfg(any(
not(target_arch = "wasm32"),
all(
Expand Down
6 changes: 1 addition & 5 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2074,11 +2074,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
if !device.is_valid() {
return Err(InvalidDevice);
}
device.lock_life().triage_suspected(
&device.trackers,
#[cfg(feature = "trace")]
None,
);
device.lock_life().triage_suspected(&device.trackers);
Ok(())
}

Expand Down
Loading

0 comments on commit c90f43b

Please sign in to comment.