wgpu: Use `write_buffer_with` rather than `write_buffer`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 4.3k
- Forks
- 300
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 61
Description
This can be a performance improvement due to reduced data copying.
From the updated (post 0.20) docs:
```
/// Write to a buffer via a directly mapped staging buffer.
///
/// Return a [`QueueWriteBufferView`] which, when dropped, schedules a copy
/// of its contents into `buffer` at `offset`. The returned view
/// dereferences to a `size`-byte long `&mut [u8]`, in which you should
/// store the data you would like written to `buffer`.
///
/// This method may perform transfers faster than [`Queue::write_buffer`],
/// because the returned [`QueueWriteBufferView`] is actually the staging
/// buffer for the write, mapped into the caller's address space. Writing
/// your data directly into this staging buffer avoids the temporary
/// CPU-side buffer needed by `write_buffer`.
///
/// Reading from the returned view is slow, and will not yield the current
/// contents of `buffer`.
///
/// Note that dropping the [`QueueWriteBufferView`] does *not* submit the
/// transfer to the GPU immediately. The transfer begins only on the next
/// call to [`Queue::submit`] after the view is dropped. To get a set of
/// scheduled transfers started immediately, it's fine to call `submit` with
/// no command buffers at all:
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the Rust codebase for wgpu Queue::write_buffer calls and inspect each write site to understand the data size and submission flow. Replace applicable writes with write_buffer_with while preserving the existing buffer contents and submission behavior; the work is done when the relevant writes no longer require the temporary CPU-side copy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100