bevy/crates/bevy_render
Aevyrie 915fa69b66 Parallel Frustum Culling (#4489)
# Objective

Working with a large number of entities with `Aabbs`, rendered with an instanced shader, I found the bottleneck became the frustum culling system. The goal of this PR is to significantly improve culling performance without any major changes. We should consider constructing a BVH for more substantial improvements.

## Solution

- Convert the inner entity query to a parallel iterator with `par_for_each_mut` using a batch size of 1,024. 
- This outperforms single threaded culling when there are more than 1,000 entities. 
  - Below this they are approximately equal, with <= 10 microseconds of multithreading overhead.
  - Above this, the multithreaded version is significantly faster, scaling linearly with core count.
- In my million-entity-workload, this PR improves my framerate by 200% - 300%.

## log-log of `check_visibility` time vs. entities for single/multithreaded
![image](https://user-images.githubusercontent.com/2632925/163709007-7eab4437-e9f9-4c06-bac0-250073885110.png)

---

## Changelog

Frustum culling is now run with a parallel query. When culling more than a thousand entities, this is faster than the previous method, scaling proportionally with the number of available cores.
2022-06-14 02:07:40 +00:00
..
macros ExtractResourcePlugin (#3745) 2022-05-30 18:36:03 +00:00
src Parallel Frustum Culling (#4489) 2022-06-14 02:07:40 +00:00
Cargo.toml Parallel Frustum Culling (#4489) 2022-06-14 02:07:40 +00:00