Skip to content
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

Examples shouldn't use bytemuck to cast out of a get_mapped_range() BufferView #6191

Open
Oberdiah opened this issue Sep 1, 2024 · 4 comments
Labels
area: documentation Documentation for crate items, public or private good first issue Good for newcomers type: bug Something isn't working

Comments

@Oberdiah
Copy link

Oberdiah commented Sep 1, 2024

Description
Currently, the examples use bytemuck::cast_slice() to cast u8 slices returned in the BufferView from get_mapped_range() to slices of larger types (u64s, u32s etc.), but this call panics if the underlying slice is not aligned to the larger type.

bytemuck::cast_slice(&timestamp_view).to_vec()

local_buffer.copy_from_slice(bytemuck::cast_slice(&view));

At present, wgpu makes no guarantees about the alignment of get_mapped_range(), and in certain situations does in fact return a slice that is not u64-aligned.

Until wgpu can guarantee alignment here, it would be nice to remove this footgun from the examples, as currently code that works there can mysteriously break when put into a larger project.

Additional Information
I had previously been using bytemuck::cast_slice() without issue in 0.18.x but upon updating to 22.x the alignment shifted. It only seems to have happened on the Vulkan backend.

@BGR360
Copy link
Contributor

BGR360 commented Sep 3, 2024

Just curious as an onlooker: what would be the correct thing to do here?

@Wumpf
Copy link
Member

Wumpf commented Sep 8, 2024

only deal with raw bytes and do memcopies as needed

@Wumpf Wumpf added type: bug Something isn't working area: documentation Documentation for crate items, public or private good first issue Good for newcomers labels Sep 8, 2024
@cwfitzgerald
Copy link
Member

We should be guarenteing 16byte alignment - this is something webgpu-native discussed at length previously. I think there's another issue about it too.

@Wumpf
Copy link
Member

Wumpf commented Sep 8, 2024

This one? webgpu-native/webgpu-headers#180

I agree, but until there's any movement there, our examples are wrong as-is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation Documentation for crate items, public or private good first issue Good for newcomers type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants