Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan: Delete smaller descriptor pools. #127

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions blade-graphics/src/vulkan/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const COUNT_BASE: u32 = 16;
#[derive(Debug)]
pub struct DescriptorPool {
sub_pools: Vec<vk::DescriptorPool>,
growth_iter: usize,
}

impl super::Device {
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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();
}
}
}
Loading