Skip to main content

oidn_wgpu/
error.rs

1//! Error types for OIDN and wgpu integration.
2//!
3//! See [`Error`] for the main error type returned by public APIs.
4
5use std::fmt;
6
7/// Errors from OIDN or oidn-wgpu.
8///
9/// This type implements [`std::error::Error`], [`Send`], and [`Sync`], so it can be
10/// used with `?` and error handling libraries, and across thread boundaries.
11#[derive(Debug)]
12#[non_exhaustive]
13pub enum Error {
14    /// OIDN API returned an error.
15    OidnError { code: u32, message: String },
16    /// Device creation failed (e.g. no supported backend).
17    DeviceCreationFailed,
18    /// Filter creation failed.
19    FilterCreationFailed,
20    /// Out of memory.
21    OutOfMemory,
22    /// Image dimensions do not match buffer size.
23    InvalidDimensions,
24    /// Unsupported texture format for denoising.
25    UnsupportedFormat,
26    /// wgpu buffer mapping failed.
27    BufferMapFailed(wgpu::BufferAsyncError),
28}
29
30impl fmt::Display for Error {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        match self {
33            Error::OidnError { code, message } => write!(f, "OIDN error ({}): {}", code, message),
34            Error::DeviceCreationFailed => write!(f, "OIDN device creation failed"),
35            Error::FilterCreationFailed => write!(f, "OIDN filter creation failed"),
36            Error::OutOfMemory => write!(f, "OIDN out of memory"),
37            Error::InvalidDimensions => write!(f, "invalid image dimensions"),
38            Error::UnsupportedFormat => write!(f, "unsupported texture format for denoising"),
39            Error::BufferMapFailed(e) => write!(f, "wgpu buffer map failed: {:?}", e),
40        }
41    }
42}
43
44impl std::error::Error for Error {}
45
46// Required for use with ? and multithreaded error handling (C-GOOD-ERR).
47unsafe impl Send for Error {}
48unsafe impl Sync for Error {}