Buffer

Struct Buffer 

Source
pub struct Buffer { /* private fields */ }

Implementations§

Source§

impl Buffer

Source

pub fn id(&self) -> BufferId

Source

pub fn slice(&self, bounds: impl RangeBounds<BufferAddress>) -> BufferSlice<'_>

Source

pub fn unmap(&self)

Methods from Deref<Target = Buffer>§

Source

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

Return the binding view of the entire buffer.

Source

pub fn as_entire_buffer_binding(&self) -> BufferBinding<'_>

Return the binding view of the entire buffer.

Source

pub unsafe fn as_hal<A>( &self, ) -> Option<impl Deref<Target = <A as Api>::Buffer> + WasmNotSendSync>
where A: HalApi,

Get the wgpu_hal buffer from this Buffer.

Find the Api struct corresponding to the active backend in wgpu_hal::api, and pass that struct to the to the A type parameter.

Returns a guard that dereferences to the type of the hal backend which implements A::Buffer.

§Deadlocks
  • The returned guard holds a read-lock on a device-local “destruction” lock, which will cause all calls to destroy to block until the guard is released.
§Errors

This method will return None if:

  • The buffer is not from the backend specified by A.
  • The buffer is from the webgpu or custom backend.
  • The buffer has had Self::destroy() called on it.
§Safety
  • The returned resource must not be destroyed unless the guard is the last reference to it and it is not in use by the GPU. The guard and handle may be dropped at any time however.
  • All the safety requirements of wgpu-hal must be upheld.
Source

pub fn slice<S>(&self, bounds: S) -> BufferSlice<'_>
where S: RangeBounds<u64>,

Returns a BufferSlice referring to the portion of self’s contents indicated by bounds. Regardless of what sort of data self stores, bounds start and end are given in bytes.

A BufferSlice can be used to supply vertex and index data, or to map buffer contents for access from the CPU. See the BufferSlice documentation for details.

The range argument can be half or fully unbounded: for example, buffer.slice(..) refers to the entire buffer, and buffer.slice(n..) refers to the portion starting at the nth byte and extending to the end of the buffer.

§Panics
  • If bounds is outside of the bounds of self.
  • If bounds has a length less than 1.
Source

pub fn unmap(&self)

Unmaps the buffer from host memory.

This terminates the effect of all previous map_async() operations and makes the buffer available for use by the GPU again.

Source

pub fn destroy(&self)

Destroy the associated native resources as soon as possible.

Source

pub fn size(&self) -> u64

Returns the length of the buffer allocation in bytes.

This is always equal to the size that was specified when creating the buffer.

Source

pub fn usage(&self) -> BufferUsages

Returns the allowed usages for this Buffer.

This is always equal to the usage that was specified when creating the buffer.

Source

pub fn map_async<S>( &self, mode: MapMode, bounds: S, callback: impl FnOnce(Result<(), BufferAsyncError>) + WasmNotSend + 'static, )
where S: RangeBounds<u64>,

Map the buffer to host (CPU) memory, making it available for reading or writing via get_mapped_range(). It is available once the callback is called with an Ok response.

For the callback to complete, either queue.submit(..), instance.poll_all(..), or device.poll(..) must be called elsewhere in the runtime, possibly integrated into an event loop or run on a separate thread.

The callback will be called on the thread that first calls the above functions after the GPU work has completed. There are no restrictions on the code you can run in the callback, however on native the call to the function will not complete until the callback returns, so prefer keeping callbacks short and used to set flags, send messages, etc.

As long as a buffer is mapped, it is not available for use by any other commands; at all times, either the GPU or the CPU has exclusive access to the contents of the buffer.

This can also be performed using BufferSlice::map_async().

§Panics
  • If the buffer is already mapped.
  • If the buffer’s BufferUsages do not allow the requested MapMode.
  • If bounds is outside of the bounds of self.
  • If bounds has a length less than 1.
  • If the start and end of bounds are not be aligned to MAP_ALIGNMENT.
Source

pub fn get_mapped_range<S>(&self, bounds: S) -> BufferView<'_>
where S: RangeBounds<u64>,

Gain read-only access to the bytes of a mapped Buffer.

Returns a BufferView referring to the buffer range represented by self. See the documentation for BufferView for details.

bounds may be less than the bounds passed to Self::map_async(), and multiple views may be obtained and used simultaneously as long as they do not overlap.

This can also be performed using BufferSlice::get_mapped_range().

§Panics
  • If bounds is outside of the bounds of self.
  • If bounds has a length less than 1.
  • If the start and end of bounds are not aligned to MAP_ALIGNMENT.
  • If the buffer to which self refers is not currently mapped.
  • If you try to create overlapping views of a buffer, mutable or otherwise.
Source

pub fn get_mapped_range_mut<S>(&self, bounds: S) -> BufferViewMut<'_>
where S: RangeBounds<u64>,

Gain write access to the bytes of a mapped Buffer.

Returns a BufferViewMut referring to the buffer range represented by self. See the documentation for BufferViewMut for more details.

bounds may be less than the bounds passed to Self::map_async(), and multiple views may be obtained and used simultaneously as long as they do not overlap.

This can also be performed using BufferSlice::get_mapped_range_mut().

§Panics
  • If bounds is outside of the bounds of self.
  • If bounds has a length less than 1.
  • If the start and end of bounds are not aligned to MAP_ALIGNMENT.
  • If the buffer to which self refers is not currently mapped.
  • If you try to create overlapping views of a buffer, mutable or otherwise.

Trait Implementations§

Source§

impl Clone for Buffer

Source§

fn clone(&self) -> Buffer

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Buffer

Source§

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

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

impl Deref for Buffer

Source§

type Target = Buffer

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<Buffer> for Buffer

Source§

fn from(value: Buffer) -> Self

Converts to this type from the input type.
Source§

impl From<Buffer> for SlotValue

Source§

fn from(value: Buffer) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Buffer

§

impl !RefUnwindSafe for Buffer

§

impl Send for Buffer

§

impl Sync for Buffer

§

impl Unpin for Buffer

§

impl !UnwindSafe for Buffer

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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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 for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> 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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
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
Source§

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

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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