pub struct PendingDropQueue<E: Fence> { /* private fields */ }Expand description
Defers the drop of CPU-side Bytes allocations until the device has
finished reading them.
§How it works
The device uploads are asynchronous: after you copy bytes into a staging buffer
and enqueue an upload command, the CPU memory must remain valid until the
device is done. PendingDropQueue manages this lifetime with a two-phase
approach:
- Stage – call
pushto hand over bytes that are in-flight. They land in thestagedlist. - Flush – call
flushto rotate the lists. The previously staged bytes move topending, a newFenceis created to mark the end of the current upload batch, and any bytes that were already pending (i.e. the batch before that) are freed after syncing the previous fence.
This double-buffer scheme means CPU memory is held for at most two flush cycles, while avoiding any unnecessary stalls on the hot path.
§Flushing policy
Call should_flush to check whether enough bytes
have accumulated to warrant a flush. You may also flush unconditionally
(e.g. at the end of a frame).
Implementations§
Source§impl<F: Fence> PendingDropQueue<F>
impl<F: Fence> PendingDropQueue<F>
Sourcepub fn new(policy: FlushingPolicy) -> Self
pub fn new(policy: FlushingPolicy) -> Self
Creates a new PendingDropQueue.
Sourcepub fn push(&mut self, bytes: Bytes)
pub fn push(&mut self, bytes: Bytes)
Enqueue bytes to be dropped once the device has finished reading them.
The bytes are added to the current staged batch and will be freed on
the flush cycle after the next call to flush.
Sourcepub fn should_flush(&self) -> bool
pub fn should_flush(&self) -> bool
Returns true when the staged batch is large enough to justify a
flush.
Sourcepub fn flush<Factory: Fn() -> F>(&mut self, factory: Factory)
pub fn flush<Factory: Fn() -> F>(&mut self, factory: Factory)
Rotate the double-buffer and free any memory the device is done with.
factory is called to produce a Fence. It should submit (or
record) a device signal command so that syncing the fence guarantees all
preceding device work is complete.