-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Use a sorted Map for vertex buffer attributes #1796
Conversation
crates/bevy_render/src/mesh/mesh.rs
Outdated
@@ -210,7 +210,7 @@ pub struct Mesh { | |||
primitive_topology: PrimitiveTopology, | |||
/// `bevy_utils::HashMap` with all defined vertex attributes (Positions, Normals, ...) for this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is out of date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better?
Very nice catch! I think this is a reasonable change and I doubt the BTreeMap will register on benchmarks. In fact, hashing the full string might end up being more expensive than BTree insertions when the tree size is small. |
bors r+ |
The `VertexBufferLayout` returned by `crates\bevy_render\src\mesh\mesh.rs:308` was unstable, because `HashMap.iter()` has a random order. This caused the pipeline_compiler to wrongly consider a specialization to be different (`crates\bevy_render\src\pipeline\pipeline_compiler.rs:123`), causing each mesh changed event to potentially result in a different `PipelineSpecialization`. This in turn caused `Draw` to emit a `set_pipeline` much more often than needed. This fix shaves off a `BindPipeline` and two `BindDescriptorSets` (for the Camera and for global renderresources) for every mesh after the first that can now use the same specialization, where it didn't before (which was random). `StableHashMap` was not a good replacement, because it isn't `Clone`, so instead I replaced it with a `BTreeMap` which is OK in this instance, because there shouldn't be many insertions on `Mesh.attributes` after the mesh is created.
Pull request successfully merged into main. Build succeeded: |
The `VertexBufferLayout` returned by `crates\bevy_render\src\mesh\mesh.rs:308` was unstable, because `HashMap.iter()` has a random order. This caused the pipeline_compiler to wrongly consider a specialization to be different (`crates\bevy_render\src\pipeline\pipeline_compiler.rs:123`), causing each mesh changed event to potentially result in a different `PipelineSpecialization`. This in turn caused `Draw` to emit a `set_pipeline` much more often than needed. This fix shaves off a `BindPipeline` and two `BindDescriptorSets` (for the Camera and for global renderresources) for every mesh after the first that can now use the same specialization, where it didn't before (which was random). `StableHashMap` was not a good replacement, because it isn't `Clone`, so instead I replaced it with a `BTreeMap` which is OK in this instance, because there shouldn't be many insertions on `Mesh.attributes` after the mesh is created.
The `VertexBufferLayout` returned by `crates\bevy_render\src\mesh\mesh.rs:308` was unstable, because `HashMap.iter()` has a random order. This caused the pipeline_compiler to wrongly consider a specialization to be different (`crates\bevy_render\src\pipeline\pipeline_compiler.rs:123`), causing each mesh changed event to potentially result in a different `PipelineSpecialization`. This in turn caused `Draw` to emit a `set_pipeline` much more often than needed. This fix shaves off a `BindPipeline` and two `BindDescriptorSets` (for the Camera and for global renderresources) for every mesh after the first that can now use the same specialization, where it didn't before (which was random). `StableHashMap` was not a good replacement, because it isn't `Clone`, so instead I replaced it with a `BTreeMap` which is OK in this instance, because there shouldn't be many insertions on `Mesh.attributes` after the mesh is created.
The
VertexBufferLayout
returned bycrates\bevy_render\src\mesh\mesh.rs:308
was unstable, becauseHashMap.iter()
has a random order. This caused the pipeline_compiler to wrongly consider a specialization to be different (crates\bevy_render\src\pipeline\pipeline_compiler.rs:123
), causing each mesh changed event to potentially result in a differentPipelineSpecialization
. This in turn causedDraw
to emit aset_pipeline
much more often than needed.This fix shaves off a
BindPipeline
and twoBindDescriptorSets
(for the Camera and for global renderresources) for every mesh after the first that can now use the same specialization, where it didn't before (which was random).StableHashMap
was not a good replacement, because it isn'tClone
, so instead I replaced it with aBTreeMap
which is OK in this instance, because there shouldn't be many insertions onMesh.attributes
after the mesh is created.