pub(crate) struct LifetimeTracker {
active: Vec<ActiveSubmission>,
ready_to_map: Vec<Arc<Buffer>>,
ready_to_compact: Vec<Arc<Blas>>,
work_done_closures: SmallVec<[SubmittedWorkDoneClosure; 1]>,
}Expand description
Resource tracking for a device.
§Host mapping buffers
A buffer cannot be mapped until all active queue submissions that use it have completed. To that end:
-
Each buffer’s
ResourceInfo::submission_indexrecords the index of the most recent queue submission that uses that buffer. -
When the device is polled, the following
LifetimeTrackermethods decide what should happen next:-
triage_submissionsmoves entries inself.active[i]for completed submissions toself.ready_to_map. At this point, bothself.activeandself.ready_to_mapare up to date with the given submission index. -
handle_mappingdrainsself.ready_to_mapand actually maps the buffers, collecting a list of notification closures to call.
-
Only calling Global::buffer_map_async clones a new Arc for the
buffer. This new Arc is only dropped by handle_mapping.
Fields§
§active: Vec<ActiveSubmission>Resources used by queue submissions still in flight. One entry per submission, with older submissions appearing before younger.
Entries are added by track_submission and drained by
LifetimeTracker::triage_submissions. Lots of methods contribute data
to particular entries.
ready_to_map: Vec<Arc<Buffer>>Buffers the user has asked us to map, and which are not used by any queue submission still in flight.
ready_to_compact: Vec<Arc<Blas>>BLASes the user has asked us to prepare to compact, and which are not used by any queue submission still in flight.
work_done_closures: SmallVec<[SubmittedWorkDoneClosure; 1]>Queue “on_submitted_work_done” closures that were initiated for while there is no currently pending submissions. These cannot be immediately invoked as they must happen after all mapped buffer callbacks are mapped, so we defer them here until the next time the device is maintained.
Implementations§
Source§impl LifetimeTracker
impl LifetimeTracker
pub fn new() -> Self
Sourcepub fn queue_empty(&self) -> bool
pub fn queue_empty(&self) -> bool
Return true if there are no queue submissions still in flight.
Sourcepub fn track_submission(
&mut self,
index: SubmissionIndex,
encoders: Vec<EncoderInFlight>,
)
pub fn track_submission( &mut self, index: SubmissionIndex, encoders: Vec<EncoderInFlight>, )
Start tracking resources associated with a new queue submission.
pub(crate) fn map(&mut self, buffer: &Arc<Buffer>) -> Option<SubmissionIndex>
pub(crate) fn prepare_compact( &mut self, blas: &Arc<Blas>, ) -> Option<SubmissionIndex>
Sourcepub fn get_buffer_latest_submission_index(
&self,
buffer: &Buffer,
) -> Option<SubmissionIndex>
pub fn get_buffer_latest_submission_index( &self, buffer: &Buffer, ) -> Option<SubmissionIndex>
Returns the submission index of the most recent submission that uses the given buffer.
Sourcepub fn get_texture_latest_submission_index(
&self,
texture: &Texture,
) -> Option<SubmissionIndex>
pub fn get_texture_latest_submission_index( &self, texture: &Texture, ) -> Option<SubmissionIndex>
Returns the submission index of the most recent submission that uses the given texture.
Sourcepub fn triage_submissions(
&mut self,
last_done: SubmissionIndex,
) -> SmallVec<[SubmittedWorkDoneClosure; 1]>
pub fn triage_submissions( &mut self, last_done: SubmissionIndex, ) -> SmallVec<[SubmittedWorkDoneClosure; 1]>
Sort out the consequences of completed submissions.
Assume that all submissions up through last_done have completed.
- Buffers used by those submissions are now ready to map, if requested.
Add any buffers in the submission’s
mappedlist toself.ready_to_map, whereLifetimeTracker::handle_mappingwill find them.
Return a list of SubmittedWorkDoneClosures to run.
pub fn schedule_resource_destruction( &mut self, temp_resource: TempResource, last_submit_index: SubmissionIndex, )
pub fn add_work_done_closure( &mut self, closure: SubmittedWorkDoneClosure, ) -> Option<SubmissionIndex>
Sourcepub(crate) fn handle_mapping(
&mut self,
snatch_guard: &SnatchGuard<'_>,
) -> Vec<BufferMapPendingClosure> ⓘ
pub(crate) fn handle_mapping( &mut self, snatch_guard: &SnatchGuard<'_>, ) -> Vec<BufferMapPendingClosure> ⓘ
Map the buffers in self.ready_to_map.
Return a list of mapping notifications to send.
See the documentation for LifetimeTracker for details.
Sourcepub(crate) fn handle_compact_read_back(
&mut self,
) -> Vec<BlasCompactReadyPendingClosure> ⓘ
pub(crate) fn handle_compact_read_back( &mut self, ) -> Vec<BlasCompactReadyPendingClosure> ⓘ
Read back compact sizes from the BLASes in self.ready_to_compact.
Return a list of mapping notifications to send.
See the documentation for LifetimeTracker for details.