Skip to content

Commit 89c0aa8

Browse files
committed
Make it harder to forget to clear or extend a resource map
1 parent b10859d commit 89c0aa8

File tree

1 file changed

+66
-38
lines changed

1 file changed

+66
-38
lines changed

wgpu-core/src/device/life.rs

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ use thiserror::Error;
2727
/// A struct that keeps lists of resources that are no longer needed by the user.
2828
#[derive(Default)]
2929
pub(crate) struct ResourceMaps<A: HalApi> {
30-
pub(crate) buffers: FastHashMap<BufferId, Arc<Buffer<A>>>,
31-
pub(crate) staging_buffers: FastHashMap<StagingBufferId, Arc<StagingBuffer<A>>>,
32-
pub(crate) textures: FastHashMap<TextureId, Arc<Texture<A>>>,
33-
pub(crate) texture_views: FastHashMap<TextureViewId, Arc<TextureView<A>>>,
34-
pub(crate) samplers: FastHashMap<SamplerId, Arc<Sampler<A>>>,
35-
pub(crate) bind_groups: FastHashMap<BindGroupId, Arc<BindGroup<A>>>,
36-
pub(crate) bind_group_layouts: FastHashMap<BindGroupLayoutId, Arc<BindGroupLayout<A>>>,
37-
pub(crate) render_pipelines: FastHashMap<RenderPipelineId, Arc<RenderPipeline<A>>>,
38-
pub(crate) compute_pipelines: FastHashMap<ComputePipelineId, Arc<ComputePipeline<A>>>,
39-
pub(crate) pipeline_layouts: FastHashMap<PipelineLayoutId, Arc<PipelineLayout<A>>>,
40-
pub(crate) render_bundles: FastHashMap<RenderBundleId, Arc<RenderBundle<A>>>,
41-
pub(crate) query_sets: FastHashMap<QuerySetId, Arc<QuerySet<A>>>,
30+
pub buffers: FastHashMap<BufferId, Arc<Buffer<A>>>,
31+
pub staging_buffers: FastHashMap<StagingBufferId, Arc<StagingBuffer<A>>>,
32+
pub textures: FastHashMap<TextureId, Arc<Texture<A>>>,
33+
pub texture_views: FastHashMap<TextureViewId, Arc<TextureView<A>>>,
34+
pub samplers: FastHashMap<SamplerId, Arc<Sampler<A>>>,
35+
pub bind_groups: FastHashMap<BindGroupId, Arc<BindGroup<A>>>,
36+
pub bind_group_layouts: FastHashMap<BindGroupLayoutId, Arc<BindGroupLayout<A>>>,
37+
pub render_pipelines: FastHashMap<RenderPipelineId, Arc<RenderPipeline<A>>>,
38+
pub compute_pipelines: FastHashMap<ComputePipelineId, Arc<ComputePipeline<A>>>,
39+
pub pipeline_layouts: FastHashMap<PipelineLayoutId, Arc<PipelineLayout<A>>>,
40+
pub render_bundles: FastHashMap<RenderBundleId, Arc<RenderBundle<A>>>,
41+
pub query_sets: FastHashMap<QuerySetId, Arc<QuerySet<A>>>,
4242
}
4343

4444
impl<A: HalApi> ResourceMaps<A> {
@@ -60,35 +60,63 @@ impl<A: HalApi> ResourceMaps<A> {
6060
}
6161

6262
pub(crate) fn clear(&mut self) {
63-
self.buffers.clear();
64-
self.staging_buffers.clear();
65-
self.textures.clear();
66-
self.texture_views.clear();
67-
self.samplers.clear();
68-
self.bind_groups.clear();
69-
self.bind_group_layouts.clear();
70-
self.render_pipelines.clear();
71-
self.compute_pipelines.clear();
72-
self.pipeline_layouts.clear();
73-
self.render_bundles.clear();
74-
self.query_sets.clear();
63+
#![allow(clippy::pattern_type_mismatch)]
64+
let ResourceMaps {
65+
buffers,
66+
staging_buffers,
67+
textures,
68+
texture_views,
69+
samplers,
70+
bind_groups,
71+
bind_group_layouts,
72+
render_pipelines,
73+
compute_pipelines,
74+
pipeline_layouts,
75+
render_bundles,
76+
query_sets,
77+
} = self;
78+
buffers.clear();
79+
staging_buffers.clear();
80+
textures.clear();
81+
texture_views.clear();
82+
samplers.clear();
83+
bind_groups.clear();
84+
bind_group_layouts.clear();
85+
render_pipelines.clear();
86+
compute_pipelines.clear();
87+
pipeline_layouts.clear();
88+
render_bundles.clear();
89+
query_sets.clear();
7590
}
7691

7792
pub(crate) fn extend(&mut self, mut other: Self) {
78-
self.buffers.extend(other.buffers.drain());
79-
self.staging_buffers.extend(other.staging_buffers.drain());
80-
self.textures.extend(other.textures.drain());
81-
self.texture_views.extend(other.texture_views.drain());
82-
self.samplers.extend(other.samplers.drain());
83-
self.bind_groups.extend(other.bind_groups.drain());
84-
self.bind_group_layouts
85-
.extend(other.bind_group_layouts.drain());
86-
self.render_pipelines.extend(other.render_pipelines.drain());
87-
self.compute_pipelines
88-
.extend(other.compute_pipelines.drain());
89-
self.pipeline_layouts.extend(other.pipeline_layouts.drain());
90-
self.render_bundles.extend(other.render_bundles.drain());
91-
self.query_sets.extend(other.query_sets.drain());
93+
#![allow(clippy::pattern_type_mismatch)]
94+
let ResourceMaps {
95+
buffers,
96+
staging_buffers,
97+
textures,
98+
texture_views,
99+
samplers,
100+
bind_groups,
101+
bind_group_layouts,
102+
render_pipelines,
103+
compute_pipelines,
104+
pipeline_layouts,
105+
render_bundles,
106+
query_sets,
107+
} = self;
108+
buffers.extend(other.buffers.drain());
109+
staging_buffers.extend(other.staging_buffers.drain());
110+
textures.extend(other.textures.drain());
111+
texture_views.extend(other.texture_views.drain());
112+
samplers.extend(other.samplers.drain());
113+
bind_groups.extend(other.bind_groups.drain());
114+
bind_group_layouts.extend(other.bind_group_layouts.drain());
115+
render_pipelines.extend(other.render_pipelines.drain());
116+
compute_pipelines.extend(other.compute_pipelines.drain());
117+
pipeline_layouts.extend(other.pipeline_layouts.drain());
118+
render_bundles.extend(other.render_bundles.drain());
119+
query_sets.extend(other.query_sets.drain());
92120
}
93121
}
94122

0 commit comments

Comments
 (0)