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