gpu_descriptor_types/
device.rs

1use crate::types::{DescriptorPoolCreateFlags, DescriptorTotalCount};
2
3/// Memory exhausted error.
4#[derive(Debug)]
5pub enum CreatePoolError {
6    /// Device memory exhausted.
7    OutOfDeviceMemory,
8
9    /// Host memory exhausted.
10    OutOfHostMemory,
11
12    /// A descriptor pool creation has failed due to fragmentation.
13    Fragmentation,
14}
15
16/// Memory exhausted error.
17#[derive(Debug)]
18pub enum DeviceAllocationError {
19    /// Device memory exhausted.
20    OutOfDeviceMemory,
21
22    /// Host memory exhausted.
23    OutOfHostMemory,
24
25    /// Failed to allocate memory from pool.
26    OutOfPoolMemory,
27
28    /// Pool allocation failed due to fragmentation of pool's memory.
29    FragmentedPool,
30}
31
32/// Abstract device that can create pools of type `P` and allocate sets `S` with layout `L`.
33pub trait DescriptorDevice<L, P, S> {
34    unsafe fn create_descriptor_pool(
35        &self,
36        descriptor_count: &DescriptorTotalCount,
37        max_sets: u32,
38        flags: DescriptorPoolCreateFlags,
39    ) -> Result<P, CreatePoolError>;
40
41    unsafe fn destroy_descriptor_pool(&self, pool: P);
42
43    unsafe fn alloc_descriptor_sets<'a>(
44        &self,
45        pool: &mut P,
46        layouts: impl ExactSizeIterator<Item = &'a L>,
47        sets: &mut impl Extend<S>,
48    ) -> Result<(), DeviceAllocationError>
49    where
50        L: 'a;
51
52    unsafe fn dealloc_descriptor_sets<'a>(&self, pool: &mut P, sets: impl Iterator<Item = S>);
53}