bevy/crates
andriyDev 7f14581495
Use explicitly added ApplyDeferred stages when computing automatically inserted sync points. (#16782)
# Objective

- The previous implementation of automatically inserting sync points did
not consider explicitly added sync points. This created additional sync
points. For example:

```
A-B
C-D-E
```

If `A` and `B` needed a sync point, and `D` was an `ApplyDeferred`, an
additional sync point would be generated between `A` and `B`.

```
A-D2-B
C-D -E
```

This can result in the following system ordering:
```
A-D2-(B-C)-D-E
```
Where only `B` and `C` run in parallel. If we could reuse `D` as the
sync point, we would get the following ordering:
```
(A-C)-D-(B-E)
```
Now we have two more opportunities for parallelism!

## Solution

- In the first pass, we:
    - Compute the number of sync points before each node
- This was already happening but now we consider `ApplyDeferred` nodes
as creating a sync point.
- Pick an arbitrary explicit `ApplyDeferred` node for each "sync point
index" that we can (some required sync points may be missing!)
- In the second pass, we:
- For each edge, if two nodes have a different number of sync points
before them then there must be a sync point between them.
- Look for an explicit `ApplyDeferred`. If one exists, use it as the
sync point.
    - Otherwise, generate a new sync point.

I believe this should also gracefully handle changes to the
`ScheduleGraph`. Since automatically inserted sync points are inserted
as systems, they won't look any different to explicit sync points, so
they are also candidates for "reusing" sync points.

One thing this solution does not handle is "deduping" sync points. If
you add 10 sync points explicitly, there will be at least 10 sync
points. You could keep track of all the sync points at the same
"distance" and then hack apart the graph to dedup those, but that could
be a follow-up step (and it's more complicated since you have to worry
about transferring edges between nodes).

## Testing

- Added a test to test the feature.
-  The existing tests from all our crates still pass.

## Showcase

- Automatically inserted sync points can now reuse explicitly inserted
`ApplyDeferred` systems! Previously, Bevy would add new sync points
between systems, ignoring the explicitly added sync points. This would
reduce parallelism of systems in some situations. Now, the parallelism
has been improved!
2025-02-24 20:51:34 +00:00
..
bevy_a11y Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_animation Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_app Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_asset Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_audio Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_color Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_core_pipeline Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_derive Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_dev_tools Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_diagnostic Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_dylib Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_ecs Use explicitly added ApplyDeferred stages when computing automatically inserted sync points. (#16782) 2025-02-24 20:51:34 +00:00
bevy_encase_derive Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_gilrs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_gizmos Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_gltf Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_image Load and convert RGB8 dds textures (#12952) 2025-02-24 20:45:56 +00:00
bevy_input Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_input_focus Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_internal Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_log Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_macro_utils Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_math Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_mesh Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_mikktspace Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_pbr Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_picking Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_platform_support Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_ptr Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_reflect Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_remote Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_render Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_scene Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_sprite Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_state Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_tasks Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_text Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_time Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_transform Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_ui Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_utils Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_window Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_winit Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00