objc2_metal/generated/
MTLIOCommandBuffer.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/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtliostatus?language=objc)
11// NS_ENUM
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct MTLIOStatus(pub NSInteger);
15impl MTLIOStatus {
16    #[doc(alias = "MTLIOStatusPending")]
17    pub const Pending: Self = Self(0);
18    #[doc(alias = "MTLIOStatusCancelled")]
19    pub const Cancelled: Self = Self(1);
20    #[doc(alias = "MTLIOStatusError")]
21    pub const Error: Self = Self(2);
22    #[doc(alias = "MTLIOStatusComplete")]
23    pub const Complete: Self = Self(3);
24}
25
26unsafe impl Encode for MTLIOStatus {
27    const ENCODING: Encoding = NSInteger::ENCODING;
28}
29
30unsafe impl RefEncode for MTLIOStatus {
31    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
32}
33
34/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtliocommandbufferhandler?language=objc)
35#[cfg(feature = "block2")]
36pub type MTLIOCommandBufferHandler =
37    *mut block2::DynBlock<dyn Fn(NonNull<ProtocolObject<dyn MTLIOCommandBuffer>>)>;
38
39extern_protocol!(
40    /// represents a list of IO commands for a queue to execute
41    ///
42    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtliocommandbuffer?language=objc)
43    pub unsafe trait MTLIOCommandBuffer: NSObjectProtocol {
44        #[cfg(feature = "block2")]
45        /// Add a block to be called when this command buffer has completed execution.
46        ///
47        /// # Safety
48        ///
49        /// `block` must be a valid pointer.
50        #[unsafe(method(addCompletedHandler:))]
51        #[unsafe(method_family = none)]
52        unsafe fn addCompletedHandler(&self, block: MTLIOCommandBufferHandler);
53
54        #[cfg(feature = "MTLIOCommandQueue")]
55        /// Encodes a command that loads from a handle
56        /// and offset into a memory location.
57        ///
58        /// # Safety
59        ///
60        /// - `pointer` must be a valid pointer.
61        /// - `size` might not be bounds-checked.
62        /// - `sourceHandleOffset` might not be bounds-checked.
63        #[unsafe(method(loadBytes:size:sourceHandle:sourceHandleOffset:))]
64        #[unsafe(method_family = none)]
65        unsafe fn loadBytes_size_sourceHandle_sourceHandleOffset(
66            &self,
67            pointer: NonNull<c_void>,
68            size: NSUInteger,
69            source_handle: &ProtocolObject<dyn MTLIOFileHandle>,
70            source_handle_offset: NSUInteger,
71        );
72
73        #[cfg(all(
74            feature = "MTLAllocation",
75            feature = "MTLBuffer",
76            feature = "MTLIOCommandQueue",
77            feature = "MTLResource"
78        ))]
79        /// Encodes a command that loads from a handle
80        /// and offset into a buffer and an offset.
81        ///
82        /// # Safety
83        ///
84        /// - `buffer` may need to be synchronized.
85        /// - `buffer` may be unretained, you must ensure it is kept alive while in use.
86        /// - `buffer` contents should be of the correct type.
87        /// - `offset` might not be bounds-checked.
88        /// - `size` might not be bounds-checked.
89        /// - `sourceHandleOffset` might not be bounds-checked.
90        #[unsafe(method(loadBuffer:offset:size:sourceHandle:sourceHandleOffset:))]
91        #[unsafe(method_family = none)]
92        unsafe fn loadBuffer_offset_size_sourceHandle_sourceHandleOffset(
93            &self,
94            buffer: &ProtocolObject<dyn MTLBuffer>,
95            offset: NSUInteger,
96            size: NSUInteger,
97            source_handle: &ProtocolObject<dyn MTLIOFileHandle>,
98            source_handle_offset: NSUInteger,
99        );
100
101        #[cfg(all(
102            feature = "MTLAllocation",
103            feature = "MTLIOCommandQueue",
104            feature = "MTLResource",
105            feature = "MTLTexture",
106            feature = "MTLTypes"
107        ))]
108        /// Encodes a command that loads a region from a handle
109        /// and offset into a texture at a given slice, level and origin.
110        ///
111        /// # Safety
112        ///
113        /// - `texture` may need to be synchronized.
114        /// - `texture` may be unretained, you must ensure it is kept alive while in use.
115        /// - `size` might not be bounds-checked.
116        /// - `sourceHandleOffset` might not be bounds-checked.
117        #[unsafe(method(loadTexture:slice:level:size:sourceBytesPerRow:sourceBytesPerImage:destinationOrigin:sourceHandle:sourceHandleOffset:))]
118        #[unsafe(method_family = none)]
119        unsafe fn loadTexture_slice_level_size_sourceBytesPerRow_sourceBytesPerImage_destinationOrigin_sourceHandle_sourceHandleOffset(
120            &self,
121            texture: &ProtocolObject<dyn MTLTexture>,
122            slice: NSUInteger,
123            level: NSUInteger,
124            size: MTLSize,
125            source_bytes_per_row: NSUInteger,
126            source_bytes_per_image: NSUInteger,
127            destination_origin: MTLOrigin,
128            source_handle: &ProtocolObject<dyn MTLIOFileHandle>,
129            source_handle_offset: NSUInteger,
130        );
131
132        #[cfg(all(
133            feature = "MTLAllocation",
134            feature = "MTLBuffer",
135            feature = "MTLResource"
136        ))]
137        /// Encodes a command that writes the status of this commandBuffer upon completion
138        /// to a buffer at a given offset
139        ///
140        /// # Safety
141        ///
142        /// - `buffer` may need to be synchronized.
143        /// - `buffer` may be unretained, you must ensure it is kept alive while in use.
144        /// - `buffer` contents should be of the correct type.
145        /// - `offset` might not be bounds-checked.
146        #[unsafe(method(copyStatusToBuffer:offset:))]
147        #[unsafe(method_family = none)]
148        unsafe fn copyStatusToBuffer_offset(
149            &self,
150            buffer: &ProtocolObject<dyn MTLBuffer>,
151            offset: NSUInteger,
152        );
153
154        /// Commit a command buffer so it can be executed as soon as possible.
155        #[unsafe(method(commit))]
156        #[unsafe(method_family = none)]
157        fn commit(&self);
158
159        /// Synchronously wait for this command buffer to complete.
160        #[unsafe(method(waitUntilCompleted))]
161        #[unsafe(method_family = none)]
162        fn waitUntilCompleted(&self);
163
164        /// request a cancellation of an in-flight command buffer.
165        #[unsafe(method(tryCancel))]
166        #[unsafe(method_family = none)]
167        fn tryCancel(&self);
168
169        /// add a barrier that starts subsequent commands after all
170        /// the previously encoded commands have completed.
171        #[unsafe(method(addBarrier))]
172        #[unsafe(method_family = none)]
173        fn addBarrier(&self);
174
175        /// Push a new named string onto a stack of string labels.
176        #[unsafe(method(pushDebugGroup:))]
177        #[unsafe(method_family = none)]
178        fn pushDebugGroup(&self, string: &NSString);
179
180        /// Pop the latest named string off of the stack.
181        #[unsafe(method(popDebugGroup))]
182        #[unsafe(method_family = none)]
183        fn popDebugGroup(&self);
184
185        /// Append this command buffer to the end of its MTLCommandQueue.
186        #[unsafe(method(enqueue))]
187        #[unsafe(method_family = none)]
188        fn enqueue(&self);
189
190        #[cfg(feature = "MTLEvent")]
191        /// Encodes a command that pauses execution of this command buffer until the specified event reaches a given value.
192        #[unsafe(method(waitForEvent:value:))]
193        #[unsafe(method_family = none)]
194        fn waitForEvent_value(&self, event: &ProtocolObject<dyn MTLSharedEvent>, value: u64);
195
196        #[cfg(feature = "MTLEvent")]
197        /// Encodes a command that signals an event with a given value.
198        #[unsafe(method(signalEvent:value:))]
199        #[unsafe(method_family = none)]
200        fn signalEvent_value(&self, event: &ProtocolObject<dyn MTLSharedEvent>, value: u64);
201
202        /// An optional label for this handle.
203        #[unsafe(method(label))]
204        #[unsafe(method_family = none)]
205        fn label(&self) -> Option<Retained<NSString>>;
206
207        /// Setter for [`label`][Self::label].
208        ///
209        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
210        #[unsafe(method(setLabel:))]
211        #[unsafe(method_family = none)]
212        fn setLabel(&self, label: Option<&NSString>);
213
214        /// status reports the completion status of the MTLIOCommandBuffer, pending, cancelled, error or complete.
215        #[unsafe(method(status))]
216        #[unsafe(method_family = none)]
217        fn status(&self) -> MTLIOStatus;
218
219        /// If an error occurred during execution, the NSError may contain more details about the problem.
220        #[unsafe(method(error))]
221        #[unsafe(method_family = none)]
222        fn error(&self) -> Option<Retained<NSError>>;
223    }
224);