Skip to content

Commit

Permalink
Improving tracker management
Browse files Browse the repository at this point in the history
  • Loading branch information
gents83 committed Sep 23, 2023
1 parent 4e68258 commit 0eac205
Show file tree
Hide file tree
Showing 18 changed files with 732 additions and 719 deletions.
5 changes: 2 additions & 3 deletions tests/tests/mem_leaks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,13 @@ fn draw_test_with_reports(
assert_eq!(report.textures.num_allocated, 1);

let submit_index = ctx.queue.submit(Some(encoder.finish()));
ctx.device
.poll(wgpu::Maintain::WaitForSubmissionIndex(submit_index));

let global_report = ctx.instance.generate_report();
let report = global_report.hub_report();
assert_eq!(report.command_buffers.num_allocated, 0);

ctx.device.poll(wgpu::Maintain::Wait);
ctx.device
.poll(wgpu::Maintain::WaitForSubmissionIndex(submit_index));

let global_report = ctx.instance.generate_report();
let report = global_report.hub_report();
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
TextureViewId,
},
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
resource::{Resource, ResourceInfo},
resource::{Resource, ResourceInfo, ResourceType},
track::{BindGroupStates, UsageConflict},
validation::{MissingBufferUsageError, MissingTextureUsageError},
FastHashMap, Label,
Expand Down Expand Up @@ -481,7 +481,7 @@ impl<A: HalApi> Drop for BindGroupLayout<A> {
}

impl<A: HalApi> Resource<BindGroupLayoutId> for BindGroupLayout<A> {
const TYPE: &'static str = "BindGroupLayout";
const TYPE: ResourceType = "BindGroupLayout";

fn as_info(&self) -> &ResourceInfo<BindGroupLayoutId> {
&self.info
Expand Down Expand Up @@ -730,7 +730,7 @@ impl<A: HalApi> PipelineLayout<A> {
}

impl<A: HalApi> Resource<PipelineLayoutId> for PipelineLayout<A> {
const TYPE: &'static str = "PipelineLayout";
const TYPE: ResourceType = "PipelineLayout";

fn as_info(&self) -> &ResourceInfo<PipelineLayoutId> {
&self.info
Expand Down Expand Up @@ -921,7 +921,7 @@ impl<A: HalApi> BindGroup<A> {
}

impl<A: HalApi> Resource<BindGroupId> for BindGroup<A> {
const TYPE: &'static str = "BindGroup";
const TYPE: ResourceType = "BindGroup";

fn as_info(&self) -> &ResourceInfo<BindGroupId> {
&self.info
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ use crate::{
id::{self, RenderBundleId},
init_tracker::{BufferInitTrackerAction, MemoryInitKind, TextureInitTrackerAction},
pipeline::{self, PipelineFlags, RenderPipeline},
resource::{Resource, ResourceInfo},
resource::{Resource, ResourceInfo, ResourceType},
track::RenderBundleScope,
validation::check_buffer_usage,
Label, LabelHelpers,
Expand Down Expand Up @@ -952,7 +952,7 @@ impl<A: HalApi> RenderBundle<A> {
}

impl<A: HalApi> Resource<RenderBundleId> for RenderBundle<A> {
const TYPE: &'static str = "RenderBundle";
const TYPE: ResourceType = "RenderBundle";

fn as_info(&self) -> &ResourceInfo<RenderBundleId> {
&self.info
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::hub::Hub;
use crate::id::CommandBufferId;

use crate::init_tracker::BufferInitTrackerAction;
use crate::resource::{Resource, ResourceInfo};
use crate::resource::{Resource, ResourceInfo, ResourceType};
use crate::track::{Tracker, UsageScope};
use crate::{global::Global, hal_api::HalApi, id, identity::GlobalIdentityHandlerFactory, Label};

Expand Down Expand Up @@ -278,7 +278,7 @@ impl<A: HalApi> CommandBuffer<A> {
}

impl<A: HalApi> Resource<CommandBufferId> for CommandBuffer<A> {
const TYPE: &'static str = "CommandBuffer";
const TYPE: ResourceType = "CommandBuffer";

fn as_info(&self) -> &ResourceInfo<CommandBufferId> {
&self.info
Expand Down
13 changes: 0 additions & 13 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device
.lock_life()
.suspected_resources
.buffers
.insert(buffer_id, buffer);
}

Expand Down Expand Up @@ -731,7 +730,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
} else {
life_lock
.suspected_resources
.textures
.insert(texture_id, texture.clone());
}
}
Expand Down Expand Up @@ -807,7 +805,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
view.device
.lock_life()
.suspected_resources
.texture_views
.insert(texture_view_id, view.clone());

if wait {
Expand Down Expand Up @@ -876,7 +873,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.samplers
.insert(sampler_id, sampler.clone());
}
}
Expand Down Expand Up @@ -965,7 +961,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.bind_group_layouts
.insert(bind_group_layout_id, layout.clone());
}
}
Expand Down Expand Up @@ -1028,7 +1023,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.pipeline_layouts
.insert(pipeline_layout_id, layout.clone());
}
}
Expand Down Expand Up @@ -1099,7 +1093,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.bind_groups
.insert(bind_group_id, bind_group.clone());
}
}
Expand Down Expand Up @@ -1376,7 +1369,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.render_bundles
.insert(render_bundle_id, bundle.clone());
}
}
Expand Down Expand Up @@ -1442,7 +1434,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device
.lock_life()
.suspected_resources
.query_sets
.insert(query_set_id, query_set.clone());
}
}
Expand Down Expand Up @@ -1558,12 +1549,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut life_lock = device.lock_life();
life_lock
.suspected_resources
.render_pipelines
.insert(render_pipeline_id, pipeline.clone());

life_lock
.suspected_resources
.pipeline_layouts
.insert(layout_id, pipeline.layout.clone());
}
}
Expand Down Expand Up @@ -1676,11 +1665,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut life_lock = device.lock_life();
life_lock
.suspected_resources
.compute_pipelines
.insert(compute_pipeline_id, pipeline.clone());
life_lock
.suspected_resources
.pipeline_layouts
.insert(layout_id, pipeline.layout.clone());
}
}
Expand Down
Loading

0 comments on commit 0eac205

Please sign in to comment.