Struct BufferSlice

Source
pub struct BufferSlice<'bs, C: Pod> { /* private fields */ }
Expand description

A wrapper for the wgpu::BufferSlice but with its data exposed.

TODO: maybe imlement a BufferSliceMut

Implementations§

Source§

impl<'bs, C: Pod> BufferSlice<'bs, C>

Source

pub async fn map_async_poll(self, device: &Device) -> BufferView<'bs, C>

Map the slice whilst polling the device.

Source

pub async fn map_async(self) -> BufferView<'bs, C>

Map the slice asynchronously. wgpu::Device::poll has to be called before this Future will complete.

Source

pub fn map_blocking(self, device: &Device) -> BufferView<'bs, C>

Map the slice and block this thread untill maping is complete.

Example:

let array = [0, 1, 2, 3, 4]; let mapped_buffer = MappedBuffer::new_storage(device, None, array);

mapped_buffer.slice_blocking(..)[0] = 1;

let i = mapped_buffer.slice(..)[0];

Source

pub async fn map_async_poll_mut(self, device: &Device) -> BufferViewMut<'bs, C>

Map the slice mutably whilst polling the device.

Source

pub async fn map_async_mut(self) -> BufferViewMut<'bs, C>

Map the slice asynchronously for writing to the buffer. wgpu::Device::poll has to be called before this Future will complete.

Source

pub fn map_blocking_mut(self, device: &Device) -> BufferViewMut<'bs, C>

Map the slice mutably and block this thread untill maping is complete.

slice.map_blocking_mut(device)[0] = 1;

Source

pub fn copy_to_buffer( &self, dst: &mut Buffer<C>, offset: BufferAddress, encoder: &mut CommandEncoder, )

Copy the buffer slice to another buffer. Only the bytes that fit into the destination buffer are copied.

use ewgpu::*;

let instance = wgpu::Instance::new(wgpu::Backends::all());

let mut gpu = GPUContextBuilder::new()
    .enable_feature(wgpu::Features::MAPPABLE_PRIMARY_BUFFERS)
    .set_limits(wgpu::Limits{
        max_push_constant_size: 128,
        ..Default::default()
    }).build();

let buffer1 = BufferBuilder::<u64>::new()
                .read().write().copy_src()
                .append_slice(&[0, 1, 2, 3])
                .set_label(Some("buffer1"))
                .build(&gpu.device);
let mut buffer2 = BufferBuilder::<u64>::new()
                .read().write().copy_dst()
                .append_slice(&[0, 0, 0, 0])
                .set_label(Some("buffer2"))
                .build(&gpu.device);

gpu.encode(|gpu, encoder|{
    buffer1.slice(..).copy_to_buffer(&mut buffer2, 1, encoder);
});

gpu.encode(|gpu, encoder|{
    assert_eq!(buffer2.slice(..).map_blocking(&gpu.device).as_ref(), [0, 0, 1, 2]);
})

Auto Trait Implementations§

§

impl<'bs, C> Freeze for BufferSlice<'bs, C>

§

impl<'bs, C> !RefUnwindSafe for BufferSlice<'bs, C>

§

impl<'bs, C> Send for BufferSlice<'bs, C>
where C: Sync,

§

impl<'bs, C> Sync for BufferSlice<'bs, C>
where C: Sync,

§

impl<'bs, C> Unpin for BufferSlice<'bs, C>

§

impl<'bs, C> !UnwindSafe for BufferSlice<'bs, C>

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<T> Downcast<T> for T

Source§

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

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>,

Source§

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>,

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> Upcast<T> for T

Source§

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