objc2_metal_performance_shaders/generated/MPSRayIntersector/
MPSInstanceAccelerationStructure.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/// Instance transformation type options
12///
13/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpstransformtype?language=objc)
14// NS_ENUM
15#[repr(transparent)]
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
17pub struct MPSTransformType(pub NSUInteger);
18impl MPSTransformType {
19    /// Instance transformations are represented by a 4x4 column major matrix of 32 bit
20    /// floats
21    #[doc(alias = "MPSTransformTypeFloat4x4")]
22    pub const Float4x4: Self = Self(0);
23    /// All instances have the identity transformation (no transformation). This can be used
24    /// to compose multiple polygon acceleration structures in an instance acceleration structure
25    /// without the cost of transforming instances. For example, geometry can be divided into
26    /// static and dynamic polygon acceleration structures which can be rebuilt and refit
27    /// independently.
28    #[doc(alias = "MPSTransformTypeIdentity")]
29    pub const Identity: Self = Self(1);
30}
31
32unsafe impl Encode for MPSTransformType {
33    const ENCODING: Encoding = NSUInteger::ENCODING;
34}
35
36unsafe impl RefEncode for MPSTransformType {
37    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40extern_class!(
41    /// An acceleration structure built over instances of other acceleration structures
42    ///
43    ///
44    /// Instancing can be used to reduce memory usage in scenes that contain many copies
45    /// of the same object(s) or to combine multiple acceleration structures such as a static and
46    /// dynamic acceleration structure into a two-level instance hierarchy.
47    ///
48    /// The typical pattern for creating an instance acceleration structure is as follows. First,
49    /// create individual bottom-level acceleration structures. Then assign these acceleration
50    /// structures to the accelerationStructures property of an instance acceleration structure.
51    ///
52    /// All of the acceleration structures in the instance hierarchy must share the same
53    /// MPSAccelerationStructureGroup. Furthermore, all of the bottom-level acceleration structures
54    /// must share the same vertex buffer, index buffer, etc. although they may have different offsets
55    /// within those buffers.
56    ///
57    ///
58    /// ```text
59    ///      MPSAccelerationStructureGroup *group = nil;
60    ///      group = [[MPSAccelerationStructureGroup alloc] initWithDevice:device];
61    ///
62    ///      MPSInstanceAccelerationStructure *instanceAccel = nil;
63    ///      instanceAccel = [[MPSInstanceAccelerationStructure alloc] initWithGroup:group];
64    ///
65    ///      NSMutableArray *accelerationStructures = [NSMutableArray array];
66    ///      instanceAccel.accelerationStructures = accelerationStructures;
67    ///
68    ///      instanceAccel.instanceCount = instanceCount;
69    ///
70    ///      for (ObjectType *objectType in objectTypes) {
71    ///          MPSTriangleAccelerationStructure *triAccel = nil;
72    ///          triAccel = [[MPSTriangleAccelerationStructure alloc] initWithGroup:group];
73    ///
74    ///          triAccel.vertexBuffer = objectType.vertexBuffer;
75    ///          triAccel.vertexBufferOffset = objectType.vertexBufferOffset;
76    ///          triAccel.triangleCount = objectType.triangleCount;
77    ///
78    ///          [triAccel rebuild];
79    ///
80    ///          [accelerationStructures addObject:triAccel];
81    ///      }
82    /// ```
83    ///
84    /// Next, create a buffer containing the acceleration structure index for each instance, and
85    /// another acceleration structure containing the transformation matrix for each instance:
86    ///
87    ///
88    /// ```text
89    ///      NSUInteger instanceBufferLength = sizeof(uint32_t) * instanceCount;
90    ///     
91    ///      id <MTLBuffer> instanceBuffer =
92    ///          [device newBufferWithLength:instanceBufferLength
93    ///                              options:MTLResourceStorageModeManaged];
94    ///     
95    ///      memcpy(instanceBuffer.contents, instances,
96    ///          instanceBufferLength);
97    ///      [instanceBuffer
98    ///          didModifyRange:NSMakeRange(0, instanceBufferLength)];
99    ///     
100    ///      instanceAccel.instanceBuffer = instanceBuffer;
101    ///
102    ///      // Similar for transformation matrix buffer
103    /// ```
104    ///
105    /// Finally, rebuild the instance acceleration structure:
106    ///
107    ///
108    /// ```text
109    ///      [instanceAccel rebuild];
110    /// ```
111    ///
112    /// Refitting and Rebuilding Bottom-Level Acceleration Structures: when a bottom level acceleration
113    /// structure is rebuild or refit, its' bounding box may change. Therefore, the instance
114    /// acceleration structure also needs to be rebuilt or refit.
115    ///
116    /// Copying and Serializing Instance Acceleration Structures: When an instance acceleration
117    /// structure is copied or serialized, the bottom level acceleration structures are not copied or
118    /// serialized. These must be copied or serialized along with the instance acceleration structure
119    /// and assigned to the new instance acceleration structure. This also applies to buffer properties
120    /// such as the instance buffer, transformation buffer, etc.
121    ///
122    /// Performance Guidelines:
123    ///
124    /// - Use instancing to reduce memory usage: if there are many copies of the same object(s) in
125    /// a scene, using instances of the same object can reduce memory usage and acceleration
126    /// structure build time. Rebuilding or refitting the top level acceleration structure can
127    /// also be much faster than rebuilding a large single level acceleration structure.
128    ///
129    /// - Consider flattening your instance hierarchy into a single acceleration structure if the
130    /// increased memory usage and acceleration structure build time are not a concern.
131    /// Intersecting a two level acceleration structure can have a significant performance cost so
132    /// only use it when necessary. Which technique to use depends on the scene and use case. For
133    /// example, in a rendering application, it may be best to use an instance hierarchy for
134    /// interactive scene editing and preview and flattening the instance hierarchy for the final
135    /// render. For smaller scenes, it may also be sufficient to refit a flattened acceleration
136    /// structure rather than rebuilding an instance hierarchy.
137    ///
138    /// - If there is only a single object in the scene, intersect its acceleration structure
139    /// directly instead of using an instance hierarchy.
140    ///
141    /// - Consider dividing objects into static and dynamic acceleration structures. If dynamic
142    /// objects require the acceleration structure to be rebuilt frequently, create a high quality
143    /// static acceleration structure and a lower quality but faster to build dynamic acceleration
144    /// structure. These two acceleration structures can then be combined with a two level
145    /// acceleration structure. Use MPSTransformTypeIdentity to reduce the overhead of this
146    /// technique. Whether this technique is more efficient than rebuilding the entire
147    /// acceleration structure depends on the scene.
148    ///
149    /// See MPSAccelerationStructure for more information
150    ///
151    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsinstanceaccelerationstructure?language=objc)
152    #[unsafe(super(MPSAccelerationStructure, MPSKernel, NSObject))]
153    #[derive(Debug, PartialEq, Eq, Hash)]
154    #[cfg(all(
155        feature = "MPSAccelerationStructure",
156        feature = "MPSCore",
157        feature = "MPSKernel"
158    ))]
159    #[deprecated]
160    pub struct MPSInstanceAccelerationStructure;
161);
162
163#[cfg(all(
164    feature = "MPSAccelerationStructure",
165    feature = "MPSCore",
166    feature = "MPSKernel"
167))]
168extern_conformance!(
169    unsafe impl NSCoding for MPSInstanceAccelerationStructure {}
170);
171
172#[cfg(all(
173    feature = "MPSAccelerationStructure",
174    feature = "MPSCore",
175    feature = "MPSKernel"
176))]
177extern_conformance!(
178    unsafe impl NSCopying for MPSInstanceAccelerationStructure {}
179);
180
181#[cfg(all(
182    feature = "MPSAccelerationStructure",
183    feature = "MPSCore",
184    feature = "MPSKernel"
185))]
186unsafe impl CopyingHelper for MPSInstanceAccelerationStructure {
187    type Result = Self;
188}
189
190#[cfg(all(
191    feature = "MPSAccelerationStructure",
192    feature = "MPSCore",
193    feature = "MPSKernel"
194))]
195extern_conformance!(
196    unsafe impl NSObjectProtocol for MPSInstanceAccelerationStructure {}
197);
198
199#[cfg(all(
200    feature = "MPSAccelerationStructure",
201    feature = "MPSCore",
202    feature = "MPSKernel"
203))]
204extern_conformance!(
205    unsafe impl NSSecureCoding for MPSInstanceAccelerationStructure {}
206);
207
208#[cfg(all(
209    feature = "MPSAccelerationStructure",
210    feature = "MPSCore",
211    feature = "MPSKernel"
212))]
213impl MPSInstanceAccelerationStructure {
214    extern_methods!(
215        #[cfg(feature = "MPSPolygonAccelerationStructure")]
216        /// Acceleration structures available for use in this instance acceleration structure. Each
217        /// instance must provide an index into this array in the instance buffer as well as a
218        /// transformation matrix in the transform buffer. All acceleration structures must share a single
219        /// vertex buffer, optional index buffer, and optional mask buffer, though they may have different
220        /// offsets within each buffer, and all acceleration structures must share the same acceleration
221        /// structure group. If a polygon acceleration structure is rebuilt or refit, the instance
222        /// acceleration structure must subsequently be rebuilt or refit.
223        #[deprecated]
224        #[unsafe(method(accelerationStructures))]
225        #[unsafe(method_family = none)]
226        pub unsafe fn accelerationStructures(
227            &self,
228        ) -> Option<Retained<NSArray<MPSPolygonAccelerationStructure>>>;
229
230        #[cfg(feature = "MPSPolygonAccelerationStructure")]
231        /// Setter for [`accelerationStructures`][Self::accelerationStructures].
232        #[deprecated]
233        #[unsafe(method(setAccelerationStructures:))]
234        #[unsafe(method_family = none)]
235        pub unsafe fn setAccelerationStructures(
236            &self,
237            acceleration_structures: Option<&NSArray<MPSPolygonAccelerationStructure>>,
238        );
239
240        /// Buffer containing the 32 bit unsigned integer index into the acceleration structure array
241        /// for each instance
242        #[deprecated]
243        #[unsafe(method(instanceBuffer))]
244        #[unsafe(method_family = none)]
245        pub unsafe fn instanceBuffer(&self) -> Option<Retained<ProtocolObject<dyn MTLBuffer>>>;
246
247        /// Setter for [`instanceBuffer`][Self::instanceBuffer].
248        ///
249        /// # Safety
250        ///
251        /// - `instance_buffer` may need to be synchronized.
252        /// - `instance_buffer` may be unretained, you must ensure it is kept alive while in use.
253        /// - `instance_buffer` contents should be of the correct type.
254        #[deprecated]
255        #[unsafe(method(setInstanceBuffer:))]
256        #[unsafe(method_family = none)]
257        pub unsafe fn setInstanceBuffer(
258            &self,
259            instance_buffer: Option<&ProtocolObject<dyn MTLBuffer>>,
260        );
261
262        /// Offset, in bytes, into the instance buffer. Defaults to 0 bytes. Must be aligned to 4
263        /// bytes.
264        #[deprecated]
265        #[unsafe(method(instanceBufferOffset))]
266        #[unsafe(method_family = none)]
267        pub unsafe fn instanceBufferOffset(&self) -> NSUInteger;
268
269        /// Setter for [`instanceBufferOffset`][Self::instanceBufferOffset].
270        #[deprecated]
271        #[unsafe(method(setInstanceBufferOffset:))]
272        #[unsafe(method_family = none)]
273        pub unsafe fn setInstanceBufferOffset(&self, instance_buffer_offset: NSUInteger);
274
275        /// Buffer containing one column major matrix_float4x4 transformation matrix per instance
276        #[deprecated]
277        #[unsafe(method(transformBuffer))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn transformBuffer(&self) -> Option<Retained<ProtocolObject<dyn MTLBuffer>>>;
280
281        /// Setter for [`transformBuffer`][Self::transformBuffer].
282        ///
283        /// # Safety
284        ///
285        /// - `transform_buffer` may need to be synchronized.
286        /// - `transform_buffer` may be unretained, you must ensure it is kept alive while in use.
287        /// - `transform_buffer` contents should be of the correct type.
288        #[deprecated]
289        #[unsafe(method(setTransformBuffer:))]
290        #[unsafe(method_family = none)]
291        pub unsafe fn setTransformBuffer(
292            &self,
293            transform_buffer: Option<&ProtocolObject<dyn MTLBuffer>>,
294        );
295
296        /// Offset, in bytes, into the transform buffer. Defaults to 0 bytes. Must be aligned to the
297        /// stride of the transform type.
298        #[deprecated]
299        #[unsafe(method(transformBufferOffset))]
300        #[unsafe(method_family = none)]
301        pub unsafe fn transformBufferOffset(&self) -> NSUInteger;
302
303        /// Setter for [`transformBufferOffset`][Self::transformBufferOffset].
304        #[deprecated]
305        #[unsafe(method(setTransformBufferOffset:))]
306        #[unsafe(method_family = none)]
307        pub unsafe fn setTransformBufferOffset(&self, transform_buffer_offset: NSUInteger);
308
309        /// Instance transform type. Defaults to MPSTransformTypeFloat4x4. Changes to this property
310        /// require rebuilding the acceleration structure.
311        #[deprecated]
312        #[unsafe(method(transformType))]
313        #[unsafe(method_family = none)]
314        pub unsafe fn transformType(&self) -> MPSTransformType;
315
316        /// Setter for [`transformType`][Self::transformType].
317        #[deprecated]
318        #[unsafe(method(setTransformType:))]
319        #[unsafe(method_family = none)]
320        pub unsafe fn setTransformType(&self, transform_type: MPSTransformType);
321
322        /// Mask buffer containing one uint32_t mask per instance. May be nil.
323        #[deprecated]
324        #[unsafe(method(maskBuffer))]
325        #[unsafe(method_family = none)]
326        pub unsafe fn maskBuffer(&self) -> Option<Retained<ProtocolObject<dyn MTLBuffer>>>;
327
328        /// Setter for [`maskBuffer`][Self::maskBuffer].
329        ///
330        /// # Safety
331        ///
332        /// - `mask_buffer` may need to be synchronized.
333        /// - `mask_buffer` may be unretained, you must ensure it is kept alive while in use.
334        /// - `mask_buffer` contents should be of the correct type.
335        #[deprecated]
336        #[unsafe(method(setMaskBuffer:))]
337        #[unsafe(method_family = none)]
338        pub unsafe fn setMaskBuffer(&self, mask_buffer: Option<&ProtocolObject<dyn MTLBuffer>>);
339
340        /// Offset, in bytes, into the mask buffer. Defaults to 0 bytes. Must be aligned to 4 bytes.
341        #[deprecated]
342        #[unsafe(method(maskBufferOffset))]
343        #[unsafe(method_family = none)]
344        pub unsafe fn maskBufferOffset(&self) -> NSUInteger;
345
346        /// Setter for [`maskBufferOffset`][Self::maskBufferOffset].
347        #[deprecated]
348        #[unsafe(method(setMaskBufferOffset:))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn setMaskBufferOffset(&self, mask_buffer_offset: NSUInteger);
351
352        /// Number of instances. Changes to this property require rebuilding the acceleration
353        /// structure.
354        #[deprecated]
355        #[unsafe(method(instanceCount))]
356        #[unsafe(method_family = none)]
357        pub unsafe fn instanceCount(&self) -> NSUInteger;
358
359        /// Setter for [`instanceCount`][Self::instanceCount].
360        #[deprecated]
361        #[unsafe(method(setInstanceCount:))]
362        #[unsafe(method_family = none)]
363        pub unsafe fn setInstanceCount(&self, instance_count: NSUInteger);
364    );
365}
366
367/// Methods declared on superclass `MPSAccelerationStructure`.
368#[cfg(all(
369    feature = "MPSAccelerationStructure",
370    feature = "MPSCore",
371    feature = "MPSKernel"
372))]
373impl MPSInstanceAccelerationStructure {
374    extern_methods!(
375        #[deprecated]
376        #[unsafe(method(init))]
377        #[unsafe(method_family = init)]
378        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
379
380        /// Initialize the acceleration structure with a Metal device
381        #[deprecated]
382        #[unsafe(method(initWithDevice:))]
383        #[unsafe(method_family = init)]
384        pub unsafe fn initWithDevice(
385            this: Allocated<Self>,
386            device: &ProtocolObject<dyn MTLDevice>,
387        ) -> Retained<Self>;
388
389        /// Initialize the acceleration structure with an NSCoder and a Metal device. Buffer
390        /// properties such as the vertex buffer, instance buffer, etc. are set to nil. Encode and decode
391        /// these buffers along with the acceleration structure instead.
392        ///
393        /// # Safety
394        ///
395        /// `a_decoder` possibly has further requirements.
396        #[deprecated]
397        #[unsafe(method(initWithCoder:device:))]
398        #[unsafe(method_family = init)]
399        pub unsafe fn initWithCoder_device(
400            this: Allocated<Self>,
401            a_decoder: &NSCoder,
402            device: &ProtocolObject<dyn MTLDevice>,
403        ) -> Option<Retained<Self>>;
404
405        #[cfg(feature = "MPSAccelerationStructureGroup")]
406        /// Initialize the acceleration structure with an acceleration structure group, if the
407        /// acceleration structure will be used in an instance hierarchy.
408        ///
409        ///
410        /// The Metal device is determined from the acceleration structure group. All
411        /// acceleration structures in the instance hierarchy must share the same group.
412        #[deprecated]
413        #[unsafe(method(initWithGroup:))]
414        #[unsafe(method_family = init)]
415        pub unsafe fn initWithGroup(
416            this: Allocated<Self>,
417            group: &MPSAccelerationStructureGroup,
418        ) -> Retained<Self>;
419
420        #[cfg(feature = "MPSAccelerationStructureGroup")]
421        /// Initialize the acceleration structure with an NSCoder and an acceleration structure
422        /// group, if the acceleration structure will be used in an instance hierarchy. All acceleration
423        /// structures in the instance hierarchy must share the same group. Buffer properties such as the
424        /// vertex buffer, instance buffer, etc. are set to nil. Encode and decode these buffers along with
425        /// the acceleration structure instead.
426        ///
427        /// # Safety
428        ///
429        /// `a_decoder` possibly has further requirements.
430        #[deprecated]
431        #[unsafe(method(initWithCoder:group:))]
432        #[unsafe(method_family = init)]
433        pub unsafe fn initWithCoder_group(
434            this: Allocated<Self>,
435            a_decoder: &NSCoder,
436            group: &MPSAccelerationStructureGroup,
437        ) -> Option<Retained<Self>>;
438    );
439}
440
441/// Methods declared on superclass `MPSKernel`.
442#[cfg(all(
443    feature = "MPSAccelerationStructure",
444    feature = "MPSCore",
445    feature = "MPSKernel"
446))]
447impl MPSInstanceAccelerationStructure {
448    extern_methods!(
449        /// Called by NSCoder to decode MPSKernels
450        ///
451        /// This isn't the right interface to decode a MPSKernel, but
452        /// it is the one that NSCoder uses. To enable your NSCoder
453        /// (e.g. NSKeyedUnarchiver) to set which device to use
454        /// extend the object to adopt the MPSDeviceProvider
455        /// protocol. Otherwise, the Metal system default device
456        /// will be used.
457        ///
458        /// # Safety
459        ///
460        /// `a_decoder` possibly has further requirements.
461        #[unsafe(method(initWithCoder:))]
462        #[unsafe(method_family = init)]
463        pub unsafe fn initWithCoder(
464            this: Allocated<Self>,
465            a_decoder: &NSCoder,
466        ) -> Option<Retained<Self>>;
467    );
468}
469
470/// Methods declared on superclass `NSObject`.
471#[cfg(all(
472    feature = "MPSAccelerationStructure",
473    feature = "MPSCore",
474    feature = "MPSKernel"
475))]
476impl MPSInstanceAccelerationStructure {
477    extern_methods!(
478        #[unsafe(method(new))]
479        #[unsafe(method_family = new)]
480        pub unsafe fn new() -> Retained<Self>;
481    );
482}