objc2_metal/generated/
MTL4Counters.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/// Represents a timestamp data entry in a counter heap of type `MTL4CounterHeapTypeTimestamp`.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4timestampheapentry?language=objc)
13#[repr(C)]
14#[derive(Clone, Copy, Debug, PartialEq)]
15pub struct MTL4TimestampHeapEntry {
16    pub timestamp: u64,
17}
18
19unsafe impl Encode for MTL4TimestampHeapEntry {
20    const ENCODING: Encoding = Encoding::Struct("?", &[<u64>::ENCODING]);
21}
22
23unsafe impl RefEncode for MTL4TimestampHeapEntry {
24    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
25}
26
27/// Defines the type of a ``MTL4CounterHeap`` and the contents of its entries.
28///
29/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4counterheaptype?language=objc)
30// NS_ENUM
31#[repr(transparent)]
32#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
33pub struct MTL4CounterHeapType(pub NSInteger);
34impl MTL4CounterHeapType {
35    /// Specifies that ``MTL4CounterHeap`` entries contain invalid data.
36    #[doc(alias = "MTL4CounterHeapTypeInvalid")]
37    pub const Invalid: Self = Self(0);
38    /// Specifies that ``MTL4CounterHeap`` entries contain GPU timestamp data.
39    #[doc(alias = "MTL4CounterHeapTypeTimestamp")]
40    pub const Timestamp: Self = Self(1);
41}
42
43unsafe impl Encode for MTL4CounterHeapType {
44    const ENCODING: Encoding = NSInteger::ENCODING;
45}
46
47unsafe impl RefEncode for MTL4CounterHeapType {
48    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
49}
50
51/// Provides a hint to the system about the desired accuracy when writing GPU counter timestamps.
52///
53/// Pass these values to ``MTL4ComputeCommandEncoder/writeTimestampWithGranularity:intoHeap:atIndex:`` and
54/// ``MTL4RenderCommandEncoder/writeTimestampWithGranularity:afterStage:intoHeap:atIndex:`` to control the
55/// desired accurracy of the counter sampling operation.
56///
57/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4timestampgranularity?language=objc)
58// NS_ENUM
59#[repr(transparent)]
60#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
61pub struct MTL4TimestampGranularity(pub NSInteger);
62impl MTL4TimestampGranularity {
63    /// A minimally-invasive timestamp which may be less precise.
64    ///
65    /// Using this granularity incurs in the lowest overhead, at the cost of precision. For example, it may sample at
66    /// command encoder boundaries.
67    #[doc(alias = "MTL4TimestampGranularityRelaxed")]
68    pub const Relaxed: Self = Self(0);
69    /// A timestamp as precise as possible.
70    ///
71    /// Using this granularity may incur in a performance penalty, for example, it may cause splitting of command encoders.
72    #[doc(alias = "MTL4TimestampGranularityPrecise")]
73    pub const Precise: Self = Self(1);
74}
75
76unsafe impl Encode for MTL4TimestampGranularity {
77    const ENCODING: Encoding = NSInteger::ENCODING;
78}
79
80unsafe impl RefEncode for MTL4TimestampGranularity {
81    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
82}
83
84extern_class!(
85    /// Groups together parameters for configuring a counter heap object at creation time.
86    ///
87    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4counterheapdescriptor?language=objc)
88    #[unsafe(super(NSObject))]
89    #[derive(Debug, PartialEq, Eq, Hash)]
90    pub struct MTL4CounterHeapDescriptor;
91);
92
93extern_conformance!(
94    unsafe impl NSCopying for MTL4CounterHeapDescriptor {}
95);
96
97unsafe impl CopyingHelper for MTL4CounterHeapDescriptor {
98    type Result = Self;
99}
100
101extern_conformance!(
102    unsafe impl NSObjectProtocol for MTL4CounterHeapDescriptor {}
103);
104
105impl MTL4CounterHeapDescriptor {
106    extern_methods!(
107        /// Assigns the type of data that the heap contains.
108        #[unsafe(method(type))]
109        #[unsafe(method_family = none)]
110        pub fn r#type(&self) -> MTL4CounterHeapType;
111
112        /// Setter for [`type`][Self::type].
113        #[unsafe(method(setType:))]
114        #[unsafe(method_family = none)]
115        pub fn setType(&self, r#type: MTL4CounterHeapType);
116
117        /// Assigns the number of entries in the heap.
118        ///
119        /// Each entry represents one item in the heap. The size of the individual entries depends on the heap type.
120        #[unsafe(method(count))]
121        #[unsafe(method_family = none)]
122        pub fn count(&self) -> NSUInteger;
123
124        /// Setter for [`count`][Self::count].
125        ///
126        /// # Safety
127        ///
128        /// This might not be bounds-checked.
129        #[unsafe(method(setCount:))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn setCount(&self, count: NSUInteger);
132    );
133}
134
135/// Methods declared on superclass `NSObject`.
136impl MTL4CounterHeapDescriptor {
137    extern_methods!(
138        #[unsafe(method(init))]
139        #[unsafe(method_family = init)]
140        pub fn init(this: Allocated<Self>) -> Retained<Self>;
141
142        #[unsafe(method(new))]
143        #[unsafe(method_family = new)]
144        pub fn new() -> Retained<Self>;
145    );
146}
147
148impl DefaultRetained for MTL4CounterHeapDescriptor {
149    #[inline]
150    fn default_retained() -> Retained<Self> {
151        Self::new()
152    }
153}
154
155extern_protocol!(
156    /// Represents an opaque, driver-controlled section of memory that can store GPU counter data.
157    ///
158    /// The data instances that this type stores correspond to the ``MTL4CounterHeapType`` heap type that you assign at creation time.
159    ///
160    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4counterheap?language=objc)
161    pub unsafe trait MTL4CounterHeap: NSObjectProtocol {
162        /// Assigns a label for later inspection or visualization.
163        #[unsafe(method(label))]
164        #[unsafe(method_family = none)]
165        fn label(&self) -> Option<Retained<NSString>>;
166
167        /// Setter for [`label`][Self::label].
168        ///
169        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
170        #[unsafe(method(setLabel:))]
171        #[unsafe(method_family = none)]
172        fn setLabel(&self, label: Option<&NSString>);
173
174        /// Queries the number of entries in the heap.
175        #[unsafe(method(count))]
176        #[unsafe(method_family = none)]
177        fn count(&self) -> NSUInteger;
178
179        /// Queries the type of the heap.
180        #[unsafe(method(type))]
181        #[unsafe(method_family = none)]
182        fn r#type(&self) -> MTL4CounterHeapType;
183
184        /// Resolves heap data on the CPU timeline.
185        ///
186        /// This method resolves heap data in the CPU timeline. Your app needs to ensure the GPU work has completed in order to
187        /// retrieve the data correctly. You can alternatively resolve the heap data in the GPU timeline by calling
188        /// ``MTL4CommandBuffer/resolveCounterHeap:withRange:intoBuffer:waitFence:updateFence:``.
189        ///
190        /// - Note: When resolving counters in the CPU timeline, signaling an instance of ``MTLSharedEvent`` after any workloads
191        /// write counters (and waiting on that signal on the CPU) is sufficient to ensure synchronization.
192        ///
193        /// - Parameter range: The range in the heap to resolve.
194        /// - Returns a newly allocated autoreleased NSData containing tightly packed resolved heap counter values.
195        ///
196        /// # Safety
197        ///
198        /// `range` might not be bounds-checked.
199        #[unsafe(method(resolveCounterRange:))]
200        #[unsafe(method_family = none)]
201        unsafe fn resolveCounterRange(&self, range: NSRange) -> Option<Retained<NSData>>;
202
203        /// Invalidates a range of entries in this counter heap.
204        ///
205        /// 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.
206        ///
207        /// - Note: Invalidated entries produce 0 when resolved.
208        ///
209        /// - Parameters:
210        /// - range: A heap index range to invalidate.
211        ///
212        /// # Safety
213        ///
214        /// `range` might not be bounds-checked.
215        #[unsafe(method(invalidateCounterRange:))]
216        #[unsafe(method_family = none)]
217        unsafe fn invalidateCounterRange(&self, range: NSRange);
218    }
219);