use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum GpuError {
NoKernels,
LibraryLoad(String),
MissingKernel(String),
Pipeline {
name: String,
message: String,
},
InvalidArgument(String),
BufferInUse,
OutOfMemory(usize),
CommandBuffer(String),
Io(String),
ReadOnly,
}
pub type Result<T> = std::result::Result<T, GpuError>;
impl fmt::Display for GpuError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoKernels => f.write_str("the Metal kernel library is unavailable in this build"),
Self::LibraryLoad(msg) => write!(f, "cannot load the Metal kernel library: {msg}"),
Self::MissingKernel(name) => write!(f, "no Metal kernel named `{name}`"),
Self::Pipeline { name, message } => {
write!(f, "cannot create pipeline `{name}`: {message}")
}
Self::InvalidArgument(msg) => write!(f, "invalid dispatch argument: {msg}"),
Self::BufferInUse => {
f.write_str("buffer is in use by submitted GPU work; wait for it first")
}
Self::OutOfMemory(n) => write!(f, "Metal could not allocate {n} bytes"),
Self::CommandBuffer(msg) => write!(f, "GPU command buffer failed: {msg}"),
Self::Io(msg) => write!(f, "I/O error: {msg}"),
Self::ReadOnly => f.write_str("the buffer is a read-only mapped file"),
}
}
}
impl std::error::Error for GpuError {}