1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[non_exhaustive]
11#[allow(missing_docs)]
12pub enum BackendOp {
13 CreateBuffer,
14 BindMemory,
15 CreateShaderModule,
16 CreatePipeline,
17 CreatePipelineLayout,
18 CreateDescriptorPool,
19 CreateDescriptorSetLayout,
20 CreateFence,
21 CreateCommandPool,
22 AllocCommandBuffer,
23 AllocDescriptorSet,
24 ResetDescriptorPool,
25 ResetCommandBuffer,
26 BeginCommandBuffer,
27 EndCommandBuffer,
28 ResetFence,
29 QueueSubmit,
30 WaitFence,
31 FreeMemory,
32 MapMemory,
33 CopyBuffer,
34 MutexPoisoned,
35 CreateInstance,
36 CreateDevice,
37 EnumerateDevices,
38 CreateAllocator,
39 GetFenceStatus,
41 CompileKernel,
43 LoadModule,
44 LoadFunction,
45 LaunchKernel,
46 StreamSync,
47 RecordEvent,
48 DeviceQuery,
49 CuBlas,
50}
51
52pub(crate) fn backend_err(op: BackendOp, e: impl std::fmt::Display) -> GpuError {
54 GpuError::Backend {
55 op,
56 detail: e.to_string(),
57 }
58}
59
60#[derive(Debug, thiserror::Error)]
62#[non_exhaustive]
63pub enum GpuError {
64 #[error("no suitable GPU device found")]
66 NoDevice,
67
68 #[error("backend not available: {0}")]
70 BackendUnavailable(String),
71
72 #[error("buffer allocation failed: requested {requested} bytes (device max: {device_max})")]
74 AllocationFailed {
75 requested: u64,
77 device_max: u64,
79 },
80
81 #[error("shader compilation error: {0}")]
83 ShaderCompilation(String),
84
85 #[error("entry point \"{name}\" not found in shader")]
87 MissingEntryPoint {
88 name: String,
90 },
91
92 #[error("dispatch failed: {0}")]
94 Dispatch(String),
95
96 #[error("readback timed out after {ms}ms")]
98 ReadbackTimeout {
99 ms: u64,
101 },
102
103 #[error("binding mismatch: shader expects {expected} buffer(s), got {got}")]
105 BindingMismatch {
106 expected: usize,
108 got: usize,
110 },
111
112 #[error("backend error ({op:?}): {detail}")]
114 Backend {
115 op: BackendOp,
117 detail: String,
119 },
120}
121
122pub type Result<T> = std::result::Result<T, GpuError>;