use crate::surface::SurfaceError;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum GpuError {
#[error("no compatible GPU adapter found: {detail}")]
NoAdapter {
detail: String,
},
#[error("GPU presentation surface creation failed: {detail}")]
SurfaceCreation {
detail: String,
},
#[error("GPU device request failed: {detail}")]
DeviceRequest {
detail: String,
},
#[error("device lost")]
DeviceLost,
#[error("surface unavailable")]
Surface(#[from] SurfaceError),
#[error("capability {name:?} unavailable")]
Capability {
name: &'static str,
},
#[error("resource {resource:?} exceeds device limit {limit}")]
LimitExceeded {
resource: &'static str,
limit: u64,
},
#[error("shader compilation failed in {label:?}: {detail}")]
ShaderCompile {
label: String,
detail: String,
},
#[error("GPU runtime operation failed: {detail}")]
Runtime {
detail: String,
},
}
impl GpuError {
#[must_use]
pub fn code(&self) -> &'static str {
match self {
Self::NoAdapter { .. } => "MOLGFX-E0001",
Self::SurfaceCreation { .. } => "MOLGFX-E0004",
Self::DeviceRequest { .. } => "MOLGFX-E0005",
Self::DeviceLost => "MOLGFX-E0002",
Self::Surface(_) => "MOLGFX-E0003",
Self::Capability { .. } => "MOLGFX-E0010",
Self::LimitExceeded { .. } => "MOLGFX-E0011",
Self::ShaderCompile { .. } => "MOLGFX-E0060",
Self::Runtime { .. } => "MOLGFX-E0061",
}
}
}
#[cfg(test)]
#[path = "error_tests.rs"]
mod tests;