objc2_metal/generated/
MTL4CommandBuffer.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    /// Options to configure a command buffer before encoding work into it.
12    ///
13    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4commandbufferoptions?language=objc)
14    #[unsafe(super(NSObject))]
15    #[derive(Debug, PartialEq, Eq, Hash)]
16    pub struct MTL4CommandBufferOptions;
17);
18
19extern_conformance!(
20    unsafe impl NSCopying for MTL4CommandBufferOptions {}
21);
22
23unsafe impl CopyingHelper for MTL4CommandBufferOptions {
24    type Result = Self;
25}
26
27extern_conformance!(
28    unsafe impl NSObjectProtocol for MTL4CommandBufferOptions {}
29);
30
31impl MTL4CommandBufferOptions {
32    extern_methods!(
33        #[cfg(feature = "MTLLogState")]
34        /// Contains information related to shader logging.
35        ///
36        /// To enable shader logging, call ``MTL4CommandBuffer/beginCommandBufferWithAllocator:options:`` with an instance
37        /// of ``MTL4CommandBufferOptions`` that contains a non-`nil` ``MTLLogState`` instance in this property.
38        ///
39        /// Shader functions log messages until the command buffer ends.
40        #[unsafe(method(logState))]
41        #[unsafe(method_family = none)]
42        pub fn logState(&self) -> Option<Retained<ProtocolObject<dyn MTLLogState>>>;
43
44        #[cfg(feature = "MTLLogState")]
45        /// Setter for [`logState`][Self::logState].
46        #[unsafe(method(setLogState:))]
47        #[unsafe(method_family = none)]
48        pub fn setLogState(&self, log_state: Option<&ProtocolObject<dyn MTLLogState>>);
49    );
50}
51
52/// Methods declared on superclass `NSObject`.
53impl MTL4CommandBufferOptions {
54    extern_methods!(
55        #[unsafe(method(init))]
56        #[unsafe(method_family = init)]
57        pub fn init(this: Allocated<Self>) -> Retained<Self>;
58
59        #[unsafe(method(new))]
60        #[unsafe(method_family = new)]
61        pub fn new() -> Retained<Self>;
62    );
63}
64
65impl DefaultRetained for MTL4CommandBufferOptions {
66    #[inline]
67    fn default_retained() -> Retained<Self> {
68        Self::new()
69    }
70}
71
72extern_protocol!(
73    /// Records a sequence of GPU commands.
74    ///
75    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4commandbuffer?language=objc)
76    pub unsafe trait MTL4CommandBuffer: NSObjectProtocol {
77        #[cfg(feature = "MTLDevice")]
78        /// Returns the GPU device that this command buffer belongs to.
79        #[unsafe(method(device))]
80        #[unsafe(method_family = none)]
81        fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
82
83        /// Assigns an optional label with this command buffer.
84        #[unsafe(method(label))]
85        #[unsafe(method_family = none)]
86        fn label(&self) -> Option<Retained<NSString>>;
87
88        /// Setter for [`label`][Self::label].
89        ///
90        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
91        #[unsafe(method(setLabel:))]
92        #[unsafe(method_family = none)]
93        fn setLabel(&self, label: Option<&NSString>);
94
95        #[cfg(feature = "MTL4CommandAllocator")]
96        /// Prepares a command buffer for encoding.
97        ///
98        /// Attaches the command buffer to the specified ``MTL4CommandAllocator`` and declares that the
99        /// application is ready to encode commands into the command buffer.
100        ///
101        /// Command allocators only service a single command buffer at a time. If you need to issue multiple
102        /// calls to this method simultaneously, for example, in a multi-threaded command encoding scenario,
103        /// create multiple instances of ``MTLCommandAllocator`` and use one for each call.
104        ///
105        /// You can safely reuse command allocators after ending the command buffer using it by calling
106        /// ``endCommandBuffer``.
107        ///
108        /// After calling this method, any prior calls to ``useResidencySet:`` and ``useResidencySets:count:``
109        /// on this command buffer instance no longer apply. Make sure to call these methods again to signal
110        /// your residency requirements to Metal.
111        ///
112        /// - Parameter allocator: ``MTL4CommandAllocator`` to attach to.
113        #[unsafe(method(beginCommandBufferWithAllocator:))]
114        #[unsafe(method_family = none)]
115        fn beginCommandBufferWithAllocator(
116            &self,
117            allocator: &ProtocolObject<dyn MTL4CommandAllocator>,
118        );
119
120        #[cfg(feature = "MTL4CommandAllocator")]
121        /// Prepares a command buffer for encoding with additional options.
122        ///
123        /// Attaches the command buffer to the specified ``MTL4CommandAllocator`` and declares that the
124        /// application is ready to encode commands into the command buffer.
125        ///
126        /// Command allocators only service a single command buffer at a time. If you need to issue multiple
127        /// calls to this method simultaneously, for example, in a multi-threaded command encoding scenario,
128        /// create multiple instances of ``MTLCommandAllocator`` and use one for each call.
129        ///
130        /// You can safely reuse command allocators after ending the command buffer using it by calling
131        /// ``endCommandBuffer``.
132        ///
133        /// After calling this method, any prior calls to ``useResidencySet:`` and ``useResidencySets:count:``
134        /// on this command buffer instance no longer apply. Make sure to call these methods again to signal
135        /// your residency requirements to Metal.
136        ///
137        /// The options you provide configure the command buffer only until the command buffer ends, in the
138        /// next call to ``endCommandBuffer``.
139        ///
140        /// - Parameters:
141        /// - allocator: ``MTL4CommandAllocator`` to attach to.
142        /// - options: ``MTL4CommandBufferOptions`` to configure the command buffer.
143        #[unsafe(method(beginCommandBufferWithAllocator:options:))]
144        #[unsafe(method_family = none)]
145        fn beginCommandBufferWithAllocator_options(
146            &self,
147            allocator: &ProtocolObject<dyn MTL4CommandAllocator>,
148            options: &MTL4CommandBufferOptions,
149        );
150
151        /// Closes a command buffer to prepare it for submission to a command queue.
152        ///
153        /// Explicitly ending the command buffer allows you to reuse the ``MTL4CommandAllocator`` to start servicing other
154        /// command buffers. It is an error to call ``commit`` on a command buffer previously recording before calling this
155        /// method.
156        #[unsafe(method(endCommandBuffer))]
157        #[unsafe(method_family = none)]
158        fn endCommandBuffer(&self);
159
160        #[cfg(all(
161            feature = "MTL4CommandEncoder",
162            feature = "MTL4RenderCommandEncoder",
163            feature = "MTL4RenderPass"
164        ))]
165        /// Creates a render command encoder from a render pass descriptor.
166        ///
167        /// - Parameters:
168        /// - descriptor: Descriptor for the render pass.
169        /// - Returns: The created ``MTL4RenderCommandEncoder`` instance, or `nil` if the function failed.
170        #[unsafe(method(renderCommandEncoderWithDescriptor:))]
171        #[unsafe(method_family = none)]
172        fn renderCommandEncoderWithDescriptor(
173            &self,
174            descriptor: &MTL4RenderPassDescriptor,
175        ) -> Option<Retained<ProtocolObject<dyn MTL4RenderCommandEncoder>>>;
176
177        #[cfg(all(
178            feature = "MTL4CommandEncoder",
179            feature = "MTL4RenderCommandEncoder",
180            feature = "MTL4RenderPass"
181        ))]
182        /// Creates a render command encoder from a render pass descriptor with additional options.
183        ///
184        /// This method creates a render command encoder to encode a render pass, whilst providing you the option to define
185        /// some render pass characteristics via an instance of ``MTL4RenderEncoderOptions``.
186        ///
187        /// Use these options to configure suspending/resuming render command encoders, which allow you to encode render passes
188        /// from multiple threads simultaneously.
189        ///
190        /// - Parameters:
191        /// - descriptor: Descriptor for the render pass.
192        /// - options: ``MTL4RenderEncoderOptions`` instance that provide render pass options.
193        /// - Returns: The created ``MTL4RenderCommandEncoder`` instance, or `nil` if the function fails.
194        #[unsafe(method(renderCommandEncoderWithDescriptor:options:))]
195        #[unsafe(method_family = none)]
196        fn renderCommandEncoderWithDescriptor_options(
197            &self,
198            descriptor: &MTL4RenderPassDescriptor,
199            options: MTL4RenderEncoderOptions,
200        ) -> Option<Retained<ProtocolObject<dyn MTL4RenderCommandEncoder>>>;
201
202        #[cfg(all(feature = "MTL4CommandEncoder", feature = "MTL4ComputeCommandEncoder"))]
203        /// Creates a compute command encoder.
204        ///
205        /// - Returns: The created ``MTL4ComputeCommandEncoder`` instance, or `nil` if the function fails.
206        #[unsafe(method(computeCommandEncoder))]
207        #[unsafe(method_family = none)]
208        fn computeCommandEncoder(
209            &self,
210        ) -> Option<Retained<ProtocolObject<dyn MTL4ComputeCommandEncoder>>>;
211
212        #[cfg(all(
213            feature = "MTL4CommandEncoder",
214            feature = "MTL4MachineLearningCommandEncoder"
215        ))]
216        /// Creates a machine learning command encoder.
217        ///
218        /// - Returns: The created ``MTL4MachineLearningCommandEncoder`` instance , or `nil` if the function fails.
219        #[unsafe(method(machineLearningCommandEncoder))]
220        #[unsafe(method_family = none)]
221        fn machineLearningCommandEncoder(
222            &self,
223        ) -> Option<Retained<ProtocolObject<dyn MTL4MachineLearningCommandEncoder>>>;
224
225        #[cfg(feature = "MTLResidencySet")]
226        /// Marks a residency set as part of the command buffer's execution.
227        ///
228        /// Ensures that Metal makes resident the resources that residency set contains during execution of this command buffer.
229        ///
230        /// - Parameter residencySet: ``MTLResidencySet`` instance to mark resident.
231        #[unsafe(method(useResidencySet:))]
232        #[unsafe(method_family = none)]
233        fn useResidencySet(&self, residency_set: &ProtocolObject<dyn MTLResidencySet>);
234
235        #[cfg(feature = "MTLResidencySet")]
236        /// Marks an array of residency sets as part of the command buffer's execution.
237        ///
238        /// Ensures that Metal makes resident the resources that residency sets contain during execution of this command buffer.
239        ///
240        /// - Parameters:
241        /// - residencySets: Array of ``MTLResidencySet`` instances to mark resident.
242        /// - count: Number of ``MTLResidencySet`` instances in the array.
243        ///
244        /// # Safety
245        ///
246        /// - `residency_sets` must be a valid pointer.
247        /// - `count` might not be bounds-checked.
248        #[unsafe(method(useResidencySets:count:))]
249        #[unsafe(method_family = none)]
250        unsafe fn useResidencySets_count(
251            &self,
252            residency_sets: NonNull<NonNull<ProtocolObject<dyn MTLResidencySet>>>,
253            count: NSUInteger,
254        );
255
256        /// Pushes a string onto a stack of debug groups for this command buffer.
257        ///
258        /// - Parameter string: The string to push.
259        #[unsafe(method(pushDebugGroup:))]
260        #[unsafe(method_family = none)]
261        fn pushDebugGroup(&self, string: &NSString);
262
263        /// Pops the latest string from the stack of debug groups for this command buffer.
264        #[unsafe(method(popDebugGroup))]
265        #[unsafe(method_family = none)]
266        fn popDebugGroup(&self);
267
268        #[cfg(feature = "MTL4Counters")]
269        /// Writes a GPU timestamp into the given counter heap.
270        ///
271        /// This method captures a timestamp after work prior to this command in the command buffer is complete.
272        /// Work after this call may or may not have started.
273        ///
274        /// You are responsible for ensuring the `counterHeap` is of type ``MTL4CounterHeapType/MTL4CounterHeapTypeTimestamp``.
275        ///
276        /// - Parameters:
277        /// - counterHeap: ``MTL4CounterHeap`` to write the timestamp into.
278        /// - index: The index within the ``MTL4CounterHeap`` that Metal writes the timestamp to.
279        ///
280        /// # Safety
281        ///
282        /// `index` might not be bounds-checked.
283        #[unsafe(method(writeTimestampIntoHeap:atIndex:))]
284        #[unsafe(method_family = none)]
285        unsafe fn writeTimestampIntoHeap_atIndex(
286            &self,
287            counter_heap: &ProtocolObject<dyn MTL4CounterHeap>,
288            index: NSUInteger,
289        );
290
291        #[cfg(all(
292            feature = "MTL4BufferRange",
293            feature = "MTL4Counters",
294            feature = "MTLFence",
295            feature = "MTLGPUAddress"
296        ))]
297        /// Encodes a command that resolves an opaque counter heap into a buffer.
298        ///
299        /// The command this method encodes converts the data within `counterHeap` into a common format
300        /// and stores it into the `bufferRange` parameter.
301        ///
302        /// The command places each entry in the counter heap within `range` sequentially, starting at `alignedOffset`.
303        /// Each entry needs to be a fixed size that you can query by calling the
304        /// ``MTLDevice/sizeOfCounterHeapEntry:`` method.
305        ///
306        /// This command runs during the `MTLStageBlit` stage of the GPU timeline. Barrier against this stage
307        /// to ensure the data is present in the resolve buffer parameter before you access it.
308        ///
309        /// - Note: Your app needs ensure the GPU places data in the heap before you resolve it by
310        /// synchronizing this stage with other GPU operations.
311        ///
312        /// Similarly, your app needs to synchronize any GPU accesses to `bufferRange` after
313        /// the command completes with barrier.
314        ///
315        /// If your app needs to access `bufferRange` from the CPU, signal an ``MTLSharedEvent``
316        /// to notify the CPU when it's ready.
317        /// Alternatively, you can resolve the heap's data from the CPU by calling
318        /// the heap's ``MTL4CounterHeap/resolveCounterRange:`` method.
319        ///
320        /// - Parameters:
321        /// - counterHeap: A heap the command resolves.
322        /// - range: A range of index values within the heap the command resolves.
323        /// - bufferRange: The buffer the command saves the data it resolves into.
324        /// - fenceToWait: A fence the GPU waits for before starting, if applicable; otherwise `nil`.
325        /// - fenceToUpdate: A fence the system updates after the command finishes resolving the data; otherwise `nil`.
326        ///
327        /// # Safety
328        ///
329        /// - `range` might not be bounds-checked.
330        /// - `bufferRange` might not be bounds-checked.
331        #[unsafe(method(resolveCounterHeap:withRange:intoBuffer:waitFence:updateFence:))]
332        #[unsafe(method_family = none)]
333        unsafe fn resolveCounterHeap_withRange_intoBuffer_waitFence_updateFence(
334            &self,
335            counter_heap: &ProtocolObject<dyn MTL4CounterHeap>,
336            range: NSRange,
337            buffer_range: MTL4BufferRange,
338            fence_to_wait: Option<&ProtocolObject<dyn MTLFence>>,
339            fence_to_update: Option<&ProtocolObject<dyn MTLFence>>,
340        );
341    }
342);