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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLPurgeableState(pub NSUInteger);
impl MTLPurgeableState {
    #[doc(alias = "MTLPurgeableStateKeepCurrent")]
    pub const KeepCurrent: Self = Self(1);
    #[doc(alias = "MTLPurgeableStateNonVolatile")]
    pub const NonVolatile: Self = Self(2);
    #[doc(alias = "MTLPurgeableStateVolatile")]
    pub const Volatile: Self = Self(3);
    #[doc(alias = "MTLPurgeableStateEmpty")]
    pub const Empty: Self = Self(4);
}

unsafe impl Encode for MTLPurgeableState {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLPurgeableState {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLCPUCacheMode(pub NSUInteger);
impl MTLCPUCacheMode {
    #[doc(alias = "MTLCPUCacheModeDefaultCache")]
    pub const DefaultCache: Self = Self(0);
    #[doc(alias = "MTLCPUCacheModeWriteCombined")]
    pub const WriteCombined: Self = Self(1);
}

unsafe impl Encode for MTLCPUCacheMode {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLCPUCacheMode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLStorageMode(pub NSUInteger);
impl MTLStorageMode {
    #[doc(alias = "MTLStorageModeShared")]
    pub const Shared: Self = Self(0);
    #[doc(alias = "MTLStorageModeManaged")]
    pub const Managed: Self = Self(1);
    #[doc(alias = "MTLStorageModePrivate")]
    pub const Private: Self = Self(2);
    #[doc(alias = "MTLStorageModeMemoryless")]
    pub const Memoryless: Self = Self(3);
}

unsafe impl Encode for MTLStorageMode {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLStorageMode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLHazardTrackingMode(pub NSUInteger);
impl MTLHazardTrackingMode {
    #[doc(alias = "MTLHazardTrackingModeDefault")]
    pub const Default: Self = Self(0);
    #[doc(alias = "MTLHazardTrackingModeUntracked")]
    pub const Untracked: Self = Self(1);
    #[doc(alias = "MTLHazardTrackingModeTracked")]
    pub const Tracked: Self = Self(2);
}

unsafe impl Encode for MTLHazardTrackingMode {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLHazardTrackingMode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLResourceOptions(pub NSUInteger);
bitflags::bitflags! {
    impl MTLResourceOptions: NSUInteger {
        const MTLResourceCPUCacheModeDefaultCache = MTLCPUCacheMode::DefaultCache.0<<MTLResourceCPUCacheModeShift;
        const MTLResourceCPUCacheModeWriteCombined = MTLCPUCacheMode::WriteCombined.0<<MTLResourceCPUCacheModeShift;
        const MTLResourceStorageModeShared = MTLStorageMode::Shared.0<<MTLResourceStorageModeShift;
        const MTLResourceStorageModeManaged = MTLStorageMode::Managed.0<<MTLResourceStorageModeShift;
        const MTLResourceStorageModePrivate = MTLStorageMode::Private.0<<MTLResourceStorageModeShift;
        const MTLResourceStorageModeMemoryless = MTLStorageMode::Memoryless.0<<MTLResourceStorageModeShift;
        const MTLResourceHazardTrackingModeDefault = MTLHazardTrackingMode::Default.0<<MTLResourceHazardTrackingModeShift;
        const MTLResourceHazardTrackingModeUntracked = MTLHazardTrackingMode::Untracked.0<<MTLResourceHazardTrackingModeShift;
        const MTLResourceHazardTrackingModeTracked = MTLHazardTrackingMode::Tracked.0<<MTLResourceHazardTrackingModeShift;
#[deprecated]
        const MTLResourceOptionCPUCacheModeDefault = MTLResourceOptions::MTLResourceCPUCacheModeDefaultCache.0;
#[deprecated]
        const MTLResourceOptionCPUCacheModeWriteCombined = MTLResourceOptions::MTLResourceCPUCacheModeWriteCombined.0;
    }
}

unsafe impl Encode for MTLResourceOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for MTLResourceOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    pub unsafe trait MTLResource: NSObjectProtocol + IsRetainable {
        #[method_id(@__retain_semantics Other label)]
        fn label(&self) -> Option<Retained<NSString>>;

        #[method(setLabel:)]
        fn setLabel(&self, label: Option<&NSString>);

        #[cfg(feature = "MTLDevice")]
        #[method_id(@__retain_semantics Other device)]
        fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;

        #[method(cpuCacheMode)]
        fn cpuCacheMode(&self) -> MTLCPUCacheMode;

        #[method(storageMode)]
        fn storageMode(&self) -> MTLStorageMode;

        #[method(hazardTrackingMode)]
        fn hazardTrackingMode(&self) -> MTLHazardTrackingMode;

        #[method(resourceOptions)]
        fn resourceOptions(&self) -> MTLResourceOptions;

        #[method(setPurgeableState:)]
        fn setPurgeableState(&self, state: MTLPurgeableState) -> MTLPurgeableState;

        #[cfg(feature = "MTLHeap")]
        #[method_id(@__retain_semantics Other heap)]
        fn heap(&self) -> Option<Retained<ProtocolObject<dyn MTLHeap>>>;

        #[method(heapOffset)]
        fn heapOffset(&self) -> NSUInteger;

        #[method(allocatedSize)]
        fn allocatedSize(&self) -> NSUInteger;

        #[method(makeAliasable)]
        unsafe fn makeAliasable(&self);

        #[method(isAliasable)]
        fn isAliasable(&self) -> bool;
    }

    unsafe impl ProtocolType for dyn MTLResource {}
);