bevy/crates/bevy_core_pipeline/src
Patrick Walton 7fc122ad16
Retain bins from frame to frame. (#17698)
This PR makes Bevy keep entities in bins from frame to frame if they
haven't changed. This reduces the time spent in `queue_material_meshes`
and related functions to near zero for static geometry. This patch uses
the same change tick technique that #17567 uses to detect when meshes
have changed in such a way as to require re-binning.

In order to quickly find the relevant bin for an entity when that entity
has changed, we introduce a new type of cache, the *bin key cache*. This
cache stores a mapping from main world entity ID to cached bin key, as
well as the tick of the most recent change to the entity. As we iterate
through the visible entities in `queue_material_meshes`, we check the
cache to see whether the entity needs to be re-binned. If it doesn't,
then we mark it as clean in the `valid_cached_entity_bin_keys` bit set.
If it does, then we insert it into the correct bin, and then mark the
entity as clean. At the end, all entities not marked as clean are
removed from the bins.

This patch has a dramatic effect on the rendering performance of most
benchmarks, as it effectively eliminates `queue_material_meshes` from
the profile. Note, however, that it generally simultaneously regresses
`batch_and_prepare_binned_render_phase` by a bit (not by enough to
outweigh the win, however). I believe that's because, before this patch,
`queue_material_meshes` put the bins in the CPU cache for
`batch_and_prepare_binned_render_phase` to use, while with this patch,
`batch_and_prepare_binned_render_phase` must load the bins into the CPU
cache itself.

On Caldera, this reduces the time spent in `queue_material_meshes` from
5+ ms to 0.2ms-0.3ms. Note that benchmarking on that scene is very noisy
right now because of https://github.com/bevyengine/bevy/issues/17535.

![Screenshot 2025-02-05
153458](https://github.com/user-attachments/assets/e55f8134-b7e3-4b78-a5af-8d83e1e213b7)
2025-02-08 20:13:33 +00:00
..
auto_exposure Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
blit Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
bloom Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
contrast_adaptive_sharpening Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
core_2d Retain bins from frame to frame. (#17698) 2025-02-08 20:13:33 +00:00
core_3d Retain bins from frame to frame. (#17698) 2025-02-08 20:13:33 +00:00
deferred Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
dof Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
experimental Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
fullscreen_vertex_shader Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
fxaa Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
motion_blur Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
oit Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
post_process Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
prepass Implement experimental GPU two-phase occlusion culling for the standard 3D mesh pipeline. (#17413) 2025-01-27 05:02:46 +00:00
skybox Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
smaa Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
taa Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
tonemapping Weak handle migration (#17695) 2025-02-05 22:44:20 +00:00
upscaling Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
lib.rs Implement experimental GPU two-phase occlusion culling for the standard 3D mesh pipeline. (#17413) 2025-01-27 05:02:46 +00:00
msaa_writeback.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00