bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.46k stars 3.6k forks source link

Retain `RenderMeshInstance` and `MeshInputUniform` data from frame to frame. #16385

Open pcwalton opened 2 weeks ago

pcwalton commented 2 weeks ago

This commit moves the front end of the rendering pipeline to a retained model when GPU preprocessing is in use (i.e. by default, except in constrained environments). RenderMeshInstance and MeshUniformData are stored from frame to frame and are updated only for the entities that changed state. This was rather tricky and requires some careful surgery to keep the data valid in the case of removals.

This patch is built on top of Bevy's change detection. Generally, this worked, except that ViewVisibility isn't currently properly tracked. Therefore, this commit adds proper change tracking for ViewVisibility. Doing this required adding a new system that runs after all check_visibility invocations, as no single check_visibility invocation has enough global information to detect changes.

On the Bistro exterior scene, with all textures forced to opaque, this patch improves steady-state extract_meshes_for_gpu_building from 93.8us to 34.5us and steady-state collect_meshes_for_gpu_building from 195.7us to 4.28us. Altogether this constitutes an improvement from 290us to 38us, which is a 7.46x speedup.

Screenshot 2024-11-13 143841

Screenshot 2024-11-13 143850

This patch is only lightly tested and shouldn't land before 0.15 is released anyway, so I'm releasing it as a draft.