1use {
2 core::fmt::{self, Display},
3 gpu_alloc_types::{DeviceMapError, OutOfMemory},
4};
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8pub enum AllocationError {
9 OutOfDeviceMemory,
13
14 OutOfHostMemory,
17
18 NoCompatibleMemoryTypes,
21
22 TooManyObjects,
29}
30
31impl From<OutOfMemory> for AllocationError {
32 fn from(err: OutOfMemory) -> Self {
33 match err {
34 OutOfMemory::OutOfDeviceMemory => AllocationError::OutOfDeviceMemory,
35 OutOfMemory::OutOfHostMemory => AllocationError::OutOfHostMemory,
36 }
37 }
38}
39
40impl Display for AllocationError {
41 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
42 match self {
43 AllocationError::OutOfDeviceMemory => fmt.write_str("Device memory exhausted"),
44 AllocationError::OutOfHostMemory => fmt.write_str("Host memory exhausted"),
45 AllocationError::NoCompatibleMemoryTypes => fmt.write_str(
46 "No compatible memory types from requested types support requested usage",
47 ),
48 AllocationError::TooManyObjects => {
49 fmt.write_str("Reached limit on allocated memory objects count")
50 }
51 }
52 }
53}
54
55#[cfg(feature = "std")]
56impl std::error::Error for AllocationError {}
57
58#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
60pub enum MapError {
61 OutOfDeviceMemory,
65
66 OutOfHostMemory,
69
70 NonHostVisible,
74
75 MapFailed,
79
80 AlreadyMapped,
82}
83
84impl From<DeviceMapError> for MapError {
85 fn from(err: DeviceMapError) -> Self {
86 match err {
87 DeviceMapError::OutOfDeviceMemory => MapError::OutOfDeviceMemory,
88 DeviceMapError::OutOfHostMemory => MapError::OutOfHostMemory,
89 DeviceMapError::MapFailed => MapError::MapFailed,
90 }
91 }
92}
93
94impl From<OutOfMemory> for MapError {
95 fn from(err: OutOfMemory) -> Self {
96 match err {
97 OutOfMemory::OutOfDeviceMemory => MapError::OutOfDeviceMemory,
98 OutOfMemory::OutOfHostMemory => MapError::OutOfHostMemory,
99 }
100 }
101}
102
103impl Display for MapError {
104 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
105 match self {
106 MapError::OutOfDeviceMemory => fmt.write_str("Device memory exhausted"),
107 MapError::OutOfHostMemory => fmt.write_str("Host memory exhausted"),
108 MapError::MapFailed => fmt.write_str("Failed to map memory object"),
109 MapError::NonHostVisible => fmt.write_str("Impossible to map non-host-visible memory"),
110 MapError::AlreadyMapped => fmt.write_str("Block is already mapped"),
111 }
112 }
113}
114
115#[cfg(feature = "std")]
116impl std::error::Error for MapError {}