Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document that
write_buffer_with
is sound to read from. (#3006)
* Document that `write_buffer_with` is sound to read from. To a reader informed about Rust's memory model, the existing claim that > dereferencing it to a `&[u8]` panics without further context sounds awfully like someone thinks they've invented a write-only reference, and that the API might actually be exposing undefined behavior via an uninitialized `&mut [u8]`. Therefore, let's specify what happens if you *do* read through the mutable reference. The text added in this commit is based on what was said in the review when `write_buffer_with` was added: https://github.com/gfx-rs/wgpu/pull/2777/files#r901392551 This is also relevant information to someone considering using `write_buffer_with()` for performance gains: for example, it suggests that it might be a bad idea to write data into the view and then sort it in-place. (Or is that not a bad idea? Is it not slow if the CPU already wrote over all the memory contiguously? I don't know.) * Changelog addition (+ fixing duplicate documentation section)
- Loading branch information