Skip to main content

Readback

Trait Readback 

Source
pub trait Readback: Debug {
    // Required methods
    fn resolve(
        &self,
        offset: u64,
        size: u64,
    ) -> impl Future<Output = Result<Vec<u8>, GpuError>> + '_;
    fn resolve_into<'a>(
        &'a self,
        offset: u64,
        size: u64,
        output: &'a mut [u8],
    ) -> impl Future<Output = Result<(), GpuError>> + 'a;
    fn begin_map(&self, offset: u64, size: u64) -> Result<(), GpuError>;
    fn try_finish_into(&self, output: &mut [u8]) -> Result<bool, GpuError>;
}
Expand description

A detached readback over one buffer.

The handle owns everything it needs to await a mapped range, so a caller can release every borrow of the renderer that submitted the copy before the wait begins. On the browser’s single JavaScript thread that is what lets a frame render while a pick is still resolving its readback.

Required Methods§

Source

fn resolve( &self, offset: u64, size: u64, ) -> impl Future<Output = Result<Vec<u8>, GpuError>> + '_

Awaits the mapped range and returns its bytes.

§Errors

The device was lost, or the buffer was not readable.

Source

fn resolve_into<'a>( &'a self, offset: u64, size: u64, output: &'a mut [u8], ) -> impl Future<Output = Result<(), GpuError>> + 'a

Copies a mapped range into caller-owned scratch without allocating bytes. Only the first size bytes are written; the remaining output is unchanged. The future borrows this detached handle and the scratch, not the renderer.

§Errors

Returns device or mapping errors, or an invalid, unaligned, overflowing range or output shorter than size, before writing any output.

Source

fn begin_map(&self, offset: u64, size: u64) -> Result<(), GpuError>

Requests a map of one range and returns at once.

The map completes as the device is polled. One request is outstanding per handle, so a ring reuses its handles and allocates nothing per request; pair every call with Self::try_finish_into.

§Errors

Returns an invalid, unaligned or overflowing range, an unreadable buffer, or a request already outstanding on this handle.

Source

fn try_finish_into(&self, output: &mut [u8]) -> Result<bool, GpuError>

Copies the requested range into output and unmaps once the map completed. Returns Ok(false) while it is still pending; never blocks.

§Errors

Returns device or mapping errors, no request outstanding, or an output shorter than the requested range.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§