pub struct GpuBuffer<T: Pod> { /* private fields */ }Expand description
GPU buffer wrapper with type safety.
This struct wraps a WGPU buffer and provides type-safe operations for uploading and downloading data to/from the GPU.
Implementations§
Source§impl<T: Pod> GpuBuffer<T>
impl<T: Pod> GpuBuffer<T>
Sourcepub fn new(
context: &GpuContext,
len: usize,
usage: BufferUsages,
) -> GpuResult<Self>
pub fn new( context: &GpuContext, len: usize, usage: BufferUsages, ) -> GpuResult<Self>
Create a new GPU buffer with the specified size and usage.
§Errors
Returns an error if buffer creation fails or size is invalid.
Sourcepub fn from_data(
context: &GpuContext,
data: &[T],
usage: BufferUsages,
) -> GpuResult<Self>
pub fn from_data( context: &GpuContext, data: &[T], usage: BufferUsages, ) -> GpuResult<Self>
Create a GPU buffer from existing data.
§Errors
Returns an error if buffer creation or upload fails.
Sourcepub fn staging(context: &GpuContext, len: usize) -> GpuResult<Self>
pub fn staging(context: &GpuContext, len: usize) -> GpuResult<Self>
Sourcepub fn write(&mut self, data: &[T]) -> GpuResult<()>
pub fn write(&mut self, data: &[T]) -> GpuResult<()>
Write data to the GPU buffer.
§Errors
Returns an error if the buffer doesn’t support writes or data size doesn’t match buffer size.
Sourcepub async fn read(&self) -> GpuResult<Vec<T>>
pub async fn read(&self) -> GpuResult<Vec<T>>
Read data from the GPU buffer asynchronously.
§Errors
Returns an error if the buffer doesn’t support reads or mapping fails.
Sourcepub fn read_blocking(&self) -> GpuResult<Vec<T>>
pub fn read_blocking(&self) -> GpuResult<Vec<T>>
Read data from the GPU buffer synchronously (blocking).
§Errors
Returns an error if the buffer doesn’t support reads or mapping fails.
Sourcepub fn copy_from(&mut self, source: &GpuBuffer<T>) -> GpuResult<()>
pub fn copy_from(&mut self, source: &GpuBuffer<T>) -> GpuResult<()>
Copy data from another GPU buffer.
§Errors
Returns an error if buffer sizes don’t match or copy is not supported.
Sourcepub fn size_bytes(&self) -> u64
pub fn size_bytes(&self) -> u64
Get the buffer size in bytes.
Sourcepub fn usage(&self) -> BufferUsages
pub fn usage(&self) -> BufferUsages
Get buffer usage flags.