bevy/crates/bevy_render/src
James Liu 88b353c4b1 Reduce the use of atomics in the render phase (#7084)
# Objective
Speed up the render phase of rendering. An extension of #6885.

`SystemState::get` increments the `World`'s change tick atomically every time it's called. This is notably more expensive than a unsynchronized increment, even without contention. It also updates the archetypes, even when there has been nothing to update when it's called repeatedly.

## Solution
Piggyback off of #6885. Split `SystemState::validate_world_and_update_archetypes` into `SystemState::validate_world` and `SystemState::update_archetypes`, and make the later `pub`. Then create safe variants of `SystemState::get_unchecked_manual` that still validate the `World` but do not update archetypes and do not increment the change tick using `World::read_change_tick` and `World::change_tick`. Update `RenderCommandState` to call `SystemState::update_archetypes` in `Draw::prepare` and `SystemState::get_manual` in `Draw::draw`.

## Performance
There's a slight perf benefit (~2%) for `main_opaque_pass_3d` on `many_foxes` (340.39 us -> 333.32 us)

![image](https://user-images.githubusercontent.com/3137680/210643746-25320b98-3e2b-4a95-8084-892c23bb8b4e.png)

## Alternatives
We can change `SystemState::get` to not increment the `World`'s change tick. Though this would still put updating the archetypes and an atomic read on the hot-path.

---

## Changelog
Added: `SystemState::get_manual`
Added: `SystemState::get_manual_mut`
Added: `SystemState::update_archetypes`
2023-01-18 02:19:19 +00:00
..
camera Add Camera::viewport_to_world_2d (#6557) 2023-01-16 23:13:11 +00:00
color Improve Color::hex performance (#6940) 2023-01-17 13:26:43 +00:00
mesh Update Box vertices comment (#7055) 2022-12-29 23:45:07 +00:00
primitives Very minor doc formatting changes (#5287) 2022-07-12 13:06:16 +00:00
render_graph Replace UUID based IDs with a atomic-counted ones (#6988) 2022-12-25 00:23:15 +00:00
render_phase Reduce the use of atomics in the render phase (#7084) 2023-01-18 02:19:19 +00:00
render_resource Make PipelineCache internally mutable. (#7205) 2023-01-16 15:41:14 +00:00
renderer Reduce branching in TrackedRenderPass (#7053) 2023-01-09 19:24:56 +00:00
texture Fix beta clippy lints (#7154) 2023-01-11 09:51:22 +00:00
view Improve render phase documentation (#7016) 2023-01-12 15:11:58 +00:00
extract_component.rs ExtractComponent output optional associated type (#6699) 2022-11-21 13:19:44 +00:00
extract_param.rs Implement ReadOnlySystemParam for Extract<> (#7182) 2023-01-13 22:35:43 +00:00
extract_resource.rs gate an import used only for a debug assert (#7165) 2023-01-11 20:52:04 +00:00
globals.rs bevy_reflect: Register missing reflected types for bevy_render (#6725) 2022-11-23 00:41:21 +00:00
lib.rs Make PipelineCache internally mutable. (#7205) 2023-01-16 15:41:14 +00:00
render_asset.rs Fix clippy::iter_with_drain (#6485) 2022-11-06 01:42:15 +00:00
settings.rs Replace WgpuAdapterInfo with RenderAdapterInfo in the documentation. (#7036) 2022-12-26 19:47:01 +00:00
spatial_bundle.rs enum Visibility component (#6320) 2022-12-25 00:39:29 +00:00