objc2_metal_fx/generated/
MTLFXSpatialScaler.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::*;
7use objc2_metal::*;
8
9use crate::*;
10
11/// The color space modes for the input and output textures you use with a spatial scaling effect instance.
12///
13/// See also [Apple's documentation](https://developer.apple.com/documentation/metalfx/mtlfxspatialscalercolorprocessingmode?language=objc)
14// NS_ENUM
15#[repr(transparent)]
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
17pub struct MTLFXSpatialScalerColorProcessingMode(pub NSInteger);
18impl MTLFXSpatialScalerColorProcessingMode {
19    /// Indicates your input and output textures use a perceptual color space (sRGB).
20    #[doc(alias = "MTLFXSpatialScalerColorProcessingModePerceptual")]
21    pub const Perceptual: Self = Self(0);
22    /// Indicates your input and output textures use a linear color space in the `[0,1]` range.
23    #[doc(alias = "MTLFXSpatialScalerColorProcessingModeLinear")]
24    pub const Linear: Self = Self(1);
25    /// Indicates your input and output textures use a high dynamic range color space, beyond the `[0,1]` range.
26    ///
27    /// When you configure this mode, MetalFX performs a reversible tone mapping operation to convert your data to the `[0,1]` range.
28    #[doc(alias = "MTLFXSpatialScalerColorProcessingModeHDR")]
29    pub const HDR: Self = Self(2);
30}
31
32unsafe impl Encode for MTLFXSpatialScalerColorProcessingMode {
33    const ENCODING: Encoding = NSInteger::ENCODING;
34}
35
36unsafe impl RefEncode for MTLFXSpatialScalerColorProcessingMode {
37    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40extern_class!(
41    /// A set of properties that configure a spatial scaling effect, and a factory method that creates the effect.
42    ///
43    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalfx/mtlfxspatialscalerdescriptor?language=objc)
44    #[unsafe(super(NSObject))]
45    #[derive(Debug, PartialEq, Eq, Hash)]
46    pub struct MTLFXSpatialScalerDescriptor;
47);
48
49extern_conformance!(
50    unsafe impl NSCopying for MTLFXSpatialScalerDescriptor {}
51);
52
53unsafe impl CopyingHelper for MTLFXSpatialScalerDescriptor {
54    type Result = Self;
55}
56
57extern_conformance!(
58    unsafe impl NSObjectProtocol for MTLFXSpatialScalerDescriptor {}
59);
60
61impl MTLFXSpatialScalerDescriptor {
62    extern_methods!(
63        /// The pixel format of the input color texture for the spatial scaler you create with this descriptor.
64        #[unsafe(method(colorTextureFormat))]
65        #[unsafe(method_family = none)]
66        pub unsafe fn colorTextureFormat(&self) -> MTLPixelFormat;
67
68        /// Setter for [`colorTextureFormat`][Self::colorTextureFormat].
69        #[unsafe(method(setColorTextureFormat:))]
70        #[unsafe(method_family = none)]
71        pub unsafe fn setColorTextureFormat(&self, color_texture_format: MTLPixelFormat);
72
73        /// The pixel format of the output texture for the spatial scaler you create with this descriptor.
74        #[unsafe(method(outputTextureFormat))]
75        #[unsafe(method_family = none)]
76        pub unsafe fn outputTextureFormat(&self) -> MTLPixelFormat;
77
78        /// Setter for [`outputTextureFormat`][Self::outputTextureFormat].
79        #[unsafe(method(setOutputTextureFormat:))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn setOutputTextureFormat(&self, output_texture_format: MTLPixelFormat);
82
83        /// The width of the input color texture for the spatial scaler you create with this descriptor.
84        #[unsafe(method(inputWidth))]
85        #[unsafe(method_family = none)]
86        pub unsafe fn inputWidth(&self) -> NSUInteger;
87
88        /// Setter for [`inputWidth`][Self::inputWidth].
89        #[unsafe(method(setInputWidth:))]
90        #[unsafe(method_family = none)]
91        pub unsafe fn setInputWidth(&self, input_width: NSUInteger);
92
93        /// The height of the input color texture for the spatial scaler you create with this descriptor.
94        #[unsafe(method(inputHeight))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn inputHeight(&self) -> NSUInteger;
97
98        /// Setter for [`inputHeight`][Self::inputHeight].
99        #[unsafe(method(setInputHeight:))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn setInputHeight(&self, input_height: NSUInteger);
102
103        /// The width of the output color texture for the spatial scaler you create with this descriptor.
104        #[unsafe(method(outputWidth))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn outputWidth(&self) -> NSUInteger;
107
108        /// Setter for [`outputWidth`][Self::outputWidth].
109        #[unsafe(method(setOutputWidth:))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn setOutputWidth(&self, output_width: NSUInteger);
112
113        /// The height of the output color texture for the spatial scaler you create with this descriptor.
114        #[unsafe(method(outputHeight))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn outputHeight(&self) -> NSUInteger;
117
118        /// Setter for [`outputHeight`][Self::outputHeight].
119        #[unsafe(method(setOutputHeight:))]
120        #[unsafe(method_family = none)]
121        pub unsafe fn setOutputHeight(&self, output_height: NSUInteger);
122
123        /// The color space of the input color texture for the spatial scaler you create with this descriptor.
124        ///
125        /// This property's default value is ``MTLFXSpatialScalerColorProcessingMode/MTLFXSpatialScalerColorProcessingModePerceptual``.
126        #[unsafe(method(colorProcessingMode))]
127        #[unsafe(method_family = none)]
128        pub unsafe fn colorProcessingMode(&self) -> MTLFXSpatialScalerColorProcessingMode;
129
130        /// Setter for [`colorProcessingMode`][Self::colorProcessingMode].
131        #[unsafe(method(setColorProcessingMode:))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn setColorProcessingMode(
134            &self,
135            color_processing_mode: MTLFXSpatialScalerColorProcessingMode,
136        );
137
138        /// Creates a spatial scaler instance for a Metal device.
139        ///
140        /// - Parameters:
141        /// - device: The Metal device that creates the spatial scaler.
142        /// - Returns:
143        /// A new spatial scaler instance upon success, or `nil` otherwise.
144        #[unsafe(method(newSpatialScalerWithDevice:))]
145        #[unsafe(method_family = new)]
146        pub unsafe fn newSpatialScalerWithDevice(
147            &self,
148            device: &ProtocolObject<dyn MTLDevice>,
149        ) -> Option<Retained<ProtocolObject<dyn MTLFXSpatialScaler>>>;
150
151        #[cfg(feature = "MTL4FXSpatialScaler")]
152        /// Creates a spatial scaler instance for a Metal device.
153        ///
154        /// - Parameters:
155        /// - device: The Metal device that creates the spatial scaler.
156        /// - compiler: A compiler instance this method can use to build pipeline state objects.
157        /// - Returns:
158        /// A new spatial scaler instance upon success, or `nil` otherwise.
159        #[unsafe(method(newSpatialScalerWithDevice:compiler:))]
160        #[unsafe(method_family = new)]
161        pub unsafe fn newSpatialScalerWithDevice_compiler(
162            &self,
163            device: &ProtocolObject<dyn MTLDevice>,
164            compiler: &ProtocolObject<dyn MTL4Compiler>,
165        ) -> Option<Retained<ProtocolObject<dyn MTL4FXSpatialScaler>>>;
166
167        /// Queries whether a Metal device supports spatial scaling compatible with Metal 4.
168        ///
169        /// - Parameters:
170        /// - device: The GPU device for which this methods tests support.
171        ///
172        /// - Returns:
173        /// <doc
174        /// ://com.apple.documentation/documentation/swift/true> if the device supports spatial scaling with
175        /// Metal 4,
176        /// <doc
177        /// ://com.apple.documentation/documentation/swift/false> otherwise.
178        #[unsafe(method(supportsMetal4FX:))]
179        #[unsafe(method_family = none)]
180        pub unsafe fn supportsMetal4FX(device: &ProtocolObject<dyn MTLDevice>) -> bool;
181
182        /// Returns a Boolean value that indicates whether the spatial scaler works with a GPU.
183        ///
184        /// - Parameters:
185        /// - device: An ``MTLDevice`` instance that represents a GPU.
186        ///
187        /// - Returns:
188        /// <doc
189        /// ://com.apple.documentation/documentation/swift/true> if the device supports spatial scaling,
190        /// <doc
191        /// ://com.apple.documentation/documentation/swift/false> otherwise.
192        #[unsafe(method(supportsDevice:))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn supportsDevice(device: &ProtocolObject<dyn MTLDevice>) -> bool;
195    );
196}
197
198/// Methods declared on superclass `NSObject`.
199impl MTLFXSpatialScalerDescriptor {
200    extern_methods!(
201        #[unsafe(method(init))]
202        #[unsafe(method_family = init)]
203        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
204
205        #[unsafe(method(new))]
206        #[unsafe(method_family = new)]
207        pub unsafe fn new() -> Retained<Self>;
208    );
209}
210
211extern_protocol!(
212    /// An upscaling effect that generates a higher resolution texture in a render pass by spatially analyzing an input texture.
213    ///
214    /// The MetalFX spatial scaler increases the size of your input texture to a larger output texture. You can use the
215    /// scaler to upscale every frame of your app’s scene or rendering in real time. With a scaler, you can draw more
216    /// complicated scenes in less time by intentionally rendering to a lower resolution to save time before upscaling.
217    ///
218    /// Create an ``MTLFXSpatialScaler`` instance following these steps:
219    /// 1. Create and configure an ``MTLFXSpatialScalerDescriptor`` instance.
220    /// 2. Call the descriptor’s ``newSpatialScalerWithDevice:`` method.
221    ///
222    /// Upscale a rendering by following these steps for every render pass:
223    /// 1. Set the spatial scaler’s ``colorTexture`` property to the input texture.
224    /// 2. Set the scaler’s ``inputContentWidth`` and ``inputContentHeight`` properties.
225    /// 3. Set the scaler’s ``outputTexture`` property to your destination texture.
226    ///
227    /// Encode the upscale commands to a command buffer by calling the spatial scaler’s ``encodeToCommandBuffer:`` method.
228    ///
229    /// ## Conforming to texture usage requirements
230    ///
231    /// Spatial scalers expose properties, such as ``colorTextureUsage``, that indicate requirements for
232    /// your textures to be compatible with it. These properties indicate the minimum set of ``MTLTextureUsage`` bits
233    /// that you are responsible for setting in your texture descriptors for this spatial scaler to use them.
234    ///
235    /// Your game or app can set extra usage bits on your textures without losing compatibility, as long at its maintains
236    /// the minimum set the scaler requests.
237    ///
238    /// ## Assigning input and output textures
239    ///
240    /// When you use an instance of a class that conforms to this protocol, you typically set its input and output textures,
241    /// as well as other properties, and then encode its work to a command buffer.
242    ///
243    /// MetalFX doesn't track that you assign the same texture instances to each property across different batches of work,
244    /// the only requirement is that you provide textures that match the pixel formats and dimensions you specify in the
245    /// ``MTLFXSpatialScalerDescriptor`` descriptor instance that creates the scaler instance.
246    ///
247    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalfx/mtlfxspatialscalerbase?language=objc)
248    pub unsafe trait MTLFXSpatialScalerBase: NSObjectProtocol {
249        /// The minimal texture usage options that your app’s input color texture needs in order to support this scaler.
250        #[unsafe(method(colorTextureUsage))]
251        #[unsafe(method_family = none)]
252        unsafe fn colorTextureUsage(&self) -> MTLTextureUsage;
253
254        /// The minimal texture usage options that your app’s output color texture needs in order to support this scaler.
255        #[unsafe(method(outputTextureUsage))]
256        #[unsafe(method_family = none)]
257        unsafe fn outputTextureUsage(&self) -> MTLTextureUsage;
258
259        /// The width, in pixels, of the region within the color texture the scaler uses as its input.
260        #[unsafe(method(inputContentWidth))]
261        #[unsafe(method_family = none)]
262        unsafe fn inputContentWidth(&self) -> NSUInteger;
263
264        /// Setter for [`inputContentWidth`][Self::inputContentWidth].
265        #[unsafe(method(setInputContentWidth:))]
266        #[unsafe(method_family = none)]
267        unsafe fn setInputContentWidth(&self, input_content_width: NSUInteger);
268
269        /// The height, in pixels, of the region within the color texture the scaler uses as its input.
270        #[unsafe(method(inputContentHeight))]
271        #[unsafe(method_family = none)]
272        unsafe fn inputContentHeight(&self) -> NSUInteger;
273
274        /// Setter for [`inputContentHeight`][Self::inputContentHeight].
275        #[unsafe(method(setInputContentHeight:))]
276        #[unsafe(method_family = none)]
277        unsafe fn setInputContentHeight(&self, input_content_height: NSUInteger);
278
279        /// Input color texture you set for the scaler that supports the correct color texture usage options.
280        #[unsafe(method(colorTexture))]
281        #[unsafe(method_family = none)]
282        unsafe fn colorTexture(&self) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
283
284        /// Setter for [`colorTexture`][Self::colorTexture].
285        ///
286        /// # Safety
287        ///
288        /// - `color_texture` may need to be synchronized.
289        /// - `color_texture` may be unretained, you must ensure it is kept alive while in use.
290        #[unsafe(method(setColorTexture:))]
291        #[unsafe(method_family = none)]
292        unsafe fn setColorTexture(&self, color_texture: Option<&ProtocolObject<dyn MTLTexture>>);
293
294        /// The output texture into which this scaler writes its output.
295        ///
296        /// You are responsible for providing a texture with a private `storageMode` to this property.
297        #[unsafe(method(outputTexture))]
298        #[unsafe(method_family = none)]
299        unsafe fn outputTexture(&self) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
300
301        /// Setter for [`outputTexture`][Self::outputTexture].
302        ///
303        /// # Safety
304        ///
305        /// - `output_texture` may need to be synchronized.
306        /// - `output_texture` may be unretained, you must ensure it is kept alive while in use.
307        #[unsafe(method(setOutputTexture:))]
308        #[unsafe(method_family = none)]
309        unsafe fn setOutputTexture(&self, output_texture: Option<&ProtocolObject<dyn MTLTexture>>);
310
311        /// The pixel format of the input color texture for this this scaler.
312        #[unsafe(method(colorTextureFormat))]
313        #[unsafe(method_family = none)]
314        unsafe fn colorTextureFormat(&self) -> MTLPixelFormat;
315
316        /// The pixel format of the output color texture for this this scaler.
317        #[unsafe(method(outputTextureFormat))]
318        #[unsafe(method_family = none)]
319        unsafe fn outputTextureFormat(&self) -> MTLPixelFormat;
320
321        /// The width, in pixels, of the input color texture for this scaler.
322        #[unsafe(method(inputWidth))]
323        #[unsafe(method_family = none)]
324        unsafe fn inputWidth(&self) -> NSUInteger;
325
326        /// The height, in pixels, of the input color texture for this scaler.
327        #[unsafe(method(inputHeight))]
328        #[unsafe(method_family = none)]
329        unsafe fn inputHeight(&self) -> NSUInteger;
330
331        /// The width, in pixels, of the output color texture for this scaler.
332        #[unsafe(method(outputWidth))]
333        #[unsafe(method_family = none)]
334        unsafe fn outputWidth(&self) -> NSUInteger;
335
336        /// The height, in pixels, of the output color texture for this scaler.
337        #[unsafe(method(outputHeight))]
338        #[unsafe(method_family = none)]
339        unsafe fn outputHeight(&self) -> NSUInteger;
340
341        /// The color processing mode you set in this spatial scaler’s descriptor.
342        #[unsafe(method(colorProcessingMode))]
343        #[unsafe(method_family = none)]
344        unsafe fn colorProcessingMode(&self) -> MTLFXSpatialScalerColorProcessingMode;
345
346        /// An optional fence that you provide to synchronize your app’s untracked resources.
347        #[unsafe(method(fence))]
348        #[unsafe(method_family = none)]
349        unsafe fn fence(&self) -> Option<Retained<ProtocolObject<dyn MTLFence>>>;
350
351        /// Setter for [`fence`][Self::fence].
352        #[unsafe(method(setFence:))]
353        #[unsafe(method_family = none)]
354        unsafe fn setFence(&self, fence: Option<&ProtocolObject<dyn MTLFence>>);
355    }
356);
357
358extern_protocol!(
359    /// An upscaling effect that generates a higher resolution texture in a render pass by spatially analyzing an input texture.
360    ///
361    /// You create instances of this class by calling ``MTLFXSpatialScalerDescriptor/newSpatialScalerWithDevice:``.
362    ///
363    /// When using instances of objects conforming to this protocol, you configure the different properties it
364    /// inherits from protocol ``MTLFXSpatialScalerBase`` and then call ``encodeToCommandBuffer:`` to
365    /// encode its work into a Metal command buffer.
366    ///
367    /// See ``MTLFXSpatialScalerBase`` for more details on configuring and using spatial scalers.
368    ///
369    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalfx/mtlfxspatialscaler?language=objc)
370    pub unsafe trait MTLFXSpatialScaler: MTLFXSpatialScalerBase {
371        /// Encode this spatial scaler work into a command buffer.
372        ///
373        /// - Parameters:
374        /// - commandBuffer: A command buffer into which this spatial scaler encodes work.
375        #[unsafe(method(encodeToCommandBuffer:))]
376        #[unsafe(method_family = none)]
377        unsafe fn encodeToCommandBuffer(
378            &self,
379            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
380        );
381    }
382);