Skip to main content

TypedBuffer

Struct TypedBuffer 

Source
pub struct TypedBuffer<T: Pod> { /* private fields */ }
Expand description

A typed wrapper around wgpu::Buffer that tracks the element count so callers never have to compute byte sizes manually.

T must implement bytemuck::Pod — the same bound used by storage_buffer_init and read_back.

§Example

use oxiui_compute_wgpu::buffer::TypedBuffer;

// Construction, upload, and download are all in element counts.

Implementations§

Source§

impl<T: Pod> TypedBuffer<T>

Source

pub fn new( device: &Device, label: &str, usage: BufferUsages, len: usize, ) -> Self

Allocate an uninitialised GPU buffer for len elements with the given usage flags.

Source

pub fn from_data(device: &Device, label: &str, data: &[T]) -> Self

Create a STORAGE | COPY_DST | COPY_SRC buffer pre-filled with data.

Source

pub fn len(&self) -> usize

Number of T elements the buffer holds.

Source

pub fn is_empty(&self) -> bool

true if the buffer holds zero elements.

Source

pub fn byte_len(&self) -> u64

Size of the buffer in bytes.

Source

pub fn as_entire_binding(&self) -> BindingResource<'_>

Return a wgpu::BindingResource covering the entire buffer, suitable for passing to BindGroupEntry::resource.

Source

pub fn inner(&self) -> &Buffer

Access the underlying wgpu::Buffer.

Source

pub fn upload(&self, queue: &Queue, data: &[T])

Write data into the buffer via queue.write_buffer.

§Panics

Panics if data.len() != self.len.

Source

pub fn download(&self, device: &Device, queue: &Queue) -> Vec<T>

Read the buffer contents back to the CPU as a Vec<T>.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for TypedBuffer<T>

§

impl<T> !UnwindSafe for TypedBuffer<T>

§

impl<T> Freeze for TypedBuffer<T>

§

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

§

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

§

impl<T> Unpin for TypedBuffer<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for TypedBuffer<T>

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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