@@ -32,9 +32,20 @@ enum IdSource {
32
32
/// - `IdentityValues` reuses the index values of freed ids before returning
33
33
/// ids with new index values. Freed vector entries get reused.
34
34
///
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
+ ///
35
45
/// [`Id`]: crate::id::Id
36
46
/// [`alloc`]: IdentityValues::alloc
37
47
/// [`release`]: IdentityValues::release
48
+ /// [player]: https://github.com/gfx-rs/wgpu/tree/trunk/player/
38
49
#[ derive( Debug ) ]
39
50
pub ( super ) struct IdentityValues {
40
51
free : Vec < ( Index , Epoch ) > ,
@@ -47,10 +58,11 @@ pub(super) struct IdentityValues {
47
58
}
48
59
49
60
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
51
64
///
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`.
54
66
pub fn alloc < T : Marker > ( & mut self ) -> Id < T > {
55
67
assert ! (
56
68
self . id_source != IdSource :: External ,
@@ -70,6 +82,11 @@ impl IdentityValues {
70
82
}
71
83
}
72
84
85
+ /// Increment the count of used IDs.
86
+ ///
87
+ /// # Panics
88
+ ///
89
+ /// If `alloc` has previously been called on this `IdentityValues`.
73
90
pub fn mark_as_used < T : Marker > ( & mut self , id : Id < T > ) -> Id < T > {
74
91
assert ! (
75
92
self . id_source != IdSource :: Allocated ,
@@ -81,7 +98,9 @@ impl IdentityValues {
81
98
id
82
99
}
83
100
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.
85
104
pub fn release < T : Marker > ( & mut self , id : Id < T > ) {
86
105
if let IdSource :: Allocated = self . id_source {
87
106
let ( index, epoch) = id. unzip ( ) ;
0 commit comments