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