use objc2::{Encode, Encoding, RefEncode};
use objc2_foundation::{NSErrorDomain, NSErrorUserInfoKey};
unsafe extern "C" {
static MTLCommandBufferErrorDomain: &'static NSErrorDomain;
static MTLCommandBufferEncoderInfoErrorKey: &'static NSErrorUserInfoKey;
}
#[inline]
pub fn command_buffer_error_domain() -> String {
unsafe { MTLCommandBufferErrorDomain }.to_string()
}
#[inline]
pub fn command_buffer_encoder_info_error_key() -> String {
unsafe { MTLCommandBufferEncoderInfoErrorKey }.to_string()
}
#[repr(u64)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[allow(unused)]
pub enum MTLCommandBufferError {
None = 0,
Internal = 1,
Timeout = 2,
PageFault = 3,
AccessRevoked = 4,
NotPermitted = 7,
OutOfMemory = 8,
InvalidResource = 9,
Memoryless = 10,
#[deprecated(note = "this error cannot occur on Apple Silicon")]
DeviceRemoved = 11,
StackOverflow = 12,
}
impl MTLCommandBufferError {
#[allow(non_upper_case_globals)]
#[deprecated(note = "use AccessRevoked")]
pub const Blacklisted: Self = Self::AccessRevoked;
}
unsafe impl Encode for MTLCommandBufferError {
const ENCODING: Encoding = u64::ENCODING;
}
unsafe impl RefEncode for MTLCommandBufferError {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
bitflags::bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLCommandBufferErrorOption: u64 { const None = 0; const EncoderExecutionStatus = 1<<0; }
}
unsafe impl Encode for MTLCommandBufferErrorOption {
const ENCODING: Encoding = u64::ENCODING;
}
unsafe impl RefEncode for MTLCommandBufferErrorOption {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[cfg(test)]
mod tests {
use super::{MTLCommandBufferError, MTLCommandBufferErrorOption};
#[test]
#[allow(deprecated)]
fn deprecated_blacklisted_error_matches_access_revoked() {
assert_eq!(MTLCommandBufferError::Blacklisted, MTLCommandBufferError::AccessRevoked);
}
#[test]
fn error_option_bits_match_metal_header_values() {
assert_eq!(MTLCommandBufferErrorOption::None.bits(), 0);
assert_eq!(MTLCommandBufferErrorOption::EncoderExecutionStatus.bits(), 1);
}
}