objc2_metal/generated/
MTLComputePipeline.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
10extern_class!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlcomputepipelinereflection?language=objc)
12    #[unsafe(super(NSObject))]
13    #[derive(Debug, PartialEq, Eq, Hash)]
14    pub struct MTLComputePipelineReflection;
15);
16
17unsafe impl Send for MTLComputePipelineReflection {}
18
19unsafe impl Sync for MTLComputePipelineReflection {}
20
21extern_conformance!(
22    unsafe impl NSObjectProtocol for MTLComputePipelineReflection {}
23);
24
25impl MTLComputePipelineReflection {
26    extern_methods!(
27        #[cfg(feature = "MTLArgument")]
28        #[unsafe(method(bindings))]
29        #[unsafe(method_family = none)]
30        pub fn bindings(&self) -> Retained<NSArray<ProtocolObject<dyn MTLBinding>>>;
31
32        #[cfg(feature = "MTLArgument")]
33        #[deprecated]
34        #[unsafe(method(arguments))]
35        #[unsafe(method_family = none)]
36        pub fn arguments(&self) -> Retained<NSArray<MTLArgument>>;
37    );
38}
39
40/// Methods declared on superclass `NSObject`.
41impl MTLComputePipelineReflection {
42    extern_methods!(
43        #[unsafe(method(init))]
44        #[unsafe(method_family = init)]
45        pub fn init(this: Allocated<Self>) -> Retained<Self>;
46
47        #[unsafe(method(new))]
48        #[unsafe(method_family = new)]
49        pub fn new() -> Retained<Self>;
50    );
51}
52
53impl DefaultRetained for MTLComputePipelineReflection {
54    #[inline]
55    fn default_retained() -> Retained<Self> {
56        Self::new()
57    }
58}
59
60extern_class!(
61    /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlcomputepipelinedescriptor?language=objc)
62    #[unsafe(super(NSObject))]
63    #[derive(Debug, PartialEq, Eq, Hash)]
64    pub struct MTLComputePipelineDescriptor;
65);
66
67extern_conformance!(
68    unsafe impl NSCopying for MTLComputePipelineDescriptor {}
69);
70
71unsafe impl CopyingHelper for MTLComputePipelineDescriptor {
72    type Result = Self;
73}
74
75extern_conformance!(
76    unsafe impl NSObjectProtocol for MTLComputePipelineDescriptor {}
77);
78
79impl MTLComputePipelineDescriptor {
80    extern_methods!(
81        /// A string to help identify this object.
82        #[unsafe(method(label))]
83        #[unsafe(method_family = none)]
84        pub fn label(&self) -> Option<Retained<NSString>>;
85
86        /// Setter for [`label`][Self::label].
87        ///
88        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
89        #[unsafe(method(setLabel:))]
90        #[unsafe(method_family = none)]
91        pub fn setLabel(&self, label: Option<&NSString>);
92
93        #[cfg(feature = "MTLLibrary")]
94        /// The function to use with the MTLComputePipelineState
95        #[unsafe(method(computeFunction))]
96        #[unsafe(method_family = none)]
97        pub fn computeFunction(&self) -> Option<Retained<ProtocolObject<dyn MTLFunction>>>;
98
99        #[cfg(feature = "MTLLibrary")]
100        /// Setter for [`computeFunction`][Self::computeFunction].
101        #[unsafe(method(setComputeFunction:))]
102        #[unsafe(method_family = none)]
103        pub fn setComputeFunction(
104            &self,
105            compute_function: Option<&ProtocolObject<dyn MTLFunction>>,
106        );
107
108        /// An optimization flag, set if the thread group size will always be a multiple of thread execution width
109        #[unsafe(method(threadGroupSizeIsMultipleOfThreadExecutionWidth))]
110        #[unsafe(method_family = none)]
111        pub fn threadGroupSizeIsMultipleOfThreadExecutionWidth(&self) -> bool;
112
113        /// Setter for [`threadGroupSizeIsMultipleOfThreadExecutionWidth`][Self::threadGroupSizeIsMultipleOfThreadExecutionWidth].
114        #[unsafe(method(setThreadGroupSizeIsMultipleOfThreadExecutionWidth:))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn setThreadGroupSizeIsMultipleOfThreadExecutionWidth(
117            &self,
118            thread_group_size_is_multiple_of_thread_execution_width: bool,
119        );
120
121        /// Optional property. Set the maxTotalThreadsPerThreadgroup. If it is not set, returns zero.
122        #[unsafe(method(maxTotalThreadsPerThreadgroup))]
123        #[unsafe(method_family = none)]
124        pub fn maxTotalThreadsPerThreadgroup(&self) -> NSUInteger;
125
126        /// Setter for [`maxTotalThreadsPerThreadgroup`][Self::maxTotalThreadsPerThreadgroup].
127        #[unsafe(method(setMaxTotalThreadsPerThreadgroup:))]
128        #[unsafe(method_family = none)]
129        pub fn setMaxTotalThreadsPerThreadgroup(
130            &self,
131            max_total_threads_per_threadgroup: NSUInteger,
132        );
133
134        #[cfg(feature = "MTLStageInputOutputDescriptor")]
135        /// An MTLStageInputOutputDescriptor to fetch data from buffers
136        #[unsafe(method(stageInputDescriptor))]
137        #[unsafe(method_family = none)]
138        pub fn stageInputDescriptor(&self) -> Option<Retained<MTLStageInputOutputDescriptor>>;
139
140        #[cfg(feature = "MTLStageInputOutputDescriptor")]
141        /// Setter for [`stageInputDescriptor`][Self::stageInputDescriptor].
142        ///
143        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
144        #[unsafe(method(setStageInputDescriptor:))]
145        #[unsafe(method_family = none)]
146        pub fn setStageInputDescriptor(
147            &self,
148            stage_input_descriptor: Option<&MTLStageInputOutputDescriptor>,
149        );
150
151        #[cfg(feature = "MTLPipeline")]
152        /// Optional properties for each buffer binding used by the compute function.
153        #[unsafe(method(buffers))]
154        #[unsafe(method_family = none)]
155        pub fn buffers(&self) -> Retained<MTLPipelineBufferDescriptorArray>;
156
157        /// This flag makes this pipeline usable with indirect command buffers.
158        #[unsafe(method(supportIndirectCommandBuffers))]
159        #[unsafe(method_family = none)]
160        pub fn supportIndirectCommandBuffers(&self) -> bool;
161
162        /// Setter for [`supportIndirectCommandBuffers`][Self::supportIndirectCommandBuffers].
163        #[unsafe(method(setSupportIndirectCommandBuffers:))]
164        #[unsafe(method_family = none)]
165        pub fn setSupportIndirectCommandBuffers(&self, support_indirect_command_buffers: bool);
166
167        #[cfg(feature = "MTLDynamicLibrary")]
168        /// The set of MTLDynamicLibrary to use to resolve external symbols before considering symbols from dependent MTLDynamicLibrary.
169        ///
170        /// Typical workflows use the libraries property of MTLCompileOptions to record dependent libraries at compile time without having to use insertLibraries.
171        /// This property can be used to override symbols from dependent libraries for experimentation or evaluating alternative implementations.
172        /// It can also be used to provide dynamic libraries that are dynamically created (for example, from source) that have no stable installName that can be used to automatically load from the file system.
173        ///
174        /// See: MTLDynamicLibrary
175        #[deprecated]
176        #[unsafe(method(insertLibraries))]
177        #[unsafe(method_family = none)]
178        pub fn insertLibraries(
179            &self,
180        ) -> Option<Retained<NSArray<ProtocolObject<dyn MTLDynamicLibrary>>>>;
181
182        #[cfg(feature = "MTLDynamicLibrary")]
183        /// Setter for [`insertLibraries`][Self::insertLibraries].
184        ///
185        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
186        #[deprecated]
187        #[unsafe(method(setInsertLibraries:))]
188        #[unsafe(method_family = none)]
189        pub fn setInsertLibraries(
190            &self,
191            insert_libraries: Option<&NSArray<ProtocolObject<dyn MTLDynamicLibrary>>>,
192        );
193
194        #[cfg(feature = "MTLDynamicLibrary")]
195        /// The set of MTLDynamicLibrary to use to resolve external symbols before considering symbols from dependent MTLDynamicLibrary.
196        ///
197        /// Typical workflows use the libraries property of MTLCompileOptions to record dependent libraries at compile time without having to use preloadedLibraries.
198        /// This property can be used to override symbols from dependent libraries for experimentation or evaluating alternative implementations.
199        /// It can also be used to provide dynamic libraries that are dynamically created (for example, from source) that have no stable installName that can be used to automatically load from the file system.
200        ///
201        /// See: MTLDynamicLibrary
202        #[unsafe(method(preloadedLibraries))]
203        #[unsafe(method_family = none)]
204        pub fn preloadedLibraries(
205            &self,
206        ) -> Retained<NSArray<ProtocolObject<dyn MTLDynamicLibrary>>>;
207
208        #[cfg(feature = "MTLDynamicLibrary")]
209        /// Setter for [`preloadedLibraries`][Self::preloadedLibraries].
210        ///
211        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
212        #[unsafe(method(setPreloadedLibraries:))]
213        #[unsafe(method_family = none)]
214        pub fn setPreloadedLibraries(
215            &self,
216            preloaded_libraries: &NSArray<ProtocolObject<dyn MTLDynamicLibrary>>,
217        );
218
219        #[cfg(feature = "MTLBinaryArchive")]
220        /// The set of MTLBinaryArchive to search for compiled code when creating the pipeline state.
221        ///
222        /// Accelerate pipeline state creation by providing archives of compiled code such that no compilation needs to happen on the fast path.
223        ///
224        /// See: MTLBinaryArchive
225        #[unsafe(method(binaryArchives))]
226        #[unsafe(method_family = none)]
227        pub fn binaryArchives(
228            &self,
229        ) -> Option<Retained<NSArray<ProtocolObject<dyn MTLBinaryArchive>>>>;
230
231        #[cfg(feature = "MTLBinaryArchive")]
232        /// Setter for [`binaryArchives`][Self::binaryArchives].
233        ///
234        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
235        #[unsafe(method(setBinaryArchives:))]
236        #[unsafe(method_family = none)]
237        pub fn setBinaryArchives(
238            &self,
239            binary_archives: Option<&NSArray<ProtocolObject<dyn MTLBinaryArchive>>>,
240        );
241
242        /// Restore all compute pipeline descriptor properties to their default values.
243        #[unsafe(method(reset))]
244        #[unsafe(method_family = none)]
245        pub fn reset(&self);
246
247        #[cfg(feature = "MTLLinkedFunctions")]
248        /// The set of functions to be linked with the pipeline state and accessed from the compute function.
249        ///
250        /// See: MTLLinkedFunctions
251        #[unsafe(method(linkedFunctions))]
252        #[unsafe(method_family = none)]
253        pub fn linkedFunctions(&self) -> Option<Retained<MTLLinkedFunctions>>;
254
255        #[cfg(feature = "MTLLinkedFunctions")]
256        /// Setter for [`linkedFunctions`][Self::linkedFunctions].
257        ///
258        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
259        #[unsafe(method(setLinkedFunctions:))]
260        #[unsafe(method_family = none)]
261        pub fn setLinkedFunctions(&self, linked_functions: Option<&MTLLinkedFunctions>);
262
263        /// This flag makes this pipeline support creating a new pipeline by adding binary functions.
264        #[unsafe(method(supportAddingBinaryFunctions))]
265        #[unsafe(method_family = none)]
266        pub fn supportAddingBinaryFunctions(&self) -> bool;
267
268        /// Setter for [`supportAddingBinaryFunctions`][Self::supportAddingBinaryFunctions].
269        #[unsafe(method(setSupportAddingBinaryFunctions:))]
270        #[unsafe(method_family = none)]
271        pub fn setSupportAddingBinaryFunctions(&self, support_adding_binary_functions: bool);
272
273        /// The maximum depth of the call stack in stack frames from the kernel. Defaults to 1 additional stack frame.
274        #[unsafe(method(maxCallStackDepth))]
275        #[unsafe(method_family = none)]
276        pub fn maxCallStackDepth(&self) -> NSUInteger;
277
278        /// Setter for [`maxCallStackDepth`][Self::maxCallStackDepth].
279        #[unsafe(method(setMaxCallStackDepth:))]
280        #[unsafe(method_family = none)]
281        pub fn setMaxCallStackDepth(&self, max_call_stack_depth: NSUInteger);
282
283        #[cfg(feature = "MTLPipeline")]
284        /// Toggle that determines whether Metal Shader Validation should be enabled or disabled for the pipeline.
285        ///
286        /// The value can be overridden using `MTL_SHADER_VALIDATION_ENABLE_PIPELINES` or `MTL_SHADER_VALIDATION_DISABLE_PIPELINES` Environment Variables.
287        #[unsafe(method(shaderValidation))]
288        #[unsafe(method_family = none)]
289        pub fn shaderValidation(&self) -> MTLShaderValidation;
290
291        #[cfg(feature = "MTLPipeline")]
292        /// Setter for [`shaderValidation`][Self::shaderValidation].
293        #[unsafe(method(setShaderValidation:))]
294        #[unsafe(method_family = none)]
295        pub fn setShaderValidation(&self, shader_validation: MTLShaderValidation);
296
297        #[cfg(feature = "MTLTypes")]
298        /// Sets the required threads-per-threadgroup during dispatches. The `threadsPerThreadgroup` argument of any dispatch must match this value if it is set.
299        /// Optional, unless the pipeline is going to use CooperativeTensors in which case this must be set.
300        /// Setting this to a size of 0 in every dimension disables this property
301        #[unsafe(method(requiredThreadsPerThreadgroup))]
302        #[unsafe(method_family = none)]
303        pub fn requiredThreadsPerThreadgroup(&self) -> MTLSize;
304
305        #[cfg(feature = "MTLTypes")]
306        /// Setter for [`requiredThreadsPerThreadgroup`][Self::requiredThreadsPerThreadgroup].
307        #[unsafe(method(setRequiredThreadsPerThreadgroup:))]
308        #[unsafe(method_family = none)]
309        pub fn setRequiredThreadsPerThreadgroup(&self, required_threads_per_threadgroup: MTLSize);
310    );
311}
312
313/// Methods declared on superclass `NSObject`.
314impl MTLComputePipelineDescriptor {
315    extern_methods!(
316        #[unsafe(method(init))]
317        #[unsafe(method_family = init)]
318        pub fn init(this: Allocated<Self>) -> Retained<Self>;
319
320        #[unsafe(method(new))]
321        #[unsafe(method_family = new)]
322        pub fn new() -> Retained<Self>;
323    );
324}
325
326impl DefaultRetained for MTLComputePipelineDescriptor {
327    #[inline]
328    fn default_retained() -> Retained<Self> {
329        Self::new()
330    }
331}
332
333extern_protocol!(
334    /// A handle to compiled code for a compute function.
335    ///
336    /// MTLComputePipelineState is a single compute function.  It can only be used with the device that it was created against.
337    ///
338    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlcomputepipelinestate?language=objc)
339    #[cfg(feature = "MTLAllocation")]
340    pub unsafe trait MTLComputePipelineState:
341        MTLAllocation + NSObjectProtocol + Send + Sync
342    {
343        #[unsafe(method(label))]
344        #[unsafe(method_family = none)]
345        fn label(&self) -> Option<Retained<NSString>>;
346
347        /// Provides access to this compute pipeline's reflection.
348        ///
349        /// Reflection is `nil` if you create the pipeline state object directly from the ``MTLDevice`` protocol.
350        #[unsafe(method(reflection))]
351        #[unsafe(method_family = none)]
352        fn reflection(&self) -> Option<Retained<MTLComputePipelineReflection>>;
353
354        #[cfg(feature = "MTLFunctionHandle")]
355        /// Gets the function handle for a function this pipeline links at the Metal IR level by name.
356        ///
357        /// - Parameters:
358        /// - name: A string representing the name of the function.
359        ///
360        /// - Returns: A function handle corresponding to the function if the name matches a function in this pipeline state,
361        /// otherwise `nil`.
362        #[unsafe(method(functionHandleWithName:))]
363        #[unsafe(method_family = none)]
364        fn functionHandleWithName(
365            &self,
366            name: &NSString,
367        ) -> Option<Retained<ProtocolObject<dyn MTLFunctionHandle>>>;
368
369        #[cfg(all(feature = "MTL4BinaryFunction", feature = "MTLFunctionHandle"))]
370        /// Gets the function handle for a function this pipeline links at the binary level.
371        ///
372        /// - Parameters:
373        /// - function: A binary function object representing the function binary to find.
374        ///
375        /// - Returns: A function handle corresponding to the function if the binary function mathces a function in this
376        /// pipeline state, otherwise `nil`.
377        #[unsafe(method(functionHandleWithBinaryFunction:))]
378        #[unsafe(method_family = none)]
379        fn functionHandleWithBinaryFunction(
380            &self,
381            function: &ProtocolObject<dyn MTL4BinaryFunction>,
382        ) -> Option<Retained<ProtocolObject<dyn MTLFunctionHandle>>>;
383
384        #[cfg(feature = "MTL4BinaryFunction")]
385        /// Allocates a new compute pipeline state by adding binary functions to this pipeline state.
386        ///
387        /// - Parameters:
388        /// - additionalBinaryFunctions: A non-`nil` array containing binary functions to add to this pipeline.
389        /// - error: An optional parameter into which Metal stores information in case of an error.
390        ///
391        /// - Returns: A new compute pipeline state upon success, otherwise `nil`.
392        #[unsafe(method(newComputePipelineStateWithBinaryFunctions:error:_))]
393        #[unsafe(method_family = new)]
394        fn newComputePipelineStateWithBinaryFunctions_error(
395            &self,
396            additional_binary_functions: &NSArray<ProtocolObject<dyn MTL4BinaryFunction>>,
397        ) -> Result<Retained<ProtocolObject<dyn MTLComputePipelineState>>, Retained<NSError>>;
398
399        #[cfg(feature = "MTLDevice")]
400        /// The device this resource was created against.  This resource can only be used with this device.
401        #[unsafe(method(device))]
402        #[unsafe(method_family = none)]
403        fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
404
405        /// The maximum total number of threads that can be in a single compute threadgroup.
406        #[unsafe(method(maxTotalThreadsPerThreadgroup))]
407        #[unsafe(method_family = none)]
408        fn maxTotalThreadsPerThreadgroup(&self) -> NSUInteger;
409
410        /// For most efficient execution, the threadgroup size should be a multiple of this when executing the kernel.
411        #[unsafe(method(threadExecutionWidth))]
412        #[unsafe(method_family = none)]
413        fn threadExecutionWidth(&self) -> NSUInteger;
414
415        /// The length in bytes of threadgroup memory that is statically allocated.
416        #[unsafe(method(staticThreadgroupMemoryLength))]
417        #[unsafe(method_family = none)]
418        fn staticThreadgroupMemoryLength(&self) -> NSUInteger;
419
420        #[cfg(feature = "MTLTypes")]
421        /// Returns imageblock memory length for given image block dimensions.
422        #[unsafe(method(imageblockMemoryLengthForDimensions:))]
423        #[unsafe(method_family = none)]
424        unsafe fn imageblockMemoryLengthForDimensions(
425            &self,
426            imageblock_dimensions: MTLSize,
427        ) -> NSUInteger;
428
429        /// Tells whether this pipeline state is usable through an Indirect Command Buffer.
430        #[unsafe(method(supportIndirectCommandBuffers))]
431        #[unsafe(method_family = none)]
432        fn supportIndirectCommandBuffers(&self) -> bool;
433
434        #[cfg(feature = "MTLTypes")]
435        /// Handle of the GPU resource suitable for storing in an Argument Buffer
436        #[unsafe(method(gpuResourceID))]
437        #[unsafe(method_family = none)]
438        fn gpuResourceID(&self) -> MTLResourceID;
439
440        #[cfg(all(feature = "MTLFunctionHandle", feature = "MTLLibrary"))]
441        /// Get the function handle for the specified function from the pipeline state.
442        #[unsafe(method(functionHandleWithFunction:))]
443        #[unsafe(method_family = none)]
444        fn functionHandleWithFunction(
445            &self,
446            function: &ProtocolObject<dyn MTLFunction>,
447        ) -> Option<Retained<ProtocolObject<dyn MTLFunctionHandle>>>;
448
449        #[cfg(feature = "MTLLibrary")]
450        /// Allocate a new compute pipeline state by adding binary functions to this pipeline state.
451        #[unsafe(method(newComputePipelineStateWithAdditionalBinaryFunctions:error:_))]
452        #[unsafe(method_family = new)]
453        fn newComputePipelineStateWithAdditionalBinaryFunctions_error(
454            &self,
455            functions: &NSArray<ProtocolObject<dyn MTLFunction>>,
456        ) -> Result<Retained<ProtocolObject<dyn MTLComputePipelineState>>, Retained<NSError>>;
457
458        #[cfg(all(feature = "MTLResource", feature = "MTLVisibleFunctionTable"))]
459        /// Allocate a visible function table for the pipeline with the provided descriptor.
460        #[unsafe(method(newVisibleFunctionTableWithDescriptor:))]
461        #[unsafe(method_family = new)]
462        fn newVisibleFunctionTableWithDescriptor(
463            &self,
464            descriptor: &MTLVisibleFunctionTableDescriptor,
465        ) -> Option<Retained<ProtocolObject<dyn MTLVisibleFunctionTable>>>;
466
467        #[cfg(all(feature = "MTLIntersectionFunctionTable", feature = "MTLResource"))]
468        /// Allocate an intersection function table for the pipeline with the provided descriptor.
469        #[unsafe(method(newIntersectionFunctionTableWithDescriptor:))]
470        #[unsafe(method_family = new)]
471        fn newIntersectionFunctionTableWithDescriptor(
472            &self,
473            descriptor: &MTLIntersectionFunctionTableDescriptor,
474        ) -> Option<Retained<ProtocolObject<dyn MTLIntersectionFunctionTable>>>;
475
476        #[cfg(feature = "MTLPipeline")]
477        /// Current state of Shader Validation for the pipeline.
478        ///
479        /// This property is not atomic.
480        ///
481        /// # Safety
482        ///
483        /// This might not be thread-safe.
484        #[unsafe(method(shaderValidation))]
485        #[unsafe(method_family = none)]
486        unsafe fn shaderValidation(&self) -> MTLShaderValidation;
487
488        #[cfg(feature = "MTLTypes")]
489        /// The required size of every compute threadgroup.
490        #[unsafe(method(requiredThreadsPerThreadgroup))]
491        #[unsafe(method_family = none)]
492        fn requiredThreadsPerThreadgroup(&self) -> MTLSize;
493    }
494);