Struct wgpu_core::LifeGuard

source ·
pub struct LifeGuard {
    pub(crate) ref_count: Option<RefCount>,
    pub(crate) submission_index: AtomicUsize,
    pub(crate) label: String,
}
Expand description

Information needed to decide when it’s safe to free some wgpu-core resource.

Each type representing a wgpu-core resource, like Device, Buffer, etc., contains a LifeGuard which indicates whether it is safe to free.

A resource may need to be retained for any of several reasons:

  • The user may hold a reference to it (via a wgpu::Buffer, say).

  • Other resources may depend on it (a texture view’s backing texture, for example).

  • It may be used by commands sent to the GPU that have not yet finished execution.

Fields§

§ref_count: Option<RefCount>

RefCount for the user’s reference to this resource.

When the user first creates a wgpu-core resource, this RefCount is created along with the resource’s LifeGuard. When the user drops the resource, we swap this out for None. Note that the resource may still be held alive by other resources.

Any Stored<T> value holds a clone of this RefCount along with the id of a T resource.

§submission_index: AtomicUsize

The index of the last queue submission in which the resource was used.

Each queue submission is fenced and assigned an index number sequentially. Thus, when a queue submission completes, we know any resources used in that submission and any lower-numbered submissions are no longer in use by the GPU.

§label: String

The label from the descriptor used to create the resource.

Implementations§

source§

impl LifeGuard

source

pub(crate) fn new(label: &str) -> Self

source

pub(crate) fn add_ref(&self) -> RefCount

source

pub(crate) fn use_at(&self, submit_index: FenceValue) -> bool

Record that this resource will be used by the queue submission with the given index.

Returns true if the resource is still held by the user.

source

pub(crate) fn life_count(&self) -> FenceValue

Trait Implementations§

source§

impl Debug for LifeGuard

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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> WasmNotSend for Twhere T: Send,

source§

impl<T> WasmNotSync for Twhere T: Sync,