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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
//! 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::*;
#[cfg(feature = "objc2-io-surface")]
use objc2_io_surface::*;
use crate::*;
/// MTLTextureType describes the dimensionality of each image, and if multiple images are arranged into an array or cube.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtltexturetype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLTextureType(pub NSUInteger);
impl MTLTextureType {
#[doc(alias = "MTLTextureType1D")]
pub const Type1D: Self = Self(0);
#[doc(alias = "MTLTextureType1DArray")]
pub const Type1DArray: Self = Self(1);
#[doc(alias = "MTLTextureType2D")]
pub const Type2D: Self = Self(2);
#[doc(alias = "MTLTextureType2DArray")]
pub const Type2DArray: Self = Self(3);
#[doc(alias = "MTLTextureType2DMultisample")]
pub const Type2DMultisample: Self = Self(4);
#[doc(alias = "MTLTextureTypeCube")]
pub const TypeCube: Self = Self(5);
#[doc(alias = "MTLTextureTypeCubeArray")]
pub const TypeCubeArray: Self = Self(6);
#[doc(alias = "MTLTextureType3D")]
pub const Type3D: Self = Self(7);
#[doc(alias = "MTLTextureType2DMultisampleArray")]
pub const Type2DMultisampleArray: Self = Self(8);
#[doc(alias = "MTLTextureTypeTextureBuffer")]
pub const TypeTextureBuffer: Self = Self(9);
}
unsafe impl Encode for MTLTextureType {
const ENCODING: Encoding = NSUInteger::ENCODING;
}
unsafe impl RefEncode for MTLTextureType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtltextureswizzle?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLTextureSwizzle(pub u8);
impl MTLTextureSwizzle {
#[doc(alias = "MTLTextureSwizzleZero")]
pub const Zero: Self = Self(0);
#[doc(alias = "MTLTextureSwizzleOne")]
pub const One: Self = Self(1);
#[doc(alias = "MTLTextureSwizzleRed")]
pub const Red: Self = Self(2);
#[doc(alias = "MTLTextureSwizzleGreen")]
pub const Green: Self = Self(3);
#[doc(alias = "MTLTextureSwizzleBlue")]
pub const Blue: Self = Self(4);
#[doc(alias = "MTLTextureSwizzleAlpha")]
pub const Alpha: Self = Self(5);
}
unsafe impl Encode for MTLTextureSwizzle {
const ENCODING: Encoding = u8::ENCODING;
}
unsafe impl RefEncode for MTLTextureSwizzle {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtltextureswizzlechannels?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MTLTextureSwizzleChannels {
pub red: MTLTextureSwizzle,
pub green: MTLTextureSwizzle,
pub blue: MTLTextureSwizzle,
pub alpha: MTLTextureSwizzle,
}
unsafe impl Encode for MTLTextureSwizzleChannels {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<MTLTextureSwizzle>::ENCODING,
<MTLTextureSwizzle>::ENCODING,
<MTLTextureSwizzle>::ENCODING,
<MTLTextureSwizzle>::ENCODING,
],
);
}
unsafe impl RefEncode for MTLTextureSwizzleChannels {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
impl MTLTextureSwizzleChannels {
// TODO: pub fn MTLTextureSwizzleChannelsMake(r: MTLTextureSwizzle,g: MTLTextureSwizzle,b: MTLTextureSwizzle,a: MTLTextureSwizzle,) -> MTLTextureSwizzleChannels;
}
extern_class!(
/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsharedtexturehandle?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLSharedTextureHandle;
);
extern_conformance!(
unsafe impl NSCoding for MTLSharedTextureHandle {}
);
extern_conformance!(
unsafe impl NSObjectProtocol for MTLSharedTextureHandle {}
);
extern_conformance!(
unsafe impl NSSecureCoding for MTLSharedTextureHandle {}
);
impl MTLSharedTextureHandle {
extern_methods!(
#[cfg(feature = "MTLDevice")]
/// The device this texture was created against.
///
/// This shared texture handle can only be used with this device.
#[unsafe(method(device))]
#[unsafe(method_family = none)]
pub fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
/// A copy of the original texture's label property, if any
#[unsafe(method(label))]
#[unsafe(method_family = none)]
pub fn label(&self) -> Option<Retained<NSString>>;
);
}
/// Methods declared on superclass `NSObject`.
impl MTLSharedTextureHandle {
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 MTLSharedTextureHandle {
#[inline]
fn default_retained() -> Retained<Self> {
Self::new()
}
}
/// MTLTextureUsage declares how the texture will be used over its lifetime (bitwise OR for multiple uses).
///
/// This information may be used by the driver to make optimization decisions.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtltextureusage?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLTextureUsage(pub NSUInteger);
bitflags::bitflags! {
impl MTLTextureUsage: NSUInteger {
#[doc(alias = "MTLTextureUsageUnknown")]
const Unknown = 0x0000;
#[doc(alias = "MTLTextureUsageShaderRead")]
const ShaderRead = 0x0001;
#[doc(alias = "MTLTextureUsageShaderWrite")]
const ShaderWrite = 0x0002;
#[doc(alias = "MTLTextureUsageRenderTarget")]
const RenderTarget = 0x0004;
#[doc(alias = "MTLTextureUsagePixelFormatView")]
const PixelFormatView = 0x0010;
#[doc(alias = "MTLTextureUsageShaderAtomic")]
const ShaderAtomic = 0x0020;
}
}
unsafe impl Encode for MTLTextureUsage {
const ENCODING: Encoding = NSUInteger::ENCODING;
}
unsafe impl RefEncode for MTLTextureUsage {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtltexturecompressiontype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLTextureCompressionType(pub NSInteger);
impl MTLTextureCompressionType {
#[doc(alias = "MTLTextureCompressionTypeLossless")]
pub const Lossless: Self = Self(0);
#[doc(alias = "MTLTextureCompressionTypeLossy")]
pub const Lossy: Self = Self(1);
}
unsafe impl Encode for MTLTextureCompressionType {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MTLTextureCompressionType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtltexturedescriptor?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLTextureDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTLTextureDescriptor {}
);
unsafe impl CopyingHelper for MTLTextureDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLTextureDescriptor {}
);
impl MTLTextureDescriptor {
extern_methods!(
#[cfg(feature = "MTLPixelFormat")]
/// Create a TextureDescriptor for a common 2D texture.
#[unsafe(method(texture2DDescriptorWithPixelFormat:width:height:mipmapped:))]
#[unsafe(method_family = none)]
pub unsafe fn texture2DDescriptorWithPixelFormat_width_height_mipmapped(
pixel_format: MTLPixelFormat,
width: NSUInteger,
height: NSUInteger,
mipmapped: bool,
) -> Retained<MTLTextureDescriptor>;
#[cfg(feature = "MTLPixelFormat")]
/// Create a TextureDescriptor for a common Cube texture.
///
/// # Safety
///
/// `size` might not be bounds-checked.
#[unsafe(method(textureCubeDescriptorWithPixelFormat:size:mipmapped:))]
#[unsafe(method_family = none)]
pub unsafe fn textureCubeDescriptorWithPixelFormat_size_mipmapped(
pixel_format: MTLPixelFormat,
size: NSUInteger,
mipmapped: bool,
) -> Retained<MTLTextureDescriptor>;
#[cfg(all(feature = "MTLPixelFormat", feature = "MTLResource"))]
/// Create a TextureDescriptor for a common texture buffer.
#[unsafe(method(textureBufferDescriptorWithPixelFormat:width:resourceOptions:usage:))]
#[unsafe(method_family = none)]
pub unsafe fn textureBufferDescriptorWithPixelFormat_width_resourceOptions_usage(
pixel_format: MTLPixelFormat,
width: NSUInteger,
resource_options: MTLResourceOptions,
usage: MTLTextureUsage,
) -> Retained<MTLTextureDescriptor>;
/// The overall type of the texture to be created. The default value is MTLTextureType2D.
#[unsafe(method(textureType))]
#[unsafe(method_family = none)]
pub fn textureType(&self) -> MTLTextureType;
/// Setter for [`textureType`][Self::textureType].
#[unsafe(method(setTextureType:))]
#[unsafe(method_family = none)]
pub fn setTextureType(&self, texture_type: MTLTextureType);
#[cfg(feature = "MTLPixelFormat")]
/// The pixel format to use when allocating this texture. This is also the pixel format that will be used to when the caller writes or reads pixels from this texture. The default value is MTLPixelFormatRGBA8Unorm.
#[unsafe(method(pixelFormat))]
#[unsafe(method_family = none)]
pub fn pixelFormat(&self) -> MTLPixelFormat;
#[cfg(feature = "MTLPixelFormat")]
/// Setter for [`pixelFormat`][Self::pixelFormat].
#[unsafe(method(setPixelFormat:))]
#[unsafe(method_family = none)]
pub fn setPixelFormat(&self, pixel_format: MTLPixelFormat);
/// The width of the texture to create. The default value is 1.
#[unsafe(method(width))]
#[unsafe(method_family = none)]
pub fn width(&self) -> NSUInteger;
/// Setter for [`width`][Self::width].
#[unsafe(method(setWidth:))]
#[unsafe(method_family = none)]
pub unsafe fn setWidth(&self, width: NSUInteger);
/// The height of the texture to create. The default value is 1.
///
/// height If allocating a 1D texture, height must be 1.
#[unsafe(method(height))]
#[unsafe(method_family = none)]
pub fn height(&self) -> NSUInteger;
/// Setter for [`height`][Self::height].
#[unsafe(method(setHeight:))]
#[unsafe(method_family = none)]
pub unsafe fn setHeight(&self, height: NSUInteger);
/// The depth of the texture to create. The default value is 1.
///
/// depth When allocating any texture types other than 3D, depth must be 1.
#[unsafe(method(depth))]
#[unsafe(method_family = none)]
pub fn depth(&self) -> NSUInteger;
/// Setter for [`depth`][Self::depth].
#[unsafe(method(setDepth:))]
#[unsafe(method_family = none)]
pub unsafe fn setDepth(&self, depth: NSUInteger);
/// The number of mipmap levels to allocate. The default value is 1.
///
/// When creating Buffer and Multisample textures, mipmapLevelCount must be 1.
#[unsafe(method(mipmapLevelCount))]
#[unsafe(method_family = none)]
pub fn mipmapLevelCount(&self) -> NSUInteger;
/// Setter for [`mipmapLevelCount`][Self::mipmapLevelCount].
///
/// # Safety
///
/// This might not be bounds-checked.
#[unsafe(method(setMipmapLevelCount:))]
#[unsafe(method_family = none)]
pub unsafe fn setMipmapLevelCount(&self, mipmap_level_count: NSUInteger);
/// The number of samples in the texture to create. The default value is 1.
///
/// When creating Buffer textures sampleCount must be 1. Implementations may round sample counts up to the next supported value.
#[unsafe(method(sampleCount))]
#[unsafe(method_family = none)]
pub fn sampleCount(&self) -> NSUInteger;
/// Setter for [`sampleCount`][Self::sampleCount].
///
/// # Safety
///
/// This might not be bounds-checked.
#[unsafe(method(setSampleCount:))]
#[unsafe(method_family = none)]
pub unsafe fn setSampleCount(&self, sample_count: NSUInteger);
/// The number of array elements to allocate. The default value is 1.
///
/// When allocating any non-Array texture type, arrayLength has to be 1. Otherwise it must be set to something greater than 1 and less than 2048.
#[unsafe(method(arrayLength))]
#[unsafe(method_family = none)]
pub fn arrayLength(&self) -> NSUInteger;
/// Setter for [`arrayLength`][Self::arrayLength].
#[unsafe(method(setArrayLength:))]
#[unsafe(method_family = none)]
pub unsafe fn setArrayLength(&self, array_length: NSUInteger);
#[cfg(feature = "MTLResource")]
/// Options to control memory allocation parameters, etc.
///
/// Contains a packed set of the storageMode, cpuCacheMode and hazardTrackingMode properties.
#[unsafe(method(resourceOptions))]
#[unsafe(method_family = none)]
pub fn resourceOptions(&self) -> MTLResourceOptions;
#[cfg(feature = "MTLResource")]
/// Setter for [`resourceOptions`][Self::resourceOptions].
#[unsafe(method(setResourceOptions:))]
#[unsafe(method_family = none)]
pub fn setResourceOptions(&self, resource_options: MTLResourceOptions);
#[cfg(feature = "MTLResource")]
/// Options to specify CPU cache mode of texture resource.
#[unsafe(method(cpuCacheMode))]
#[unsafe(method_family = none)]
pub fn cpuCacheMode(&self) -> MTLCPUCacheMode;
#[cfg(feature = "MTLResource")]
/// Setter for [`cpuCacheMode`][Self::cpuCacheMode].
#[unsafe(method(setCpuCacheMode:))]
#[unsafe(method_family = none)]
pub fn setCpuCacheMode(&self, cpu_cache_mode: MTLCPUCacheMode);
#[cfg(feature = "MTLResource")]
/// To specify storage mode of texture resource.
#[unsafe(method(storageMode))]
#[unsafe(method_family = none)]
pub fn storageMode(&self) -> MTLStorageMode;
#[cfg(feature = "MTLResource")]
/// Setter for [`storageMode`][Self::storageMode].
#[unsafe(method(setStorageMode:))]
#[unsafe(method_family = none)]
pub fn setStorageMode(&self, storage_mode: MTLStorageMode);
#[cfg(feature = "MTLResource")]
/// Set hazard tracking mode for the texture. The default value is MTLHazardTrackingModeDefault.
///
/// For resources created from the device, MTLHazardTrackingModeDefault is treated as MTLHazardTrackingModeTracked.
/// For resources created on a heap, MTLHazardTrackingModeDefault is treated as the hazardTrackingMode of the heap itself.
/// In either case, it is possible to opt-out of hazard tracking by setting MTLHazardTrackingModeUntracked.
/// It is not possible to opt-in to hazard tracking on a heap that itself is not hazard tracked.
/// For optimal performance, perform hazard tracking manually through MTLFence or MTLEvent instead.
#[unsafe(method(hazardTrackingMode))]
#[unsafe(method_family = none)]
pub fn hazardTrackingMode(&self) -> MTLHazardTrackingMode;
#[cfg(feature = "MTLResource")]
/// Setter for [`hazardTrackingMode`][Self::hazardTrackingMode].
#[unsafe(method(setHazardTrackingMode:))]
#[unsafe(method_family = none)]
pub fn setHazardTrackingMode(&self, hazard_tracking_mode: MTLHazardTrackingMode);
/// Description of texture usage
#[unsafe(method(usage))]
#[unsafe(method_family = none)]
pub fn usage(&self) -> MTLTextureUsage;
/// Setter for [`usage`][Self::usage].
#[unsafe(method(setUsage:))]
#[unsafe(method_family = none)]
pub fn setUsage(&self, usage: MTLTextureUsage);
/// Allow GPU-optimization for the contents of this texture. The default value is true.
///
/// Useful for opting-out of GPU-optimization when implicit optimization (e.g. RT writes) is regressing CPU-read-back performance. See the documentation for optimizeContentsForGPUAccess: and optimizeContentsForCPUAccess: APIs.
#[unsafe(method(allowGPUOptimizedContents))]
#[unsafe(method_family = none)]
pub fn allowGPUOptimizedContents(&self) -> bool;
/// Setter for [`allowGPUOptimizedContents`][Self::allowGPUOptimizedContents].
#[unsafe(method(setAllowGPUOptimizedContents:))]
#[unsafe(method_family = none)]
pub fn setAllowGPUOptimizedContents(&self, allow_gpu_optimized_contents: bool);
/// Controls how the texture contents will be compressed when written to by the GPU. Compression can be used to reduce the bandwidth usage and storage requirements of a texture.
///
/// The default compression type is lossless, meaning that no loss of precision will occur when the texture content is modified.
/// Losslessly compressed textures may benefit from reduced bandwidth usage when regions of correlated color values are written, but do not benefit from reduced storage requirements.
/// Enabling lossy compression for textures that can tolerate some precision loss will guarantee both reduced bandwidth usage and reduced storage requirements.
/// The amount of precision loss depends on the color values stored; regions with correlated color values can be represented with limited to no precision loss, whereas regions with unrelated color values suffer more precision loss.
/// Enabling lossy compression requires both storageMode == MTLStorageModePrivate, allowGPUOptimizedContents == YES, and cannot be combined with either MTLTextureUsagePixelFormatView, MTLTextureUsageShaderWrite, MTLTextureUsageShaderAtomic, MTLTextureType1D(Array) or MTLTextureTypeTextureBuffer.
/// Moreover, not all MTLPixelFormat are supported with lossy compression, verify that the MTLDevice's GPU family supports the lossy compression feature for the pixelFormat requested.
/// Set allowGPUOptimizedContents to NO to opt out of both lossless and lossy compression; such textures do not benefit from either reduced bandwidth usage or reduced storage requirements, but have predictable CPU readback performance.
#[unsafe(method(compressionType))]
#[unsafe(method_family = none)]
pub fn compressionType(&self) -> MTLTextureCompressionType;
/// Setter for [`compressionType`][Self::compressionType].
#[unsafe(method(setCompressionType:))]
#[unsafe(method_family = none)]
pub fn setCompressionType(&self, compression_type: MTLTextureCompressionType);
/// Channel swizzle to use when reading or sampling from the texture, the default value is MTLTextureSwizzleChannelsDefault.
#[unsafe(method(swizzle))]
#[unsafe(method_family = none)]
pub fn swizzle(&self) -> MTLTextureSwizzleChannels;
/// Setter for [`swizzle`][Self::swizzle].
#[unsafe(method(setSwizzle:))]
#[unsafe(method_family = none)]
pub fn setSwizzle(&self, swizzle: MTLTextureSwizzleChannels);
#[cfg(feature = "MTLResource")]
/// Determines the page size for a placement sparse texture.
///
/// Set this property to a non-zero value to create a *placement sparse texture*.
///
/// Placement sparse textures are instances of ``MTLTexture`` that you assign memory to using a ``MTLHeap`` instance
/// of type ``MTLHeapType/MTLHeapTypePlacement`` and a ``MTLHeapDescriptor/maxCompatiblePlacementSparsePageSize``
/// at least as large as the ``MTLSparsePageSize`` value you assign to this property.
///
/// This value is 0 by default.
#[unsafe(method(placementSparsePageSize))]
#[unsafe(method_family = none)]
pub fn placementSparsePageSize(&self) -> MTLSparsePageSize;
#[cfg(feature = "MTLResource")]
/// Setter for [`placementSparsePageSize`][Self::placementSparsePageSize].
#[unsafe(method(setPlacementSparsePageSize:))]
#[unsafe(method_family = none)]
pub fn setPlacementSparsePageSize(&self, placement_sparse_page_size: MTLSparsePageSize);
);
}
/// Methods declared on superclass `NSObject`.
impl MTLTextureDescriptor {
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 MTLTextureDescriptor {
#[inline]
fn default_retained() -> Retained<Self> {
Self::new()
}
}
extern_class!(
/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtltextureviewdescriptor?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLTextureViewDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTLTextureViewDescriptor {}
);
unsafe impl CopyingHelper for MTLTextureViewDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLTextureViewDescriptor {}
);
impl MTLTextureViewDescriptor {
extern_methods!(
#[cfg(feature = "MTLPixelFormat")]
/// A desired pixel format of a texture view.
#[unsafe(method(pixelFormat))]
#[unsafe(method_family = none)]
pub fn pixelFormat(&self) -> MTLPixelFormat;
#[cfg(feature = "MTLPixelFormat")]
/// Setter for [`pixelFormat`][Self::pixelFormat].
#[unsafe(method(setPixelFormat:))]
#[unsafe(method_family = none)]
pub fn setPixelFormat(&self, pixel_format: MTLPixelFormat);
/// A desired texture view of a texture view.
#[unsafe(method(textureType))]
#[unsafe(method_family = none)]
pub fn textureType(&self) -> MTLTextureType;
/// Setter for [`textureType`][Self::textureType].
#[unsafe(method(setTextureType:))]
#[unsafe(method_family = none)]
pub fn setTextureType(&self, texture_type: MTLTextureType);
/// A desired range of mip levels of a texture view.
#[unsafe(method(levelRange))]
#[unsafe(method_family = none)]
pub fn levelRange(&self) -> NSRange;
/// Setter for [`levelRange`][Self::levelRange].
///
/// # Safety
///
/// This might not be bounds-checked.
#[unsafe(method(setLevelRange:))]
#[unsafe(method_family = none)]
pub unsafe fn setLevelRange(&self, level_range: NSRange);
/// A desired range of slices of a texture view.
#[unsafe(method(sliceRange))]
#[unsafe(method_family = none)]
pub fn sliceRange(&self) -> NSRange;
/// Setter for [`sliceRange`][Self::sliceRange].
///
/// # Safety
///
/// This might not be bounds-checked.
#[unsafe(method(setSliceRange:))]
#[unsafe(method_family = none)]
pub unsafe fn setSliceRange(&self, slice_range: NSRange);
/// A desired swizzle format of a texture view.
#[unsafe(method(swizzle))]
#[unsafe(method_family = none)]
pub fn swizzle(&self) -> MTLTextureSwizzleChannels;
/// Setter for [`swizzle`][Self::swizzle].
#[unsafe(method(setSwizzle:))]
#[unsafe(method_family = none)]
pub fn setSwizzle(&self, swizzle: MTLTextureSwizzleChannels);
);
}
/// Methods declared on superclass `NSObject`.
impl MTLTextureViewDescriptor {
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 MTLTextureViewDescriptor {
#[inline]
fn default_retained() -> Retained<Self> {
Self::new()
}
}
extern_protocol!(
/// MTLTexture represents a collection of 1D, 2D, or 3D images.
///
/// Each image in a texture is a 1D, 2D, 2DMultisample, or 3D image. The texture contains one or more images arranged in a mipmap stack. If there are multiple mipmap stacks, each one is referred to as a slice of the texture. 1D, 2D, 2DMultisample, and 3D textures have a single slice. In 1DArray and 2DArray textures, every slice is an array element. A Cube texture always has 6 slices, one for each face. In a CubeArray texture, each set of six slices is one element in the array.
///
/// Most APIs that operate on individual images in a texture address those images via a tuple of a Slice, and Mipmap Level within that slice.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtltexture?language=objc)
#[cfg(all(feature = "MTLAllocation", feature = "MTLResource"))]
pub unsafe trait MTLTexture: MTLResource {
/// The resource this texture was created from. It may be a texture or a buffer. If this texture is not reusing storage of another MTLResource, then nil is returned.
#[deprecated = "Use parentTexture or buffer instead"]
#[unsafe(method(rootResource))]
#[unsafe(method_family = none)]
fn rootResource(&self) -> Option<Retained<ProtocolObject<dyn MTLResource>>>;
/// The texture this texture view was created from, or nil if this is not a texture view or it was not created from a texture.
#[unsafe(method(parentTexture))]
#[unsafe(method_family = none)]
fn parentTexture(&self) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
/// The base level of the texture this texture view was created from, or 0 if this is not a texture view.
#[unsafe(method(parentRelativeLevel))]
#[unsafe(method_family = none)]
fn parentRelativeLevel(&self) -> NSUInteger;
/// The base slice of the texture this texture view was created from, or 0 if this is not a texture view.
#[unsafe(method(parentRelativeSlice))]
#[unsafe(method_family = none)]
fn parentRelativeSlice(&self) -> NSUInteger;
#[cfg(feature = "MTLBuffer")]
/// The buffer this texture view was created from, or nil if this is not a texture view or it was not created from a buffer.
#[unsafe(method(buffer))]
#[unsafe(method_family = none)]
fn buffer(&self) -> Option<Retained<ProtocolObject<dyn MTLBuffer>>>;
/// The offset of the buffer this texture view was created from, or 0 if this is not a texture view.
#[unsafe(method(bufferOffset))]
#[unsafe(method_family = none)]
fn bufferOffset(&self) -> NSUInteger;
/// The bytesPerRow of the buffer this texture view was created from, or 0 if this is not a texture view.
#[unsafe(method(bufferBytesPerRow))]
#[unsafe(method_family = none)]
fn bufferBytesPerRow(&self) -> NSUInteger;
#[cfg(feature = "objc2-io-surface")]
/// If this texture was created from an IOSurface, this returns a reference to that IOSurface. iosurface is nil if this texture was not created from an IOSurface.
#[unsafe(method(iosurface))]
#[unsafe(method_family = none)]
fn iosurface(&self) -> Option<Retained<IOSurfaceRef>>;
/// If this texture was created from an IOSurface, this returns the plane of the IOSurface from which the texture was created. iosurfacePlane is 0 if this texture was not created from an IOSurface.
#[unsafe(method(iosurfacePlane))]
#[unsafe(method_family = none)]
fn iosurfacePlane(&self) -> NSUInteger;
/// The type of this texture.
#[unsafe(method(textureType))]
#[unsafe(method_family = none)]
fn textureType(&self) -> MTLTextureType;
#[cfg(feature = "MTLPixelFormat")]
/// The MTLPixelFormat that is used to interpret this texture's contents.
#[unsafe(method(pixelFormat))]
#[unsafe(method_family = none)]
fn pixelFormat(&self) -> MTLPixelFormat;
/// The width of the MTLTexture instance in pixels.
#[unsafe(method(width))]
#[unsafe(method_family = none)]
fn width(&self) -> NSUInteger;
/// The height of the MTLTexture instance in pixels.
///
/// . height is 1 if the texture is 1D.
#[unsafe(method(height))]
#[unsafe(method_family = none)]
fn height(&self) -> NSUInteger;
/// The depth of this MTLTexture instance in pixels.
///
/// If this MTLTexture is not a 3D texture, the depth is 1
#[unsafe(method(depth))]
#[unsafe(method_family = none)]
fn depth(&self) -> NSUInteger;
/// The number of mipmap levels in each slice of this MTLTexture.
#[unsafe(method(mipmapLevelCount))]
#[unsafe(method_family = none)]
fn mipmapLevelCount(&self) -> NSUInteger;
/// The number of samples in each pixel of this MTLTexture.
///
/// If this texture is any type other than 2DMultisample, samples is 1.
#[unsafe(method(sampleCount))]
#[unsafe(method_family = none)]
fn sampleCount(&self) -> NSUInteger;
/// The number of array elements in this MTLTexture.
///
/// For non-Array texture types, arrayLength is 1.
#[unsafe(method(arrayLength))]
#[unsafe(method_family = none)]
fn arrayLength(&self) -> NSUInteger;
/// Description of texture usage.
#[unsafe(method(usage))]
#[unsafe(method_family = none)]
fn usage(&self) -> MTLTextureUsage;
/// If YES, this texture can be shared with other processes.
///
/// Texture can be shared across process addres space boundaries through use of sharedTextureHandle and XPC.
#[unsafe(method(isShareable))]
#[unsafe(method_family = none)]
fn isShareable(&self) -> bool;
/// If YES, this texture can only be used with a MTLAttachmentDescriptor, and cannot be used as a texture argument for MTLRenderCommandEncoder, MTLBlitCommandEncoder, or MTLComputeCommandEncoder. Furthermore, when this property's value is YES, readPixels/writePixels may not be used with this texture.
///
/// Textures obtained from CAMetalDrawables may have this property set to YES, depending on the value of frameBufferOnly passed to their parent CAMetalLayer. Textures created directly by the application will not have any restrictions.
#[unsafe(method(isFramebufferOnly))]
#[unsafe(method_family = none)]
fn isFramebufferOnly(&self) -> bool;
/// For sparse textures this property returns index of first mipmap that is packed in tail.
/// Mapping this mipmap level will map all subsequent mipmap levels.
#[optional]
#[unsafe(method(firstMipmapInTail))]
#[unsafe(method_family = none)]
fn firstMipmapInTail(&self) -> NSUInteger;
/// Amount of memory in bytes required to map sparse texture tail.
#[optional]
#[unsafe(method(tailSizeInBytes))]
#[unsafe(method_family = none)]
fn tailSizeInBytes(&self) -> NSUInteger;
#[optional]
#[unsafe(method(isSparse))]
#[unsafe(method_family = none)]
fn isSparse(&self) -> bool;
/// Allow GPU-optimization for the contents texture. The default value is true.
///
/// Useful for opting-out of GPU-optimization when implicit optimization (e.g. RT writes) is regressing CPU-read-back performance. See the documentation for optimizeContentsForGPUAccess: and optimizeContentsForCPUAccess: APIs.
#[unsafe(method(allowGPUOptimizedContents))]
#[unsafe(method_family = none)]
fn allowGPUOptimizedContents(&self) -> bool;
/// Returns the compression type of the texture
///
/// See the compressionType property on MTLTextureDescriptor
#[unsafe(method(compressionType))]
#[unsafe(method_family = none)]
fn compressionType(&self) -> MTLTextureCompressionType;
#[cfg(feature = "MTLTypes")]
/// Handle of the GPU resource suitable for storing in an Argument Buffer
#[unsafe(method(gpuResourceID))]
#[unsafe(method_family = none)]
fn gpuResourceID(&self) -> MTLResourceID;
#[cfg(feature = "MTLTypes")]
/// Copies a block of pixels from a texture slice into the application's memory.
///
/// # Safety
///
/// `pixel_bytes` must be a valid pointer.
#[unsafe(method(getBytes:bytesPerRow:bytesPerImage:fromRegion:mipmapLevel:slice:))]
#[unsafe(method_family = none)]
unsafe fn getBytes_bytesPerRow_bytesPerImage_fromRegion_mipmapLevel_slice(
&self,
pixel_bytes: NonNull<c_void>,
bytes_per_row: NSUInteger,
bytes_per_image: NSUInteger,
region: MTLRegion,
level: NSUInteger,
slice: NSUInteger,
);
#[cfg(feature = "MTLTypes")]
/// Copy a block of pixel data from the caller's pointer into a texture slice.
///
/// # Safety
///
/// `pixel_bytes` must be a valid pointer.
#[unsafe(method(replaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:))]
#[unsafe(method_family = none)]
unsafe fn replaceRegion_mipmapLevel_slice_withBytes_bytesPerRow_bytesPerImage(
&self,
region: MTLRegion,
level: NSUInteger,
slice: NSUInteger,
pixel_bytes: NonNull<c_void>,
bytes_per_row: NSUInteger,
bytes_per_image: NSUInteger,
);
#[cfg(feature = "MTLTypes")]
/// Convenience for getBytes:bytesPerRow:bytesPerImage:fromRegion:mipmapLevel:slice: that doesn't require slice related arguments
///
/// # Safety
///
/// `pixel_bytes` must be a valid pointer.
#[unsafe(method(getBytes:bytesPerRow:fromRegion:mipmapLevel:))]
#[unsafe(method_family = none)]
unsafe fn getBytes_bytesPerRow_fromRegion_mipmapLevel(
&self,
pixel_bytes: NonNull<c_void>,
bytes_per_row: NSUInteger,
region: MTLRegion,
level: NSUInteger,
);
#[cfg(feature = "MTLTypes")]
/// Convenience for replaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage: that doesn't require slice related arguments
///
/// # Safety
///
/// `pixel_bytes` must be a valid pointer.
#[unsafe(method(replaceRegion:mipmapLevel:withBytes:bytesPerRow:))]
#[unsafe(method_family = none)]
unsafe fn replaceRegion_mipmapLevel_withBytes_bytesPerRow(
&self,
region: MTLRegion,
level: NSUInteger,
pixel_bytes: NonNull<c_void>,
bytes_per_row: NSUInteger,
);
#[cfg(feature = "MTLPixelFormat")]
/// Create a new texture which shares the same storage as the source texture, but with a different (but compatible) pixel format.
#[unsafe(method(newTextureViewWithPixelFormat:))]
#[unsafe(method_family = new)]
fn newTextureViewWithPixelFormat(
&self,
pixel_format: MTLPixelFormat,
) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
#[cfg(feature = "MTLPixelFormat")]
/// Create a new texture which shares the same storage as the source texture, but with a different (but compatible) pixel format, texture type, levels and slices.
///
/// # Safety
///
/// - `levelRange` might not be bounds-checked.
/// - `sliceRange` might not be bounds-checked.
#[unsafe(method(newTextureViewWithPixelFormat:textureType:levels:slices:))]
#[unsafe(method_family = new)]
unsafe fn newTextureViewWithPixelFormat_textureType_levels_slices(
&self,
pixel_format: MTLPixelFormat,
texture_type: MTLTextureType,
level_range: NSRange,
slice_range: NSRange,
) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
/// Create a new texture handle, that can be shared across process addres space boundaries.
#[unsafe(method(newSharedTextureHandle))]
#[unsafe(method_family = new)]
fn newSharedTextureHandle(&self) -> Option<Retained<MTLSharedTextureHandle>>;
/// Create a new texture which shares the same storage as the source texture, but with different (but compatible) properties specified by the descriptor
#[unsafe(method(newTextureViewWithDescriptor:))]
#[unsafe(method_family = new)]
fn newTextureViewWithDescriptor(
&self,
descriptor: &MTLTextureViewDescriptor,
) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
/// For Metal texture objects that are remote views, this returns the texture associated with the storage on the originating device.
#[unsafe(method(remoteStorageTexture))]
#[unsafe(method_family = none)]
fn remoteStorageTexture(&self) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
#[cfg(feature = "MTLDevice")]
/// On Metal devices that support peer to peer transfers, this method is used to create a remote texture view on another device
/// within the peer group. The receiver must use MTLStorageModePrivate or be backed by an IOSurface.
#[unsafe(method(newRemoteTextureViewForDevice:))]
#[unsafe(method_family = new)]
fn newRemoteTextureViewForDevice(
&self,
device: &ProtocolObject<dyn MTLDevice>,
) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
/// The channel swizzle used when reading or sampling from this texture
#[unsafe(method(swizzle))]
#[unsafe(method_family = none)]
fn swizzle(&self) -> MTLTextureSwizzleChannels;
#[cfg(feature = "MTLPixelFormat")]
/// Create a new texture which shares the same storage as the source texture, but with a different (but compatible) pixel format, texture type, levels, slices and swizzle.
///
/// # Safety
///
/// - `levelRange` might not be bounds-checked.
/// - `sliceRange` might not be bounds-checked.
#[unsafe(method(newTextureViewWithPixelFormat:textureType:levels:slices:swizzle:))]
#[unsafe(method_family = new)]
unsafe fn newTextureViewWithPixelFormat_textureType_levels_slices_swizzle(
&self,
pixel_format: MTLPixelFormat,
texture_type: MTLTextureType,
level_range: NSRange,
slice_range: NSRange,
swizzle: MTLTextureSwizzleChannels,
) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
/// Query support tier for sparse textures.
#[unsafe(method(sparseTextureTier))]
#[unsafe(method_family = none)]
fn sparseTextureTier(&self) -> MTLTextureSparseTier;
}
);