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 strThe label every buffer is created with, reused when one is replaced.
usage: BufferUsagesThe usages every buffer is created with.
allocator: AllocatorWhere 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
impl VertexStreamPool
Sourcepub fn new(
_device: &Device,
label: &'static str,
usage: BufferUsages,
initial_element_capacity: u32,
) -> Self
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.
Sourcepub fn element_capacity(&self) -> u32
pub fn element_capacity(&self) -> u32
How many elements the pool can hold.
Sourcepub fn byte_offset(layout: &VertexBufferLayoutDesc, index: u32) -> u64
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.
Sourcepub fn buffer(&self, layout: &VertexBufferLayoutDesc) -> Option<&Buffer>
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.
Sourcepub fn allocate(
&mut self,
device: &Device,
queue: &Queue,
layouts: &[VertexBufferLayoutDesc],
count: u32,
) -> Option<VertexAllocation>
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.
Sourcepub fn release(&mut self, allocation: Allocation)
pub fn release(&mut self, allocation: Allocation)
Sourcefn reserve(
&mut self,
device: &Device,
queue: &Queue,
layouts: &[VertexBufferLayoutDesc],
end: u32,
)
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.
Auto Trait Implementations§
impl !RefUnwindSafe for VertexStreamPool
impl !UnwindSafe for VertexStreamPool
impl Forget for VertexStreamPool
impl Freeze for VertexStreamPool
impl Send for VertexStreamPool
impl Sync for VertexStreamPool
impl Unpin for VertexStreamPool
impl UnsafeUnpin for VertexStreamPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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