Skip to main content

Readback

Struct Readback 

Source
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

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Readback

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,