summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image.rs
diff options
context:
space:
mode:
authorLibravatar Malte Veerman <malte.veerman@gmail.com>2020-01-18 12:49:11 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-25 13:27:03 +0100
commit8f9f44b9e8ff1f1629d2b19edd2ecdad79e80836 (patch)
tree3bac834d0aaba2c1f6e454a1c51e0a710e727dd4 /wgpu/src/image.rs
parent2f695ef9803c9c08f64961f1b9902a661a385160 (diff)
downloadiced-8f9f44b9e8ff1f1629d2b19edd2ecdad79e80836.tar.gz
iced-8f9f44b9e8ff1f1629d2b19edd2ecdad79e80836.tar.bz2
iced-8f9f44b9e8ff1f1629d2b19edd2ecdad79e80836.zip
When deallocating the last allocation in an allocator mark its layer as empty
Diffstat (limited to 'wgpu/src/image.rs')
-rw-r--r--wgpu/src/image.rs47
1 files changed, 23 insertions, 24 deletions
diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs
index 2fd73b54..97e30403 100644
--- a/wgpu/src/image.rs
+++ b/wgpu/src/image.rs
@@ -660,37 +660,36 @@ impl TextureArray {
fn deallocate(&mut self, allocation: &ImageAllocation) {
match allocation {
ImageAllocation::SingleAllocation(allocation) => {
- if let Some(layer) = self.layers.get_mut(allocation.layer()) {
- match allocation {
- ArrayAllocation::WholeLayer { .. } => {
- *layer = TextureLayer::Empty;
- }
- ArrayAllocation::AtlasAllocation { allocation, .. } => {
- if let TextureLayer::Atlas(allocator) = layer {
- allocator.deallocate(allocation.id);
- }
- }
- }
- }
+ self.deallocate_single_allocation(allocation);
}
ImageAllocation::MultipleAllocations { mappings, .. } => {
for mapping in mappings {
- if let Some(layer) = self.layers.get_mut(mapping.allocation.layer()) {
- match &mapping.allocation {
- ArrayAllocation::WholeLayer { .. } => {
- *layer = TextureLayer::Empty;
- }
- ArrayAllocation::AtlasAllocation { allocation, .. } => {
- if let TextureLayer::Atlas(allocator) = layer {
- allocator.deallocate(allocation.id);
- }
- }
+ self.deallocate_single_allocation(&mapping.allocation);
+ }
+ }
+ }
+ }
+
+ fn deallocate_single_allocation(&mut self, allocation: &ArrayAllocation) {
+ if let Some(layer) = self.layers.get_mut(allocation.layer()) {
+ match allocation {
+ ArrayAllocation::WholeLayer { .. } => {
+ *layer = TextureLayer::Empty;
+ }
+ ArrayAllocation::AtlasAllocation { allocation, .. } => {
+ if let TextureLayer::Atlas(allocator) = layer {
+ allocator.deallocate(allocation.id);
+
+ let mut empty_allocator = true;
+ allocator.for_each_allocated_rectangle(|_, _| empty_allocator = false);
+
+ if empty_allocator {
+ *layer = TextureLayer::Empty;
}
}
}
}
}
-
}
fn upload<C, I>(
@@ -953,7 +952,7 @@ const QUAD_VERTS: [Vertex; 4] = [
},
];
-const ATLAS_SIZE: u32 = 4096;
+const ATLAS_SIZE: u32 = 256;
#[repr(C)]
#[derive(Debug, Clone, Copy)]