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

Update ash to 0.38 #39

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions ash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gpu-descriptor-ash"
version = "0.2.0"
version = "0.3.0"
authors = ["Zakarum <zakarumych@ya.ru>"]
edition = "2018"
description = "gpu-descriptor integration with ash"
Expand All @@ -12,7 +12,7 @@ repository = "https://github.com/zakarumych/gpu-descriptor"
readme = "../README.md"

[dependencies]
gpu-descriptor-types = { path = "../types", version = "0.1" }
gpu-descriptor-types = { path = "../types", version = "0.2" }
tracing = { version = "0.1", optional = true, default-features = false }
ash = { version = "0.37", default-features = false }
ash = { version = "0.38", default-features = false }
smallvec = "1.0"
6 changes: 3 additions & 3 deletions ash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl DescriptorDevice<vk::DescriptorSetLayout, vk::DescriptorPool, vk::Descripto
max_sets: u32,
flags: DescriptorPoolCreateFlags,
) -> Result<vk::DescriptorPool, CreatePoolError> {
let mut array = [vk::DescriptorPoolSize::builder().build(); 13];
let mut array = [vk::DescriptorPoolSize::default(); 13];
let mut len = 0;

if descriptor_count.sampler != 0 {
Expand Down Expand Up @@ -124,7 +124,7 @@ impl DescriptorDevice<vk::DescriptorSetLayout, vk::DescriptorPool, vk::Descripto
}

let result = self.device.create_descriptor_pool(
&vk::DescriptorPoolCreateInfo::builder()
&vk::DescriptorPoolCreateInfo::default()
.max_sets(max_sets)
.pool_sizes(&array[..len])
.flags(ash_flags),
Expand Down Expand Up @@ -153,7 +153,7 @@ impl DescriptorDevice<vk::DescriptorSetLayout, vk::DescriptorPool, vk::Descripto
let set_layouts: smallvec::SmallVec<[_; 16]> = layouts.copied().collect();

match self.device.allocate_descriptor_sets(
&vk::DescriptorSetAllocateInfo::builder()
&vk::DescriptorSetAllocateInfo::default()
.set_layouts(&set_layouts)
.descriptor_pool(*pool),
) {
Expand Down
4 changes: 2 additions & 2 deletions erupt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gpu-descriptor-erupt"
version = "0.4.0"
version = "0.5.0"
authors = ["Zakarum <zakarumych@ya.ru>"]
edition = "2018"
description = "gpu-descriptor integration with erupt"
Expand All @@ -12,7 +12,7 @@ repository = "https://github.com/zakarumych/gpu-descriptor"
readme = "../README.md"

[dependencies]
gpu-descriptor-types = { path = "../types", version = "0.1" }
gpu-descriptor-types = { path = "../types", version = "0.2" }
tracing = { version = "0.1", optional = true, default-features = false }
erupt = { version = "0.23", default-features = false }
smallvec = "1.0"
4 changes: 2 additions & 2 deletions gpu-descriptor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gpu-descriptor"
version = "0.2.4"
version = "0.3.0"
authors = ["Zakarum <zakarumych@ya.ru>"]
edition = "2018"
description = "Implementation agnostic descriptor allocator for Vulkan like APIs"
Expand All @@ -16,7 +16,7 @@ std = []
default = ["std"]

[dependencies]
gpu-descriptor-types = { path = "../types", version = "0.1" }
gpu-descriptor-types = { path = "../types", version = "0.2" }
tracing = { version = "0.1", optional = true, default-features = false }
bitflags = { version = "2.4", default-features = false }
serde = { version = "1.0", optional = true, default-features = false, features = [
Expand Down
37 changes: 28 additions & 9 deletions gpu-descriptor/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct DescriptorPool<P> {
struct DescriptorBucket<P> {
offset: u64,
pools: VecDeque<DescriptorPool<P>>,
total: u64,
total: u32,
update_after_bind: bool,
size: DescriptorTotalCount,
}
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<P> DescriptorBucket<P> {
fn new_pool_size(&self, minimal_set_count: u32) -> (DescriptorTotalCount, u32) {
let mut max_sets = MIN_SETS // at least MIN_SETS
.max(minimal_set_count) // at least enough for allocation
.max(self.total.min(MAX_SETS as u64) as u32) // at least as much as was allocated so far capped to MAX_SETS
.max(self.total.min(MAX_SETS)) // at least as much as was allocated so far capped to MAX_SETS
.checked_next_power_of_two() // rounded up to nearest 2^N
.unwrap_or(i32::MAX as u32);

Expand Down Expand Up @@ -260,7 +260,7 @@ impl<P> DescriptorBucket<P> {
count -= allocate;
pool.available -= allocate;
pool.allocated += allocate;
self.total += u64::from(allocate);
self.total += allocate;

if count == 0 {
return Ok(());
Expand Down Expand Up @@ -329,7 +329,7 @@ impl<P> DescriptorBucket<P> {
allocated: allocate,
available: max_sets - allocate,
});
self.total += allocate as u64;
self.total += allocate;
}

Ok(())
Expand Down Expand Up @@ -357,7 +357,7 @@ impl<P> DescriptorBucket<P> {

pool.available += count;
pool.allocated -= count;
self.total -= u64::from(count);
self.total -= count;
#[cfg(feature = "tracing")]
tracing::trace!("Freed {} from descriptor bucket", count);

Expand Down Expand Up @@ -396,10 +396,11 @@ impl<P> DescriptorBucket<P> {
#[derive(Debug)]
pub struct DescriptorAllocator<P, S> {
buckets: HashMap<(DescriptorTotalCount, bool), DescriptorBucket<P>>,
total: u64,
sets_cache: Vec<DescriptorSet<S>>,
raw_sets_cache: Vec<S>,
max_update_after_bind_descriptors_in_all_pools: u32,
current_update_after_bind_descriptors_in_all_pools: u32,
total: u32,
}

impl<P, S> Drop for DescriptorAllocator<P, S> {
Expand All @@ -422,6 +423,7 @@ impl<P, S> DescriptorAllocator<P, S> {
sets_cache: Vec::new(),
raw_sets_cache: Vec::new(),
max_update_after_bind_descriptors_in_all_pools,
current_update_after_bind_descriptors_in_all_pools: 0,
}
}

Expand Down Expand Up @@ -450,8 +452,18 @@ impl<P, S> DescriptorAllocator<P, S> {
return Ok(Vec::new());
}

let descriptor_count = count * layout_descriptor_count.total();

let update_after_bind = flags.contains(DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND);

if update_after_bind
&& self.max_update_after_bind_descriptors_in_all_pools
- self.current_update_after_bind_descriptors_in_all_pools
< descriptor_count
{
return Err(AllocationError::Fragmentation);
}

#[cfg(feature = "tracing")]
tracing::trace!(
"Allocating {} sets with layout {:?} @ {:?}",
Expand All @@ -465,7 +477,14 @@ impl<P, S> DescriptorAllocator<P, S> {
.entry((*layout_descriptor_count, update_after_bind))
.or_insert_with(|| DescriptorBucket::new(update_after_bind, *layout_descriptor_count));
match bucket.allocate(device, layout, count, &mut self.sets_cache) {
Ok(()) => Ok(core::mem::replace(&mut self.sets_cache, Vec::new())),
Ok(()) => {
self.total += descriptor_count;
if update_after_bind {
self.current_update_after_bind_descriptors_in_all_pools += descriptor_count;
}

Ok(core::mem::take(&mut self.sets_cache))
}
Err(err) => {
debug_assert!(self.raw_sets_cache.is_empty());

Expand Down Expand Up @@ -519,7 +538,7 @@ impl<P, S> DescriptorAllocator<P, S> {
.get_mut(&last_key)
.expect("Set must be allocated from this allocator");

debug_assert!(u64::try_from(self.raw_sets_cache.len())
debug_assert!(u32::try_from(self.raw_sets_cache.len())
.ok()
.map_or(false, |count| count <= bucket.total));

Expand All @@ -537,7 +556,7 @@ impl<P, S> DescriptorAllocator<P, S> {
.get_mut(&last_key)
.expect("Set must be allocated from this allocator");

debug_assert!(u64::try_from(self.raw_sets_cache.len())
debug_assert!(u32::try_from(self.raw_sets_cache.len())
.ok()
.map_or(false, |count| count <= bucket.total));

Expand Down
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gpu-descriptor-types"
version = "0.1.2"
version = "0.2.0"
authors = ["Zakarum <zakarumych@ya.ru>"]
edition = "2018"
description = "Core types of gpu-descriptor crate"
Expand Down
24 changes: 23 additions & 1 deletion types/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,32 @@ pub enum DeviceAllocationError {

/// Abstract device that can create pools of type `P` and allocate sets `S` with layout `L`.
pub trait DescriptorDevice<L, P, S> {
/// Creates a new descriptor pool.
///
/// # Safety
///
/// Actually safe.
/// TODO: Remove `unsafe` with next breaking change.
unsafe fn create_descriptor_pool(
&self,
descriptor_count: &DescriptorTotalCount,
max_sets: u32,
flags: DescriptorPoolCreateFlags,
) -> Result<P, CreatePoolError>;

/// Destroys descriptor pool.
///
/// # Safety
///
/// Pool must be created from this device.
/// All descriptor sets allocated from this pool become invalid.
unsafe fn destroy_descriptor_pool(&self, pool: P);

/// Allocates descriptor sets.
///
/// # Safety
///
/// Pool must be created from this device.
unsafe fn alloc_descriptor_sets<'a>(
&self,
pool: &mut P,
Expand All @@ -49,5 +66,10 @@ pub trait DescriptorDevice<L, P, S> {
where
L: 'a;

unsafe fn dealloc_descriptor_sets<'a>(&self, pool: &mut P, sets: impl Iterator<Item = S>);
/// Deallocates descriptor sets.
///
/// # Safety
///
/// Sets must be allocated from specified pool and not deallocated before.
unsafe fn dealloc_descriptor_sets(&self, pool: &mut P, sets: impl Iterator<Item = S>);
}
19 changes: 19 additions & 0 deletions types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ pub struct DescriptorTotalCount {
pub inline_uniform_block_bytes: u32,
pub inline_uniform_block_bindings: u32,
}

impl DescriptorTotalCount {
pub fn total(&self) -> u32 {
self.sampler
+ self.combined_image_sampler
+ self.sampled_image
+ self.storage_image
+ self.uniform_texel_buffer
+ self.storage_texel_buffer
+ self.uniform_buffer
+ self.storage_buffer
+ self.uniform_buffer_dynamic
+ self.storage_buffer_dynamic
+ self.input_attachment
+ self.acceleration_structure
+ self.inline_uniform_block_bytes
+ self.inline_uniform_block_bindings
}
}