bevy/crates/bevy_pbr/src
Robert Swain bc7416aa22
Use 4-byte LightmapSlabIndex for batching instead of 16-byte AssetId<Image> (#18326)
Less data accessed and compared gives better batching performance.

# Objective

- Use a smaller id to represent the lightmap in batch data to enable a
faster implementation of draw streams.
- Improve batching performance for 3D sorted render phases.

## Solution

- 3D batching can use `LightmapSlabIndex` (a `NonMaxU32` which is 4
bytes) instead of the lightmap `AssetId<Image>` (an enum where the
largest variant is a 16-byte UUID) to discern the ability to batch.

## Testing

Tested main (yellow) vs this PR (red) on an M4 Max using the
`many_cubes` example with `WGPU_SETTINGS_PRIO=webgl2` to avoid
GPU-preprocessing, and modifying the materials in `many_cubes` to have
`AlphaMode::Blend` so that they would rely on the less efficient sorted
render phase batching.
<img width="1500" alt="Screenshot_2025-03-15_at_12 17 21"
src="https://github.com/user-attachments/assets/14709bd3-6d06-40fb-aa51-e1d2d606ebe3"
/>
A 44.75us or 7.5% reduction in median execution time of the batch and
prepare sorted render phase system for the `Transparent3d` phase
(handling 160k cubes).

---

## Migration Guide

- Changed: `RenderLightmap::new()` no longer takes an `AssetId<Image>`
argument for the asset id of the lightmap image.
2025-03-15 14:16:32 +00:00
..
atmosphere Generic system config (#17962) 2025-03-12 00:12:30 +00:00
cluster Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
decal Generic system config (#17962) 2025-03-12 00:12:30 +00:00
deferred Remove prepasses from the render world when they're removed from the main world. (#17565) 2025-02-14 06:43:35 +00:00
light Revert "Replace Ambient Lights with Environment Map Lights (#17482)" (#18167) 2025-03-05 23:08:46 +00:00
light_probe Generic system config (#17962) 2025-03-12 00:12:30 +00:00
lightmap Use 4-byte LightmapSlabIndex for batching instead of 16-byte AssetId<Image> (#18326) 2025-03-15 14:16:32 +00:00
meshlet Generic system config (#17962) 2025-03-12 00:12:30 +00:00
prepass Allow prepass to run without ATTRIBUTE_NORMAL (#17881) 2025-02-24 21:22:34 +00:00
render Use 4-byte LightmapSlabIndex for batching instead of 16-byte AssetId<Image> (#18326) 2025-03-15 14:16:32 +00:00
ssao Generic system config (#17962) 2025-03-12 00:12:30 +00:00
ssr Generic system config (#17962) 2025-03-12 00:12:30 +00:00
volumetric_fog Generic system config (#17962) 2025-03-12 00:12:30 +00:00
components.rs Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
extended_material.rs Use global binding arrays for bindless resources. (#17898) 2025-02-21 05:55:36 +00:00
fog.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
lib.rs Revert "Replace Ambient Lights with Environment Map Lights (#17482)" (#18167) 2025-03-05 23:08:46 +00:00
material_bind_groups.rs Reimplement bindless storage buffers. (#17994) 2025-03-10 21:32:19 +00:00
material.rs Reextract meshes when their material assets change. (#18123) 2025-03-03 06:28:33 +00:00
mesh_material.rs impl Eq/PartialEq for MeshMaterial{2|3}d (#17990) 2025-02-23 23:58:10 +00:00
parallax.rs bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
pbr_material.rs Add a new #[data] attribute to AsBindGroup that allows packing data for multiple materials into a single array. (#17965) 2025-02-24 21:38:55 +00:00
wireframe.rs Replace internal uses of insert_or_spawn_batch (#18035) 2025-03-06 16:16:36 +00:00