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
impl LifeGuard
pub(crate) fn new(label: &str) -> Self
pub(crate) fn add_ref(&self) -> RefCount
sourcepub(crate) fn use_at(&self, submit_index: FenceValue) -> bool
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.