fix(examples): use pod_collect_to_vec for mapped buffer reads - #9378
Merged
cwfitzgerald merged 1 commit intoApr 8, 2026
Merged
Conversation
Replace bytemuck::cast_slice with bytemuck::allocation::pod_collect_to_vec when reading from mapped buffer ranges. cast_slice requires the source slice to be properly aligned for the target type, but BufferView from get_mapped_range() is not guaranteed to meet alignment requirements. pod_collect_to_vec copies bytes into a new properly-aligned Vec, avoiding potential undefined behavior from misaligned reads. Closes gfx-rs#6191
countgitmick
force-pushed
the
fix/examples-bytemuck-alignment
branch
from
April 6, 2026 05:54
b349e56 to
2f5cbe4
Compare
Contributor
Author
|
Rebased on trunk to resolve merge conflicts from the examples restructure. Also caught a missed call site in Updated file list (8 files):
|
ErichDonGubler
approved these changes
Apr 7, 2026
Member
|
question: Is there an interesting |
Member
|
It's example only. |
slyedoc
pushed a commit
to slyedoc/wgpu
that referenced
this pull request
May 28, 2026
…#9378) Co-authored-by: countgitmick <countgitmick@users.noreply.github.com>
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.
Summary
bytemuck::cast_slicewithbytemuck::allocation::pod_collect_to_vecwhen reading from mapped buffer rangesextern_crate_allocfeature to workspace bytemuck dependencycast_slicerequires the source slice to be properly aligned for the target type, butBufferViewfromget_mapped_range()is not guaranteed to meet alignment requirements.pod_collect_to_veccopies bytes into a new properly-alignedVec, avoiding potential undefined behavior from misaligned reads.As suggested by @cwfitzgerald in #6191.
Files changed
examples/src/hello_workgroups/mod.rsexamples/src/hello_synchronization/mod.rsexamples/src/hello_compute/mod.rsexamples/src/repeated_compute/mod.rsexamples/src/timestamp_queries/mod.rsCargo.toml(addextern_crate_allocfeature to bytemuck)Test plan
cargo check -p wgpu-examplescargo fmt --check -p wgpu-examplesCloses #6191