Add BindGroupLayout caching via descriptors#21205
Conversation
|
Can you add more motivation to the PR description please? I'm having trouble following why this is a good idea. |
tychedelia
left a comment
There was a problem hiding this comment.
Awesome work. Thanks for doing all this. I'd like to see some benchmarking as I'm a little worried about performance. However, my intuition is that we are extremely read heavy and so it feels likely that we can work around any performance issues if they come up. I can help with benchmarking if necessary. But overall the code looks great!
| #[derive(Clone, Debug, PartialEq, Eq, Hash, Default)] | ||
| pub struct BindGroupLayoutDescriptor { | ||
| /// Debug label of the bind group layout descriptor. This will show up in graphics debuggers for easy identification. | ||
| pub label: Option<Cow<'static, str>>, |
There was a problem hiding this comment.
as an aside, I kinda feel like we should make labels non-optional in all our code but that's for another PR.
There was a problem hiding this comment.
Yeah this would be a good follow-up.
There was a problem hiding this comment.
We should be using the same DebugName strategy that ECS uses for system names.
There was a problem hiding this comment.
I can help with benchmarking if necessary
@tychedelia I would definitely appreciate that (especially if you can explain how)
| #[derive(Resource)] | ||
| pub struct PipelineCache { | ||
| layout_cache: Arc<Mutex<LayoutCache>>, | ||
| bindgroup_layout_cache: Arc<Mutex<BindGroupLayoutCache>>, |
There was a problem hiding this comment.
I'd like to see benchmarking before any changes but this might be a rare scenario RwLock could win. Or maybe even something like dashmap. Anyway, just curious how much contention there actually is on this.
There was a problem hiding this comment.
We might get wins doing this on the layout_cache too. I thinkt he shader_cache probably wouldnt see any significant wins from it but might as well be consistent if we switch to RwLock
atlv24
left a comment
There was a problem hiding this comment.
I have made a migration guide Zeophlite#4
| #[expect(clippy::option_map_or_none, reason = "TODO")] | ||
| label: Self::label().map_or(None, |f| Some(f.into())), |
There was a problem hiding this comment.
| #[expect(clippy::option_map_or_none, reason = "TODO")] | |
| label: Self::label().map_or(None, |f| Some(f.into())), | |
| label: Self::label().map(|f| f.into()), |
jasmine-nominal
left a comment
There was a problem hiding this comment.
Lgtm once the clippy lint is addressed.
This will be very helpful for an upcoming PR I'm working on to simplify render boilerplate. I'd also like if we could extend this to cache the actual pipelines.
| #[expect(clippy::redundant_closure_for_method_calls, reason = "TODO")] | ||
| descriptor.label.as_ref().map(|s| s.as_ref()), |
There was a problem hiding this comment.
| #[expect(clippy::redundant_closure_for_method_calls, reason = "TODO")] | |
| descriptor.label.as_ref().map(|s| s.as_ref()), | |
| descriptor.label.as_ref().map(Cow::as_ref), |
# Objective - Defer creating `BindGroupLayout` by using a `BindGroupLayoutDescriptor` and cache the results - Unblocks `bevy_material` (render-less material definitions) - Blocked by bevyengine#21533 ## Solution - Reviewers, look at first commit for mechanism, and following for usage ## Testing - CI --------- Co-authored-by: atlas <email@atlasdostal.com>
* Fix compile error when compiling with DLSS enabled after #21205 * Use permutation sampling for ReSTIR DI temporal reuse to fix artifacts under DLSS-RR * For both DI and GI, removed the spatial raytrace, and moved it to the final reservoir before shading. * Reduced DI initial samples 32 -> 8 for better performance at the cost of quality * Various specular GI improvements and bugfixes (still kinda terrible overall, I need to do some research on how people usually do this kind of thing) * Made the world cache adapt faster / be less stable * Switched spatial hashing collisions from to linear probing --------- Co-authored-by: Jasmine Schweitzer <jasmine.schweitzer@nominal.io>
|
Has anyone looked at perf in the end on that PR? Or memory consumption? @alice-i-cecile or @tychedelia maybe? I'm upgrading Hanabi, and where I had before a bunch of trivially cloneable |
|
It had no impact on the performance of Bevy's stress tests |
Objective
BindGroupLayoutby using aBindGroupLayoutDescriptorand cache the resultsbevy_material(render-less material definitions)Solution
Testing