Skip to content

Commit

Permalink
Simplify ResourceMaps (#4880)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
nical committed Dec 18, 2023
1 parent 790c40f commit 192a2fe
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 150 deletions.
13 changes: 13 additions & 0 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device
.lock_life()
.suspected_resources
.buffers
.insert(buffer_id, buffer);
}

Expand Down Expand Up @@ -784,6 +785,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device
.lock_life()
.suspected_resources
.textures
.insert(texture_id, texture.clone());
}
}
Expand Down Expand Up @@ -861,6 +863,7 @@ 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 @@ -931,6 +934,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.samplers
.insert(sampler_id, sampler.clone());
}
}
Expand Down Expand Up @@ -1017,6 +1021,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.bind_group_layouts
.insert(bind_group_layout_id, layout.clone());
}
}
Expand Down Expand Up @@ -1080,6 +1085,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.pipeline_layouts
.insert(pipeline_layout_id, layout.clone());
}
}
Expand Down Expand Up @@ -1154,6 +1160,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.bind_groups
.insert(bind_group_id, bind_group.clone());
}
}
Expand Down Expand Up @@ -1448,6 +1455,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.device
.lock_life()
.suspected_resources
.render_bundles
.insert(render_bundle_id, bundle.clone());
}
}
Expand Down Expand Up @@ -1517,6 +1525,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device
.lock_life()
.suspected_resources
.query_sets
.insert(query_set_id, query_set.clone());
}
}
Expand Down Expand Up @@ -1653,10 +1662,12 @@ 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 @@ -1788,9 +1799,11 @@ 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 192a2fe

Please sign in to comment.