objc2_metal/generated/
MTLLibrary.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlautoreleasedrenderpipelinereflection?language=objc)
11#[cfg(feature = "MTLRenderPipeline")]
12pub type MTLAutoreleasedRenderPipelineReflection = MTLRenderPipelineReflection;
13
14/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlautoreleasedcomputepipelinereflection?language=objc)
15#[cfg(feature = "MTLComputePipeline")]
16pub type MTLAutoreleasedComputePipelineReflection = MTLComputePipelineReflection;
17
18/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlnewlibrarycompletionhandler?language=objc)
19#[cfg(feature = "block2")]
20pub type MTLNewLibraryCompletionHandler =
21    *mut block2::DynBlock<dyn Fn(*mut ProtocolObject<dyn MTLLibrary>, *mut NSError)>;
22
23/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlnewrenderpipelinestatecompletionhandler?language=objc)
24#[cfg(all(
25    feature = "MTLAllocation",
26    feature = "MTLRenderPipeline",
27    feature = "block2"
28))]
29pub type MTLNewRenderPipelineStateCompletionHandler =
30    *mut block2::DynBlock<dyn Fn(*mut ProtocolObject<dyn MTLRenderPipelineState>, *mut NSError)>;
31
32/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlnewrenderpipelinestatewithreflectioncompletionhandler?language=objc)
33#[cfg(all(
34    feature = "MTLAllocation",
35    feature = "MTLRenderPipeline",
36    feature = "block2"
37))]
38pub type MTLNewRenderPipelineStateWithReflectionCompletionHandler = *mut block2::DynBlock<
39    dyn Fn(
40        *mut ProtocolObject<dyn MTLRenderPipelineState>,
41        *mut MTLRenderPipelineReflection,
42        *mut NSError,
43    ),
44>;
45
46/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlnewcomputepipelinestatecompletionhandler?language=objc)
47#[cfg(all(
48    feature = "MTLAllocation",
49    feature = "MTLComputePipeline",
50    feature = "block2"
51))]
52pub type MTLNewComputePipelineStateCompletionHandler =
53    *mut block2::DynBlock<dyn Fn(*mut ProtocolObject<dyn MTLComputePipelineState>, *mut NSError)>;
54
55/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlnewcomputepipelinestatewithreflectioncompletionhandler?language=objc)
56#[cfg(all(
57    feature = "MTLAllocation",
58    feature = "MTLComputePipeline",
59    feature = "block2"
60))]
61pub type MTLNewComputePipelineStateWithReflectionCompletionHandler = *mut block2::DynBlock<
62    dyn Fn(
63        *mut ProtocolObject<dyn MTLComputePipelineState>,
64        *mut MTLComputePipelineReflection,
65        *mut NSError,
66    ),
67>;
68
69/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlnewdynamiclibrarycompletionhandler?language=objc)
70#[cfg(all(feature = "MTLDynamicLibrary", feature = "block2"))]
71pub type MTLNewDynamicLibraryCompletionHandler =
72    *mut block2::DynBlock<dyn Fn(*mut ProtocolObject<dyn MTLDynamicLibrary>, *mut NSError)>;
73
74/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlautoreleasedargument?language=objc)
75#[deprecated = "Use MTLBinding and cast to specific Binding (MTLTextureBinding, MTLBufferBinding, .etc) instead"]
76#[cfg(feature = "MTLArgument")]
77pub type MTLAutoreleasedArgument = MTLArgument;
78
79/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlpatchtype?language=objc)
80// NS_ENUM
81#[repr(transparent)]
82#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
83pub struct MTLPatchType(pub NSUInteger);
84impl MTLPatchType {
85    #[doc(alias = "MTLPatchTypeNone")]
86    pub const None: Self = Self(0);
87    #[doc(alias = "MTLPatchTypeTriangle")]
88    pub const Triangle: Self = Self(1);
89    #[doc(alias = "MTLPatchTypeQuad")]
90    pub const Quad: Self = Self(2);
91}
92
93unsafe impl Encode for MTLPatchType {
94    const ENCODING: Encoding = NSUInteger::ENCODING;
95}
96
97unsafe impl RefEncode for MTLPatchType {
98    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
99}
100
101extern_class!(
102    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlvertexattribute?language=objc)
103    #[unsafe(super(NSObject))]
104    #[derive(Debug, PartialEq, Eq, Hash)]
105    pub struct MTLVertexAttribute;
106);
107
108extern_conformance!(
109    unsafe impl NSObjectProtocol for MTLVertexAttribute {}
110);
111
112impl MTLVertexAttribute {
113    extern_methods!(
114        #[unsafe(method(name))]
115        #[unsafe(method_family = none)]
116        pub fn name(&self) -> Retained<NSString>;
117
118        #[unsafe(method(attributeIndex))]
119        #[unsafe(method_family = none)]
120        pub fn attributeIndex(&self) -> NSUInteger;
121
122        #[cfg(feature = "MTLDataType")]
123        #[unsafe(method(attributeType))]
124        #[unsafe(method_family = none)]
125        pub fn attributeType(&self) -> MTLDataType;
126
127        #[unsafe(method(isActive))]
128        #[unsafe(method_family = none)]
129        pub fn isActive(&self) -> bool;
130
131        #[unsafe(method(isPatchData))]
132        #[unsafe(method_family = none)]
133        pub fn isPatchData(&self) -> bool;
134
135        #[unsafe(method(isPatchControlPointData))]
136        #[unsafe(method_family = none)]
137        pub fn isPatchControlPointData(&self) -> bool;
138    );
139}
140
141/// Methods declared on superclass `NSObject`.
142impl MTLVertexAttribute {
143    extern_methods!(
144        #[unsafe(method(init))]
145        #[unsafe(method_family = init)]
146        pub fn init(this: Allocated<Self>) -> Retained<Self>;
147
148        #[unsafe(method(new))]
149        #[unsafe(method_family = new)]
150        pub fn new() -> Retained<Self>;
151    );
152}
153
154impl DefaultRetained for MTLVertexAttribute {
155    #[inline]
156    fn default_retained() -> Retained<Self> {
157        Self::new()
158    }
159}
160
161extern_class!(
162    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlattribute?language=objc)
163    #[unsafe(super(NSObject))]
164    #[derive(Debug, PartialEq, Eq, Hash)]
165    pub struct MTLAttribute;
166);
167
168extern_conformance!(
169    unsafe impl NSObjectProtocol for MTLAttribute {}
170);
171
172impl MTLAttribute {
173    extern_methods!(
174        #[unsafe(method(name))]
175        #[unsafe(method_family = none)]
176        pub fn name(&self) -> Retained<NSString>;
177
178        #[unsafe(method(attributeIndex))]
179        #[unsafe(method_family = none)]
180        pub fn attributeIndex(&self) -> NSUInteger;
181
182        #[cfg(feature = "MTLDataType")]
183        #[unsafe(method(attributeType))]
184        #[unsafe(method_family = none)]
185        pub fn attributeType(&self) -> MTLDataType;
186
187        #[unsafe(method(isActive))]
188        #[unsafe(method_family = none)]
189        pub fn isActive(&self) -> bool;
190
191        #[unsafe(method(isPatchData))]
192        #[unsafe(method_family = none)]
193        pub fn isPatchData(&self) -> bool;
194
195        #[unsafe(method(isPatchControlPointData))]
196        #[unsafe(method_family = none)]
197        pub fn isPatchControlPointData(&self) -> bool;
198    );
199}
200
201/// Methods declared on superclass `NSObject`.
202impl MTLAttribute {
203    extern_methods!(
204        #[unsafe(method(init))]
205        #[unsafe(method_family = init)]
206        pub fn init(this: Allocated<Self>) -> Retained<Self>;
207
208        #[unsafe(method(new))]
209        #[unsafe(method_family = new)]
210        pub fn new() -> Retained<Self>;
211    );
212}
213
214impl DefaultRetained for MTLAttribute {
215    #[inline]
216    fn default_retained() -> Retained<Self> {
217        Self::new()
218    }
219}
220
221/// An identifier for a top-level Metal function.
222///
223/// Each location in the API where a program is used requires a function written for that specific usage.
224///
225///
226/// A vertex shader, usable for a MTLRenderPipelineState.
227///
228///
229/// A fragment shader, usable for a MTLRenderPipelineState.
230///
231///
232/// A compute kernel, usable to create a MTLComputePipelineState.
233///
234/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlfunctiontype?language=objc)
235// NS_ENUM
236#[repr(transparent)]
237#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
238pub struct MTLFunctionType(pub NSUInteger);
239impl MTLFunctionType {
240    #[doc(alias = "MTLFunctionTypeVertex")]
241    pub const Vertex: Self = Self(1);
242    #[doc(alias = "MTLFunctionTypeFragment")]
243    pub const Fragment: Self = Self(2);
244    #[doc(alias = "MTLFunctionTypeKernel")]
245    pub const Kernel: Self = Self(3);
246    #[doc(alias = "MTLFunctionTypeVisible")]
247    pub const Visible: Self = Self(5);
248    #[doc(alias = "MTLFunctionTypeIntersection")]
249    pub const Intersection: Self = Self(6);
250    #[doc(alias = "MTLFunctionTypeMesh")]
251    pub const Mesh: Self = Self(7);
252    #[doc(alias = "MTLFunctionTypeObject")]
253    pub const Object: Self = Self(8);
254}
255
256unsafe impl Encode for MTLFunctionType {
257    const ENCODING: Encoding = NSUInteger::ENCODING;
258}
259
260unsafe impl RefEncode for MTLFunctionType {
261    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
262}
263
264extern_class!(
265    /// describe an uberShader constant used by the function
266    ///
267    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlfunctionconstant?language=objc)
268    #[unsafe(super(NSObject))]
269    #[derive(Debug, PartialEq, Eq, Hash)]
270    pub struct MTLFunctionConstant;
271);
272
273extern_conformance!(
274    unsafe impl NSObjectProtocol for MTLFunctionConstant {}
275);
276
277impl MTLFunctionConstant {
278    extern_methods!(
279        #[unsafe(method(name))]
280        #[unsafe(method_family = none)]
281        pub fn name(&self) -> Retained<NSString>;
282
283        #[cfg(feature = "MTLDataType")]
284        #[unsafe(method(type))]
285        #[unsafe(method_family = none)]
286        pub fn r#type(&self) -> MTLDataType;
287
288        #[unsafe(method(index))]
289        #[unsafe(method_family = none)]
290        pub fn index(&self) -> NSUInteger;
291
292        #[unsafe(method(required))]
293        #[unsafe(method_family = none)]
294        pub fn required(&self) -> bool;
295    );
296}
297
298/// Methods declared on superclass `NSObject`.
299impl MTLFunctionConstant {
300    extern_methods!(
301        #[unsafe(method(init))]
302        #[unsafe(method_family = init)]
303        pub fn init(this: Allocated<Self>) -> Retained<Self>;
304
305        #[unsafe(method(new))]
306        #[unsafe(method_family = new)]
307        pub fn new() -> Retained<Self>;
308    );
309}
310
311impl DefaultRetained for MTLFunctionConstant {
312    #[inline]
313    fn default_retained() -> Retained<Self> {
314        Self::new()
315    }
316}
317
318extern_protocol!(
319    /// A handle to intermediate code used as inputs for either a MTLComputePipelineState or a MTLRenderPipelineState.
320    ///
321    /// MTLFunction is a single vertex shader, fragment shader, or compute function.  A Function can only be used with the device that it was created against.
322    ///
323    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlfunction?language=objc)
324    pub unsafe trait MTLFunction: NSObjectProtocol + Send + Sync {
325        /// A string to help identify this object.
326        #[unsafe(method(label))]
327        #[unsafe(method_family = none)]
328        fn label(&self) -> Option<Retained<NSString>>;
329
330        /// Setter for [`label`][Self::label].
331        ///
332        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
333        #[unsafe(method(setLabel:))]
334        #[unsafe(method_family = none)]
335        fn setLabel(&self, label: Option<&NSString>);
336
337        #[cfg(feature = "MTLDevice")]
338        /// The device this resource was created against.  This resource can only be used with this device.
339        #[unsafe(method(device))]
340        #[unsafe(method_family = none)]
341        fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
342
343        /// The overall kind of entry point: compute, vertex, or fragment.
344        #[unsafe(method(functionType))]
345        #[unsafe(method_family = none)]
346        fn functionType(&self) -> MTLFunctionType;
347
348        /// Returns the patch type. MTLPatchTypeNone if it is not a post tessellation vertex shader.
349        #[unsafe(method(patchType))]
350        #[unsafe(method_family = none)]
351        fn patchType(&self) -> MTLPatchType;
352
353        /// Returns the number of patch control points if it was specified in the shader. Returns -1 if it
354        /// was not specified.
355        #[unsafe(method(patchControlPointCount))]
356        #[unsafe(method_family = none)]
357        fn patchControlPointCount(&self) -> NSInteger;
358
359        #[unsafe(method(vertexAttributes))]
360        #[unsafe(method_family = none)]
361        fn vertexAttributes(&self) -> Option<Retained<NSArray<MTLVertexAttribute>>>;
362
363        /// Returns an array describing the attributes
364        #[unsafe(method(stageInputAttributes))]
365        #[unsafe(method_family = none)]
366        fn stageInputAttributes(&self) -> Option<Retained<NSArray<MTLAttribute>>>;
367
368        /// The name of the function in the shading language.
369        #[unsafe(method(name))]
370        #[unsafe(method_family = none)]
371        fn name(&self) -> Retained<NSString>;
372
373        /// A dictionary containing information about all function contents, keyed by the constant names.
374        #[unsafe(method(functionConstantsDictionary))]
375        #[unsafe(method_family = none)]
376        fn functionConstantsDictionary(
377            &self,
378        ) -> Retained<NSDictionary<NSString, MTLFunctionConstant>>;
379
380        #[cfg(feature = "MTLArgumentEncoder")]
381        /// Creates an argument encoder which will encode arguments matching the layout of the argument buffer at the given bind point index.
382        ///
383        /// # Safety
384        ///
385        /// `bufferIndex` might not be bounds-checked.
386        #[unsafe(method(newArgumentEncoderWithBufferIndex:))]
387        #[unsafe(method_family = new)]
388        unsafe fn newArgumentEncoderWithBufferIndex(
389            &self,
390            buffer_index: NSUInteger,
391        ) -> Retained<ProtocolObject<dyn MTLArgumentEncoder>>;
392
393        #[cfg(all(feature = "MTLArgument", feature = "MTLArgumentEncoder"))]
394        /// Creates an argument encoder which will encode arguments matching the layout of the argument buffer at the given bind point index.
395        ///
396        /// # Safety
397        ///
398        /// `bufferIndex` might not be bounds-checked.
399        #[deprecated = "Use MTLDevice's newArgumentEncoderWithBufferBinding: instead"]
400        #[unsafe(method(newArgumentEncoderWithBufferIndex:reflection:))]
401        #[unsafe(method_family = new)]
402        unsafe fn newArgumentEncoderWithBufferIndex_reflection(
403            &self,
404            buffer_index: NSUInteger,
405            reflection: Option<&mut Option<Retained<MTLAutoreleasedArgument>>>,
406        ) -> Retained<ProtocolObject<dyn MTLArgumentEncoder>>;
407
408        #[cfg(feature = "MTLFunctionDescriptor")]
409        /// The options this function was created with.
410        #[unsafe(method(options))]
411        #[unsafe(method_family = none)]
412        fn options(&self) -> MTLFunctionOptions;
413    }
414);
415
416/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtllanguageversion?language=objc)
417// NS_ENUM
418#[repr(transparent)]
419#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
420pub struct MTLLanguageVersion(pub NSUInteger);
421impl MTLLanguageVersion {
422    #[doc(alias = "MTLLanguageVersion1_0")]
423    #[deprecated = "Use a newer language standard"]
424    pub const Version1_0: Self = Self(1 << 16);
425    #[doc(alias = "MTLLanguageVersion1_1")]
426    pub const Version1_1: Self = Self((1 << 16) + 1);
427    #[doc(alias = "MTLLanguageVersion1_2")]
428    pub const Version1_2: Self = Self((1 << 16) + 2);
429    #[doc(alias = "MTLLanguageVersion2_0")]
430    pub const Version2_0: Self = Self(2 << 16);
431    #[doc(alias = "MTLLanguageVersion2_1")]
432    pub const Version2_1: Self = Self((2 << 16) + 1);
433    #[doc(alias = "MTLLanguageVersion2_2")]
434    pub const Version2_2: Self = Self((2 << 16) + 2);
435    #[doc(alias = "MTLLanguageVersion2_3")]
436    pub const Version2_3: Self = Self((2 << 16) + 3);
437    #[doc(alias = "MTLLanguageVersion2_4")]
438    pub const Version2_4: Self = Self((2 << 16) + 4);
439    #[doc(alias = "MTLLanguageVersion3_0")]
440    pub const Version3_0: Self = Self((3 << 16) + 0);
441    #[doc(alias = "MTLLanguageVersion3_1")]
442    pub const Version3_1: Self = Self((3 << 16) + 1);
443    #[doc(alias = "MTLLanguageVersion3_2")]
444    pub const Version3_2: Self = Self((3 << 16) + 2);
445    #[doc(alias = "MTLLanguageVersion4_0")]
446    pub const Version4_0: Self = Self((4 << 16) + 0);
447}
448
449unsafe impl Encode for MTLLanguageVersion {
450    const ENCODING: Encoding = NSUInteger::ENCODING;
451}
452
453unsafe impl RefEncode for MTLLanguageVersion {
454    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
455}
456
457/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtllibrarytype?language=objc)
458// NS_ENUM
459#[repr(transparent)]
460#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
461pub struct MTLLibraryType(pub NSInteger);
462impl MTLLibraryType {
463    #[doc(alias = "MTLLibraryTypeExecutable")]
464    pub const Executable: Self = Self(0);
465    #[doc(alias = "MTLLibraryTypeDynamic")]
466    pub const Dynamic: Self = Self(1);
467}
468
469unsafe impl Encode for MTLLibraryType {
470    const ENCODING: Encoding = NSInteger::ENCODING;
471}
472
473unsafe impl RefEncode for MTLLibraryType {
474    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
475}
476
477/// Optimization level for the Metal compiler.
478///
479///
480/// Optimize for program performance.
481///
482///
483/// Like default, with extra optimizations to reduce code size.
484///
485/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtllibraryoptimizationlevel?language=objc)
486// NS_ENUM
487#[repr(transparent)]
488#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
489pub struct MTLLibraryOptimizationLevel(pub NSInteger);
490impl MTLLibraryOptimizationLevel {
491    #[doc(alias = "MTLLibraryOptimizationLevelDefault")]
492    pub const Default: Self = Self(0);
493    #[doc(alias = "MTLLibraryOptimizationLevelSize")]
494    pub const Size: Self = Self(1);
495}
496
497unsafe impl Encode for MTLLibraryOptimizationLevel {
498    const ENCODING: Encoding = NSInteger::ENCODING;
499}
500
501unsafe impl RefEncode for MTLLibraryOptimizationLevel {
502    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
503}
504
505/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlcompilesymbolvisibility?language=objc)
506// NS_ENUM
507#[repr(transparent)]
508#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
509pub struct MTLCompileSymbolVisibility(pub NSInteger);
510impl MTLCompileSymbolVisibility {
511    #[doc(alias = "MTLCompileSymbolVisibilityDefault")]
512    pub const Default: Self = Self(0);
513    #[doc(alias = "MTLCompileSymbolVisibilityHidden")]
514    pub const Hidden: Self = Self(1);
515}
516
517unsafe impl Encode for MTLCompileSymbolVisibility {
518    const ENCODING: Encoding = NSInteger::ENCODING;
519}
520
521unsafe impl RefEncode for MTLCompileSymbolVisibility {
522    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
523}
524
525/// An enum to indicate if the compiler can perform optimizations for floating-point arithmetic that may violate the IEEE 754 standard
526///
527///
528/// Disables unsafe floating-point optimizations
529///
530///
531/// Allows aggressive, unsafe floating-point optimizations but preserves infs and nans
532///
533///
534/// Allows aggressive, unsafe floating-point optimizations
535///
536/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlmathmode?language=objc)
537// NS_ENUM
538#[repr(transparent)]
539#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
540pub struct MTLMathMode(pub NSInteger);
541impl MTLMathMode {
542    #[doc(alias = "MTLMathModeSafe")]
543    pub const Safe: Self = Self(0);
544    #[doc(alias = "MTLMathModeRelaxed")]
545    pub const Relaxed: Self = Self(1);
546    #[doc(alias = "MTLMathModeFast")]
547    pub const Fast: Self = Self(2);
548}
549
550unsafe impl Encode for MTLMathMode {
551    const ENCODING: Encoding = NSInteger::ENCODING;
552}
553
554unsafe impl RefEncode for MTLMathMode {
555    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
556}
557
558/// An enum to indicate the default math functions for single precision floating-point
559///
560///
561/// Sets the default math functions for single precision floating-point to the corresponding functions in `metal::fast` namespace
562///
563///
564/// Sets the default math functions for single precision floating-point to the corresponding functions in 'metal::precise' namespace
565///
566/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlmathfloatingpointfunctions?language=objc)
567// NS_ENUM
568#[repr(transparent)]
569#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
570pub struct MTLMathFloatingPointFunctions(pub NSInteger);
571impl MTLMathFloatingPointFunctions {
572    #[doc(alias = "MTLMathFloatingPointFunctionsFast")]
573    pub const Fast: Self = Self(0);
574    #[doc(alias = "MTLMathFloatingPointFunctionsPrecise")]
575    pub const Precise: Self = Self(1);
576}
577
578unsafe impl Encode for MTLMathFloatingPointFunctions {
579    const ENCODING: Encoding = NSInteger::ENCODING;
580}
581
582unsafe impl RefEncode for MTLMathFloatingPointFunctions {
583    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
584}
585
586extern_class!(
587    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlcompileoptions?language=objc)
588    #[unsafe(super(NSObject))]
589    #[derive(Debug, PartialEq, Eq, Hash)]
590    pub struct MTLCompileOptions;
591);
592
593extern_conformance!(
594    unsafe impl NSCopying for MTLCompileOptions {}
595);
596
597unsafe impl CopyingHelper for MTLCompileOptions {
598    type Result = Self;
599}
600
601extern_conformance!(
602    unsafe impl NSObjectProtocol for MTLCompileOptions {}
603);
604
605impl MTLCompileOptions {
606    extern_methods!(
607        /// List of preprocessor macros to consider to when compiling this program. Specified as key value pairs, using a NSDictionary. The keys must be NSString objects and values can be either NSString or NSNumber objects.
608        ///
609        /// The default value is nil.
610        #[unsafe(method(preprocessorMacros))]
611        #[unsafe(method_family = none)]
612        pub fn preprocessorMacros(&self) -> Option<Retained<NSDictionary<NSString, NSObject>>>;
613
614        /// Setter for [`preprocessorMacros`][Self::preprocessorMacros].
615        ///
616        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
617        ///
618        /// # Safety
619        ///
620        /// `preprocessor_macros` generic should be of the correct type.
621        #[unsafe(method(setPreprocessorMacros:))]
622        #[unsafe(method_family = none)]
623        pub unsafe fn setPreprocessorMacros(
624            &self,
625            preprocessor_macros: Option<&NSDictionary<NSString, NSObject>>,
626        );
627
628        /// If YES, enables the compiler to perform optimizations for floating-point arithmetic that may violate the IEEE 754 standard. It also enables the high precision variant of math functions for single precision floating-point scalar and vector types. fastMathEnabled defaults to YES.
629        #[deprecated = "Use mathMode instead"]
630        #[unsafe(method(fastMathEnabled))]
631        #[unsafe(method_family = none)]
632        pub fn fastMathEnabled(&self) -> bool;
633
634        /// Setter for [`fastMathEnabled`][Self::fastMathEnabled].
635        #[deprecated = "Use mathMode instead"]
636        #[unsafe(method(setFastMathEnabled:))]
637        #[unsafe(method_family = none)]
638        pub fn setFastMathEnabled(&self, fast_math_enabled: bool);
639
640        /// Sets the floating-point arithmetic optimizations. Default depends on the language standard version.
641        #[unsafe(method(mathMode))]
642        #[unsafe(method_family = none)]
643        pub fn mathMode(&self) -> MTLMathMode;
644
645        /// Setter for [`mathMode`][Self::mathMode].
646        #[unsafe(method(setMathMode:))]
647        #[unsafe(method_family = none)]
648        pub fn setMathMode(&self, math_mode: MTLMathMode);
649
650        /// Sets the default math functions for single precision floating-point. Default is `MTLMathFloatingPointFunctionsFast`.
651        #[unsafe(method(mathFloatingPointFunctions))]
652        #[unsafe(method_family = none)]
653        pub fn mathFloatingPointFunctions(&self) -> MTLMathFloatingPointFunctions;
654
655        /// Setter for [`mathFloatingPointFunctions`][Self::mathFloatingPointFunctions].
656        #[unsafe(method(setMathFloatingPointFunctions:))]
657        #[unsafe(method_family = none)]
658        pub fn setMathFloatingPointFunctions(
659            &self,
660            math_floating_point_functions: MTLMathFloatingPointFunctions,
661        );
662
663        /// set the metal language version used to interpret the source.
664        #[unsafe(method(languageVersion))]
665        #[unsafe(method_family = none)]
666        pub fn languageVersion(&self) -> MTLLanguageVersion;
667
668        /// Setter for [`languageVersion`][Self::languageVersion].
669        #[unsafe(method(setLanguageVersion:))]
670        #[unsafe(method_family = none)]
671        pub fn setLanguageVersion(&self, language_version: MTLLanguageVersion);
672
673        /// Which type the library should be compiled as. The default value is MTLLibraryTypeExecutable.
674        ///
675        /// MTLLibraryTypeExecutable is suitable to build a library of "kernel", "vertex" and "fragment" qualified functions.
676        /// MTLLibraryType is suitable when the compilation result will instead be used to instantiate a MTLDynamicLibrary.
677        /// MTLDynamicLibrary contains no qualified functions, but it's unqualified functions and variables can be used as an external dependency for compiling other libraries.
678        #[unsafe(method(libraryType))]
679        #[unsafe(method_family = none)]
680        pub fn libraryType(&self) -> MTLLibraryType;
681
682        /// Setter for [`libraryType`][Self::libraryType].
683        #[unsafe(method(setLibraryType:))]
684        #[unsafe(method_family = none)]
685        pub fn setLibraryType(&self, library_type: MTLLibraryType);
686
687        /// The install name of this dynamic library.
688        ///
689        /// The install name is used when a pipeline state is created that depends, directly or indirectly, on a dynamic library.
690        /// The installName is embedded into any other MTLLibrary that links against the compilation result.
691        /// This property should be set such that the dynamic library can be found in the file system at the time a pipeline state is created.
692        /// Specify one of:
693        /// - an absolute path to a file from which the dynamic library can be loaded, or
694        /// - a path relative to
695        /// @
696        /// executable_path, where
697        /// @
698        /// executable_path is substituted with the directory name from which the MTLLibrary containing the MTLFunction entrypoint used to create the pipeline state is loaded, or
699        /// - a path relative to
700        /// @
701        /// loader_path, where
702        /// @
703        /// loader_path is substituted with the directory name from which the MTLLibrary with the reference to this installName embedded is loaded.
704        /// The first is appropriate for MTLDynamicLibrary written to the file-system using its serializeToURL:error: method on the current device.
705        /// The others are appropriate when the MTLDynamicLibrary is installed as part of a bundle or app, where the absolute path is not known.
706        /// This property is ignored when the type property is not set to MTLLibraryTypeDynamic.
707        /// This propery should not be null if the property type is set to MTLLibraryTypeDynamic: the compilation will fail in that scenario.
708        #[unsafe(method(installName))]
709        #[unsafe(method_family = none)]
710        pub fn installName(&self) -> Option<Retained<NSString>>;
711
712        /// Setter for [`installName`][Self::installName].
713        ///
714        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
715        #[unsafe(method(setInstallName:))]
716        #[unsafe(method_family = none)]
717        pub fn setInstallName(&self, install_name: Option<&NSString>);
718
719        #[cfg(feature = "MTLDynamicLibrary")]
720        /// A set of MTLDynamicLibrary instances to link against.
721        /// The installName of the provided MTLDynamicLibrary is embedded into the compilation result.
722        /// When a function from the resulting MTLLibrary is used (either as an MTLFunction, or as an to create a pipeline state, the embedded install names are used to automatically load the MTLDynamicLibrary instances.
723        /// This property can be null if no libraries should be automatically loaded, either because the MTLLibrary has no external dependencies, or because you will use preloadedLibraries to specify the libraries to use at pipeline creation time.
724        #[unsafe(method(libraries))]
725        #[unsafe(method_family = none)]
726        pub fn libraries(&self)
727            -> Option<Retained<NSArray<ProtocolObject<dyn MTLDynamicLibrary>>>>;
728
729        #[cfg(feature = "MTLDynamicLibrary")]
730        /// Setter for [`libraries`][Self::libraries].
731        ///
732        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
733        #[unsafe(method(setLibraries:))]
734        #[unsafe(method_family = none)]
735        pub fn setLibraries(
736            &self,
737            libraries: Option<&NSArray<ProtocolObject<dyn MTLDynamicLibrary>>>,
738        );
739
740        /// If YES,  set the compiler to compile shaders to preserve invariance.  The default is false.
741        #[unsafe(method(preserveInvariance))]
742        #[unsafe(method_family = none)]
743        pub fn preserveInvariance(&self) -> bool;
744
745        /// Setter for [`preserveInvariance`][Self::preserveInvariance].
746        #[unsafe(method(setPreserveInvariance:))]
747        #[unsafe(method_family = none)]
748        pub fn setPreserveInvariance(&self, preserve_invariance: bool);
749
750        /// Sets the compiler optimization level.
751        #[unsafe(method(optimizationLevel))]
752        #[unsafe(method_family = none)]
753        pub fn optimizationLevel(&self) -> MTLLibraryOptimizationLevel;
754
755        /// Setter for [`optimizationLevel`][Self::optimizationLevel].
756        #[unsafe(method(setOptimizationLevel:))]
757        #[unsafe(method_family = none)]
758        pub fn setOptimizationLevel(&self, optimization_level: MTLLibraryOptimizationLevel);
759
760        /// Adds a compiler command to force the default visibility of symbols to be hidden
761        #[unsafe(method(compileSymbolVisibility))]
762        #[unsafe(method_family = none)]
763        pub fn compileSymbolVisibility(&self) -> MTLCompileSymbolVisibility;
764
765        /// Setter for [`compileSymbolVisibility`][Self::compileSymbolVisibility].
766        #[unsafe(method(setCompileSymbolVisibility:))]
767        #[unsafe(method_family = none)]
768        pub fn setCompileSymbolVisibility(
769            &self,
770            compile_symbol_visibility: MTLCompileSymbolVisibility,
771        );
772
773        /// Adds a compiler command to allow the reference of undefined symbols
774        #[unsafe(method(allowReferencingUndefinedSymbols))]
775        #[unsafe(method_family = none)]
776        pub fn allowReferencingUndefinedSymbols(&self) -> bool;
777
778        /// Setter for [`allowReferencingUndefinedSymbols`][Self::allowReferencingUndefinedSymbols].
779        #[unsafe(method(setAllowReferencingUndefinedSymbols:))]
780        #[unsafe(method_family = none)]
781        pub fn setAllowReferencingUndefinedSymbols(
782            &self,
783            allow_referencing_undefined_symbols: bool,
784        );
785
786        /// Adds a compiler command to specify the total threads per threadgroup
787        #[unsafe(method(maxTotalThreadsPerThreadgroup))]
788        #[unsafe(method_family = none)]
789        pub fn maxTotalThreadsPerThreadgroup(&self) -> NSUInteger;
790
791        /// Setter for [`maxTotalThreadsPerThreadgroup`][Self::maxTotalThreadsPerThreadgroup].
792        #[unsafe(method(setMaxTotalThreadsPerThreadgroup:))]
793        #[unsafe(method_family = none)]
794        pub fn setMaxTotalThreadsPerThreadgroup(
795            &self,
796            max_total_threads_per_threadgroup: NSUInteger,
797        );
798
799        #[cfg(feature = "MTLTypes")]
800        /// Sets the required threads-per-threadgroup during dispatches. The `threadsPerThreadgroup` argument of any dispatch must match this value if it is set.
801        /// Optional, unless the pipeline is going to use CooperativeTensors in which case this must be set.
802        /// Setting this to a size of 0 in every dimension disables this property
803        #[unsafe(method(requiredThreadsPerThreadgroup))]
804        #[unsafe(method_family = none)]
805        pub fn requiredThreadsPerThreadgroup(&self) -> MTLSize;
806
807        #[cfg(feature = "MTLTypes")]
808        /// Setter for [`requiredThreadsPerThreadgroup`][Self::requiredThreadsPerThreadgroup].
809        #[unsafe(method(setRequiredThreadsPerThreadgroup:))]
810        #[unsafe(method_family = none)]
811        pub fn setRequiredThreadsPerThreadgroup(&self, required_threads_per_threadgroup: MTLSize);
812
813        /// If YES,  set the compiler to enable any logging in the shader. The default is false.
814        #[unsafe(method(enableLogging))]
815        #[unsafe(method_family = none)]
816        pub fn enableLogging(&self) -> bool;
817
818        /// Setter for [`enableLogging`][Self::enableLogging].
819        #[unsafe(method(setEnableLogging:))]
820        #[unsafe(method_family = none)]
821        pub fn setEnableLogging(&self, enable_logging: bool);
822    );
823}
824
825/// Methods declared on superclass `NSObject`.
826impl MTLCompileOptions {
827    extern_methods!(
828        #[unsafe(method(init))]
829        #[unsafe(method_family = init)]
830        pub fn init(this: Allocated<Self>) -> Retained<Self>;
831
832        #[unsafe(method(new))]
833        #[unsafe(method_family = new)]
834        pub fn new() -> Retained<Self>;
835    );
836}
837
838impl DefaultRetained for MTLCompileOptions {
839    #[inline]
840    fn default_retained() -> Retained<Self> {
841        Self::new()
842    }
843}
844
845extern_class!(
846    /// Represents a reflection object containing information about a function in a Metal library.
847    ///
848    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlfunctionreflection?language=objc)
849    #[unsafe(super(NSObject))]
850    #[derive(Debug, PartialEq, Eq, Hash)]
851    pub struct MTLFunctionReflection;
852);
853
854unsafe impl Send for MTLFunctionReflection {}
855
856unsafe impl Sync for MTLFunctionReflection {}
857
858extern_conformance!(
859    unsafe impl NSObjectProtocol for MTLFunctionReflection {}
860);
861
862impl MTLFunctionReflection {
863    extern_methods!(
864        #[cfg(feature = "MTLArgument")]
865        /// Provides a list of inputs and outputs of the function.
866        #[unsafe(method(bindings))]
867        #[unsafe(method_family = none)]
868        pub fn bindings(&self) -> Retained<NSArray<ProtocolObject<dyn MTLBinding>>>;
869    );
870}
871
872/// Methods declared on superclass `NSObject`.
873impl MTLFunctionReflection {
874    extern_methods!(
875        #[unsafe(method(init))]
876        #[unsafe(method_family = init)]
877        pub fn init(this: Allocated<Self>) -> Retained<Self>;
878
879        #[unsafe(method(new))]
880        #[unsafe(method_family = new)]
881        pub fn new() -> Retained<Self>;
882    );
883}
884
885impl DefaultRetained for MTLFunctionReflection {
886    #[inline]
887    fn default_retained() -> Retained<Self> {
888        Self::new()
889    }
890}
891
892extern "C" {
893    /// NSErrors raised when creating a library.
894    ///
895    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtllibraryerrordomain?language=objc)
896    pub static MTLLibraryErrorDomain: &'static NSErrorDomain;
897}
898
899/// NSErrors raised when creating a library.
900///
901/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtllibraryerror?language=objc)
902// NS_ENUM
903#[repr(transparent)]
904#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
905pub struct MTLLibraryError(pub NSUInteger);
906impl MTLLibraryError {
907    #[doc(alias = "MTLLibraryErrorUnsupported")]
908    pub const Unsupported: Self = Self(1);
909    #[doc(alias = "MTLLibraryErrorInternal")]
910    pub const Internal: Self = Self(2);
911    #[doc(alias = "MTLLibraryErrorCompileFailure")]
912    pub const CompileFailure: Self = Self(3);
913    #[doc(alias = "MTLLibraryErrorCompileWarning")]
914    pub const CompileWarning: Self = Self(4);
915    #[doc(alias = "MTLLibraryErrorFunctionNotFound")]
916    pub const FunctionNotFound: Self = Self(5);
917    #[doc(alias = "MTLLibraryErrorFileNotFound")]
918    pub const FileNotFound: Self = Self(6);
919}
920
921unsafe impl Encode for MTLLibraryError {
922    const ENCODING: Encoding = NSUInteger::ENCODING;
923}
924
925unsafe impl RefEncode for MTLLibraryError {
926    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
927}
928
929extern_protocol!(
930    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtllibrary?language=objc)
931    pub unsafe trait MTLLibrary: NSObjectProtocol + Send + Sync {
932        /// A string to help identify this object.
933        #[unsafe(method(label))]
934        #[unsafe(method_family = none)]
935        fn label(&self) -> Option<Retained<NSString>>;
936
937        /// Setter for [`label`][Self::label].
938        ///
939        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
940        #[unsafe(method(setLabel:))]
941        #[unsafe(method_family = none)]
942        fn setLabel(&self, label: Option<&NSString>);
943
944        #[cfg(feature = "MTLDevice")]
945        /// The device this resource was created against.  This resource can only be used with this device.
946        #[unsafe(method(device))]
947        #[unsafe(method_family = none)]
948        fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
949
950        /// Returns a pointer to a function object, return nil if the function is not found in the library.
951        #[unsafe(method(newFunctionWithName:))]
952        #[unsafe(method_family = new)]
953        fn newFunctionWithName(
954            &self,
955            function_name: &NSString,
956        ) -> Option<Retained<ProtocolObject<dyn MTLFunction>>>;
957
958        #[cfg(feature = "MTLFunctionConstantValues")]
959        /// Returns a pointer to a function object obtained by applying the constant values to the named function.
960        ///
961        /// This method will call the compiler. Use newFunctionWithName:constantValues:completionHandler: to
962        /// avoid waiting on the compiler.
963        #[unsafe(method(newFunctionWithName:constantValues:error:_))]
964        #[unsafe(method_family = new)]
965        fn newFunctionWithName_constantValues_error(
966            &self,
967            name: &NSString,
968            constant_values: &MTLFunctionConstantValues,
969        ) -> Result<Retained<ProtocolObject<dyn MTLFunction>>, Retained<NSError>>;
970
971        #[cfg(all(feature = "MTLFunctionConstantValues", feature = "block2"))]
972        /// Returns a pointer to a function object obtained by applying the constant values to the named function.
973        ///
974        /// This method is asynchronous since it is will call the compiler.
975        #[unsafe(method(newFunctionWithName:constantValues:completionHandler:))]
976        #[unsafe(method_family = none)]
977        fn newFunctionWithName_constantValues_completionHandler(
978            &self,
979            name: &NSString,
980            constant_values: &MTLFunctionConstantValues,
981            completion_handler: &block2::DynBlock<
982                dyn Fn(*mut ProtocolObject<dyn MTLFunction>, *mut NSError),
983            >,
984        );
985
986        /// Returns a reflection object for a matching function name in this library instance.
987        ///
988        /// - Parameters:
989        /// - functionName: The name of the function.
990        ///
991        /// - Returns: An object containing the reflection information, or `nil` if no function in the library matches the name.
992        #[unsafe(method(reflectionForFunctionWithName:))]
993        #[unsafe(method_family = none)]
994        fn reflectionForFunctionWithName(
995            &self,
996            function_name: &NSString,
997        ) -> Option<Retained<MTLFunctionReflection>>;
998
999        #[cfg(all(feature = "MTLFunctionDescriptor", feature = "block2"))]
1000        /// Create a new MTLFunction object asynchronously.
1001        #[unsafe(method(newFunctionWithDescriptor:completionHandler:))]
1002        #[unsafe(method_family = none)]
1003        fn newFunctionWithDescriptor_completionHandler(
1004            &self,
1005            descriptor: &MTLFunctionDescriptor,
1006            completion_handler: &block2::DynBlock<
1007                dyn Fn(*mut ProtocolObject<dyn MTLFunction>, *mut NSError),
1008            >,
1009        );
1010
1011        #[cfg(feature = "MTLFunctionDescriptor")]
1012        /// Create  a new MTLFunction object synchronously.
1013        #[unsafe(method(newFunctionWithDescriptor:error:_))]
1014        #[unsafe(method_family = new)]
1015        fn newFunctionWithDescriptor_error(
1016            &self,
1017            descriptor: &MTLFunctionDescriptor,
1018        ) -> Result<Retained<ProtocolObject<dyn MTLFunction>>, Retained<NSError>>;
1019
1020        #[cfg(all(feature = "MTLFunctionDescriptor", feature = "block2"))]
1021        /// Create a new MTLFunction object asynchronously.
1022        #[unsafe(method(newIntersectionFunctionWithDescriptor:completionHandler:))]
1023        #[unsafe(method_family = none)]
1024        fn newIntersectionFunctionWithDescriptor_completionHandler(
1025            &self,
1026            descriptor: &MTLIntersectionFunctionDescriptor,
1027            completion_handler: &block2::DynBlock<
1028                dyn Fn(*mut ProtocolObject<dyn MTLFunction>, *mut NSError),
1029            >,
1030        );
1031
1032        #[cfg(feature = "MTLFunctionDescriptor")]
1033        /// Create  a new MTLFunction object synchronously.
1034        #[unsafe(method(newIntersectionFunctionWithDescriptor:error:_))]
1035        #[unsafe(method_family = new)]
1036        fn newIntersectionFunctionWithDescriptor_error(
1037            &self,
1038            descriptor: &MTLIntersectionFunctionDescriptor,
1039        ) -> Result<Retained<ProtocolObject<dyn MTLFunction>>, Retained<NSError>>;
1040
1041        /// The array contains NSString objects, with the name of each function in library.
1042        #[unsafe(method(functionNames))]
1043        #[unsafe(method_family = none)]
1044        fn functionNames(&self) -> Retained<NSArray<NSString>>;
1045
1046        /// The library type provided when this MTLLibrary was created.
1047        /// Libraries with MTLLibraryTypeExecutable can be used to obtain MTLFunction from.
1048        /// Libraries with MTLLibraryTypeDynamic can be used to resolve external references in other MTLLibrary from.
1049        ///
1050        /// See: MTLCompileOptions
1051        #[unsafe(method(type))]
1052        #[unsafe(method_family = none)]
1053        fn r#type(&self) -> MTLLibraryType;
1054
1055        /// The installName provided when this MTLLibrary was created.
1056        ///
1057        /// Always nil if the type of the library is not MTLLibraryTypeDynamic.
1058        ///
1059        /// See: MTLCompileOptions
1060        #[unsafe(method(installName))]
1061        #[unsafe(method_family = none)]
1062        fn installName(&self) -> Option<Retained<NSString>>;
1063    }
1064);