pub struct MeshPool { /* private fields */ }Expand description
One vertex pool and one index pool, with a free-list suballocator over each.
See the module docs for the fragmentation, growth and residency policies, all three of which are decisions rather than accidents.
Implementations§
Source§impl MeshPool
impl MeshPool
Sourcepub fn new(
device: &dyn Device,
desc: &MeshPoolDesc<'_>,
) -> Result<Self, MeshPoolError>
pub fn new( device: &dyn Device, desc: &MeshPoolDesc<'_>, ) -> Result<Self, MeshPoolError>
Creates both pools, empty.
§Errors
MeshPoolError::Hal from any seam call. A failure part-way through
releases whatever was already created.
Sourcepub const fn attribute_base(&self) -> u32
pub const fn attribute_base(&self) -> u32
The same boundary as a word index, which is what the shaders take.
FrameUniforms::vertex_pool’s x lane and
crcbl_shaders::skinning::Params::attribute_base are both this number:
a vertex v’s position is at word 3 v and its attributes at word
attribute_base() + 5 v. It is the one thing about the split a shader
cannot derive, because the pool’s capacity has never been something a
shader was told.
MeshPool::new refuses a capacity above i32::MAX, so the product
with POSITION_STRIDE / 4 cannot overflow a u32: three times two
billion is short of four.
Sourcepub const fn vertex_buffer(&self) -> BufferHandle
pub const fn vertex_buffer(&self) -> BufferHandle
The vertex pool. Bound as a storage buffer; the vertex stage indexes it.
Sourcepub const fn index_buffer(&self) -> BufferHandle
pub const fn index_buffer(&self) -> BufferHandle
The index pool. Bound once, at offset zero, for every mesh in it.
Sourcepub const fn table_buffer(&self) -> BufferHandle
pub const fn table_buffer(&self) -> BufferHandle
The mesh table. Bound as a read-only storage buffer; the vertex stage indexes it with an instance’s mesh id.
Sourcepub fn table_entries(&self) -> Vec<GpuMesh>
pub fn table_entries(&self) -> Vec<GpuMesh>
The mesh table as the device holds it: every slot, a resident mesh’s entry where one is and the cleared entry everywhere else.
Built from the residents rather than mirrored, because the one place an
entry is written writes exactly a resident’s range — so this is what a
readback of table_buffer would decode to, without
a buffer the device has to make readable. For crate::cull’s oracle,
which indexes it by an instance’s mesh id.
Sourcepub const fn mesh_capacity(&self) -> u32
pub const fn mesh_capacity(&self) -> u32
How many meshes the table holds, which is the bound every mesh id is below.
Sourcepub fn upload(
&mut self,
device: &dyn Device,
queue: QueueHandle,
mesh: &MeshUpload<'_>,
) -> Result<MeshHandle, MeshPoolError>
pub fn upload( &mut self, device: &dyn Device, queue: QueueHandle, mesh: &MeshUpload<'_>, ) -> Result<MeshHandle, MeshPoolError>
Suballocates room for a mesh and records a staging copy into it.
The returned mesh is not resident until MeshPool::flush has run, and
MeshPool::mesh says so.
§Errors
MeshPoolError::EmptyMesh or MeshPoolError::VertexStrideMismatch
for data this pool cannot describe, MeshPoolError::PoolExhausted when
either pool has no block large enough, MeshPoolError::MeshTableFull
when the table has no entry left, and MeshPoolError::Hal from any
seam call. Nothing is left allocated on any failing path: a vertex range
taken before the index pool refused is given back.
Sourcepub fn flush(&mut self, device: &dyn Device) -> Result<(), MeshPoolError>
pub fn flush(&mut self, device: &dyn Device) -> Result<(), MeshPoolError>
Waits for every submitted upload, making its meshes resident, and releases the staging buffers they used.
§Errors
MeshPoolError::UploadTimedOut if the transfers have not completed
within UPLOAD_TIMEOUT, in which case nothing becomes resident and
nothing is released — the staging buffers may still be being read.
MeshPoolError::Hal if the wait itself failed.
Sourcepub fn mesh(&self, handle: MeshHandle) -> Option<MeshRange>
pub fn mesh(&self, handle: MeshHandle) -> Option<MeshRange>
Where handle’s mesh is, or None if there is nothing safe to draw.
None covers both halves of that: a handle this pool never issued or has
since freed, and a mesh whose upload has not completed. A caller cannot
obtain a range for a mesh the GPU may not have received yet, which is
§3.1’s “renderer consumes meshes only after the timeline value passes”
expressed as a type rather than as a rule to remember.
Sourcepub fn table_index(&self, handle: MeshHandle) -> Option<u32>
pub fn table_index(&self, handle: MeshHandle) -> Option<u32>
Which entry of the mesh table handle is: the number an instance’s
GpuInstance::mesh carries.
None on the same terms as MeshPool::mesh, and for the same reason:
handing out an id for a mesh whose bytes may not have landed would move
§3.1’s residency gate from “the caller cannot get one” to “the caller
must remember not to ask”.
Sourcepub fn free(
&mut self,
device: &dyn Device,
handle: MeshHandle,
) -> Result<bool, MeshPoolError>
pub fn free( &mut self, device: &dyn Device, handle: MeshHandle, ) -> Result<bool, MeshPoolError>
Clears a mesh’s table entry and returns its space to both free lists.
The space is reusable immediately, which is only true because uploads are
drained by MeshPool::flush before anything draws — freeing a mesh a
submitted-but-unfinished copy still writes into would be a hazard, and
P9’s streaming path is where that stops being free.
The entry is cleared before the space goes back, which is why this needs a device at all: an entry that outlived its mesh would resolve an instance’s mesh id to space some other mesh now owns. Cleared, it reads as the empty range — see the module docs, which also name the case clearing cannot cover.
Returns whether the handle named a live mesh; a second free of the same
handle answers false rather than corrupting the free list, because the
handle’s generation has moved on.
§Errors
MeshPoolError::Hal if the entry could not be cleared, in which case
nothing is freed — the mesh is still live and the caller can retry.
Sourcepub fn vertex_count(&self, handle: MeshHandle) -> Option<u32>
pub fn vertex_count(&self, handle: MeshHandle) -> Option<u32>
How many vertices handle’s mesh occupies in the vertex pool, or None
on MeshPool::mesh’s terms.
The fourth integer MeshRange deliberately does not carry, because a
draw pulls through indices and needs none of it. A crate::skinning
region does need it — a skinned run is exactly as long as the bind pose
it deforms — and this is the only place the number exists.
Sourcepub fn reserve_vertices(&mut self, count: u32) -> Result<u32, MeshPoolError>
pub fn reserve_vertices(&mut self, count: u32) -> Result<u32, MeshPoolError>
Takes count vertices of the pool for a run no upload fills, and
returns where it starts.
The same suballocator MeshPool::upload draws from, without the
staging copy, the mesh-table entry or the residency gate — because the
caller is not uploading a mesh. crate::skinning’s transient skinned
region is what this exists for: a run of the pool a compute pass writes
and the vertex stage then pulls, whose bytes never come from the host at
all.
Two consequences, both of them the point rather than gaps:
- The space is undefined until something writes it. There is no staging buffer and no copy, so a draw over a reserved run that no dispatch has filled reads whatever the allocation came with.
- It is disjoint from every other live allocation, which is what makes the skinning kernel’s precondition true rather than merely asserted: the free list never hands out an address twice, so a range reserved here cannot overlap the bind-pose range a mesh occupies.
It comes back through
release_vertices rather than
free: there is no handle, no table entry and no
generation here, so nothing can tell a second release from a first.
§Errors
MeshPoolError::EmptyReservation for a zero-length request, which has
no address to hand back, and MeshPoolError::PoolExhausted when no
single free block is large enough — see the module docs on why
that can happen with the space free in total.
Sourcepub fn release_vertices(&mut self, base: u32, count: u32)
pub fn release_vertices(&mut self, base: u32, count: u32)
Gives a run taken by reserve_vertices back.
base and count must be exactly what that call handed out and asked
for. Releasing a run twice, or one that was never reserved, corrupts the
free list — a debug build catches the overlap it produces, and a release
build hands the same address out twice.
Sourcepub fn vertex_space(&self) -> (u32, u32)
pub fn vertex_space(&self) -> (u32, u32)
Vertices free, and the largest single run of them: the pair that tells
fragmentation from a full pool. Indices in
MeshPool::index_space.
Sourcepub fn index_space(&self) -> (u32, u32)
pub fn index_space(&self) -> (u32, u32)
Indices free, and the largest single run of them.