mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Rewrite the consume() to use the last usage properly
This commit is contained in:
parent
b03d7de335
commit
d597e97db8
@ -3,6 +3,7 @@ use resource::{BufferUsageFlags, TextureUsageFlags};
|
|||||||
|
|
||||||
use std::collections::hash_map::{Entry, HashMap};
|
use std::collections::hash_map::{Entry, HashMap};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use std::mem;
|
||||||
use std::ops::{BitOr, Range};
|
use std::ops::{BitOr, Range};
|
||||||
|
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ impl GenericUsage for TextureUsageFlags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct Track<U> {
|
struct Track<U> {
|
||||||
ref_count: RefCount,
|
ref_count: RefCount,
|
||||||
init: U,
|
init: U,
|
||||||
@ -126,12 +128,19 @@ impl<
|
|||||||
) -> impl 'a + Iterator<Item = (I, Range<U>)> {
|
) -> impl 'a + Iterator<Item = (I, Range<U>)> {
|
||||||
other.map
|
other.map
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(move |(id, new)| match self.transit(id.0.clone(), &new.ref_count, new.last, TrackPermit::REPLACE) {
|
.flat_map(move |(id, new)| match self.map.entry(WeaklyStored(id.0.clone())) {
|
||||||
Ok(Tracktion::Init) |
|
Entry::Vacant(e) => {
|
||||||
Ok(Tracktion::Keep) => None,
|
e.insert(new.clone());
|
||||||
Ok(Tracktion::Replace { old }) => Some((id.0.clone(), old .. new.last)),
|
None
|
||||||
Ok(Tracktion::Extend { .. }) |
|
}
|
||||||
Err(_) => panic!("Unable to consume a resource transition!"),
|
Entry::Occupied(mut e) => {
|
||||||
|
let old = mem::replace(&mut e.get_mut().last, new.last);
|
||||||
|
if old == new.init {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some((id.0.clone(), old .. new.last))
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user