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}
31
32pub type Result<T> = std::result::Result<T, GpuError>;
34
35impl fmt::Display for GpuError {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Self::NoKernels => f.write_str("the Metal kernel library is unavailable in this build"),
39 Self::LibraryLoad(msg) => write!(f, "cannot load the Metal kernel library: {msg}"),
40 Self::MissingKernel(name) => write!(f, "no Metal kernel named `{name}`"),
41 Self::Pipeline { name, message } => {
42 write!(f, "cannot create pipeline `{name}`: {message}")
43 }
44 Self::InvalidArgument(msg) => write!(f, "invalid dispatch argument: {msg}"),
45 Self::BufferInUse => {
46 f.write_str("buffer is in use by submitted GPU work; wait for it first")
47 }
48 Self::OutOfMemory(n) => write!(f, "Metal could not allocate {n} bytes"),
49 Self::CommandBuffer(msg) => write!(f, "GPU command buffer failed: {msg}"),
50 }
51 }
52}
53
54impl std::error::Error for GpuError {}