Skip to content

Conversation

@superdump
Copy link
Contributor

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.
Screenshot_2025-03-15_at_12 17 21
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.

…Image>

Less data accessed and compared gives better batching performance.
@superdump superdump requested a review from pcwalton March 15, 2025 11:33
Copy link
Contributor

@pcwalton pcwalton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! BTW I think AssetId is actually larger than 16 bytes because it doesn't just contain a UUID, it also contains an enum tag.

@mockersf mockersf added this pull request to the merge queue Mar 15, 2025
Merged via the queue into bevyengine:main with commit bc7416a Mar 15, 2025
32 checks passed
joshua-holmes pushed a commit to joshua-holmes/bevy that referenced this pull request Mar 24, 2025
…Image> (bevyengine#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants