@@ -4991,11 +4991,24 @@ impl<'a> Drop for QueueWriteBufferView<'a> {
4991
4991
impl Queue {
4992
4992
/// Schedule a data write into `buffer` starting at `offset`.
4993
4993
///
4994
- /// This method is intended to have low performance costs.
4995
- /// As such, the write is not immediately submitted, and instead enqueued
4996
- /// internally to happen at the start of the next `submit()` call.
4997
- ///
4998
4994
/// This method fails if `data` overruns the size of `buffer` starting at `offset`.
4995
+ ///
4996
+ /// This does *not* submit the transfer to the GPU immediately. Calls to
4997
+ /// `write_buffer` begin execution only on the next call to
4998
+ /// [`Queue::submit`]. To get a set of scheduled transfers started
4999
+ /// immediately, it's fine to call `submit` with no command buffers at all:
5000
+ ///
5001
+ /// ```no_run
5002
+ /// # let queue: wgpu::Queue = todo!();
5003
+ /// queue.submit([]);
5004
+ /// ```
5005
+ ///
5006
+ /// However, `data` will be immediately copied into staging memory, so the
5007
+ /// caller may discard it any time after this call completes.
5008
+ ///
5009
+ /// If possible, consider using [`Queue::write_buffer_with`] instead. That
5010
+ /// method avoids an intermediate copy and is often able to transfer data
5011
+ /// more efficiently than this one.
4999
5012
pub fn write_buffer ( & self , buffer : & Buffer , offset : BufferAddress , data : & [ u8 ] ) {
5000
5013
DynContext :: queue_write_buffer (
5001
5014
& * self . context ,
@@ -5008,14 +5021,32 @@ impl Queue {
5008
5021
)
5009
5022
}
5010
5023
5011
- /// Schedule a data write into `buffer` starting at `offset` via the returned
5012
- /// [`QueueWriteBufferView`].
5024
+ /// Write to a buffer via a directly mapped staging buffer.
5025
+ ///
5026
+ /// Return a [`QueueWriteBufferView`] which, when dropped, schedules a copy
5027
+ /// of its contents into `buffer` at `offset`. The returned view
5028
+ /// dereferences to a `size`-byte long `&mut [u8]`, in which you should
5029
+ /// store the data you would like written to `buffer`.
5030
+ ///
5031
+ /// This method may perform transfers faster than [`Queue::write_buffer`],
5032
+ /// because the returned [`QueueWriteBufferView`] is actually the staging
5033
+ /// buffer for the write, mapped into the caller's address space. Writing
5034
+ /// your data directly into this staging buffer avoids the temporary
5035
+ /// CPU-side buffer needed by `write_buffer`.
5013
5036
///
5014
- /// Reading from this buffer is slow and will not yield the actual contents of the buffer.
5037
+ /// Reading from the returned view is slow, and will not yield the current
5038
+ /// contents of `buffer`.
5015
5039
///
5016
- /// This method is intended to have low performance costs.
5017
- /// As such, the write is not immediately submitted, and instead enqueued
5018
- /// internally to happen at the start of the next `submit()` call.
5040
+ /// Note that dropping the [`QueueWriteBufferView`] does *not* submit the
5041
+ /// transfer to the GPU immediately. The transfer begins only on the next
5042
+ /// call to [`Queue::submit`] after the view is dropped. To get a set of
5043
+ /// scheduled transfers started immediately, it's fine to call `submit` with
5044
+ /// no command buffers at all:
5045
+ ///
5046
+ /// ```no_run
5047
+ /// # let queue: wgpu::Queue = todo!();
5048
+ /// queue.submit([]);
5049
+ /// ```
5019
5050
///
5020
5051
/// This method fails if `size` is greater than the size of `buffer` starting at `offset`.
5021
5052
#[ must_use]
@@ -5059,13 +5090,20 @@ impl Queue {
5059
5090
/// texture (coordinate offset, mip level) that will be overwritten.
5060
5091
/// * `size` is the size, in texels, of the region to be written.
5061
5092
///
5062
- /// This method is intended to have low performance costs.
5063
- /// As such, the write is not immediately submitted, and instead enqueued
5064
- /// internally to happen at the start of the next `submit()` call.
5065
- /// However, `data` will be immediately copied into staging memory; so the caller may
5066
- /// discard it any time after this call completes.
5067
- ///
5068
5093
/// This method fails if `size` overruns the size of `texture`, or if `data` is too short.
5094
+ ///
5095
+ /// This does *not* submit the transfer to the GPU immediately. Calls to
5096
+ /// `write_texture` begin execution only on the next call to
5097
+ /// [`Queue::submit`]. To get a set of scheduled transfers started
5098
+ /// immediately, it's fine to call `submit` with no command buffers at all:
5099
+ ///
5100
+ /// ```no_run
5101
+ /// # let queue: wgpu::Queue = todo!();
5102
+ /// queue.submit([]);
5103
+ /// ```
5104
+ ///
5105
+ /// However, `data` will be immediately copied into staging memory, so the
5106
+ /// caller may discard it any time after this call completes.
5069
5107
pub fn write_texture (
5070
5108
& self ,
5071
5109
texture : ImageCopyTexture < ' _ > ,
0 commit comments