Fix unaligned slice::from_raw_parts in gles push contant handling. #6341
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.
Connections
Fixes #6327
Description
Fixes calling
slice::from_raw_parts
with an unaligned pointer by usingbytemuck::pod_read_unaligned
instead (which copies the value to the stack). I assume this is fine for values of the sizes used in push constants. If it seems useful to try to avoid this, then the push constants need to be stored aligned instead (actually looking at this, it would probably be easy to makeCommandBuffer::add_push_constant_data
include some padding to align the data).This adds a new dependency on
bytemuck
inwgpu-hal
. I don't know whether adding this is acceptable (e.g. for firefox).Testing
I updated to a recent rustc nightly (
rustc 1.83.0-nightly (2bd1e894e 2024-09-26)
) and usedrustup override set nightly
followed bycargo xtask test
on a linux system where the gles backend is present.Before the fix I saw panics from new debug assertions in
slice::from_raw_parts
with these tests:wgpu_test::regression::issue_3349::multi_stage_data_binding
wgpu_test::shader::struct_layout::push_constant_input
After the fix these test no longer panic.
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.