diff options
author | 2024-04-24 21:29:30 +0200 | |
---|---|---|
committer | 2024-04-24 21:29:30 +0200 | |
commit | 493c36ac712ef04523065b94988a88cc4db16b1a (patch) | |
tree | 9a19baac6fa56025a2aa29f3e5d77c7c98cec4b7 /wgpu/src/image/atlas | |
parent | fdcec0319757d2f87c82787eab34c6bef8c5a799 (diff) | |
download | iced-493c36ac712ef04523065b94988a88cc4db16b1a.tar.gz iced-493c36ac712ef04523065b94988a88cc4db16b1a.tar.bz2 iced-493c36ac712ef04523065b94988a88cc4db16b1a.zip |
Make image `Cache` eviction strategy less aggressive in `iced_wgpu`
Instead of trimming unconditionally at the end of
a frame, we now trim the cache only when there is a
cache miss.
This way, images that are not visible but still a
part of the layout will stay cached. Eviction will
only happen when the images are not a part of the
UI for two consectuive frames.
Diffstat (limited to 'wgpu/src/image/atlas')
-rw-r--r-- | wgpu/src/image/atlas/allocator.rs | 4 | ||||
-rw-r--r-- | wgpu/src/image/atlas/layer.rs | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/wgpu/src/image/atlas/allocator.rs b/wgpu/src/image/atlas/allocator.rs index 204a5c26..a51ac1f5 100644 --- a/wgpu/src/image/atlas/allocator.rs +++ b/wgpu/src/image/atlas/allocator.rs @@ -33,6 +33,10 @@ impl Allocator { pub fn is_empty(&self) -> bool { self.allocations == 0 } + + pub fn allocations(&self) -> usize { + self.allocations + } } pub struct Region { diff --git a/wgpu/src/image/atlas/layer.rs b/wgpu/src/image/atlas/layer.rs index cf089601..fd6788d9 100644 --- a/wgpu/src/image/atlas/layer.rs +++ b/wgpu/src/image/atlas/layer.rs @@ -11,4 +11,12 @@ impl Layer { pub fn is_empty(&self) -> bool { matches!(self, Layer::Empty) } + + pub fn allocations(&self) -> usize { + match self { + Layer::Empty => 0, + Layer::Busy(allocator) => allocator.allocations(), + Layer::Full => 1, + } + } } |