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 /// Creates a new descriptor pool.
35 ///
36 /// # Safety
37 ///
38 /// Actually safe.
39 /// TODO: Remove `unsafe` with next breaking change.
40 unsafe fn create_descriptor_pool(
41 &self,
42 descriptor_count: &DescriptorTotalCount,
43 max_sets: u32,
44 flags: DescriptorPoolCreateFlags,
45 ) -> Result<P, CreatePoolError>;
46
47 /// Destroys descriptor pool.
48 ///
49 /// # Safety
50 ///
51 /// Pool must be created from this device.
52 /// All descriptor sets allocated from this pool become invalid.
53 unsafe fn destroy_descriptor_pool(&self, pool: P);
54
55 /// Allocates descriptor sets.
56 ///
57 /// # Safety
58 ///
59 /// Pool must be created from this device.
60 unsafe fn alloc_descriptor_sets<'a>(
61 &self,
62 pool: &mut P,
63 layouts: impl ExactSizeIterator<Item = &'a L>,
64 sets: &mut impl Extend<S>,
65 ) -> Result<(), DeviceAllocationError>
66 where
67 L: 'a;
68
69 /// Deallocates descriptor sets.
70 ///
71 /// # Safety
72 ///
73 /// Sets must be allocated from specified pool and not deallocated before.
74 unsafe fn dealloc_descriptor_sets(&self, pool: &mut P, sets: impl Iterator<Item = S>);
75}