Skip to content

Commit 192a2fe

Browse files
authored
Simplify ResourceMaps (#4880)
* Remove the abstractions in resource maps ResourceMaps had a rather convoluted system for erasing types that isn't needed anywhere except in one place in the triage_resource function. Everywhere else we are always dealing with specific types so using a member of the resource maps is simpler than going through an abstraction. More importantly there was a constraint that all contents of the resource maps implement the Resource trait which got in the way of some of the ongoing buffer snatching changes. This commit simplifies this by removing the abstraction. Each resource type has its hash map directly in ResourceMaps and it is easier to have different requirements and behaviors depending on the type of the each resource.
1 parent 790c40f commit 192a2fe

File tree

4 files changed

+222
-150
lines changed

4 files changed

+222
-150
lines changed

wgpu-core/src/device/global.rs

+13
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
521521
device
522522
.lock_life()
523523
.suspected_resources
524+
.buffers
524525
.insert(buffer_id, buffer);
525526
}
526527

@@ -784,6 +785,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
784785
device
785786
.lock_life()
786787
.suspected_resources
788+
.textures
787789
.insert(texture_id, texture.clone());
788790
}
789791
}
@@ -861,6 +863,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
861863
view.device
862864
.lock_life()
863865
.suspected_resources
866+
.texture_views
864867
.insert(texture_view_id, view.clone());
865868

866869
if wait {
@@ -931,6 +934,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
931934
.device
932935
.lock_life()
933936
.suspected_resources
937+
.samplers
934938
.insert(sampler_id, sampler.clone());
935939
}
936940
}
@@ -1017,6 +1021,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
10171021
.device
10181022
.lock_life()
10191023
.suspected_resources
1024+
.bind_group_layouts
10201025
.insert(bind_group_layout_id, layout.clone());
10211026
}
10221027
}
@@ -1080,6 +1085,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
10801085
.device
10811086
.lock_life()
10821087
.suspected_resources
1088+
.pipeline_layouts
10831089
.insert(pipeline_layout_id, layout.clone());
10841090
}
10851091
}
@@ -1154,6 +1160,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
11541160
.device
11551161
.lock_life()
11561162
.suspected_resources
1163+
.bind_groups
11571164
.insert(bind_group_id, bind_group.clone());
11581165
}
11591166
}
@@ -1448,6 +1455,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
14481455
.device
14491456
.lock_life()
14501457
.suspected_resources
1458+
.render_bundles
14511459
.insert(render_bundle_id, bundle.clone());
14521460
}
14531461
}
@@ -1517,6 +1525,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
15171525
device
15181526
.lock_life()
15191527
.suspected_resources
1528+
.query_sets
15201529
.insert(query_set_id, query_set.clone());
15211530
}
15221531
}
@@ -1653,10 +1662,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
16531662
let mut life_lock = device.lock_life();
16541663
life_lock
16551664
.suspected_resources
1665+
.render_pipelines
16561666
.insert(render_pipeline_id, pipeline.clone());
16571667

16581668
life_lock
16591669
.suspected_resources
1670+
.pipeline_layouts
16601671
.insert(layout_id, pipeline.layout.clone());
16611672
}
16621673
}
@@ -1788,9 +1799,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
17881799
let mut life_lock = device.lock_life();
17891800
life_lock
17901801
.suspected_resources
1802+
.compute_pipelines
17911803
.insert(compute_pipeline_id, pipeline.clone());
17921804
life_lock
17931805
.suspected_resources
1806+
.pipeline_layouts
17941807
.insert(layout_id, pipeline.layout.clone());
17951808
}
17961809
}

0 commit comments

Comments
 (0)