Skip to main content

VertexStreamPool

Struct VertexStreamPool 

Source
pub struct VertexStreamPool {
    label: &'static str,
    usage: BufferUsages,
    allocator: Allocator,
    streams: HashMap<VertexBufferLayoutDesc, Stream>,
}
Expand description

One large buffer per vertex layout, sub-allocated into element ranges.

See the module documentation for why every layout shares one allocator, and for what a pool is for.

Fields§

§label: &'static str

The label every buffer is created with, reused when one is replaced.

§usage: BufferUsages

The usages every buffer is created with.

§allocator: Allocator

Where the free element indices are, shared by every layout.

§streams: HashMap<VertexBufferLayoutDesc, Stream>

The buffer of each layout the pool has been asked for.

Implementations§

Source§

impl VertexStreamPool

Source

pub fn new( _device: &Device, label: &'static str, usage: BufferUsages, initial_element_capacity: u32, ) -> Self

Creates a pool whose buffers hold initial_element_capacity elements each.

No buffer exists until a layout is asked for; the capacity is only what the allocator starts with, and it grows on demand.

Source

pub fn element_capacity(&self) -> u32

How many elements the pool can hold.

Source

pub fn byte_offset(layout: &VertexBufferLayoutDesc, index: u32) -> u64

The byte offset of element index in a layout’s buffer.

This is index times the layout’s stride, which is always a multiple of [wgpu::VERTEX_ALIGNMENT], so the result satisfies the alignment [wgpu::Queue::write_buffer] asks for.

Source

pub fn buffer(&self, layout: &VertexBufferLayoutDesc) -> Option<&Buffer>

The buffer of layout, if the pool has been asked for it.

This changes when the pool grows, so read it again instead of holding one.

Source

pub fn allocate( &mut self, device: &Device, queue: &Queue, layouts: &[VertexBufferLayoutDesc], count: u32, ) -> Option<VertexAllocation>

Makes sure every layout in layouts has a buffer, then reserves count elements in all of them at once.

A layout with no attributes and no stride declares nothing to read, so it is skipped: it gets no buffer and no part in the allocation.

Returns None only if the pool cannot grow any further (its element count would overflow a u32, or it has run out of node slots for its allocations).

Growing allocates new buffers and copies the old contents into them; existing allocations keep their element indices, but the buffers they name change, so a caller holding one must re-read Self::buffer.

Source

pub fn release(&mut self, allocation: Allocation)

Hands an allocation back to the pool.

§Panics

Panics if the allocation was already released.

Source

fn reserve( &mut self, device: &Device, queue: &Queue, layouts: &[VertexBufferLayoutDesc], end: u32, )

Grows every layout’s buffer until it covers end elements.

A layout that already covers them is left alone, so a pool shared by meshes of wildly different strides only pays for each layout as far as that layout goes.

Source

fn grow(&mut self, count: u32) -> Option<()>

Grows the allocator until count elements fit.

Returns None if it cannot grow, leaving the pool unchanged.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

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.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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>

§

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

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

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

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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