1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum GpuError {
9 NoKernels,
12 LibraryLoad(String),
14 MissingKernel(String),
16 Pipeline {
18 name: String,
20 message: String,
22 },
23 InvalidArgument(String),
25 BufferInUse,
27 OutOfMemory(usize),
29 CommandBuffer(String),
31 Io(String),
33 ReadOnly,
35}
36
37pub type Result<T> = std::result::Result<T, GpuError>;
39
40impl fmt::Display for GpuError {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 match self {
43 Self::NoKernels => f.write_str("the Metal kernel library is unavailable in this build"),
44 Self::LibraryLoad(msg) => write!(f, "cannot load the Metal kernel library: {msg}"),
45 Self::MissingKernel(name) => write!(f, "no Metal kernel named `{name}`"),
46 Self::Pipeline { name, message } => {
47 write!(f, "cannot create pipeline `{name}`: {message}")
48 }
49 Self::InvalidArgument(msg) => write!(f, "invalid dispatch argument: {msg}"),
50 Self::BufferInUse => {
51 f.write_str("buffer is in use by submitted GPU work; wait for it first")
52 }
53 Self::OutOfMemory(n) => write!(f, "Metal could not allocate {n} bytes"),
54 Self::CommandBuffer(msg) => write!(f, "GPU command buffer failed: {msg}"),
55 Self::Io(msg) => write!(f, "I/O error: {msg}"),
56 Self::ReadOnly => f.write_str("the buffer is a read-only mapped file"),
57 }
58 }
59}
60
61impl std::error::Error for GpuError {}