Add AlignedVec and use it to improve ShaderBuffer#24938
Open
beicause wants to merge 8 commits into
Open
Conversation
7297dd3 to
1ed30a7
Compare
4ae500b to
c3efcc5
Compare
Co-authored-by: Patrick Walton <pcwalton@mimiga.net>
c3efcc5 to
39b006d
Compare
d46b172 to
b007b76
Compare
Member
Author
|
Benchmark results: old
|
Contributor
|
Seems fine to me. |
Member
Author
|
Actually, after replacing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Alternative to #24915.
Accessing data in
ShaderBufferis inconvenient. BecauseVec<u8>may not aligned to the type of element of storage buffer so you have to usebytemuck::pod_read_unaligned/copy_from_slicewhich incurs extra copies and may be slow if you read/write in a loop. This happends in #24922 (comment)Solution
Add
AlignedVecto bevy_platform based on https://github.com/rkyv/rkyv/blob/main/rkyv/src/util/alloc/aligned_vec.rs but the alignment can be set at runtime.By dynamically allocating an aligned byte array, we can directly index and read/write elements using
bytemuck::cast_slice / cast_slice_mut, and success is guaranteed as long as you always use the same typeT. (Previously, castingVec<u8>could also success because the memory allocation might satisfy the larger alignment, but this is not guaranteed)I also included the
ShaderBufferDataimprovement from #24922 and removed methods that takeShaderType.Testing