objc2_metal/generated/MTLCommandEncoder.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/// Describes how a resource will be used by a shader through an argument buffer
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlresourceusage?language=objc)
13// NS_OPTIONS
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct MTLResourceUsage(pub NSUInteger);
17bitflags::bitflags! {
18 impl MTLResourceUsage: NSUInteger {
19 #[doc(alias = "MTLResourceUsageRead")]
20 const Read = 1<<0;
21 #[doc(alias = "MTLResourceUsageWrite")]
22 const Write = 1<<1;
23 #[doc(alias = "MTLResourceUsageSample")]
24#[deprecated]
25 const Sample = 1<<2;
26 }
27}
28
29unsafe impl Encode for MTLResourceUsage {
30 const ENCODING: Encoding = NSUInteger::ENCODING;
31}
32
33unsafe impl RefEncode for MTLResourceUsage {
34 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
35}
36
37/// Describes the types of resources that the a barrier operates on
38///
39/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlbarrierscope?language=objc)
40// NS_OPTIONS
41#[repr(transparent)]
42#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
43pub struct MTLBarrierScope(pub NSUInteger);
44bitflags::bitflags! {
45 impl MTLBarrierScope: NSUInteger {
46 #[doc(alias = "MTLBarrierScopeBuffers")]
47 const Buffers = 1<<0;
48 #[doc(alias = "MTLBarrierScopeTextures")]
49 const Textures = 1<<1;
50 #[doc(alias = "MTLBarrierScopeRenderTargets")]
51 const RenderTargets = 1<<2;
52 }
53}
54
55unsafe impl Encode for MTLBarrierScope {
56 const ENCODING: Encoding = NSUInteger::ENCODING;
57}
58
59unsafe impl RefEncode for MTLBarrierScope {
60 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
61}
62
63/// Describes stages of GPU work.
64///
65/// All commands you encoder into command buffers relate to one or more shader stages,
66/// for example, a compute dispatch command from a compute command encoder relates to
67/// stage ``MTLStageDispatch``.
68///
69/// Use these stages to issue barriers between shader stages to ensure Metal correctly
70/// synchronizes GPU commands.
71///
72/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlstages?language=objc)
73// NS_OPTIONS
74#[repr(transparent)]
75#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
76pub struct MTLStages(pub NSUInteger);
77bitflags::bitflags! {
78 impl MTLStages: NSUInteger {
79/// Represents all vertex shader stage work in a render pass.
80 #[doc(alias = "MTLStageVertex")]
81 const Vertex = 1<<0;
82/// Represents all fragment shader stage work in a render pass.
83 #[doc(alias = "MTLStageFragment")]
84 const Fragment = 1<<1;
85/// Represents all tile shading stage work in a render pass.
86 #[doc(alias = "MTLStageTile")]
87 const Tile = 1<<2;
88/// Represents all object shader stage work in a render pass.
89 #[doc(alias = "MTLStageObject")]
90 const Object = 1<<3;
91/// Represents all mesh shader stage work work in a render pass.
92 #[doc(alias = "MTLStageMesh")]
93 const Mesh = 1<<4;
94/// Represents all sparse and placement sparse resource mapping updates.
95 #[doc(alias = "MTLStageResourceState")]
96 const ResourceState = 1<<26;
97/// Represents all compute dispatches in a compute pass.
98 #[doc(alias = "MTLStageDispatch")]
99 const Dispatch = 1<<27;
100/// Represents all blit operations in a pass.
101 #[doc(alias = "MTLStageBlit")]
102 const Blit = 1<<28;
103/// Represents all acceleration structure operations.
104 #[doc(alias = "MTLStageAccelerationStructure")]
105 const AccelerationStructure = 1<<29;
106/// Represents all machine learning network dispatch operations.
107 #[doc(alias = "MTLStageMachineLearning")]
108 const MachineLearning = 1<<30;
109/// Convenience mask representing all stages of GPU work.
110 #[doc(alias = "MTLStageAll")]
111 const All = NSIntegerMax as _;
112 }
113}
114
115unsafe impl Encode for MTLStages {
116 const ENCODING: Encoding = NSUInteger::ENCODING;
117}
118
119unsafe impl RefEncode for MTLStages {
120 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
121}
122
123extern_protocol!(
124 /// MTLCommandEncoder is the common interface for objects that write commands into MTLCommandBuffers.
125 ///
126 /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlcommandencoder?language=objc)
127 pub unsafe trait MTLCommandEncoder: NSObjectProtocol {
128 #[cfg(feature = "MTLDevice")]
129 /// The device this resource was created against.
130 #[unsafe(method(device))]
131 #[unsafe(method_family = none)]
132 fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
133
134 /// A string to help identify this object.
135 #[unsafe(method(label))]
136 #[unsafe(method_family = none)]
137 fn label(&self) -> Option<Retained<NSString>>;
138
139 /// Setter for [`label`][Self::label].
140 ///
141 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
142 #[unsafe(method(setLabel:))]
143 #[unsafe(method_family = none)]
144 fn setLabel(&self, label: Option<&NSString>);
145
146 /// Declare that all command generation from this encoder is complete, and detach from the MTLCommandBuffer.
147 #[unsafe(method(endEncoding))]
148 #[unsafe(method_family = none)]
149 fn endEncoding(&self);
150
151 /// Encodes a consumer barrier on work you commit to the same command queue.
152 ///
153 /// Encode a barrier that guarantees that any subsequent work you encode in the current command encoder that corresponds
154 /// to the `beforeStages` stages doesn't proceed until Metal completes all work prior to the current command encoder
155 /// corresponding to the `afterQueueStages` stages, completes.
156 ///
157 /// Metal can reorder the exact point where it applies the barrier, so use this method for synchronizing between different passes.
158 ///
159 /// If you need to synchronize work within a pass that you encode with an instance of a subclass of ``MTLCommandEncoder``,
160 /// use memory barriers instead. For subclasses of ``MTL4CommandEncoder``, use encoder barriers.
161 ///
162 /// You can specify `afterQueueStages` and `beforeStages` that contain ``MTLStages`` unrelated to the current command
163 /// encoder.
164 ///
165 /// - Parameters:
166 /// - afterQueueStages: ``MTLStages`` mask that represents the stages of work to wait for.
167 /// This argument applies to work corresponding to these stages you
168 /// encode in prior command encoders, and not for the current encoder.
169 /// - beforeStages: ``MTLStages`` mask that represents the stages of work that wait.
170 /// This argument applies to work you encode in the current command encoder.
171 #[unsafe(method(barrierAfterQueueStages:beforeStages:))]
172 #[unsafe(method_family = none)]
173 fn barrierAfterQueueStages_beforeStages(
174 &self,
175 after_queue_stages: MTLStages,
176 before_stages: MTLStages,
177 );
178
179 /// Inserts a debug string into the command buffer. This does not change any API behavior, but can be useful when debugging.
180 #[unsafe(method(insertDebugSignpost:))]
181 #[unsafe(method_family = none)]
182 fn insertDebugSignpost(&self, string: &NSString);
183
184 /// Push a new named string onto a stack of string labels.
185 #[unsafe(method(pushDebugGroup:))]
186 #[unsafe(method_family = none)]
187 fn pushDebugGroup(&self, string: &NSString);
188
189 /// Pop the latest named string off of the stack.
190 #[unsafe(method(popDebugGroup))]
191 #[unsafe(method_family = none)]
192 fn popDebugGroup(&self);
193 }
194);