Calculate set count from pool sizes

This commit is contained in:
hodasemi 2023-04-14 13:36:26 +02:00
parent 73834e4013
commit b852dd3cdf
2 changed files with 14 additions and 16 deletions

View file

@ -6,7 +6,6 @@ use std::sync::Arc;
pub struct DescriptorPoolBuilder { pub struct DescriptorPoolBuilder {
layout: Option<Arc<DescriptorSetLayout>>, layout: Option<Arc<DescriptorSetLayout>>,
descriptor_count: u32,
flags: VkDescriptorPoolCreateFlagBits, flags: VkDescriptorPoolCreateFlagBits,
} }
@ -17,12 +16,6 @@ impl DescriptorPoolBuilder {
self self
} }
pub fn set_descriptor_set_count(mut self, count: u32) -> Self {
self.descriptor_count = count;
self
}
pub fn set_layout(mut self, layout: Arc<DescriptorSetLayout>) -> Self { pub fn set_layout(mut self, layout: Arc<DescriptorSetLayout>) -> Self {
self.layout = Some(layout); self.layout = Some(layout);
@ -34,16 +27,24 @@ impl DescriptorPoolBuilder {
if self.layout.is_none() { if self.layout.is_none() {
panic!("no layout set!"); panic!("no layout set!");
} }
if self.descriptor_count == 0 {
panic!("descriptor count must be greater than 0");
}
} }
let layout = self.layout.expect("descriptor set layout was not set!"); let layout = self.layout.expect("descriptor set layout was not set!");
let descriptor_count: u32 = layout
.pool_sizes()
.iter()
.map(|pool| pool.descriptorCount)
.sum();
if cfg!(debug_assertions) {
if descriptor_count == 0 {
panic!("descriptor count must be greater than 0");
}
}
let descriptor_pool_ci = let descriptor_pool_ci =
VkDescriptorPoolCreateInfo::new(self.flags, self.descriptor_count, layout.pool_sizes()); VkDescriptorPoolCreateInfo::new(self.flags, descriptor_count, layout.pool_sizes());
let descriptor_pool = device.create_descriptor_pool(&descriptor_pool_ci)?; let descriptor_pool = device.create_descriptor_pool(&descriptor_pool_ci)?;
@ -66,7 +67,6 @@ impl DescriptorPool {
pub fn builder() -> DescriptorPoolBuilder { pub fn builder() -> DescriptorPoolBuilder {
DescriptorPoolBuilder { DescriptorPoolBuilder {
layout: None, layout: None,
descriptor_count: 1,
flags: VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.into(), flags: VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.into(),
} }
} }
@ -124,7 +124,6 @@ use crate::{ffi::*, handle_ffi_result};
#[no_mangle] #[no_mangle]
pub extern "C" fn create_descriptor_pool( pub extern "C" fn create_descriptor_pool(
flags: VkDescriptorPoolCreateFlagBits, flags: VkDescriptorPoolCreateFlagBits,
descriptor_count: u32,
descriptor_set_layout: *const DescriptorSetLayout, descriptor_set_layout: *const DescriptorSetLayout,
device: *const Device, device: *const Device,
) -> *const DescriptorPool { ) -> *const DescriptorPool {
@ -133,7 +132,6 @@ pub extern "C" fn create_descriptor_pool(
let pool_res = DescriptorPool::builder() let pool_res = DescriptorPool::builder()
.set_flags(flags) .set_flags(flags)
.set_descriptor_set_count(descriptor_count)
.set_layout(layout) .set_layout(layout)
.build(device); .build(device);

View file

@ -105,7 +105,7 @@ impl DescriptorSetLayout {
} }
} }
pub fn pool_sizes(&self) -> &[VkDescriptorPoolSize] { pub(crate) fn pool_sizes(&self) -> &[VkDescriptorPoolSize] {
self.pool_sizes.as_slice() self.pool_sizes.as_slice()
} }
} }