bevy/crates/bevy_gizmos/src
Tim d2a07f9f72
Retained Gizmos (#15473)
# Objective
Add a way to use the gizmo API in a retained manner, for increased
performance.

## Solution
- Move gizmo API from `Gizmos` to `GizmoBuffer`, ~ab~using `Deref` to
keep usage the same as before.
- Merge non-strip and strip variant of `LineGizmo` into one, storing the
data in a `GizmoBuffer` to have the same API for retained `LineGizmo`s.

### Review guide
- The meat of the changes are in `lib.rs`, `retained.rs`, `gizmos.rs`,
`pipeline_3d.rs` and `pipeline_2d.rs`
- The other files contain almost exclusively the churn from moving the
gizmo API from `Gizmos` to `GizmoBuffer`

## Testing
### Performance

Performance compared to the immediate mode API is from 65 to 80 times
better for static lines.

```
7900 XTX, 3700X
1707.9k lines/ms: gizmos_retained (21.3ms)
3488.5k lines/ms: gizmos_retained_continuous_polyline (31.3ms)
   0.5k lines/ms: gizmos_retained_separate (97.7ms)

3054.9k lines/ms: bevy_polyline_retained_nan (16.8ms)
3596.3k lines/ms: bevy_polyline_retained_continuous_polyline (14.2ms)
   0.6k lines/ms: bevy_polyline_retained_separate (78.9ms)

  26.9k lines/ms: gizmos_immediate (14.9ms)
  43.8k lines/ms: gizmos_immediate_continuous_polyline (18.3ms)
```
Looks like performance is good enough, being close to par with
`bevy_polyline`.

Benchmarks can be found here: 
This branch:
https://github.com/tim-blackbird/line_racing/tree/retained-gizmos
Bevy 0.14: https://github.com/DGriffin91/line_racing

## Showcase
```rust 
fn setup(
    mut commands: Commands,
    mut gizmo_assets: ResMut<Assets<GizmoAsset>>
) {
    let mut gizmo = GizmoAsset::default();

    // A sphere made out of one million lines!
    gizmo
        .sphere(default(), 1., CRIMSON)
        .resolution(1_000_000 / 3);

    commands.spawn(Gizmo {
        handle: gizmo_assets.add(gizmo),
        ..default()
    });
}
```

## Follow-up work
- Port over to the retained rendering world proper
- Calculate visibility and cull `Gizmo`s
2024-12-04 21:21:06 +00:00
..
primitives Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
aabb.rs Reflect derived traits on all components and resources: bevy_gizmos (#15217) 2024-09-15 14:41:49 +00:00
arcs.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
arrows.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
circles.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
config.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
cross.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
curves.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
gizmos.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
grid.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
lib.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
light.rs Implement From translation and rotation for isometries (#15733) 2024-10-08 16:09:28 +00:00
line_joints.wgsl Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
lines.wgsl Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
pipeline_2d.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
pipeline_3d.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
retained.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00
rounded_box.rs Retained Gizmos (#15473) 2024-12-04 21:21:06 +00:00