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 Capture(String),
37}
38
39pub type Result<T> = std::result::Result<T, GpuError>;
41
42impl fmt::Display for GpuError {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 match self {
45 Self::NoKernels => f.write_str("the Metal kernel library is unavailable in this build"),
46 Self::LibraryLoad(msg) => write!(f, "cannot load the Metal kernel library: {msg}"),
47 Self::MissingKernel(name) => write!(f, "no Metal kernel named `{name}`"),
48 Self::Pipeline { name, message } => {
49 write!(f, "cannot create pipeline `{name}`: {message}")
50 }
51 Self::InvalidArgument(msg) => write!(f, "invalid dispatch argument: {msg}"),
52 Self::BufferInUse => {
53 f.write_str("buffer is in use by submitted GPU work; wait for it first")
54 }
55 Self::OutOfMemory(n) => write!(f, "Metal could not allocate {n} bytes"),
56 Self::CommandBuffer(msg) => write!(f, "GPU command buffer failed: {msg}"),
57 Self::Io(msg) => write!(f, "I/O error: {msg}"),
58 Self::ReadOnly => f.write_str("the buffer is a read-only mapped file"),
59 Self::Capture(msg) => write!(f, "GPU capture: {msg}"),
60 }
61 }
62}
63
64impl std::error::Error for GpuError {}