use objc2::{
encode::{Encode, Encoding, RefEncode},
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
};
use objc2_foundation::{CopyingHelper, NSCopying, NSInteger, NSObject, NSObjectProtocol, NSString};
use crate::*;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4ShaderReflection(pub usize);
bitflags::bitflags! {
impl MTL4ShaderReflection: usize {
#[doc(alias = "MTL4ShaderReflectionNone")]
const None = 0;
#[doc(alias = "MTL4ShaderReflectionBindingInfo")]
const BindingInfo = 1<<0;
#[doc(alias = "MTL4ShaderReflectionBufferTypeInfo")]
const BufferTypeInfo = 1<<1;
}
}
unsafe impl Encode for MTL4ShaderReflection {
const ENCODING: Encoding = usize::ENCODING;
}
unsafe impl RefEncode for MTL4ShaderReflection {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4AlphaToOneState(pub NSInteger);
impl MTL4AlphaToOneState {
#[doc(alias = "MTL4AlphaToOneStateDisabled")]
pub const DISABLED: Self = Self(0);
#[doc(alias = "MTL4AlphaToOneStateEnabled")]
pub const ENABLED: Self = Self(1);
}
unsafe impl Encode for MTL4AlphaToOneState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MTL4AlphaToOneState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4AlphaToCoverageState(pub NSInteger);
impl MTL4AlphaToCoverageState {
#[doc(alias = "MTL4AlphaToCoverageStateDisabled")]
pub const DISABLED: Self = Self(0);
#[doc(alias = "MTL4AlphaToCoverageStateEnabled")]
pub const ENABLED: Self = Self(1);
}
unsafe impl Encode for MTL4AlphaToCoverageState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MTL4AlphaToCoverageState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4BlendState(pub NSInteger);
impl MTL4BlendState {
#[doc(alias = "MTL4BlendStateDisabled")]
pub const DISABLED: Self = Self(0);
#[doc(alias = "MTL4BlendStateEnabled")]
pub const ENABLED: Self = Self(1);
#[doc(alias = "MTL4BlendStateUnspecialized")]
pub const UNSPECIALIZED: Self = Self(2);
}
unsafe impl Encode for MTL4BlendState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MTL4BlendState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4IndirectCommandBufferSupportState(pub NSInteger);
impl MTL4IndirectCommandBufferSupportState {
#[doc(alias = "MTL4IndirectCommandBufferSupportStateDisabled")]
pub const DISABLED: Self = Self(0);
#[doc(alias = "MTL4IndirectCommandBufferSupportStateEnabled")]
pub const ENABLED: Self = Self(1);
}
unsafe impl Encode for MTL4IndirectCommandBufferSupportState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MTL4IndirectCommandBufferSupportState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTL4PipelineOptions;
);
extern_conformance!(
unsafe impl NSCopying for MTL4PipelineOptions {}
);
unsafe impl CopyingHelper for MTL4PipelineOptions {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTL4PipelineOptions {}
);
impl MTL4PipelineOptions {
extern_methods!(
#[unsafe(method(shaderValidation))]
#[unsafe(method_family = none)]
pub fn shader_validation(&self) -> MTLShaderValidation;
#[unsafe(method(setShaderValidation:))]
#[unsafe(method_family = none)]
pub fn set_shader_validation(
&self,
shader_validation: MTLShaderValidation,
);
#[unsafe(method(shaderReflection))]
#[unsafe(method_family = none)]
pub fn shader_reflection(&self) -> MTL4ShaderReflection;
#[unsafe(method(setShaderReflection:))]
#[unsafe(method_family = none)]
pub fn set_shader_reflection(
&self,
shader_reflection: MTL4ShaderReflection,
);
);
}
impl MTL4PipelineOptions {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new() -> Retained<Self>;
);
}
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTL4PipelineDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTL4PipelineDescriptor {}
);
unsafe impl CopyingHelper for MTL4PipelineDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTL4PipelineDescriptor {}
);
impl MTL4PipelineDescriptor {
extern_methods!(
#[unsafe(method(options))]
#[unsafe(method_family = none)]
pub fn options(&self) -> Option<Retained<MTL4PipelineOptions>>;
#[unsafe(method(setOptions:))]
#[unsafe(method_family = none)]
pub fn set_options(
&self,
options: Option<&MTL4PipelineOptions>,
);
);
}
impl MTL4PipelineDescriptor {
pub fn label(&self) -> Option<String> {
let s: Option<Retained<NSString>> = unsafe { msg_send![self, label] };
s.map(|v| v.to_string())
}
pub fn set_label(
&self,
label: Option<&str>,
) {
unsafe {
let _: () = msg_send![self, setLabel: label.map(NSString::from_str).as_deref()];
}
}
}
impl MTL4PipelineDescriptor {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new() -> Retained<Self>;
);
}