SlabAllocator

Struct SlabAllocator 

Source
pub struct SlabAllocator<Runtime: IsRuntime> { /* private fields */ }
Expand description

Manages slab allocations and updates over a parameterised buffer.

Create a new instance using SlabAllocator::new.

Upon creation you will need to call SlabAllocator::get_buffer or SlabAllocator::commit at least once before any data is written to the internal buffer.

Implementations§

Source§

impl SlabAllocator<WgpuRuntime>

Source

pub async fn read( &self, range: impl RangeBounds<usize>, ) -> Result<Vec<u32>, SlabAllocatorError>

Read the slab range from the GPU.

Source

pub async fn read_one<T: SlabItem + Default>( &self, id: Id<T>, ) -> Result<T, SlabAllocatorError>

Read on value from the GPU.

Source

pub async fn read_array<T: SlabItem + Default>( &self, array: Array<T>, ) -> Result<Vec<T>, SlabAllocatorError>

Read an array of typed values from the GPU.

Source

pub fn device(&self) -> &Device

Source

pub fn queue(&self) -> &Queue

Source§

impl<R: IsRuntime> SlabAllocator<R>

Source

pub fn new( runtime: impl AsRef<R>, name: impl AsRef<str>, default_buffer_usages: R::BufferUsages, ) -> Self

Source

pub fn len(&self) -> usize

The length of the underlying buffer, in u32 slots.

This does not include data that has not yet been committed.

Source

pub fn is_empty(&self) -> bool

Whether the underlying buffer is empty.

This does not include data that has not yet been committed.

Source

pub fn get_buffer(&self) -> Option<SlabBuffer<R::Buffer>>

Return the internal buffer used by this slab, if it has been created.

Source

pub fn new_value<T: SlabItem + Clone + Send + Sync + 'static>( &self, value: T, ) -> Hybrid<T>

Stage a new value that lives on the GPU and CPU.

Source

pub fn new_array<T: SlabItem + Clone + Send + Sync + 'static>( &self, values: impl IntoIterator<Item = T>, ) -> HybridArray<T>

Stage a contiguous array of new values that live on the GPU and CPU.

Source

pub fn get_updated_source_ids(&self) -> FxHashSet<SourceId>

Return the ids of all sources that require updating.

Source

pub fn has_queued_updates(&self) -> bool

Returns whether any update sources, most likely from Hybrid or Gpu values, have queued updates waiting to be committed.

Source

pub fn commit(&self) -> SlabBuffer<R::Buffer>

Perform upkeep on the slab, synchronizing changes to the internal buffer.

Changes made to Hybrid and Gpu values created by this slab are not committed until this function has been called.

The internal buffer is not created until the first time this function is called.

Returns a SlabBuffer wrapping the internal buffer that is currently in use by the allocator.

Source

pub fn upkeep(&self) -> SlabBuffer<R::Buffer>

👎Deprecated since 0.1.5: please use commit instead
Source

pub fn defrag(&self)

Defragments the internal “recycle” buffer.

Source

pub fn runtime(&self) -> &R

Trait Implementations§

Source§

impl<R: IsRuntime> Clone for SlabAllocator<R>

Source§

fn clone(&self) -> Self

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

Auto Trait Implementations§

§

impl<Runtime> Freeze for SlabAllocator<Runtime>
where Runtime: Freeze, <Runtime as IsRuntime>::BufferUsages: Freeze,

§

impl<Runtime> RefUnwindSafe for SlabAllocator<Runtime>
where Runtime: RefUnwindSafe, <Runtime as IsRuntime>::BufferUsages: RefUnwindSafe,

§

impl<Runtime> Send for SlabAllocator<Runtime>
where Runtime: Send, <Runtime as IsRuntime>::BufferUsages: Send, <Runtime as IsRuntime>::Buffer: Sync + Send,

§

impl<Runtime> Sync for SlabAllocator<Runtime>
where Runtime: Sync, <Runtime as IsRuntime>::BufferUsages: Sync, <Runtime as IsRuntime>::Buffer: Sync + Send,

§

impl<Runtime> Unpin for SlabAllocator<Runtime>
where Runtime: Unpin, <Runtime as IsRuntime>::BufferUsages: Unpin,

§

impl<Runtime> UnwindSafe for SlabAllocator<Runtime>
where Runtime: UnwindSafe, <Runtime as IsRuntime>::BufferUsages: UnwindSafe,

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> 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> 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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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