-
Notifications
You must be signed in to change notification settings - Fork 111
/
device.rs
2137 lines (1864 loc) · 68.1 KB
/
device.rs
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
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2017 GFX developers
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
use super::*;
use block::Block;
use log::warn;
use objc::runtime::{NO, YES};
use std::{ffi::CStr, os::raw::c_char, path::Path, ptr};
/// Available on macOS 10.11+, iOS 8.0+, tvOS 9.0+
///
/// See <https://developer.apple.com/documentation/metal/mtlfeatureset>
#[allow(non_camel_case_types)]
#[deprecated(
note = "Since iOS 8.0–16.0 iPadOS 8.0–16.0 macOS 10.11–13.0 Mac Catalyst 13.1–16.0 tvOS 9.0–16.0"
)]
#[repr(u64)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum MTLFeatureSet {
iOS_GPUFamily1_v1 = 0,
iOS_GPUFamily2_v1 = 1,
iOS_GPUFamily1_v2 = 2,
iOS_GPUFamily2_v2 = 3,
iOS_GPUFamily3_v1 = 4,
iOS_GPUFamily1_v3 = 5,
iOS_GPUFamily2_v3 = 6,
iOS_GPUFamily3_v2 = 7,
iOS_GPUFamily1_v4 = 8,
iOS_GPUFamily2_v4 = 9,
iOS_GPUFamily3_v3 = 10,
iOS_GPUFamily4_v1 = 11,
iOS_GPUFamily1_v5 = 12,
iOS_GPUFamily2_v5 = 13,
iOS_GPUFamily3_v4 = 14,
iOS_GPUFamily4_v2 = 15,
iOS_GPUFamily5_v1 = 16,
tvOS_GPUFamily1_v1 = 30000,
tvOS_GPUFamily1_v2 = 30001,
tvOS_GPUFamily1_v3 = 30002,
tvOS_GPUFamily2_v1 = 30003,
tvOS_GPUFamily1_v4 = 30004,
tvOS_GPUFamily2_v2 = 30005,
macOS_GPUFamily1_v1 = 10000,
macOS_GPUFamily1_v2 = 10001,
// Available on macOS 10.12+
macOS_ReadWriteTextureTier2 = 10002,
macOS_GPUFamily1_v3 = 10003,
macOS_GPUFamily1_v4 = 10004,
macOS_GPUFamily2_v1 = 10005,
}
/// Available on macOS 10.15+, iOS 13.0+
///
/// See <https://developer.apple.com/documentation/metal/mtlgpufamily>
#[repr(i64)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum MTLGPUFamily {
Common1 = 3001,
Common2 = 3002,
Common3 = 3003,
Apple1 = 1001,
Apple2 = 1002,
Apple3 = 1003,
Apple4 = 1004,
Apple5 = 1005,
Apple6 = 1006,
Apple7 = 1007,
Apple8 = 1008,
Apple9 = 1009,
Mac1 = 2001,
Mac2 = 2002,
MacCatalyst1 = 4001,
MacCatalyst2 = 4002,
Metal3 = 5001,
}
/// See <https://developer.apple.com/documentation/metal/mtldevicelocation>
#[repr(u64)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum MTLDeviceLocation {
BuiltIn = 0,
Slot = 1,
External = 2,
Unspecified = u64::MAX,
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct PixelFormatCapabilities: u32 {
const Filter = 1 << 0;
const Write = 1 << 1;
const Color = 1 << 2;
const Blend = 1 << 3;
const Msaa = 1 << 4;
const Resolve = 1 << 5;
}
}
#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
enum OS {
iOS,
tvOS,
macOS,
}
const KB: u32 = 1024;
const MB: u32 = 1024 * KB;
const GB: u32 = 1024 * MB;
impl MTLFeatureSet {
fn os(&self) -> OS {
let value = *self as u64;
if value < 10_000 {
OS::iOS
} else if value < 20_000 {
OS::macOS
} else if value >= 30_000 || value < 40_000 {
OS::tvOS
} else {
unreachable!()
}
}
// returns the minor version on macos
fn os_version(&self) -> u32 {
use MTLFeatureSet::*;
match self {
iOS_GPUFamily1_v1 | iOS_GPUFamily2_v1 => 8,
iOS_GPUFamily1_v2 | iOS_GPUFamily2_v2 | iOS_GPUFamily3_v1 => 9,
iOS_GPUFamily1_v3 | iOS_GPUFamily2_v3 | iOS_GPUFamily3_v2 => 10,
iOS_GPUFamily1_v4 | iOS_GPUFamily2_v4 | iOS_GPUFamily3_v3 | iOS_GPUFamily4_v1 => 11,
iOS_GPUFamily1_v5 | iOS_GPUFamily2_v5 | iOS_GPUFamily3_v4 | iOS_GPUFamily4_v2
| iOS_GPUFamily5_v1 => 12,
tvOS_GPUFamily1_v1 => 9,
tvOS_GPUFamily1_v2 => 10,
tvOS_GPUFamily1_v3 | tvOS_GPUFamily2_v1 => 11,
tvOS_GPUFamily1_v4 | tvOS_GPUFamily2_v2 => 12,
macOS_GPUFamily1_v1 => 11,
macOS_GPUFamily1_v2 | macOS_ReadWriteTextureTier2 => 12,
macOS_GPUFamily1_v3 => 13,
macOS_GPUFamily1_v4 | macOS_GPUFamily2_v1 => 14,
}
}
fn gpu_family(&self) -> u32 {
use MTLFeatureSet::*;
match self {
iOS_GPUFamily1_v1
| iOS_GPUFamily1_v2
| iOS_GPUFamily1_v3
| iOS_GPUFamily1_v4
| iOS_GPUFamily1_v5
| tvOS_GPUFamily1_v1
| tvOS_GPUFamily1_v2
| tvOS_GPUFamily1_v3
| tvOS_GPUFamily1_v4
| macOS_GPUFamily1_v1
| macOS_GPUFamily1_v2
| macOS_ReadWriteTextureTier2
| macOS_GPUFamily1_v3
| macOS_GPUFamily1_v4 => 1,
iOS_GPUFamily2_v1 | iOS_GPUFamily2_v2 | iOS_GPUFamily2_v3 | iOS_GPUFamily2_v4
| iOS_GPUFamily2_v5 | tvOS_GPUFamily2_v1 | tvOS_GPUFamily2_v2 | macOS_GPUFamily2_v1 => {
2
}
iOS_GPUFamily3_v1 | iOS_GPUFamily3_v2 | iOS_GPUFamily3_v3 | iOS_GPUFamily3_v4 => 3,
iOS_GPUFamily4_v1 | iOS_GPUFamily4_v2 => 4,
iOS_GPUFamily5_v1 => 5,
}
}
fn version(&self) -> u32 {
use MTLFeatureSet::*;
match self {
iOS_GPUFamily1_v1
| iOS_GPUFamily2_v1
| iOS_GPUFamily3_v1
| iOS_GPUFamily4_v1
| iOS_GPUFamily5_v1
| macOS_GPUFamily1_v1
| macOS_GPUFamily2_v1
| macOS_ReadWriteTextureTier2
| tvOS_GPUFamily1_v1
| tvOS_GPUFamily2_v1 => 1,
iOS_GPUFamily1_v2 | iOS_GPUFamily2_v2 | iOS_GPUFamily3_v2 | iOS_GPUFamily4_v2
| macOS_GPUFamily1_v2 | tvOS_GPUFamily1_v2 | tvOS_GPUFamily2_v2 => 2,
iOS_GPUFamily1_v3 | iOS_GPUFamily2_v3 | iOS_GPUFamily3_v3 | macOS_GPUFamily1_v3
| tvOS_GPUFamily1_v3 => 3,
iOS_GPUFamily1_v4 | iOS_GPUFamily2_v4 | iOS_GPUFamily3_v4 | tvOS_GPUFamily1_v4
| macOS_GPUFamily1_v4 => 4,
iOS_GPUFamily1_v5 | iOS_GPUFamily2_v5 => 5,
}
}
pub fn supports_metal_kit(&self) -> bool {
true
}
pub fn supports_metal_performance_shaders(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 2,
OS::tvOS => true,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_programmable_blending(&self) -> bool {
self.os() != OS::macOS
}
pub fn supports_pvrtc_pixel_formats(&self) -> bool {
self.os() != OS::macOS
}
pub fn supports_eac_etc_pixel_formats(&self) -> bool {
self.os() != OS::macOS
}
pub fn supports_astc_pixel_formats(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 2,
OS::tvOS => true,
OS::macOS => false,
}
}
pub fn supports_linear_textures(&self) -> bool {
self.os() != OS::macOS || self.os_version() >= 13
}
pub fn supports_bc_pixel_formats(&self) -> bool {
self.os() == OS::macOS
}
pub fn supports_msaa_depth_resolve(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => false,
}
}
pub fn supports_counting_occlusion_query(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => true,
}
}
pub fn supports_base_vertex_instance_drawing(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => true,
}
}
pub fn supports_indirect_buffers(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => true,
}
}
pub fn supports_cube_map_texture_arrays(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 4,
OS::tvOS => false,
OS::macOS => true,
}
}
pub fn supports_texture_barriers(&self) -> bool {
self.os() == OS::macOS
}
pub fn supports_layered_rendering(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 5,
OS::tvOS => false,
OS::macOS => true,
}
}
pub fn supports_tessellation(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3 && self.os_version() >= 10,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_resource_heaps(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_memoryless_render_targets(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => false,
}
}
pub fn supports_function_specialization(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_function_buffer_read_writes(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3 && self.os_version() >= 10,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_function_texture_read_writes(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 4,
OS::tvOS => false,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_array_of_textures(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3 && self.os_version() >= 10,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_array_of_samplers(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3 && self.os_version() >= 11,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_stencil_texture_views(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_depth_16_pixel_format(&self) -> bool {
self.os() == OS::macOS && self.os_version() >= 12
}
pub fn supports_extended_range_pixel_formats(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3 && self.os_version() >= 10,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => false,
}
}
pub fn supports_wide_color_pixel_format(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 11,
OS::tvOS => self.os_version() >= 11,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_combined_msaa_store_and_resolve_action(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3 && self.os_version() >= 10,
OS::tvOS => self.gpu_family() >= 2,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_deferred_store_action(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_msaa_blits(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => true,
}
}
pub fn supports_srgb_writes(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3 || (self.gpu_family() >= 2 && self.version() >= 3),
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.gpu_family() >= 2,
}
}
pub fn supports_16_bit_unsigned_integer_coordinates(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_extract_insert_and_reverse_bits(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_simd_barrier(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_sampler_max_anisotropy(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_sampler_lod_clamp(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 10,
OS::tvOS => self.os_version() >= 10,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_border_color(&self) -> bool {
self.os() == OS::macOS && self.os_version() >= 12
}
pub fn supports_dual_source_blending(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 11,
OS::tvOS => self.os_version() >= 11,
OS::macOS => self.os_version() >= 12,
}
}
pub fn supports_argument_buffers(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 11,
OS::tvOS => self.os_version() >= 11,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_programmable_sample_positions(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 11,
OS::tvOS => self.os_version() >= 11,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_uniform_type(&self) -> bool {
match self.os() {
OS::iOS => self.os_version() >= 11,
OS::tvOS => self.os_version() >= 11,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_imageblocks(&self) -> bool {
self.os() == OS::iOS && self.gpu_family() >= 4
}
pub fn supports_tile_shaders(&self) -> bool {
self.os() == OS::iOS && self.gpu_family() >= 4
}
pub fn supports_imageblock_sample_coverage_control(&self) -> bool {
self.os() == OS::iOS && self.gpu_family() >= 4
}
pub fn supports_threadgroup_sharing(&self) -> bool {
self.os() == OS::iOS && self.gpu_family() >= 4
}
pub fn supports_post_depth_coverage(&self) -> bool {
self.os() == OS::iOS && self.gpu_family() >= 4
}
pub fn supports_quad_scoped_permute_operations(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 4,
OS::tvOS => false,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_raster_order_groups(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 4,
OS::tvOS => false,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_non_uniform_threadgroup_size(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 4,
OS::tvOS => false,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_multiple_viewports(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 5,
OS::tvOS => false,
OS::macOS => self.os_version() >= 13,
}
}
pub fn supports_device_notifications(&self) -> bool {
self.os() == OS::macOS && self.os_version() >= 13
}
pub fn supports_stencil_feedback(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 5,
OS::tvOS => false,
OS::macOS => self.gpu_family() >= 2,
}
}
pub fn supports_stencil_resolve(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 5,
OS::tvOS => false,
OS::macOS => self.gpu_family() >= 2,
}
}
pub fn supports_binary_archive(&self) -> bool {
match self.os() {
OS::iOS => self.gpu_family() >= 3,
OS::tvOS => self.gpu_family() >= 3,
OS::macOS => self.gpu_family() >= 1,
}
}
pub fn max_vertex_attributes(&self) -> u32 {
31
}
pub fn max_buffer_argument_entries(&self) -> u32 {
31
}
pub fn max_texture_argument_entries(&self) -> u32 {
if self.os() == OS::macOS {
128
} else {
31
}
}
pub fn max_sampler_state_argument_entries(&self) -> u32 {
16
}
pub fn max_threadgroup_memory_argument_entries(&self) -> u32 {
31
}
pub fn max_inlined_constant_data_buffers(&self) -> u32 {
if self.os() == OS::macOS {
14
} else {
31
}
}
pub fn max_inline_constant_buffer_length(&self) -> u32 {
4 * KB
}
pub fn max_threads_per_threadgroup(&self) -> u32 {
if self.os() == OS::macOS || self.gpu_family() >= 4 {
1024
} else {
512
}
}
pub fn max_total_threadgroup_memory_allocation(&self) -> u32 {
match (self.os(), self.gpu_family()) {
(OS::iOS, 5) => 64 * KB,
(OS::iOS, 4) => {
if self.os_version() >= 12 {
64 * KB
} else {
32 * KB
}
}
(OS::iOS, 3) => 16 * KB,
(OS::iOS, _) => 16 * KB - 32,
(OS::tvOS, 1) => 16 * KB - 32,
(OS::tvOS, _) => 16 * KB,
(OS::macOS, _) => 32 * KB,
}
}
pub fn max_total_tile_memory_allocation(&self) -> u32 {
if self.os() == OS::iOS && self.gpu_family() == 4 {
32 * KB
} else {
0
}
}
pub fn threadgroup_memory_length_alignment(&self) -> u32 {
16
}
pub fn max_constant_buffer_function_memory_allocation(&self) -> Option<u32> {
if self.os() == OS::macOS {
Some(64 * KB)
} else {
None
}
}
pub fn max_fragment_inputs(&self) -> u32 {
if self.os() == OS::macOS {
32
} else {
60
}
}
pub fn max_fragment_input_components(&self) -> u32 {
if self.os() == OS::macOS {
128
} else {
60
}
}
pub fn max_function_constants(&self) -> u32 {
match self.os() {
OS::iOS if self.os_version() >= 11 => 65536,
OS::tvOS if self.os_version() >= 10 => 65536,
OS::macOS if self.os_version() >= 12 => 65536,
_ => 0,
}
}
pub fn max_tessellation_factor(&self) -> u32 {
if self.supports_tessellation() {
match self.os() {
OS::iOS if self.gpu_family() >= 5 => 64,
OS::iOS => 16,
OS::tvOS => 16,
OS::macOS => 64,
}
} else {
0
}
}
pub fn max_viewports_and_scissor_rectangles(&self) -> u32 {
if self.supports_multiple_viewports() {
16
} else {
1
}
}
pub fn max_raster_order_groups(&self) -> u32 {
if self.supports_raster_order_groups() {
8
} else {
0
}
}
pub fn max_buffer_length(&self) -> u32 {
if self.os() == OS::macOS && self.os_version() >= 12 {
1 * GB
} else {
256 * MB
}
}
pub fn min_buffer_offset_alignment(&self) -> u32 {
if self.os() == OS::macOS {
256
} else {
4
}
}
pub fn max_1d_texture_size(&self) -> u32 {
match (self.os(), self.gpu_family()) {
(OS::iOS, 1) | (OS::iOS, 2) => {
if self.version() <= 2 {
4096
} else {
8192
}
}
(OS::tvOS, 1) => 8192,
_ => 16384,
}
}
pub fn max_2d_texture_size(&self) -> u32 {
match (self.os(), self.gpu_family()) {
(OS::iOS, 1) | (OS::iOS, 2) => {
if self.version() <= 2 {
4096
} else {
8192
}
}
(OS::tvOS, 1) => 8192,
_ => 16384,
}
}
pub fn max_cube_map_texture_size(&self) -> u32 {
match (self.os(), self.gpu_family()) {
(OS::iOS, 1) | (OS::iOS, 2) => {
if self.version() <= 2 {
4096
} else {
8192
}
}
(OS::tvOS, 1) => 8192,
_ => 16384,
}
}
pub fn max_3d_texture_size(&self) -> u32 {
2048
}
pub fn max_array_layers(&self) -> u32 {
2048
}
pub fn copy_texture_buffer_alignment(&self) -> u32 {
match (self.os(), self.gpu_family()) {
(OS::iOS, 1) | (OS::iOS, 2) | (OS::tvOS, 1) => 64,
(OS::iOS, _) | (OS::tvOS, _) => 16,
(OS::macOS, _) => 256,
}
}
/// If this function returns `None` but linear textures are supported,
/// the buffer alignment can be discovered via API query
pub fn new_texture_buffer_alignment(&self) -> Option<u32> {
match self.os() {
OS::iOS => {
if self.os_version() >= 11 {
None
} else if self.gpu_family() == 3 {
Some(16)
} else {
Some(64)
}
}
OS::tvOS => {
if self.os_version() >= 11 {
None
} else {
Some(64)
}
}
OS::macOS => None,
}
}
pub fn max_color_render_targets(&self) -> u32 {
if self.os() == OS::iOS && self.gpu_family() == 1 {
4
} else {
8
}
}
pub fn max_point_primitive_size(&self) -> u32 {
511
}
pub fn max_total_color_render_target_size(&self) -> Option<u32> {
match (self.os(), self.gpu_family()) {
(OS::iOS, 1) => Some(128),
(OS::iOS, 2) | (OS::iOS, 3) => Some(256),
(OS::iOS, _) => Some(512),
(OS::tvOS, _) => Some(256),
(OS::macOS, _) => None,
}
}
pub fn max_visibility_query_offset(&self) -> u32 {
64 * KB - 8
}
pub fn a8_unorm_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::Filter
}
pub fn r8_unorm_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::all()
}
pub fn r8_unorm_srgb_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::macOS {
PixelFormatCapabilities::empty()
} else if self.supports_srgb_writes() {
PixelFormatCapabilities::all()
} else {
!PixelFormatCapabilities::Write
}
}
pub fn r8_snorm_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::iOS && self.gpu_family() == 1 {
!PixelFormatCapabilities::Resolve
} else {
PixelFormatCapabilities::all()
}
}
pub fn r8_uint_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::Write
| PixelFormatCapabilities::Color
| PixelFormatCapabilities::Msaa
}
pub fn r8_sint_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::Write
| PixelFormatCapabilities::Color
| PixelFormatCapabilities::Msaa
}
pub fn r16_unorm_capabilities(&self) -> PixelFormatCapabilities {
if self.os() != OS::macOS {
!PixelFormatCapabilities::Resolve
} else {
PixelFormatCapabilities::all()
}
}
pub fn r16_snorm_capabilities(&self) -> PixelFormatCapabilities {
if self.os() != OS::macOS {
!PixelFormatCapabilities::Resolve
} else {
PixelFormatCapabilities::all()
}
}
pub fn r16_uint_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::Write
| PixelFormatCapabilities::Color
| PixelFormatCapabilities::Msaa
}
pub fn r16_sint_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::Write
| PixelFormatCapabilities::Color
| PixelFormatCapabilities::Msaa
}
pub fn r16_float_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::all()
}
pub fn rg8_unorm_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::all()
}
pub fn rg8_unorm_srgb_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::macOS {
PixelFormatCapabilities::empty()
} else if self.supports_srgb_writes() {
PixelFormatCapabilities::all()
} else {
!PixelFormatCapabilities::Write
}
}
pub fn rg8_snorm_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::iOS && self.gpu_family() == 1 {
!PixelFormatCapabilities::Resolve
} else {
PixelFormatCapabilities::all()
}
}
pub fn rg8_uint_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::Write
| PixelFormatCapabilities::Color
| PixelFormatCapabilities::Msaa
}
pub fn rg8_sint_capabilities(&self) -> PixelFormatCapabilities {
PixelFormatCapabilities::Write
| PixelFormatCapabilities::Color
| PixelFormatCapabilities::Msaa
}
pub fn b5_g6_r5_unorm_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::macOS {
PixelFormatCapabilities::empty()
} else {
!PixelFormatCapabilities::Write
}
}
pub fn a1_bgr5_unorm_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::macOS {
PixelFormatCapabilities::empty()
} else {
!PixelFormatCapabilities::Write
}
}
pub fn abgr4_unorm_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::macOS {
PixelFormatCapabilities::empty()
} else {
!PixelFormatCapabilities::Write
}
}
pub fn bgr5_a1_unorm_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::macOS {
PixelFormatCapabilities::empty()
} else {
!PixelFormatCapabilities::Write
}
}
pub fn r32_uint_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::iOS && self.os_version() == 8 {
PixelFormatCapabilities::Color
} else if self.os() == OS::macOS {
PixelFormatCapabilities::Color
| PixelFormatCapabilities::Write
| PixelFormatCapabilities::Msaa
} else {
PixelFormatCapabilities::Color | PixelFormatCapabilities::Write
}
}
pub fn r32_sint_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::iOS && self.os_version() == 8 {
PixelFormatCapabilities::Color
} else if self.os() == OS::macOS {
PixelFormatCapabilities::Color
| PixelFormatCapabilities::Write
| PixelFormatCapabilities::Msaa
} else {
PixelFormatCapabilities::Color | PixelFormatCapabilities::Write
}
}
pub fn r32_float_capabilities(&self) -> PixelFormatCapabilities {
if self.os() == OS::iOS && self.os_version() == 8 {
PixelFormatCapabilities::Color
| PixelFormatCapabilities::Blend