#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
#[allow(missing_docs)]
pub enum BackendOp {
CreateBuffer,
BindMemory,
CreateShaderModule,
CreatePipeline,
CreatePipelineLayout,
CreateDescriptorPool,
CreateDescriptorSetLayout,
CreateFence,
CreateCommandPool,
AllocCommandBuffer,
AllocDescriptorSet,
ResetDescriptorPool,
ResetCommandBuffer,
BeginCommandBuffer,
EndCommandBuffer,
ResetFence,
QueueSubmit,
WaitFence,
FreeMemory,
MapMemory,
CopyBuffer,
MutexPoisoned,
CreateInstance,
CreateDevice,
EnumerateDevices,
CreateAllocator,
GetFenceStatus,
CompileKernel,
LoadModule,
LoadFunction,
LaunchKernel,
StreamSync,
RecordEvent,
DeviceQuery,
CuBlas,
}
pub(crate) fn backend_err(op: BackendOp, e: impl std::fmt::Display) -> GpuError {
GpuError::Backend {
op,
detail: e.to_string(),
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum GpuError {
#[error("no suitable GPU device found")]
NoDevice,
#[error("backend not available: {0}")]
BackendUnavailable(String),
#[error("buffer allocation failed: requested {requested} bytes (device max: {device_max})")]
AllocationFailed {
requested: u64,
device_max: u64,
},
#[error("shader compilation error: {0}")]
ShaderCompilation(String),
#[error("entry point \"{name}\" not found in shader")]
MissingEntryPoint {
name: String,
},
#[error("dispatch failed: {0}")]
Dispatch(String),
#[error("readback timed out after {ms}ms")]
ReadbackTimeout {
ms: u64,
},
#[error("binding mismatch: shader expects {expected} buffer(s), got {got}")]
BindingMismatch {
expected: usize,
got: usize,
},
#[error("backend error ({op:?}): {detail}")]
Backend {
op: BackendOp,
detail: String,
},
}
pub type Result<T> = std::result::Result<T, GpuError>;