@bloomengine/engine 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/native/tvos/Cargo.lock +1 -0
  2. package/native/tvos/Cargo.toml +2 -0
  3. package/native/tvos/metal-patched/Cargo.toml +178 -0
  4. package/native/tvos/metal-patched/LICENSE-APACHE +201 -0
  5. package/native/tvos/metal-patched/LICENSE-MIT +25 -0
  6. package/native/tvos/metal-patched/src/acceleration_structure.rs +667 -0
  7. package/native/tvos/metal-patched/src/acceleration_structure_pass.rs +108 -0
  8. package/native/tvos/metal-patched/src/argument.rs +366 -0
  9. package/native/tvos/metal-patched/src/blitpass.rs +102 -0
  10. package/native/tvos/metal-patched/src/buffer.rs +71 -0
  11. package/native/tvos/metal-patched/src/capturedescriptor.rs +76 -0
  12. package/native/tvos/metal-patched/src/capturemanager.rs +113 -0
  13. package/native/tvos/metal-patched/src/commandbuffer.rs +192 -0
  14. package/native/tvos/metal-patched/src/commandqueue.rs +44 -0
  15. package/native/tvos/metal-patched/src/computepass.rs +107 -0
  16. package/native/tvos/metal-patched/src/constants.rs +152 -0
  17. package/native/tvos/metal-patched/src/counters.rs +119 -0
  18. package/native/tvos/metal-patched/src/depthstencil.rs +190 -0
  19. package/native/tvos/metal-patched/src/device.rs +2134 -0
  20. package/native/tvos/metal-patched/src/drawable.rs +39 -0
  21. package/native/tvos/metal-patched/src/encoder.rs +2041 -0
  22. package/native/tvos/metal-patched/src/heap.rs +281 -0
  23. package/native/tvos/metal-patched/src/indirect_encoder.rs +344 -0
  24. package/native/tvos/metal-patched/src/lib.rs +657 -0
  25. package/native/tvos/metal-patched/src/library.rs +902 -0
  26. package/native/tvos/metal-patched/src/mps.rs +575 -0
  27. package/native/tvos/metal-patched/src/pipeline/compute.rs +475 -0
  28. package/native/tvos/metal-patched/src/pipeline/mod.rs +71 -0
  29. package/native/tvos/metal-patched/src/pipeline/render.rs +762 -0
  30. package/native/tvos/metal-patched/src/renderpass.rs +443 -0
  31. package/native/tvos/metal-patched/src/resource.rs +182 -0
  32. package/native/tvos/metal-patched/src/sampler.rs +165 -0
  33. package/native/tvos/metal-patched/src/sync.rs +178 -0
  34. package/native/tvos/metal-patched/src/texture.rs +352 -0
  35. package/native/tvos/metal-patched/src/types.rs +90 -0
  36. package/native/tvos/metal-patched/src/vertexdescriptor.rs +250 -0
  37. package/native/tvos/src/lib.rs +151 -0
  38. package/package.json +5 -1
@@ -0,0 +1,443 @@
1
+ // Copyright 2016 GFX developers
2
+ //
3
+ // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4
+ // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5
+ // http://opensource.org/licenses/MIT>, at your option. This file may not be
6
+ // copied, modified, or distributed except according to those terms.
7
+
8
+ use super::*;
9
+
10
+ /// See <https://developer.apple.com/documentation/metal/mtlloadaction>
11
+ #[repr(u64)]
12
+ #[derive(Copy, Clone, Debug)]
13
+ pub enum MTLLoadAction {
14
+ DontCare = 0,
15
+ Load = 1,
16
+ Clear = 2,
17
+ }
18
+
19
+ /// See <https://developer.apple.com/documentation/metal/mtlstoreaction>
20
+ #[repr(u64)]
21
+ #[derive(Copy, Clone, Debug)]
22
+ pub enum MTLStoreAction {
23
+ DontCare = 0,
24
+ Store = 1,
25
+ MultisampleResolve = 2,
26
+ StoreAndMultisampleResolve = 3,
27
+ Unknown = 4,
28
+ CustomSampleDepthStore = 5,
29
+ }
30
+
31
+ /// See <https://developer.apple.com/documentation/metal/mtlclearcolor>
32
+ #[repr(C)]
33
+ #[derive(Copy, Clone, Debug)]
34
+ pub struct MTLClearColor {
35
+ pub red: f64,
36
+ pub green: f64,
37
+ pub blue: f64,
38
+ pub alpha: f64,
39
+ }
40
+
41
+ impl MTLClearColor {
42
+ #[inline]
43
+ pub fn new(red: f64, green: f64, blue: f64, alpha: f64) -> Self {
44
+ Self {
45
+ red,
46
+ green,
47
+ blue,
48
+ alpha,
49
+ }
50
+ }
51
+ }
52
+
53
+ /// See <https://developer.apple.com/documentation/metal/mtlmultisamplestencilresolvefilter>
54
+ #[repr(u32)]
55
+ #[allow(non_camel_case_types)]
56
+ pub enum MTLMultisampleStencilResolveFilter {
57
+ Sample0 = 0,
58
+ DepthResolvedSample = 1,
59
+ }
60
+
61
+ /// See <https://developer.apple.com/documentation/metal/mtlrenderpassattachmentdescriptor>
62
+ pub enum MTLRenderPassAttachmentDescriptor {}
63
+
64
+ foreign_obj_type! {
65
+ type CType = MTLRenderPassAttachmentDescriptor;
66
+ pub struct RenderPassAttachmentDescriptor;
67
+ }
68
+
69
+ impl RenderPassAttachmentDescriptorRef {
70
+ pub fn texture(&self) -> Option<&TextureRef> {
71
+ unsafe { msg_send![self, texture] }
72
+ }
73
+
74
+ pub fn set_texture(&self, texture: Option<&TextureRef>) {
75
+ unsafe { msg_send![self, setTexture: texture] }
76
+ }
77
+
78
+ pub fn level(&self) -> NSUInteger {
79
+ unsafe { msg_send![self, level] }
80
+ }
81
+
82
+ pub fn set_level(&self, level: NSUInteger) {
83
+ unsafe { msg_send![self, setLevel: level] }
84
+ }
85
+
86
+ pub fn slice(&self) -> NSUInteger {
87
+ unsafe { msg_send![self, slice] }
88
+ }
89
+
90
+ pub fn set_slice(&self, slice: NSUInteger) {
91
+ unsafe { msg_send![self, setSlice: slice] }
92
+ }
93
+
94
+ pub fn depth_plane(&self) -> NSUInteger {
95
+ unsafe { msg_send![self, depthPlane] }
96
+ }
97
+
98
+ pub fn set_depth_plane(&self, depth_plane: NSUInteger) {
99
+ unsafe { msg_send![self, setDepthPlane: depth_plane] }
100
+ }
101
+
102
+ pub fn resolve_texture(&self) -> Option<&TextureRef> {
103
+ unsafe { msg_send![self, resolveTexture] }
104
+ }
105
+
106
+ pub fn set_resolve_texture(&self, resolve_texture: Option<&TextureRef>) {
107
+ unsafe { msg_send![self, setResolveTexture: resolve_texture] }
108
+ }
109
+
110
+ pub fn resolve_level(&self) -> NSUInteger {
111
+ unsafe { msg_send![self, resolveLevel] }
112
+ }
113
+
114
+ pub fn set_resolve_level(&self, resolve_level: NSUInteger) {
115
+ unsafe { msg_send![self, setResolveLevel: resolve_level] }
116
+ }
117
+
118
+ pub fn resolve_slice(&self) -> NSUInteger {
119
+ unsafe { msg_send![self, resolveSlice] }
120
+ }
121
+
122
+ pub fn set_resolve_slice(&self, resolve_slice: NSUInteger) {
123
+ unsafe { msg_send![self, setResolveSlice: resolve_slice] }
124
+ }
125
+
126
+ pub fn resolve_depth_plane(&self) -> NSUInteger {
127
+ unsafe { msg_send![self, resolveDepthPlane] }
128
+ }
129
+
130
+ pub fn set_resolve_depth_plane(&self, resolve_depth_plane: NSUInteger) {
131
+ unsafe { msg_send![self, setResolveDepthPlane: resolve_depth_plane] }
132
+ }
133
+
134
+ pub fn load_action(&self) -> MTLLoadAction {
135
+ unsafe { msg_send![self, loadAction] }
136
+ }
137
+
138
+ pub fn set_load_action(&self, load_action: MTLLoadAction) {
139
+ unsafe { msg_send![self, setLoadAction: load_action] }
140
+ }
141
+
142
+ pub fn store_action(&self) -> MTLStoreAction {
143
+ unsafe { msg_send![self, storeAction] }
144
+ }
145
+
146
+ pub fn set_store_action(&self, store_action: MTLStoreAction) {
147
+ unsafe { msg_send![self, setStoreAction: store_action] }
148
+ }
149
+ }
150
+
151
+ /// See <https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptor>
152
+ pub enum MTLRenderPassColorAttachmentDescriptor {}
153
+
154
+ foreign_obj_type! {
155
+ type CType = MTLRenderPassColorAttachmentDescriptor;
156
+ pub struct RenderPassColorAttachmentDescriptor;
157
+ type ParentType = RenderPassAttachmentDescriptor;
158
+ }
159
+
160
+ impl RenderPassColorAttachmentDescriptor {
161
+ pub fn new() -> Self {
162
+ unsafe {
163
+ let class = class!(MTLRenderPassColorAttachmentDescriptor);
164
+ msg_send![class, new]
165
+ }
166
+ }
167
+ }
168
+
169
+ impl RenderPassColorAttachmentDescriptorRef {
170
+ pub fn clear_color(&self) -> MTLClearColor {
171
+ unsafe { msg_send![self, clearColor] }
172
+ }
173
+
174
+ pub fn set_clear_color(&self, clear_color: MTLClearColor) {
175
+ unsafe { msg_send![self, setClearColor: clear_color] }
176
+ }
177
+ }
178
+
179
+ /// See <https://developer.apple.com/documentation/metal/mtlrenderpassdepthattachmentdescriptor>
180
+ pub enum MTLRenderPassDepthAttachmentDescriptor {}
181
+
182
+ foreign_obj_type! {
183
+ type CType = MTLRenderPassDepthAttachmentDescriptor;
184
+ pub struct RenderPassDepthAttachmentDescriptor;
185
+ type ParentType = RenderPassAttachmentDescriptor;
186
+ }
187
+
188
+ impl RenderPassDepthAttachmentDescriptorRef {
189
+ pub fn clear_depth(&self) -> f64 {
190
+ unsafe { msg_send![self, clearDepth] }
191
+ }
192
+
193
+ pub fn set_clear_depth(&self, clear_depth: f64) {
194
+ unsafe { msg_send![self, setClearDepth: clear_depth] }
195
+ }
196
+ }
197
+
198
+ /// See <https://developer.apple.com/documentation/metal/mtlrenderpassstencilattachmentdescriptor>
199
+ pub enum MTLRenderPassStencilAttachmentDescriptor {}
200
+
201
+ foreign_obj_type! {
202
+ type CType = MTLRenderPassStencilAttachmentDescriptor;
203
+ pub struct RenderPassStencilAttachmentDescriptor;
204
+ type ParentType = RenderPassAttachmentDescriptor;
205
+ }
206
+
207
+ impl RenderPassStencilAttachmentDescriptorRef {
208
+ pub fn clear_stencil(&self) -> u32 {
209
+ unsafe { msg_send![self, clearStencil] }
210
+ }
211
+
212
+ pub fn set_clear_stencil(&self, clear_stencil: u32) {
213
+ unsafe { msg_send![self, setClearStencil: clear_stencil] }
214
+ }
215
+
216
+ pub fn stencil_resolve_filter(&self) -> MTLMultisampleStencilResolveFilter {
217
+ unsafe { msg_send![self, stencilResolveFilter] }
218
+ }
219
+
220
+ pub fn set_stencil_resolve_filter(
221
+ &self,
222
+ stencil_resolve_filter: MTLMultisampleStencilResolveFilter,
223
+ ) {
224
+ unsafe { msg_send![self, setStencilResolveFilter: stencil_resolve_filter] }
225
+ }
226
+ }
227
+
228
+ /// See <https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptorarray>
229
+ pub enum MTLRenderPassColorAttachmentDescriptorArray {}
230
+
231
+ foreign_obj_type! {
232
+ type CType = MTLRenderPassColorAttachmentDescriptorArray;
233
+ pub struct RenderPassColorAttachmentDescriptorArray;
234
+ }
235
+
236
+ impl RenderPassColorAttachmentDescriptorArrayRef {
237
+ pub fn object_at(&self, index: NSUInteger) -> Option<&RenderPassColorAttachmentDescriptorRef> {
238
+ unsafe { msg_send![self, objectAtIndexedSubscript: index] }
239
+ }
240
+
241
+ pub fn set_object_at(
242
+ &self,
243
+ index: NSUInteger,
244
+ attachment: Option<&RenderPassColorAttachmentDescriptorRef>,
245
+ ) {
246
+ unsafe {
247
+ msg_send![self, setObject:attachment
248
+ atIndexedSubscript:index]
249
+ }
250
+ }
251
+ }
252
+
253
+ /// See <https://developer.apple.com/documentation/metal/mtlrenderpasssamplebufferattachmentdescriptor>
254
+ pub enum MTLRenderPassSampleBufferAttachmentDescriptor {}
255
+
256
+ foreign_obj_type! {
257
+ type CType = MTLRenderPassSampleBufferAttachmentDescriptor;
258
+ pub struct RenderPassSampleBufferAttachmentDescriptor;
259
+ }
260
+
261
+ impl RenderPassSampleBufferAttachmentDescriptor {
262
+ pub fn new() -> Self {
263
+ let class = class!(MTLRenderPassSampleBufferAttachmentDescriptor);
264
+ unsafe { msg_send![class, new] }
265
+ }
266
+ }
267
+
268
+ impl RenderPassSampleBufferAttachmentDescriptorRef {
269
+ pub fn sample_buffer(&self) -> Option<&CounterSampleBufferRef> {
270
+ unsafe { msg_send![self, sampleBuffer] }
271
+ }
272
+
273
+ pub fn set_sample_buffer(&self, sample_buffer: &CounterSampleBufferRef) {
274
+ unsafe { msg_send![self, setSampleBuffer: sample_buffer] }
275
+ }
276
+
277
+ pub fn start_of_vertex_sample_index(&self) -> NSUInteger {
278
+ unsafe { msg_send![self, startOfVertexSampleIndex] }
279
+ }
280
+
281
+ pub fn set_start_of_vertex_sample_index(&self, start_of_vertex_sample_index: NSUInteger) {
282
+ unsafe {
283
+ msg_send![
284
+ self,
285
+ setStartOfVertexSampleIndex: start_of_vertex_sample_index
286
+ ]
287
+ }
288
+ }
289
+
290
+ pub fn end_of_vertex_sample_index(&self) -> NSUInteger {
291
+ unsafe { msg_send![self, endOfVertexSampleIndex] }
292
+ }
293
+
294
+ pub fn set_end_of_vertex_sample_index(&self, end_of_vertex_sample_index: NSUInteger) {
295
+ unsafe { msg_send![self, setEndOfVertexSampleIndex: end_of_vertex_sample_index] }
296
+ }
297
+
298
+ pub fn start_of_fragment_sample_index(&self) -> NSUInteger {
299
+ unsafe { msg_send![self, startOfFragmentSampleIndex] }
300
+ }
301
+
302
+ pub fn set_start_of_fragment_sample_index(&self, start_of_fragment_sample_index: NSUInteger) {
303
+ unsafe {
304
+ msg_send![
305
+ self,
306
+ setStartOfFragmentSampleIndex: start_of_fragment_sample_index
307
+ ]
308
+ }
309
+ }
310
+
311
+ pub fn end_of_fragment_sample_index(&self) -> NSUInteger {
312
+ unsafe { msg_send![self, endOfFragmentSampleIndex] }
313
+ }
314
+
315
+ pub fn set_end_of_fragment_sample_index(&self, end_of_fragment_sample_index: NSUInteger) {
316
+ unsafe {
317
+ msg_send![
318
+ self,
319
+ setEndOfFragmentSampleIndex: end_of_fragment_sample_index
320
+ ]
321
+ }
322
+ }
323
+ }
324
+
325
+ /// See <https://developer.apple.com/documentation/metal/mtlrenderpasssamplebufferattachmentdescriptorarray>
326
+ pub enum MTLRenderPassSampleBufferAttachmentDescriptorArray {}
327
+
328
+ foreign_obj_type! {
329
+ type CType = MTLRenderPassSampleBufferAttachmentDescriptorArray;
330
+ pub struct RenderPassSampleBufferAttachmentDescriptorArray;
331
+ }
332
+
333
+ impl RenderPassSampleBufferAttachmentDescriptorArrayRef {
334
+ pub fn object_at(
335
+ &self,
336
+ index: NSUInteger,
337
+ ) -> Option<&RenderPassSampleBufferAttachmentDescriptorRef> {
338
+ unsafe { msg_send![self, objectAtIndexedSubscript: index] }
339
+ }
340
+
341
+ pub fn set_object_at(
342
+ &self,
343
+ index: NSUInteger,
344
+ attachment: Option<&RenderPassSampleBufferAttachmentDescriptorRef>,
345
+ ) {
346
+ unsafe {
347
+ msg_send![self, setObject:attachment
348
+ atIndexedSubscript:index]
349
+ }
350
+ }
351
+ }
352
+
353
+ /// ## Important!
354
+ /// When configuring a [`MTLTextureDescriptor`] object for use with an attachment, set its usage
355
+ /// value to renderTarget if you already know that you intend to use the resulting MTLTexture object in
356
+ /// an attachment. This may significantly improve your app’s performance with certain hardware.
357
+ ///
358
+ /// See <https://developer.apple.com/documentation/metal/mtlrenderpassdescriptor>
359
+ pub enum MTLRenderPassDescriptor {}
360
+
361
+ foreign_obj_type! {
362
+ type CType = MTLRenderPassDescriptor;
363
+ pub struct RenderPassDescriptor;
364
+ }
365
+
366
+ impl RenderPassDescriptor {
367
+ /// Creates a default render pass descriptor with no attachments.
368
+ pub fn new<'a>() -> &'a RenderPassDescriptorRef {
369
+ unsafe { msg_send![class!(MTLRenderPassDescriptor), renderPassDescriptor] }
370
+ }
371
+ }
372
+
373
+ impl RenderPassDescriptorRef {
374
+ pub fn color_attachments(&self) -> &RenderPassColorAttachmentDescriptorArrayRef {
375
+ unsafe { msg_send![self, colorAttachments] }
376
+ }
377
+
378
+ pub fn depth_attachment(&self) -> Option<&RenderPassDepthAttachmentDescriptorRef> {
379
+ unsafe { msg_send![self, depthAttachment] }
380
+ }
381
+
382
+ pub fn set_depth_attachment(
383
+ &self,
384
+ depth_attachment: Option<&RenderPassDepthAttachmentDescriptorRef>,
385
+ ) {
386
+ unsafe { msg_send![self, setDepthAttachment: depth_attachment] }
387
+ }
388
+
389
+ pub fn stencil_attachment(&self) -> Option<&RenderPassStencilAttachmentDescriptorRef> {
390
+ unsafe { msg_send![self, stencilAttachment] }
391
+ }
392
+
393
+ pub fn set_stencil_attachment(
394
+ &self,
395
+ stencil_attachment: Option<&RenderPassStencilAttachmentDescriptorRef>,
396
+ ) {
397
+ unsafe { msg_send![self, setStencilAttachment: stencil_attachment] }
398
+ }
399
+
400
+ pub fn visibility_result_buffer(&self) -> Option<&BufferRef> {
401
+ unsafe { msg_send![self, visibilityResultBuffer] }
402
+ }
403
+
404
+ pub fn set_visibility_result_buffer(&self, buffer: Option<&BufferRef>) {
405
+ unsafe { msg_send![self, setVisibilityResultBuffer: buffer] }
406
+ }
407
+
408
+ pub fn render_target_array_length(&self) -> NSUInteger {
409
+ unsafe { msg_send![self, renderTargetArrayLength] }
410
+ }
411
+
412
+ pub fn set_render_target_array_length(&self, length: NSUInteger) {
413
+ unsafe { msg_send![self, setRenderTargetArrayLength: length] }
414
+ }
415
+
416
+ pub fn render_target_width(&self) -> NSUInteger {
417
+ unsafe { msg_send![self, renderTargetWidth] }
418
+ }
419
+
420
+ pub fn set_render_target_width(&self, size: NSUInteger) {
421
+ unsafe { msg_send![self, setRenderTargetWidth: size] }
422
+ }
423
+
424
+ pub fn render_target_height(&self) -> NSUInteger {
425
+ unsafe { msg_send![self, renderTargetHeight] }
426
+ }
427
+
428
+ pub fn set_render_target_height(&self, size: NSUInteger) {
429
+ unsafe { msg_send![self, setRenderTargetHeight: size] }
430
+ }
431
+
432
+ pub fn default_raster_sample_count(&self) -> NSUInteger {
433
+ unsafe { msg_send![self, defaultRasterSampleCount] }
434
+ }
435
+
436
+ pub fn set_default_raster_sample_count(&self, count: NSUInteger) {
437
+ unsafe { msg_send![self, setDefaultRasterSampleCount: count] }
438
+ }
439
+
440
+ pub fn sample_buffer_attachments(&self) -> &RenderPassSampleBufferAttachmentDescriptorArrayRef {
441
+ unsafe { msg_send![self, sampleBufferAttachments] }
442
+ }
443
+ }
@@ -0,0 +1,182 @@
1
+ // Copyright 2016 GFX developers
2
+ //
3
+ // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4
+ // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5
+ // http://opensource.org/licenses/MIT>, at your option. This file may not be
6
+ // copied, modified, or distributed except according to those terms.
7
+
8
+ use super::*;
9
+ use objc::runtime::{NO, YES};
10
+
11
+ /// See <https://developer.apple.com/documentation/metal/mtlpurgeablestate>
12
+ #[repr(u64)]
13
+ #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
14
+ pub enum MTLPurgeableState {
15
+ KeepCurrent = 1,
16
+ NonVolatile = 2,
17
+ Volatile = 3,
18
+ Empty = 4,
19
+ }
20
+
21
+ /// See <https://developer.apple.com/documentation/metal/mtlcpucachemode>
22
+ #[repr(u64)]
23
+ #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
24
+ pub enum MTLCPUCacheMode {
25
+ DefaultCache = 0,
26
+ WriteCombined = 1,
27
+ }
28
+
29
+ /// See <https://developer.apple.com/documentation/metal/mtlstoragemode>
30
+ #[repr(u64)]
31
+ #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
32
+ pub enum MTLStorageMode {
33
+ Shared = 0,
34
+ Managed = 1,
35
+ Private = 2,
36
+ /// Only available on macos(11.0), macCatalyst(14.0), ios(10.0)
37
+ Memoryless = 3,
38
+ }
39
+
40
+ /// Only available on macos(10.15), ios(13.0)
41
+ ///
42
+ /// See <https://developer.apple.com/documentation/metal/mtlhazardtrackingmode>
43
+ #[repr(u64)]
44
+ #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
45
+ pub enum MTLHazardTrackingMode {
46
+ Default = 0,
47
+ Untracked = 1,
48
+ Tracked = 2,
49
+ }
50
+
51
+ pub const MTLResourceCPUCacheModeShift: NSUInteger = 0;
52
+ pub const MTLResourceCPUCacheModeMask: NSUInteger = 0xf << MTLResourceCPUCacheModeShift;
53
+ pub const MTLResourceStorageModeShift: NSUInteger = 4;
54
+ pub const MTLResourceStorageModeMask: NSUInteger = 0xf << MTLResourceStorageModeShift;
55
+ pub const MTLResourceHazardTrackingModeShift: NSUInteger = 8;
56
+ pub const MTLResourceHazardTrackingModeMask: NSUInteger = 0x3 << MTLResourceHazardTrackingModeShift;
57
+
58
+ bitflags::bitflags! {
59
+ /// See <https://developer.apple.com/documentation/metal/mtlresourceoptions>
60
+ #[allow(non_upper_case_globals)]
61
+ #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
62
+ pub struct MTLResourceOptions: NSUInteger {
63
+ const CPUCacheModeDefaultCache = (MTLCPUCacheMode::DefaultCache as NSUInteger) << MTLResourceCPUCacheModeShift;
64
+ const CPUCacheModeWriteCombined = (MTLCPUCacheMode::WriteCombined as NSUInteger) << MTLResourceCPUCacheModeShift;
65
+
66
+ const StorageModeShared = (MTLStorageMode::Shared as NSUInteger) << MTLResourceStorageModeShift;
67
+ const StorageModeManaged = (MTLStorageMode::Managed as NSUInteger) << MTLResourceStorageModeShift;
68
+ const StorageModePrivate = (MTLStorageMode::Private as NSUInteger) << MTLResourceStorageModeShift;
69
+ const StorageModeMemoryless = (MTLStorageMode::Memoryless as NSUInteger) << MTLResourceStorageModeShift;
70
+
71
+ /// Only available on macos(10.13), ios(10.0)
72
+ const HazardTrackingModeDefault = (MTLHazardTrackingMode::Default as NSUInteger) << MTLResourceHazardTrackingModeShift;
73
+ /// Only available on macos(10.13), ios(10.0)
74
+ const HazardTrackingModeUntracked = (MTLHazardTrackingMode::Untracked as NSUInteger) << MTLResourceHazardTrackingModeShift;
75
+ /// Only available on macos(10.15), ios(13.0)
76
+ const HazardTrackingModeTracked = (MTLHazardTrackingMode::Tracked as NSUInteger) << MTLResourceHazardTrackingModeShift;
77
+ }
78
+ }
79
+
80
+ bitflags::bitflags! {
81
+ /// Options that describe how a graphics or compute function uses an argument buffer’s resource.
82
+ ///
83
+ /// Enabling certain options for certain resources determines whether the Metal driver should
84
+ /// convert the resource to another format (for example, whether to decompress a color render target).
85
+ ///
86
+ /// See <https://developer.apple.com/documentation/metal/mtlresourceusage>
87
+ #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
88
+ pub struct MTLResourceUsage: NSUInteger {
89
+ /// An option that enables reading from the resource.
90
+ const Read = 1 << 0;
91
+ /// An option that enables writing to the resource.
92
+ const Write = 1 << 1;
93
+ /// An option that enables sampling from the resource.
94
+ ///
95
+ /// Specify this option only if the resource is a texture.
96
+ const Sample = 1 << 2;
97
+ }
98
+ }
99
+
100
+ /// See <https://developer.apple.com/documentation/metal/mtlsizeandalign>
101
+ #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
102
+ #[repr(C)]
103
+ pub struct MTLSizeAndAlign {
104
+ pub size: NSUInteger,
105
+ pub align: NSUInteger,
106
+ }
107
+
108
+ /// See <https://developer.apple.com/documentation/metal/mtlresource>
109
+ pub enum MTLResource {}
110
+
111
+ foreign_obj_type! {
112
+ type CType = MTLResource;
113
+ pub struct Resource;
114
+ type ParentType = NsObject;
115
+ }
116
+
117
+ impl ResourceRef {
118
+ pub fn device(&self) -> &DeviceRef {
119
+ unsafe { msg_send![self, device] }
120
+ }
121
+
122
+ pub fn label(&self) -> &str {
123
+ unsafe {
124
+ let label = msg_send![self, label];
125
+ crate::nsstring_as_str(label)
126
+ }
127
+ }
128
+
129
+ pub fn set_label(&self, label: &str) {
130
+ unsafe {
131
+ let nslabel = crate::nsstring_from_str(label);
132
+ let () = msg_send![self, setLabel: nslabel];
133
+ }
134
+ }
135
+
136
+ pub fn cpu_cache_mode(&self) -> MTLCPUCacheMode {
137
+ unsafe { msg_send![self, cpuCacheMode] }
138
+ }
139
+
140
+ pub fn storage_mode(&self) -> MTLStorageMode {
141
+ unsafe { msg_send![self, storageMode] }
142
+ }
143
+
144
+ pub fn set_purgeable_state(&self, state: MTLPurgeableState) -> MTLPurgeableState {
145
+ unsafe { msg_send![self, setPurgeableState: state] }
146
+ }
147
+
148
+ /// Only available on macOS 10.13+ & iOS 10.11+
149
+ pub fn allocated_size(&self) -> NSUInteger {
150
+ unsafe { msg_send![self, allocatedSize] }
151
+ }
152
+
153
+ /// Only available on macos(10.15), ios(13.0)
154
+ pub fn hazard_tracking_mode(&self) -> MTLHazardTrackingMode {
155
+ unsafe { msg_send![self, hazardTrackingMode] }
156
+ }
157
+
158
+ /// Only available on macos(10.15), ios(13.0)
159
+ pub fn resource_options(&self) -> MTLResourceOptions {
160
+ unsafe { msg_send![self, resourceOptions] }
161
+ }
162
+
163
+ /// Only available on macos(10.13), ios(10.0)
164
+ pub fn heap(&self) -> &HeapRef {
165
+ unsafe { msg_send![self, heap] }
166
+ }
167
+
168
+ /// Only available on macos(10.15), ios(13.0)
169
+ pub fn heap_offset(&self) -> NSUInteger {
170
+ unsafe { msg_send![self, heapOffset] }
171
+ }
172
+
173
+ /// Only available on macos(10.13), ios(10.0)
174
+ pub fn make_aliasable(&self) {
175
+ unsafe { msg_send![self, makeAliasable] }
176
+ }
177
+
178
+ /// Only available on macos(10.13), ios(10.0)
179
+ pub fn is_aliasable(&self) -> bool {
180
+ unsafe { msg_send_bool![self, isAliasable] }
181
+ }
182
+ }