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:

    1. triage_submissions moves entries in self.active[i] for completed submissions to self.ready_to_map. At this point, both self.active and self.ready_to_map are up to date with the given submission index.

    2. handle_mapping drains self.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

source

pub fn new() -> Self

source

pub fn queue_empty(&self) -> bool

Return true if there are no queue submissions still in flight.

source

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.

source

pub(crate) fn map(&mut self, buffer: &Arc<Buffer>) -> Option<SubmissionIndex>

source

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.

source

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.

source

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.

source

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.

source

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.

Return a list of SubmittedWorkDoneClosures to run.

source

pub fn schedule_resource_destruction( &mut self, temp_resource: TempResource, last_submit_index: SubmissionIndex, )

source

pub fn add_work_done_closure( &mut self, closure: SubmittedWorkDoneClosure, ) -> Option<SubmissionIndex>

source

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.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<T> WasmNotSend for T
where T: Send,