Skip to main content

GpuBufferHandle

Struct GpuBufferHandle 

Source
pub struct GpuBufferHandle { /* private fields */ }
Expand description

Cheaply cloneable handle for a GPU-resident buffer.

The handle records the byte length originally requested by the caller, the backing allocation length, the logical element count, and the actual usage flags used to create the underlying wgpu::Buffer.

Implementations§

Source§

impl GpuBufferHandle

Source

pub fn upload( device: &Device, queue: &Queue, bytes: &[u8], usage: BufferUsages, ) -> Result<Self, BackendError>

Upload bytes into a new GPU buffer.

The created buffer always includes COPY_DST so the upload is legal.

§Errors

Returns a backend error when the requested allocation length cannot fit u64.

Source

pub fn alloc( device: &Device, len: u64, usage: BufferUsages, ) -> Result<Self, BackendError>

Allocate a GPU-resident buffer without uploading host contents.

§Errors

Returns a backend error when len cannot be represented as a valid wgpu buffer size.

Source

pub fn readback( &self, device: &Device, queue: &Queue, out: &mut Vec<u8>, ) -> Result<(), BackendError>

Download this GPU buffer into out.

This is intended for terminal output and test assertions, not hot-loop dispatch. The buffer must have COPY_SRC usage.

§Errors

Returns a backend error when the handle is not copy-readable or the GPU mapping fails.

Source

pub fn readback_prefix( &self, device: &Device, queue: &Queue, len: u64, out: &mut Vec<u8>, ) -> Result<(), BackendError>

Download the first len logical bytes of this GPU buffer into out.

Hot paths that publish a device-side count should read back only the counted prefix instead of the whole capacity-sized buffer. The copy is rounded up to wgpu’s 4-byte copy granularity internally, then truncated back to exactly len bytes before returning.

§Errors

Returns a backend error when the handle is not copy-readable, len exceeds the logical buffer length, or the GPU mapping fails.

Source

pub fn readback_range( &self, device: &Device, queue: &Queue, byte_offset: u64, len: u64, out: &mut Vec<u8>, ) -> Result<(), BackendError>

Download len logical bytes starting at byte_offset into out.

The internal GPU copy is alignment-expanded when necessary, then the returned host slice is trimmed back to exactly the requested range.

§Errors

Returns a backend error when the handle is not copy-readable, the range exceeds the logical buffer length, or the GPU mapping fails.

Source

pub fn id(&self) -> u64

Stable process-local handle id used for cache signatures.

Source

pub fn from_resident_id(id: u64) -> Option<Self>

Resolve a process-local resident buffer id back into a live GPU handle.

Source

pub fn resident_handle(&self) -> Result<ResidentHandle, BackendError>

Resident handle naming this buffer, owner included.

§Errors

Returns a backend error when this process could not mint an identity for the WGPU resident namespace.

Source

pub fn from_resident_handle( handle: ResidentHandle, context: &str, ) -> Result<Option<Self>, BackendError>

Resolve a resident handle back into a live GPU handle.

Ok(None) means the handle named a WGPU buffer that is no longer live.

§Errors

Returns a backend error when handle was minted by a different backend instance, which is refused rather than resolved: its id would name an unrelated buffer here.

Source

pub fn buffer(&self) -> &Buffer

Underlying wgpu::Buffer.

Source

pub fn buffer_arc(&self) -> Arc<Buffer>

Clone the internal Arc<wgpu::Buffer> - cheap, reference- count only. Used by the indirect dispatch path (C-B4) which needs to stash the buffer alongside other args.

Source

pub fn byte_len(&self) -> u64

Logical byte length requested by the caller.

Source

pub fn allocation_len(&self) -> u64

Backing allocation length.

Source

pub fn element_count(&self) -> usize

Logical element count. Byte buffers report one element per byte.

Source

pub fn usage(&self) -> BufferUsages

Actual usage flags on the underlying GPU allocation.

Trait Implementations§

Source§

impl Clone for GpuBufferHandle

Source§

fn clone(&self) -> GpuBufferHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GpuBufferHandle

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<GpuBufferHandle> for GpuResource

Source§

fn from(handle: GpuBufferHandle) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more