Skip to content

Commit 1791064

Browse files
Update comments on IdentityValues (#8183)
1 parent a9638c8 commit 1791064

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

wgpu-core/src/identity.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,20 @@ enum IdSource {
3232
/// - `IdentityValues` reuses the index values of freed ids before returning
3333
/// ids with new index values. Freed vector entries get reused.
3434
///
35+
/// - The non-reuse property is achieved by storing an `epoch` alongside the
36+
/// index in an `Id`. Index values are reused, but only with a different
37+
/// epoch.
38+
///
39+
/// `IdentityValues` can also be used to track the count of IDs allocated by
40+
/// some external allocator. Combining internal and external allocation is not
41+
/// allowed; calling both `alloc` and `mark_as_used` on the same
42+
/// `IdentityValues` will result in a panic. The external mode is used when
43+
/// [playing back a trace of wgpu operations][player].
44+
///
3545
/// [`Id`]: crate::id::Id
3646
/// [`alloc`]: IdentityValues::alloc
3747
/// [`release`]: IdentityValues::release
48+
/// [player]: https://github.com/gfx-rs/wgpu/tree/trunk/player/
3849
#[derive(Debug)]
3950
pub(super) struct IdentityValues {
4051
free: Vec<(Index, Epoch)>,
@@ -47,10 +58,11 @@ pub(super) struct IdentityValues {
4758
}
4859

4960
impl IdentityValues {
50-
/// Allocate a fresh, never-before-seen id with the given `backend`.
61+
/// Allocate a fresh, never-before-seen ID.
62+
///
63+
/// # Panics
5164
///
52-
/// The backend is incorporated into the id, so that ids allocated with
53-
/// different `backend` values are always distinct.
65+
/// If `mark_as_used` has previously been called on this `IdentityValues`.
5466
pub fn alloc<T: Marker>(&mut self) -> Id<T> {
5567
assert!(
5668
self.id_source != IdSource::External,
@@ -70,6 +82,11 @@ impl IdentityValues {
7082
}
7183
}
7284

85+
/// Increment the count of used IDs.
86+
///
87+
/// # Panics
88+
///
89+
/// If `alloc` has previously been called on this `IdentityValues`.
7390
pub fn mark_as_used<T: Marker>(&mut self, id: Id<T>) -> Id<T> {
7491
assert!(
7592
self.id_source != IdSource::Allocated,
@@ -81,7 +98,9 @@ impl IdentityValues {
8198
id
8299
}
83100

84-
/// Free `id`. It will never be returned from `alloc` again.
101+
/// Free `id` and/or decrement the count of used IDs.
102+
///
103+
/// Freed IDs will never be returned from `alloc` again.
85104
pub fn release<T: Marker>(&mut self, id: Id<T>) {
86105
if let IdSource::Allocated = self.id_source {
87106
let (index, epoch) = id.unzip();

0 commit comments

Comments
 (0)