diff --git a/blade-graphics/src/vulkan/descriptor.rs b/blade-graphics/src/vulkan/descriptor.rs index 285cb576..e23d6984 100644 --- a/blade-graphics/src/vulkan/descriptor.rs +++ b/blade-graphics/src/vulkan/descriptor.rs @@ -7,6 +7,7 @@ const COUNT_BASE: u32 = 16; #[derive(Debug)] pub struct DescriptorPool { sub_pools: Vec, + growth_iter: usize, } impl super::Device { @@ -60,6 +61,7 @@ impl super::Device { let vk_pool = self.create_descriptor_sub_pool(COUNT_BASE); DescriptorPool { sub_pools: vec![vk_pool], + growth_iter: 0, } } @@ -75,6 +77,7 @@ impl super::Device { layout: &super::DescriptorSetLayout, ) -> vk::DescriptorSet { let descriptor_set_layouts = [layout.raw]; + let mut descriptor_set_info = vk::DescriptorSetAllocateInfo::default() .descriptor_pool(pool.sub_pools[0]) .set_layouts(&descriptor_set_layouts); @@ -85,9 +88,9 @@ impl super::Device { Err(other) => panic!("Unexpected descriptor allocation error: {:?}", other), }; - let next_max_sets = COUNT_BASE.pow(pool.sub_pools.len() as u32 + 1); + let next_max_sets = COUNT_BASE.pow(pool.growth_iter as u32 + 1); + pool.growth_iter += 1; let vk_pool = self.create_descriptor_sub_pool(next_max_sets); - // Always insert in front to avoid expecting any overflows down the road pool.sub_pools.insert(0, vk_pool); descriptor_set_info.descriptor_pool = vk_pool; @@ -100,12 +103,16 @@ impl super::Device { } pub(super) fn reset_descriptor_pool(&self, pool: &mut DescriptorPool) { - for &vk_pool in pool.sub_pools.iter() { + for vk_pool in pool.sub_pools.drain(1..) { unsafe { - self.core - .reset_descriptor_pool(vk_pool, vk::DescriptorPoolResetFlags::empty()) - .unwrap(); + self.core.destroy_descriptor_pool(vk_pool, None); } } + + unsafe { + self.core + .reset_descriptor_pool(pool.sub_pools[0], vk::DescriptorPoolResetFlags::empty()) + .unwrap(); + } } }