pub struct Readback { /* private fields */ }Expand description
A read-back in flight, with no wait in it.
read_bytes_many waits on an mpsc channel, which is correct on a native
thread and fatal on the browser’s: under WebGPU Device::poll is a
documented no-op and map_async completes only when control returns to the
event loop, so a thread that blocks on recv() is the thread that would have
run the event loop and the tab deadlocks. This is the same staging copy with
the wait taken out – submit, then ask again next frame.
One frame of latency at best, more under load, and that is the honest shape
of a GPU read-back. read_bytes_many stays as it is: a native test wants
the answer on the next line, and this is its deferred sibling rather than a
replacement.
Implementations§
Source§impl Readback
impl Readback
Sourcepub fn ready(&self, device: &Device) -> bool
pub fn ready(&self, device: &Device) -> bool
Whether the mapping has completed. Call once a frame.
Polls with wgpu::PollType::Poll, which is one call site for both
targets and no cfg: on a native backend it is the pump that lets the
map_async callback fire, and under WebGPU it is a documented no-op
returning PollStatus::QueueEmpty because the browser polls for us and
the callback arrives from the event loop.
The poll result is dropped deliberately. A device that failed to poll
shows up here as a read-back that never becomes ready, and
Readback::take is the one place that reports an error, because it is
the one place a caller is asking for bytes.
Sourcepub fn take(self) -> Result<Vec<Vec<u8>>>
pub fn take(self) -> Result<Vec<Vec<u8>>>
The bytes, one Vec per request, in request order. Unmaps the staging
buffer.
§Errors
Error::MapFailed if the map was refused, Error::DeviceLost if the
mapping has not completed – calling this before Readback::ready
returns true is the caller’s bug, and returning half a buffer would
hide it.