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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//! 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::*;
/// Represents a timestamp data entry in a counter heap of type `MTL4CounterHeapTypeTimestamp`.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4timestampheapentry?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MTL4TimestampHeapEntry {
pub timestamp: u64,
}
unsafe impl Encode for MTL4TimestampHeapEntry {
const ENCODING: Encoding = Encoding::Struct("?", &[<u64>::ENCODING]);
}
unsafe impl RefEncode for MTL4TimestampHeapEntry {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Defines the type of a ``MTL4CounterHeap`` and the contents of its entries.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4counterheaptype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4CounterHeapType(pub NSInteger);
impl MTL4CounterHeapType {
/// Specifies that ``MTL4CounterHeap`` entries contain invalid data.
#[doc(alias = "MTL4CounterHeapTypeInvalid")]
pub const Invalid: Self = Self(0);
/// Specifies that ``MTL4CounterHeap`` entries contain GPU timestamp data.
#[doc(alias = "MTL4CounterHeapTypeTimestamp")]
pub const Timestamp: Self = Self(1);
}
unsafe impl Encode for MTL4CounterHeapType {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MTL4CounterHeapType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Provides a hint to the system about the desired accuracy when writing GPU counter timestamps.
///
/// Pass these values to ``MTL4ComputeCommandEncoder/writeTimestampWithGranularity:intoHeap:atIndex:`` and
/// ``MTL4RenderCommandEncoder/writeTimestampWithGranularity:afterStage:intoHeap:atIndex:`` to control the
/// desired accurracy of the counter sampling operation.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4timestampgranularity?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4TimestampGranularity(pub NSInteger);
impl MTL4TimestampGranularity {
/// A minimally-invasive timestamp which may be less precise.
///
/// Using this granularity incurs in the lowest overhead, at the cost of precision. For example, it may sample at
/// command encoder boundaries.
#[doc(alias = "MTL4TimestampGranularityRelaxed")]
pub const Relaxed: Self = Self(0);
/// A timestamp as precise as possible.
///
/// Using this granularity may incur in a performance penalty, for example, it may cause splitting of command encoders.
#[doc(alias = "MTL4TimestampGranularityPrecise")]
pub const Precise: Self = Self(1);
}
unsafe impl Encode for MTL4TimestampGranularity {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MTL4TimestampGranularity {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
/// Groups together parameters for configuring a counter heap object at creation time.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4counterheapdescriptor?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTL4CounterHeapDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTL4CounterHeapDescriptor {}
);
unsafe impl CopyingHelper for MTL4CounterHeapDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTL4CounterHeapDescriptor {}
);
impl MTL4CounterHeapDescriptor {
extern_methods!(
/// Assigns the type of data that the heap contains.
#[unsafe(method(type))]
#[unsafe(method_family = none)]
pub fn r#type(&self) -> MTL4CounterHeapType;
/// Setter for [`type`][Self::type].
#[unsafe(method(setType:))]
#[unsafe(method_family = none)]
pub fn setType(&self, r#type: MTL4CounterHeapType);
/// Assigns the number of entries in the heap.
///
/// Each entry represents one item in the heap. The size of the individual entries depends on the heap type.
#[unsafe(method(count))]
#[unsafe(method_family = none)]
pub fn count(&self) -> NSUInteger;
/// Setter for [`count`][Self::count].
///
/// # Safety
///
/// This might not be bounds-checked.
#[unsafe(method(setCount:))]
#[unsafe(method_family = none)]
pub unsafe fn setCount(&self, count: NSUInteger);
);
}
/// Methods declared on superclass `NSObject`.
impl MTL4CounterHeapDescriptor {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new() -> Retained<Self>;
);
}
impl DefaultRetained for MTL4CounterHeapDescriptor {
#[inline]
fn default_retained() -> Retained<Self> {
Self::new()
}
}
extern_protocol!(
/// Represents an opaque, driver-controlled section of memory that can store GPU counter data.
///
/// The data instances that this type stores correspond to the ``MTL4CounterHeapType`` heap type that you assign at creation time.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4counterheap?language=objc)
pub unsafe trait MTL4CounterHeap: NSObjectProtocol {
/// Assigns a label for later inspection or visualization.
#[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>);
/// Queries the number of entries in the heap.
#[unsafe(method(count))]
#[unsafe(method_family = none)]
fn count(&self) -> NSUInteger;
/// Queries the type of the heap.
#[unsafe(method(type))]
#[unsafe(method_family = none)]
fn r#type(&self) -> MTL4CounterHeapType;
/// Resolves heap data on the CPU timeline.
///
/// This method resolves heap data in the CPU timeline. Your app needs to ensure the GPU work has completed in order to
/// retrieve the data correctly. You can alternatively resolve the heap data in the GPU timeline by calling
/// ``MTL4CommandBuffer/resolveCounterHeap:withRange:intoBuffer:waitFence:updateFence:``.
///
/// - Note: When resolving counters in the CPU timeline, signaling an instance of ``MTLSharedEvent`` after any workloads
/// write counters (and waiting on that signal on the CPU) is sufficient to ensure synchronization.
///
/// - Parameter range: The range in the heap to resolve.
/// - Returns a newly allocated autoreleased NSData containing tightly packed resolved heap counter values.
///
/// # Safety
///
/// `range` might not be bounds-checked.
#[unsafe(method(resolveCounterRange:))]
#[unsafe(method_family = none)]
unsafe fn resolveCounterRange(&self, range: NSRange) -> Option<Retained<NSData>>;
/// Invalidates a range of entries in this counter heap.
///
/// The effect of this call is immediate on the CPU timeline. You are responsible for ensuring that this counter heap is not currently in use on the GPU.
///
/// - Note: Invalidated entries produce 0 when resolved.
///
/// - Parameters:
/// - range: A heap index range to invalidate.
///
/// # Safety
///
/// `range` might not be bounds-checked.
#[unsafe(method(invalidateCounterRange:))]
#[unsafe(method_family = none)]
unsafe fn invalidateCounterRange(&self, range: NSRange);
}
);