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>
impl<'bs, C: Pod> BufferSlice<'bs, C>
Sourcepub async fn map_async_poll(self, device: &Device) -> BufferView<'bs, C>
pub async fn map_async_poll(self, device: &Device) -> BufferView<'bs, C>
Map the slice whilst polling the device.
Sourcepub async fn map_async(self) -> BufferView<'bs, C>
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.
Sourcepub fn map_blocking(self, device: &Device) -> BufferView<'bs, C>
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];
Sourcepub async fn map_async_poll_mut(self, device: &Device) -> BufferViewMut<'bs, C>
pub async fn map_async_poll_mut(self, device: &Device) -> BufferViewMut<'bs, C>
Map the slice mutably whilst polling the device.
Sourcepub async fn map_async_mut(self) -> BufferViewMut<'bs, C>
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.
Sourcepub fn map_blocking_mut(self, device: &Device) -> BufferViewMut<'bs, C>
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;
Sourcepub fn copy_to_buffer(
&self,
dst: &mut Buffer<C>,
offset: BufferAddress,
encoder: &mut CommandEncoder,
)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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