When deallocating the last allocation in an allocator mark its layer as empty

This commit is contained in:
Malte Veerman 2020-01-18 12:49:11 +01:00 committed by Héctor Ramón Jiménez
parent 2f695ef980
commit 8f9f44b9e8

View file

@ -660,6 +660,17 @@ impl TextureArray {
fn deallocate(&mut self, allocation: &ImageAllocation) { fn deallocate(&mut self, allocation: &ImageAllocation) {
match allocation { match allocation {
ImageAllocation::SingleAllocation(allocation) => { ImageAllocation::SingleAllocation(allocation) => {
self.deallocate_single_allocation(allocation);
}
ImageAllocation::MultipleAllocations { mappings, .. } => {
for mapping in mappings {
self.deallocate_single_allocation(&mapping.allocation);
}
}
}
}
fn deallocate_single_allocation(&mut self, allocation: &ArrayAllocation) {
if let Some(layer) = self.layers.get_mut(allocation.layer()) { if let Some(layer) = self.layers.get_mut(allocation.layer()) {
match allocation { match allocation {
ArrayAllocation::WholeLayer { .. } => { ArrayAllocation::WholeLayer { .. } => {
@ -668,30 +679,18 @@ impl TextureArray {
ArrayAllocation::AtlasAllocation { allocation, .. } => { ArrayAllocation::AtlasAllocation { allocation, .. } => {
if let TextureLayer::Atlas(allocator) = layer { if let TextureLayer::Atlas(allocator) = layer {
allocator.deallocate(allocation.id); allocator.deallocate(allocation.id);
}
} let mut empty_allocator = true;
} allocator.for_each_allocated_rectangle(|_, _| empty_allocator = false);
}
} if empty_allocator {
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; *layer = TextureLayer::Empty;
} }
ArrayAllocation::AtlasAllocation { allocation, .. } => {
if let TextureLayer::Atlas(allocator) = layer {
allocator.deallocate(allocation.id);
} }
} }
} }
} }
} }
}
}
}
fn upload<C, I>( fn upload<C, I>(
&mut self, &mut self,
@ -953,7 +952,7 @@ const QUAD_VERTS: [Vertex; 4] = [
}, },
]; ];
const ATLAS_SIZE: u32 = 4096; const ATLAS_SIZE: u32 = 256;
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]