mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 05:51:03 +01:00
When accessing a buffer for writing, do not expose (or internally create) any `&'a mut [u8]` references to that memory, so as to avoid exposing write-combining memory that might visibly misbehave in atomic operations. Instead, expose the new pointer type `WriteOnly<'a, [u8]>` which offers only write operations. This can be sliced and reborrowed, allowing it to be used in most ways which `&mut [u8]` would be, hopefully with near-zero overhead. This pointer type might also allow users to opt in to uninitialized memory for performance, while confining the consequences to GPU UB rather than Rust UB. However, that is a future possibility and is not implemented in this commit other than as a consideration in defining the API of the `WriteOnly` type. This change is not a complete solution to the problem of write-combining memory because it is still possible to read after writing by calling `get_mapped_range()` after `get_mapped_range_mut()`. However, that is solvable separately, perhaps with a barrier or a validation change, and is not particularly coupled with this part of the solution.