pub struct RowPaddedBuffer { /* private fields */ }
Expand description

A wrapper around a wgpu buffer suitable for copying to and from Textures. Automatically handles the padding necessary for buffer-to-texture and texture-to-buffer copies.

Note: as of wgpu 0.6, texture-to-buffer and buffer-to-texture copies require that image rows are padded to a multiple wgpu::COPY_BYTES_PER_ROW_ALIGNMENT bytes. Note that this is a requirement on the buffers, not on the textures! You can have textures of whatever size you like, but when you copy them to/from a buffer, the buffer rows need padding. This is referred to as “pitch alignment”.

In a RowPaddedBuffer, the image is stored in row-major order, with rows padded at the end with uninitialized bytes to reach the necessary size.

Implementations§

source§

impl RowPaddedBuffer

source

pub fn from_image_buffer<P, Container>( device: &Device, image_buffer: &ImageBuffer<P, Container> ) -> RowPaddedBuffer
where P: 'static + Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

Initialize from an image buffer (i.e. an image on CPU).

source

pub async fn read<'b>( &'b self ) -> Result<ImageReadMapping<'b>, BufferAsyncError>

Asynchronously maps the buffer of bytes from GPU to host memory.

Note: The returned future will not be ready until the memory is mapped and the device is polled. You should not rely on the being ready immediately.

source§

impl RowPaddedBuffer

source

pub fn new( device: &Device, width: u32, height: u32, usage: BufferUsages ) -> RowPaddedBuffer

Create a row-padded buffer on the device.

Width should be given in bytes.

source

pub fn for_texture( device: &Device, texture: &Texture, usage: BufferUsages ) -> RowPaddedBuffer

Creates a buffer compatible with a 2d slice of the given texture.

source

pub fn width(&self) -> u32

The width of the buffer, in bytes, NOT including padding bytes.

source

pub fn row_padding(&self) -> u32

The padding of each row of this buffer.

source

pub fn padded_width(&self) -> u32

The width of the buffer, in bytes, INCLUDING padding bytes.

source

pub fn height(&self) -> u32

The height of the buffer.

source

pub fn write(&self, buf: &[u8])

Copy data into the padded buffer.

Will copy data_width bytes of data into each row of the buffer, leaving the remainder of the buffer unmodified.

The buffer usage must include BufferUsages::map_read().

source

pub fn encode_copy_into( &self, encoder: &mut CommandEncoder, destination: &Texture )

Encode a copy into a texture. Assumes the texture is 2d.

The copy will not be performed until the encoded command buffer is submitted.

source

pub fn encode_copy_into_at( &self, encoder: &mut CommandEncoder, destination: &Texture, depth: u32 )

Encode a copy into a 3d texture at a given depth. Will copy this buffer (modulo padding) to a slice of the texture at the given depth.

The copy will not be performed until the encoded command buffer is submitted.

source

pub fn encode_copy_from(&self, encoder: &mut CommandEncoder, source: &Texture)

Encode a copy from a texture.

The copy will not be performed until the encoded command buffer is submitted.

source

pub fn encode_copy_from_at( &self, encoder: &mut CommandEncoder, source: &Texture, depth: u32 )

Encode a copy from a 3d texture at a given depth. Will copy a slice of the texture to fill this whole buffer (modulo padding).

The copy will not be performed until the encoded command buffer is submitted.

Trait Implementations§

source§

impl Debug for RowPaddedBuffer

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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<T, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

§

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