Local Bevy patch
bevy_pbr is the unmodified crates.io 0.18.1 source except for the changes
described below. Its original MIT and Apache licenses are included. Cargo selects
it through the workspace [patch.crates-io] entry; the Cargo registry is untouched.
Cached lightmap bindings
Bevy 0.18.1 rebuilds a bind group for every allocated lightmap slab and every render phase on each frame, even when all bound GPU resources are unchanged. On San Vanelona, mesh binding preparation measured roughly 10 ms per frame.
Local changes are restricted to:
src/lightmap/mod.rs: each slab retains at most eight bindings. Lookup compares the actual wgpu buffer identity, binding offset and size, and layout identity. Texture insertion/removal clears the cache. FIFO eviction bounds retained old buffers when phases disappear or instance buffers resize.src/render/mesh_bindings.rs: reuse or create the binding through that cache. The lightmap slab parameter is now mutable.src/lightmap/cache_tests.rs: explicit GPU regression test.
Writing new instance data into an existing buffer does not require rebuilding a bind group. Changing the buffer, bound range, layout, or texture does. The patch does not skip extraction, uploads, animation, or visibility updates. It retains the existing single-texture and binding-array rendering paths and shaders.
Run the Vulkan test explicitly:
cargo test -p bevy_pbr --lib cache_tracks_binding_identity_and_texture_replacement --locked -- --ignored
It covers cloned versus replaced buffers, changed binding ranges/layouts, writes to an existing buffer, texture insertion/removal, bounded eviction, and actual bind-group construction/reuse. Regular game tests and a city screenshot/benchmark also exercise the patched renderer.
Upstream references reviewed September 6, 2026:
- Bevy issue 23595 reports
increasing
prepare_mesh_bind_groupscost. That report points at mesh scanning; local measurements and source inspection identified lightmap binding recreation as the opportunity addressed here. - Bevy 0.19 rendering improvements explain further GPU batching and CPU overhead reductions. An engine migration is separate from this small patch; 0.19.1 source still rebuilds lightmap groups.
When upgrading Bevy, reassess this patch and rerun the GPU test, stationary and moving-camera benchmarks, and visual comparison. Do not assume an unchanged private renderer implementation across engine versions.