objc2_metal/generated/
MTL4CommandEncoder.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/// Memory consistency options for synchronization commands.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4visibilityoptions?language=objc)
13// NS_OPTIONS
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct MTL4VisibilityOptions(pub NSUInteger);
17bitflags::bitflags! {
18    impl MTL4VisibilityOptions: NSUInteger {
19/// Don't flush caches. When you use this option on a barrier, it turns it into an execution barrier.
20        #[doc(alias = "MTL4VisibilityOptionNone")]
21        const None = 0;
22/// Flushes caches to the GPU (device) memory coherence point.
23        #[doc(alias = "MTL4VisibilityOptionDevice")]
24        const Device = 1<<0;
25/// Flushes caches to ensure that aliased virtual addresses are memory consistent.
26///
27/// On some systems this may be the GPU+CPU (system) memory coherence point
28/// and on other systems it may be the GPU (device) memory coherence point.
29        #[doc(alias = "MTL4VisibilityOptionResourceAlias")]
30        const ResourceAlias = 1<<1;
31    }
32}
33
34unsafe impl Encode for MTL4VisibilityOptions {
35    const ENCODING: Encoding = NSUInteger::ENCODING;
36}
37
38unsafe impl RefEncode for MTL4VisibilityOptions {
39    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
40}
41
42extern_protocol!(
43    /// An encoder that writes GPU commands into a command buffer.
44    ///
45    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4commandencoder?language=objc)
46    pub unsafe trait MTL4CommandEncoder: NSObjectProtocol {
47        /// Provides an optional label to assign to the command encoder for debug purposes.
48        #[unsafe(method(label))]
49        #[unsafe(method_family = none)]
50        fn label(&self) -> Option<Retained<NSString>>;
51
52        /// Setter for [`label`][Self::label].
53        ///
54        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
55        #[unsafe(method(setLabel:))]
56        #[unsafe(method_family = none)]
57        fn setLabel(&self, label: Option<&NSString>);
58
59        #[cfg(feature = "MTL4CommandBuffer")]
60        /// Returns the command buffer that is currently encoding commands.
61        ///
62        /// This property may return undefined results if you call it after calling ``endEncoding``.
63        #[unsafe(method(commandBuffer))]
64        #[unsafe(method_family = none)]
65        fn commandBuffer(&self) -> Option<Retained<ProtocolObject<dyn MTL4CommandBuffer>>>;
66
67        #[cfg(feature = "MTLCommandEncoder")]
68        /// Encodes a consumer barrier on work you commit to the same command queue.
69        ///
70        /// Encode a barrier that guarantees that any subsequent work you encode in the current command encoder that corresponds
71        /// to the `beforeStages` stages doesn't proceed until Metal completes all work prior to the current command encoder
72        /// corresponding to the `afterQueueStages` stages, completes.
73        ///
74        /// Metal can reorder the exact point where it applies the barrier, so encode the barrier as close to the command that
75        /// consumes the resource as possible. Don't use this method for synchronizing resource access within the same pass.
76        ///
77        /// If you need to synchronize work within a pass that you encode with an instance of a subclass of ``MTLCommandEncoder``,
78        /// use memory barriers instead. For subclasses of ``MTL4CommandEncoder``, use encoder barriers.
79        ///
80        /// You can specify `afterQueueStages` and `beforeStages` that contain ``MTLStages`` unrelated to the current command
81        /// encoder.
82        ///
83        /// - Parameters:
84        /// - afterQueueStages: ``MTLStages`` mask that represents the stages of work to wait for.
85        /// This argument applies to work corresponding to these stages you
86        /// encode in prior command encoders, and not for the current encoder.
87        /// - beforeStages:     ``MTLStages`` mask that represents the stages of work that wait.
88        /// This argument applies to work you encode in the current command encoder.
89        /// - visibilityOptions: ``MTL4VisibilityOptions`` of the barrier.
90        #[unsafe(method(barrierAfterQueueStages:beforeStages:visibilityOptions:))]
91        #[unsafe(method_family = none)]
92        fn barrierAfterQueueStages_beforeStages_visibilityOptions(
93            &self,
94            after_queue_stages: MTLStages,
95            before_stages: MTLStages,
96            visibility_options: MTL4VisibilityOptions,
97        );
98
99        #[cfg(feature = "MTLCommandEncoder")]
100        /// Encodes a producer barrier on work committed to the same command queue.
101        ///
102        /// This method encodes a barrier that guarantees that any work you encode using *subsequent command encoders*,
103        /// corresponding to `beforeQueueStages`, don't begin until all commands you previously encode in the current
104        /// encoder (and prior encoders), corresponding to `afterStages`, complete.
105        ///
106        /// When calling this method, you can pass any ``MTLStages`` to parameters `afterStages` and `beforeQueueStages`,
107        /// even stages that don't relate to the current or prior command encoders.
108        ///
109        /// - Parameters:
110        /// - afterStages:       ``MTLStages`` mask that represents the stages of work to wait for.
111        /// This argument applies to work corresponding to these stages you encode in
112        /// the current command encoder prior to this barrier command.
113        /// - beforeQueueStages: ``MTLStages`` mask that represents the stages of work that need to wait.
114        /// This argument applies to subsequent encoders and not to work in the current
115        /// command encoder.
116        /// - visibilityOptions: ``MTL4VisibilityOptions`` of the barrier, controlling cache flush behavior.
117        #[unsafe(method(barrierAfterStages:beforeQueueStages:visibilityOptions:))]
118        #[unsafe(method_family = none)]
119        fn barrierAfterStages_beforeQueueStages_visibilityOptions(
120            &self,
121            after_stages: MTLStages,
122            before_queue_stages: MTLStages,
123            visibility_options: MTL4VisibilityOptions,
124        );
125
126        #[cfg(feature = "MTLCommandEncoder")]
127        /// Encodes an intra-pass barrier.
128        ///
129        /// Encode a barrier that guarantees that any subsequent work you encode in the *current command encoder*,
130        /// corresponding to `beforeEncoderStages`, doesn't begin until all prior commands in this command encoder,
131        /// corresponding to `afterEncoderStages`, completes.
132        ///
133        /// When calling this method, it's your responsibility to ensure parameters `afterEncoderStages` and `beforeEncoderStages`
134        /// contain a combination of ``MTLStages`` for which this encoder can encode commands. For example, for a
135        /// ``MTL4ComputeCommandEncoder`` instance, you can provide any combination of ``MTLStages/MTLStageDispatch``,
136        /// ``MTLStages/MTLStageBlit`` and ``MTLStages/MTLStageAccelerationStructure``.
137        ///
138        /// - Parameters:
139        /// - afterEncoderStages:  ``MTLStages`` mask that represents the stages of work to wait for.
140        /// This argument only applies to subsequent work you encode in the current command encoder.
141        /// - beforeEncoderStages: ``MTLStages`` mask that represents the stages of work that wait.
142        /// This argument only applies to work you encode in the current command encoder prior to
143        /// this barrier.
144        /// - visibilityOptions: ``MTL4VisibilityOptions`` of the barrier, controlling cache flush behavior.
145        #[unsafe(method(barrierAfterEncoderStages:beforeEncoderStages:visibilityOptions:))]
146        #[unsafe(method_family = none)]
147        fn barrierAfterEncoderStages_beforeEncoderStages_visibilityOptions(
148            &self,
149            after_encoder_stages: MTLStages,
150            before_encoder_stages: MTLStages,
151            visibility_options: MTL4VisibilityOptions,
152        );
153
154        #[cfg(all(feature = "MTLCommandEncoder", feature = "MTLFence"))]
155        /// Encodes a command to update a GPU fence.
156        ///
157        /// This method encodes a command that updates a ``MTLFence`` instance after all previously-encoded commands in the
158        /// current command encoder, corresponding to `afterEncoderStages`, complete.
159        ///
160        /// Use parameter `afterEncoderStages` to pass in a combination of ``MTLStages`` for which this encoder can encode work.
161        /// For example, for a ``MTL4ComputeCommandEncoder`` you can provide any combination of ``MTLStages/MTLStageDispatch``,
162        /// ``MTLStages/MTLStageBlit`` and ``MTLStages/MTLStageAccelerationStructure``.
163        ///
164        /// - Parameters:
165        /// - fence:              ``MTLFence`` instance to update.
166        /// - afterEncoderStages: ``MTLStages`` value that represents the stages of work to wait for.
167        /// This argument only applies to work encoded in the current command encoder.
168        #[unsafe(method(updateFence:afterEncoderStages:))]
169        #[unsafe(method_family = none)]
170        fn updateFence_afterEncoderStages(
171            &self,
172            fence: &ProtocolObject<dyn MTLFence>,
173            after_encoder_stages: MTLStages,
174        );
175
176        #[cfg(all(feature = "MTLCommandEncoder", feature = "MTLFence"))]
177        /// Encodes a command to wait on a GPU fence.
178        ///
179        /// Encode a command that guarantees that any subsequent work you encode via this current command encoder,
180        /// corresponding to `beforeEncoderStages`, doesn't begin until all prior updates to the fence is complete.
181        ///
182        /// To successfully wait for a fence update, schedule update and wait operations on the same command queue.
183        ///
184        /// Use parameter `beforeEncoderStages` to pass in a combination of ``MTLStages`` for which this encoder can encode
185        /// work. For example, for a ``MTL4ComputeCommandEncoder`` you can provide any combination of
186        /// ``MTLStages/MTLStageDispatch``, ``MTLStages/MTLStageBlit`` and ``MTLStages/MTLStageAccelerationStructure``.
187        ///
188        /// - Parameters:
189        /// - fence:              ``MTLFence`` instance to wait for.
190        /// - beforeEncoderStages:``MTLStages`` value that represents the stages of work that wait.
191        /// This argument only applies to work you encode in the current command encoder.
192        #[unsafe(method(waitForFence:beforeEncoderStages:))]
193        #[unsafe(method_family = none)]
194        fn waitForFence_beforeEncoderStages(
195            &self,
196            fence: &ProtocolObject<dyn MTLFence>,
197            before_encoder_stages: MTLStages,
198        );
199
200        /// Inserts a debug string into the frame data to aid debugging.
201        ///
202        /// Calling this method doesn't change any behaviors, but can be useful for debugging purposes.
203        ///
204        /// - Parameter string: The debug string to insert as a signpost.
205        #[unsafe(method(insertDebugSignpost:))]
206        #[unsafe(method_family = none)]
207        fn insertDebugSignpost(&self, string: &NSString);
208
209        /// Pushes a string onto this encoder's stack of debug groups.
210        ///
211        /// - Parameter string: The debug string to push.
212        #[unsafe(method(pushDebugGroup:))]
213        #[unsafe(method_family = none)]
214        fn pushDebugGroup(&self, string: &NSString);
215
216        /// Pops the latest debug group string from this encoder's stack of debug groups.
217        #[unsafe(method(popDebugGroup))]
218        #[unsafe(method_family = none)]
219        fn popDebugGroup(&self);
220
221        /// Declares that all command generation from this encoder is complete.
222        #[unsafe(method(endEncoding))]
223        #[unsafe(method_family = none)]
224        fn endEncoding(&self);
225    }
226);