Struct wgpu_core::device::life::LifetimeTracker
source · pub(crate) struct LifetimeTracker {
active: Vec<ActiveSubmission>,
ready_to_map: Vec<Arc<Buffer>>,
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_index
records the index of the most recent queue submission that uses that buffer. -
When the device is polled, the following
LifetimeTracker
methods decide what should happen next:-
triage_submissions
moves entries inself.active[i]
for completed submissions toself.ready_to_map
. At this point, bothself.active
andself.ready_to_map
are up to date with the given submission index. -
handle_mapping
drainsself.ready_to_map
and 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.
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,
temp_resources: impl Iterator<Item = TempResource>,
encoders: Vec<EncoderInFlight>,
)
pub fn track_submission( &mut self, index: SubmissionIndex, temp_resources: impl Iterator<Item = TempResource>, encoders: Vec<EncoderInFlight>, )
Start tracking resources associated with a new queue submission.
pub(crate) fn map(&mut self, buffer: &Arc<Buffer>) -> 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_blas_latest_submission_index(
&self,
blas: &Blas,
) -> Option<SubmissionIndex>
pub fn get_blas_latest_submission_index( &self, blas: &Blas, ) -> Option<SubmissionIndex>
Returns the submission index of the most recent submission that uses the given blas.
sourcepub fn get_tlas_latest_submission_index(
&self,
tlas: &Tlas,
) -> Option<SubmissionIndex>
pub fn get_tlas_latest_submission_index( &self, tlas: &Tlas, ) -> Option<SubmissionIndex>
Returns the submission index of the most recent submission that uses the given tlas.
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
mapped
list toself.ready_to_map
, whereLifetimeTracker::handle_mapping
will find them.
Return a list of SubmittedWorkDoneClosure
s 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.