Retained `Gizmo`s
Objective
Add a way to use the gizmo API in a retained manner, for increased performance.
Solution
- Move gizmo API from
GizmostoGizmoBuffer, ~ab~usingDerefto keep usage the same as before. - Merge non-strip and strip variant of
LineGizmointo one, storing the data in aGizmoBufferto have the same API for retainedLineGizmos.
Review guide
- The meat of the changes are in
lib.rs,retained.rs,gizmos.rs,pipeline_3d.rsandpipeline_2d.rs - The other files contain almost exclusively the churn from moving the gizmo API from
GizmostoGizmoBuffer
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
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
Gizmos
It's still a bit rough, but it's now in a working state! Performance feels good, I'm going to plug it into https://github.com/DGriffin91/line_racing/ and have a look at some real numbers!
Feel free to try it out, but I'd hold off on reviews for now :)
I've fixed some issues with this PR.
- I botched the port to the retained render world initially. I've re-done the port with bare minimum effort using
TemporaryRenderEntityto keep things simple here. - I initially had used the whole
GizmoConfigin theLineGizmocomponent, but I overlooked the render layers setting in there.RenderLayersis a component so it would be confusing to have it inside another component here. To solve that I've split the line specific settings out into aLineGizmoConfigstruct and re-used that inside bothGizmoConfigand theLineGizmocomponent. - Line joints were not working. Had to re-route some data to fix that.
I also decided to add support for the Transform component in this PR after all, since it was easier that I expected.
My idea was to expand the Gizmos parameter with more than just lines, but it made sense to me to make the retained versions separate? I'm not 100% sure on it
I think I'd prefer waiting until we actually need them to be separate to show that in the name. Right now it just looks a bit off that there's a Line prefix there.
Any thoughts on alternative names for LineGizmo?
GizmoRetainedGizmoRetainedGizmos
I don't really like having 'retained' in the name, but besides just Gizmo that is all I can think of.
I kinda like GizmoAsset because it uses the asset system and it doesn't have the retained naming, but I'm honestly not sure either.
I kinda like
GizmoAssetbecause it uses the asset system and it doesn't have the retained naming, but I'm honestly not sure either.
We just don't use FooAsset anywhere else, do we?
We just don't use FooAsset anywhere else, do we?
No, but we do in this PR. We need a name for both the component (currently LineGizmo) and the asset (currently LineGizmoAsset)
edit: My preference is still LineGizmo, but I'm fine with just Gizmo as well. We will need to restructure things in the future anyways for text, billboards/images (#14995), meshes, picking support, etc.
Any thoughts on alternative names for
LineGizmo?
None, but I think Gizmo is a good idea to follow.
I've thought about it a bit more and decided to go through with removing the 'line' naming from this PR, see the Rename commit(dbdb9ad) for the changes to naming and docs
Bumping to 0.16, sorry. Rendering's stability is too poor to merge this right now.
This is really nice.
I realize this is a bikeshed, but I'd like to point out that the name Gizmo truly makes no sense any more. This is just polyline rendering with an immediate and retained API, and helpers to convert primitive shapes into polylines.
@tim-blackbird I like this and it's well-reviewed. Can you resolve merge conflicts and ping me to merge please?
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to https://github.com/bevyengine/bevy-website/issues/1963 if you'd like to help out.