Fix cache eviction logic of active image allocations
This commit is contained in:
parent
b072006f1a
commit
44cfb27e41
2 changed files with 16 additions and 10 deletions
|
|
@ -192,10 +192,12 @@ impl From<&Handle> for Handle {
|
||||||
impl std::fmt::Debug for Handle {
|
impl std::fmt::Debug for Handle {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Path(_, path) => write!(f, "Path({path:?})"),
|
Self::Path(id, path) => write!(f, "Path({id:?}, {path:?})"),
|
||||||
Self::Bytes(_, _) => write!(f, "Bytes(...)"),
|
Self::Bytes(id, _) => write!(f, "Bytes({id:?}, ...)"),
|
||||||
Self::Rgba { width, height, .. } => {
|
Self::Rgba {
|
||||||
write!(f, "Pixels({width} * {height})")
|
id, width, height, ..
|
||||||
|
} => {
|
||||||
|
write!(f, "Pixels({id:?}, {width} * {height})")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,17 +100,21 @@ impl Cache {
|
||||||
let hits = &self.hits;
|
let hits = &self.hits;
|
||||||
|
|
||||||
self.map.retain(|k, memory| {
|
self.map.retain(|k, memory| {
|
||||||
|
// Retain active allocations
|
||||||
|
if let Memory::Device { allocation, .. } = memory
|
||||||
|
&& allocation
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|allocation| allocation.strong_count() > 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
let retain = hits.contains(k);
|
let retain = hits.contains(k);
|
||||||
|
|
||||||
if !retain
|
if !retain
|
||||||
&& let Memory::Device {
|
&& let Memory::Device {
|
||||||
entry,
|
entry, bind_group, ..
|
||||||
bind_group,
|
|
||||||
allocation: memory,
|
|
||||||
} = memory
|
} = memory
|
||||||
&& memory
|
|
||||||
.as_ref()
|
|
||||||
.is_none_or(|memory| memory.strong_count() == 0)
|
|
||||||
{
|
{
|
||||||
if let Some(bind_group) = bind_group.take() {
|
if let Some(bind_group) = bind_group.take() {
|
||||||
on_drop(bind_group);
|
on_drop(bind_group);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue