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>
impl SlabAllocator<WgpuRuntime>
Sourcepub async fn read(
&self,
range: impl RangeBounds<usize>,
) -> Result<Vec<u32>, SlabAllocatorError>
pub async fn read( &self, range: impl RangeBounds<usize>, ) -> Result<Vec<u32>, SlabAllocatorError>
Read the slab range from the GPU.
Sourcepub async fn read_one<T: SlabItem + Default>(
&self,
id: Id<T>,
) -> Result<T, SlabAllocatorError>
pub async fn read_one<T: SlabItem + Default>( &self, id: Id<T>, ) -> Result<T, SlabAllocatorError>
Read on value from the GPU.
Sourcepub async fn read_array<T: SlabItem + Default>(
&self,
array: Array<T>,
) -> Result<Vec<T>, SlabAllocatorError>
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.
pub fn device(&self) -> &Device
pub fn queue(&self) -> &Queue
Source§impl<R: IsRuntime> SlabAllocator<R>
impl<R: IsRuntime> SlabAllocator<R>
pub fn new( runtime: impl AsRef<R>, name: impl AsRef<str>, default_buffer_usages: R::BufferUsages, ) -> Self
Sourcepub fn len(&self) -> usize
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.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the underlying buffer is empty.
This does not include data that has not yet been committed.
Sourcepub fn get_buffer(&self) -> Option<SlabBuffer<R::Buffer>>
pub fn get_buffer(&self) -> Option<SlabBuffer<R::Buffer>>
Return the internal buffer used by this slab, if it has been created.
Sourcepub fn new_value<T: SlabItem + Clone + Send + Sync + 'static>(
&self,
value: T,
) -> Hybrid<T>
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.
Sourcepub fn new_array<T: SlabItem + Clone + Send + Sync + 'static>(
&self,
values: impl IntoIterator<Item = T>,
) -> HybridArray<T>
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.
Sourcepub fn get_updated_source_ids(&self) -> FxHashSet<SourceId>
pub fn get_updated_source_ids(&self) -> FxHashSet<SourceId>
Return the ids of all sources that require updating.
Sourcepub fn has_queued_updates(&self) -> bool
pub fn has_queued_updates(&self) -> bool
Sourcepub fn commit(&self) -> SlabBuffer<R::Buffer>
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.
pub fn upkeep(&self) -> SlabBuffer<R::Buffer>
commit instead