Struct Buffer

Source
pub struct Buffer {
    pub(crate) raw: Snatchable<Box<dyn DynBuffer>>,
    pub(crate) device: Arc<Device>,
    pub(crate) usage: BufferUsages,
    pub(crate) size: BufferAddress,
    pub(crate) initialization_status: RwLock<InitTracker<BufferAddress>>,
    pub(crate) label: String,
    pub(crate) tracking_data: TrackingData,
    pub(crate) map_state: Mutex<BufferMapState>,
    pub(crate) bind_groups: Mutex<WeakVec<BindGroup>>,
    pub(crate) timestamp_normalization_bind_group: Snatchable<TimestampNormalizationBindGroup>,
    pub(crate) indirect_validation_bind_groups: Snatchable<BindGroups>,
}

Fields§

§raw: Snatchable<Box<dyn DynBuffer>>§device: Arc<Device>§usage: BufferUsages§size: BufferAddress§initialization_status: RwLock<InitTracker<BufferAddress>>§label: String

The label from the descriptor used to create the resource.

§tracking_data: TrackingData§map_state: Mutex<BufferMapState>§bind_groups: Mutex<WeakVec<BindGroup>>§timestamp_normalization_bind_group: Snatchable<TimestampNormalizationBindGroup>§indirect_validation_bind_groups: Snatchable<BindGroups>

Implementations§

Source§

impl Buffer

Source

pub(crate) fn check_destroyed( &self, guard: &SnatchGuard<'_>, ) -> Result<(), DestroyedResourceError>

Source

pub(crate) fn check_usage( &self, expected: BufferUsages, ) -> Result<(), MissingBufferUsageError>

Checks that the given buffer usage contains the required buffer usage, returns an error otherwise.

Source

pub fn resolve_binding_size( &self, offset: BufferAddress, binding_size: Option<BufferSize>, ) -> Result<u64, BindingError>

Resolve the size of a binding for buffer with offset and size.

If size is None, then the remainder of the buffer starting from offset is used.

If the binding would overflow the buffer, then an error is returned.

Zero-size bindings are permitted here for historical reasons. Although zero-size bindings are permitted by WebGPU, they are not permitted by some backends. See Buffer::binding and #3170.

Source

pub fn binding<'a>( &'a self, offset: BufferAddress, binding_size: Option<BufferSize>, snatch_guard: &'a SnatchGuard<'_>, ) -> Result<(BufferBinding<'a, dyn DynBuffer>, u64), BindingError>

Create a new hal::BufferBinding for the buffer with offset and binding_size.

If binding_size is None, then the remainder of the buffer starting from offset is used.

If the binding would overflow the buffer, then an error is returned.

A zero-size binding at the end of the buffer is permitted here for historical reasons. Although zero-size bindings are permitted by WebGPU, they are not permitted by some backends. The zero-size binding need to be quashed or remapped to a non-zero size, either universally in wgpu-core, or in specific backends that do not support them. See #3170.

Although it seems like it would be simpler and safer to use the resolved size in the returned hal::BufferBinding, doing this (and removing redundant logic in backends to resolve the implicit size) was observed to cause problems in certain CTS tests, so an implicit size specification is preserved in the output.

Source

pub(crate) fn map_async( self: &Arc<Self>, offset: BufferAddress, size: Option<BufferAddress>, op: BufferMapOperation, ) -> Result<SubmissionIndex, (BufferMapOperation, BufferAccessError)>

Returns the mapping callback in case of error so that the callback can be fired outside of the locks that are held in this function.

Source

pub(crate) fn map( &self, snatch_guard: &SnatchGuard<'_>, ) -> Option<BufferMapPendingClosure>

This function returns None only if Self::map_state is not BufferMapState::Waiting.

Source

pub(crate) fn unmap(self: &Arc<Self>) -> Result<(), BufferAccessError>

Source

fn unmap_inner( self: &Arc<Self>, ) -> Result<Option<BufferMapPendingClosure>, BufferAccessError>

Source

pub(crate) fn destroy(self: &Arc<Self>)

Trait Implementations§

Source§

impl Debug for Buffer

Source§

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

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

impl Drop for Buffer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Labeled for Buffer

Source§

fn label(&self) -> &str

Returns a string identifying this resource for logging and errors. Read more
Source§

fn error_ident(&self) -> ResourceErrorIdent

Source§

impl ParentDevice for Buffer

Source§

fn device(&self) -> &Arc<Device>

Source§

fn is_equal(self: &Arc<Self>, other: &Arc<Self>) -> bool

Source§

fn same_device_as<O: ParentDevice>(&self, other: &O) -> Result<(), DeviceError>

Source§

fn same_device(&self, device: &Device) -> Result<(), DeviceError>

Source§

impl RawResourceAccess for Buffer

Source§

type DynResource = dyn DynBuffer

Source§

fn raw<'a>( &'a self, guard: &'a SnatchGuard<'_>, ) -> Option<&'a Self::DynResource>

Get access to the raw resource if it is not destroyed. Read more
Source§

fn try_raw<'a>( &'a self, guard: &'a SnatchGuard<'_>, ) -> Result<&'a Self::DynResource, DestroyedResourceError>

Get access to the raw resource if it is not destroyed. Read more
Source§

impl ResourceType for Buffer

Source§

const TYPE: &'static str = "Buffer"

Source§

impl StorageItem for Buffer

Source§

impl Trackable for Buffer

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> 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
§

impl<T> Downcast<T> for T

§

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, 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.
§

impl<T> Upcast<T> for T

§

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,