@bloomengine/engine 0.4.1 → 0.4.2
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.
- package/native/tvos/metal-patched/Cargo.toml +178 -0
- package/native/tvos/metal-patched/LICENSE-APACHE +201 -0
- package/native/tvos/metal-patched/LICENSE-MIT +25 -0
- package/native/tvos/metal-patched/src/acceleration_structure.rs +667 -0
- package/native/tvos/metal-patched/src/acceleration_structure_pass.rs +108 -0
- package/native/tvos/metal-patched/src/argument.rs +366 -0
- package/native/tvos/metal-patched/src/blitpass.rs +102 -0
- package/native/tvos/metal-patched/src/buffer.rs +71 -0
- package/native/tvos/metal-patched/src/capturedescriptor.rs +76 -0
- package/native/tvos/metal-patched/src/capturemanager.rs +113 -0
- package/native/tvos/metal-patched/src/commandbuffer.rs +192 -0
- package/native/tvos/metal-patched/src/commandqueue.rs +44 -0
- package/native/tvos/metal-patched/src/computepass.rs +107 -0
- package/native/tvos/metal-patched/src/constants.rs +152 -0
- package/native/tvos/metal-patched/src/counters.rs +119 -0
- package/native/tvos/metal-patched/src/depthstencil.rs +190 -0
- package/native/tvos/metal-patched/src/device.rs +2134 -0
- package/native/tvos/metal-patched/src/drawable.rs +39 -0
- package/native/tvos/metal-patched/src/encoder.rs +2041 -0
- package/native/tvos/metal-patched/src/heap.rs +281 -0
- package/native/tvos/metal-patched/src/indirect_encoder.rs +344 -0
- package/native/tvos/metal-patched/src/lib.rs +657 -0
- package/native/tvos/metal-patched/src/library.rs +902 -0
- package/native/tvos/metal-patched/src/mps.rs +575 -0
- package/native/tvos/metal-patched/src/pipeline/compute.rs +475 -0
- package/native/tvos/metal-patched/src/pipeline/mod.rs +71 -0
- package/native/tvos/metal-patched/src/pipeline/render.rs +762 -0
- package/native/tvos/metal-patched/src/renderpass.rs +443 -0
- package/native/tvos/metal-patched/src/resource.rs +182 -0
- package/native/tvos/metal-patched/src/sampler.rs +165 -0
- package/native/tvos/metal-patched/src/sync.rs +178 -0
- package/native/tvos/metal-patched/src/texture.rs +352 -0
- package/native/tvos/metal-patched/src/types.rs +90 -0
- package/native/tvos/metal-patched/src/vertexdescriptor.rs +250 -0
- package/package.json +5 -1
|
@@ -0,0 +1,165 @@
|
|
|
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::{depthstencil::MTLCompareFunction, DeviceRef, MTLResourceID, NSUInteger};
|
|
9
|
+
|
|
10
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsamplerminmagfilter>
|
|
11
|
+
#[repr(u64)]
|
|
12
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
13
|
+
pub enum MTLSamplerMinMagFilter {
|
|
14
|
+
Nearest = 0,
|
|
15
|
+
Linear = 1,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsamplermipfilter>
|
|
19
|
+
#[repr(u64)]
|
|
20
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
21
|
+
pub enum MTLSamplerMipFilter {
|
|
22
|
+
NotMipmapped = 0,
|
|
23
|
+
Nearest = 1,
|
|
24
|
+
Linear = 2,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsampleraddressmode>
|
|
28
|
+
#[repr(u64)]
|
|
29
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
30
|
+
pub enum MTLSamplerAddressMode {
|
|
31
|
+
ClampToEdge = 0,
|
|
32
|
+
MirrorClampToEdge = 1,
|
|
33
|
+
Repeat = 2,
|
|
34
|
+
MirrorRepeat = 3,
|
|
35
|
+
ClampToZero = 4,
|
|
36
|
+
ClampToBorderColor = 5,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsamplerbordercolor>
|
|
40
|
+
#[repr(u64)]
|
|
41
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
42
|
+
pub enum MTLSamplerBorderColor {
|
|
43
|
+
TransparentBlack = 0,
|
|
44
|
+
OpaqueBlack = 1,
|
|
45
|
+
OpaqueWhite = 2,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsamplerdescriptor>
|
|
49
|
+
pub enum MTLSamplerDescriptor {}
|
|
50
|
+
|
|
51
|
+
foreign_obj_type! {
|
|
52
|
+
type CType = MTLSamplerDescriptor;
|
|
53
|
+
pub struct SamplerDescriptor;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
impl SamplerDescriptor {
|
|
57
|
+
pub fn new() -> Self {
|
|
58
|
+
unsafe {
|
|
59
|
+
let class = class!(MTLSamplerDescriptor);
|
|
60
|
+
msg_send![class, new]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
impl SamplerDescriptorRef {
|
|
66
|
+
pub fn set_min_filter(&self, filter: MTLSamplerMinMagFilter) {
|
|
67
|
+
unsafe { msg_send![self, setMinFilter: filter] }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
pub fn set_mag_filter(&self, filter: MTLSamplerMinMagFilter) {
|
|
71
|
+
unsafe { msg_send![self, setMagFilter: filter] }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
pub fn set_mip_filter(&self, filter: MTLSamplerMipFilter) {
|
|
75
|
+
unsafe { msg_send![self, setMipFilter: filter] }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
pub fn set_address_mode_s(&self, mode: MTLSamplerAddressMode) {
|
|
79
|
+
unsafe { msg_send![self, setSAddressMode: mode] }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
pub fn set_address_mode_t(&self, mode: MTLSamplerAddressMode) {
|
|
83
|
+
unsafe { msg_send![self, setTAddressMode: mode] }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
pub fn set_address_mode_r(&self, mode: MTLSamplerAddressMode) {
|
|
87
|
+
unsafe { msg_send![self, setRAddressMode: mode] }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
pub fn set_max_anisotropy(&self, anisotropy: NSUInteger) {
|
|
91
|
+
unsafe { msg_send![self, setMaxAnisotropy: anisotropy] }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
pub fn set_compare_function(&self, func: MTLCompareFunction) {
|
|
95
|
+
unsafe { msg_send![self, setCompareFunction: func] }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#[cfg(feature = "private")]
|
|
99
|
+
pub unsafe fn set_lod_bias(&self, bias: f32) {
|
|
100
|
+
msg_send![self, setLodBias: bias]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
pub fn set_lod_min_clamp(&self, clamp: f32) {
|
|
104
|
+
unsafe { msg_send![self, setLodMinClamp: clamp] }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pub fn set_lod_max_clamp(&self, clamp: f32) {
|
|
108
|
+
unsafe { msg_send![self, setLodMaxClamp: clamp] }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
pub fn set_lod_average(&self, enable: bool) {
|
|
112
|
+
unsafe { msg_send![self, setLodAverage: enable] }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
pub fn set_normalized_coordinates(&self, enable: bool) {
|
|
116
|
+
unsafe { msg_send![self, setNormalizedCoordinates: enable] }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
pub fn set_support_argument_buffers(&self, enable: bool) {
|
|
120
|
+
unsafe { msg_send![self, setSupportArgumentBuffers: enable] }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
pub fn set_border_color(&self, color: MTLSamplerBorderColor) {
|
|
124
|
+
unsafe { msg_send![self, setBorderColor: color] }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
pub fn label(&self) -> &str {
|
|
128
|
+
unsafe {
|
|
129
|
+
let label = msg_send![self, label];
|
|
130
|
+
crate::nsstring_as_str(label)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
pub fn set_label(&self, label: &str) {
|
|
135
|
+
unsafe {
|
|
136
|
+
let nslabel = crate::nsstring_from_str(label);
|
|
137
|
+
let () = msg_send![self, setLabel: nslabel];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsamplerstate>
|
|
143
|
+
pub enum MTLSamplerState {}
|
|
144
|
+
|
|
145
|
+
foreign_obj_type! {
|
|
146
|
+
type CType = MTLSamplerState;
|
|
147
|
+
pub struct SamplerState;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
impl SamplerStateRef {
|
|
151
|
+
pub fn device(&self) -> &DeviceRef {
|
|
152
|
+
unsafe { msg_send![self, device] }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
pub fn label(&self) -> &str {
|
|
156
|
+
unsafe {
|
|
157
|
+
let label = msg_send![self, label];
|
|
158
|
+
crate::nsstring_as_str(label)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
pub fn gpu_resource_id(&self) -> MTLResourceID {
|
|
163
|
+
unsafe { msg_send![self, gpuResourceID] }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
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 block::{Block, RcBlock};
|
|
10
|
+
use std::ptr;
|
|
11
|
+
|
|
12
|
+
#[cfg(feature = "dispatch")]
|
|
13
|
+
use dispatch;
|
|
14
|
+
|
|
15
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsharedeventnotificationblock>
|
|
16
|
+
type MTLSharedEventNotificationBlock<'a> = RcBlock<(&'a SharedEventRef, u64), ()>;
|
|
17
|
+
|
|
18
|
+
/// See <https://developer.apple.com/documentation/metal/mtlevent>
|
|
19
|
+
pub enum MTLEvent {}
|
|
20
|
+
|
|
21
|
+
foreign_obj_type! {
|
|
22
|
+
type CType = MTLEvent;
|
|
23
|
+
pub struct Event;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
impl EventRef {
|
|
27
|
+
pub fn device(&self) -> &DeviceRef {
|
|
28
|
+
unsafe { msg_send![self, device] }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsharedevent>
|
|
33
|
+
pub enum MTLSharedEvent {}
|
|
34
|
+
|
|
35
|
+
foreign_obj_type! {
|
|
36
|
+
type CType = MTLSharedEvent;
|
|
37
|
+
pub struct SharedEvent;
|
|
38
|
+
type ParentType = Event;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl SharedEventRef {
|
|
42
|
+
pub fn signaled_value(&self) -> u64 {
|
|
43
|
+
unsafe { msg_send![self, signaledValue] }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub fn set_signaled_value(&self, new_value: u64) {
|
|
47
|
+
unsafe { msg_send![self, setSignaledValue: new_value] }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// Schedules a notification handler to be called after the shareable event’s signal value
|
|
51
|
+
/// equals or exceeds a given value.
|
|
52
|
+
pub fn notify(
|
|
53
|
+
&self,
|
|
54
|
+
listener: &SharedEventListenerRef,
|
|
55
|
+
value: u64,
|
|
56
|
+
block: MTLSharedEventNotificationBlock,
|
|
57
|
+
) {
|
|
58
|
+
unsafe {
|
|
59
|
+
// If the block doesn't have a signature, this segfaults.
|
|
60
|
+
// Taken from https://github.com/servo/pathfinder/blob/e858c8dc1d8ff02a5b603e21e09a64d6b3e11327/metal/src/lib.rs#L2327
|
|
61
|
+
let block = mem::transmute::<
|
|
62
|
+
MTLSharedEventNotificationBlock,
|
|
63
|
+
*mut BlockBase<(&SharedEventRef, u64), ()>,
|
|
64
|
+
>(block);
|
|
65
|
+
(*block).flags |= BLOCK_HAS_SIGNATURE | BLOCK_HAS_COPY_DISPOSE;
|
|
66
|
+
(*block).extra = ptr::addr_of!(BLOCK_EXTRA);
|
|
67
|
+
let () = msg_send![self, notifyListener:listener atValue:value block:block];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
extern "C" fn dtor(_: *mut BlockBase<(&SharedEventRef, u64), ()>) {}
|
|
71
|
+
|
|
72
|
+
const SIGNATURE: &[u8] = b"v16@?0Q8\0";
|
|
73
|
+
const SIGNATURE_PTR: *const i8 = &SIGNATURE[0] as *const u8 as *const i8;
|
|
74
|
+
static mut BLOCK_EXTRA: BlockExtra<(&SharedEventRef, u64), ()> = BlockExtra {
|
|
75
|
+
unknown0: 0 as *mut i32,
|
|
76
|
+
unknown1: 0 as *mut i32,
|
|
77
|
+
unknown2: 0 as *mut i32,
|
|
78
|
+
dtor,
|
|
79
|
+
signature: &SIGNATURE_PTR,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsharedeventlistener>
|
|
85
|
+
pub enum MTLSharedEventListener {}
|
|
86
|
+
|
|
87
|
+
foreign_obj_type! {
|
|
88
|
+
type CType = MTLSharedEventListener;
|
|
89
|
+
pub struct SharedEventListener;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
impl SharedEventListener {
|
|
93
|
+
pub unsafe fn from_queue_handle(queue: dispatch_queue_t) -> Self {
|
|
94
|
+
let listener: SharedEventListener = msg_send![class!(MTLSharedEventListener), alloc];
|
|
95
|
+
let ptr: *mut Object = msg_send![listener.as_ref(), initWithDispatchQueue: queue];
|
|
96
|
+
if ptr.is_null() {
|
|
97
|
+
panic!("[MTLSharedEventListener alloc] initWithDispatchQueue failed");
|
|
98
|
+
}
|
|
99
|
+
listener
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#[cfg(feature = "dispatch")]
|
|
103
|
+
pub fn from_queue(queue: &dispatch::Queue) -> Self {
|
|
104
|
+
unsafe {
|
|
105
|
+
let raw_queue = std::mem::transmute::<&dispatch::Queue, *const dispatch_queue_t>(queue);
|
|
106
|
+
Self::from_queue_handle(*raw_queue)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// See <https://developer.apple.com/documentation/metal/mtlfence>
|
|
112
|
+
pub enum MTLFence {}
|
|
113
|
+
|
|
114
|
+
foreign_obj_type! {
|
|
115
|
+
type CType = MTLFence;
|
|
116
|
+
pub struct Fence;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
impl FenceRef {
|
|
120
|
+
pub fn device(&self) -> &DeviceRef {
|
|
121
|
+
unsafe { msg_send![self, device] }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
pub fn label(&self) -> &str {
|
|
125
|
+
unsafe {
|
|
126
|
+
let label = msg_send![self, label];
|
|
127
|
+
crate::nsstring_as_str(label)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
pub fn set_label(&self, label: &str) {
|
|
132
|
+
unsafe {
|
|
133
|
+
let nslabel = crate::nsstring_from_str(label);
|
|
134
|
+
let () = msg_send![self, setLabel: nslabel];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
bitflags::bitflags! {
|
|
140
|
+
/// The render stages at which a synchronization command is triggered.
|
|
141
|
+
///
|
|
142
|
+
/// Render stages provide finer control for specifying when synchronization must occur,
|
|
143
|
+
/// allowing for vertex and fragment processing to overlap in execution.
|
|
144
|
+
///
|
|
145
|
+
/// See <https://developer.apple.com/documentation/metal/mtlrenderstages>
|
|
146
|
+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
|
147
|
+
pub struct MTLRenderStages: NSUInteger {
|
|
148
|
+
/// The vertex rendering stage.
|
|
149
|
+
const Vertex = 1 << 0;
|
|
150
|
+
/// The fragment rendering stage.
|
|
151
|
+
const Fragment = 1 << 1;
|
|
152
|
+
/// The tile rendering stage.
|
|
153
|
+
const Tile = 1 << 2;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const BLOCK_HAS_COPY_DISPOSE: i32 = 0x02000000;
|
|
158
|
+
const BLOCK_HAS_SIGNATURE: i32 = 0x40000000;
|
|
159
|
+
|
|
160
|
+
#[repr(C)]
|
|
161
|
+
struct BlockBase<A, R> {
|
|
162
|
+
isa: *const std::ffi::c_void, // 0x00
|
|
163
|
+
flags: i32, // 0x08
|
|
164
|
+
_reserved: i32, // 0x0c
|
|
165
|
+
invoke: unsafe extern "C" fn(*mut Block<A, R>, ...) -> R, // 0x10
|
|
166
|
+
extra: *const BlockExtra<A, R>, // 0x18
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
type BlockExtraDtor<A, R> = extern "C" fn(*mut BlockBase<A, R>);
|
|
170
|
+
|
|
171
|
+
#[repr(C)]
|
|
172
|
+
struct BlockExtra<A, R> {
|
|
173
|
+
unknown0: *mut i32, // 0x00
|
|
174
|
+
unknown1: *mut i32, // 0x08
|
|
175
|
+
unknown2: *mut i32, // 0x10
|
|
176
|
+
dtor: BlockExtraDtor<A, R>, // 0x18
|
|
177
|
+
signature: *const *const i8, // 0x20
|
|
178
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
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
|
+
use objc::runtime::{NO, YES};
|
|
11
|
+
|
|
12
|
+
/// See <https://developer.apple.com/documentation/metal/mtltexturetype>
|
|
13
|
+
#[repr(u64)]
|
|
14
|
+
#[allow(non_camel_case_types)]
|
|
15
|
+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
|
16
|
+
pub enum MTLTextureType {
|
|
17
|
+
D1 = 0,
|
|
18
|
+
D1Array = 1,
|
|
19
|
+
D2 = 2,
|
|
20
|
+
D2Array = 3,
|
|
21
|
+
D2Multisample = 4,
|
|
22
|
+
Cube = 5,
|
|
23
|
+
CubeArray = 6,
|
|
24
|
+
D3 = 7,
|
|
25
|
+
D2MultisampleArray = 8,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// See <https://developer.apple.com/documentation/metal/mtltexturecompressiontype>
|
|
29
|
+
#[repr(u64)]
|
|
30
|
+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
|
31
|
+
pub enum MTLTextureCompressionType {
|
|
32
|
+
Lossless = 0,
|
|
33
|
+
Lossy = 1,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bitflags::bitflags! {
|
|
37
|
+
/// See <https://developer.apple.com/documentation/metal/mtltextureusage>
|
|
38
|
+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
|
39
|
+
pub struct MTLTextureUsage: NSUInteger {
|
|
40
|
+
const Unknown = 0x0000;
|
|
41
|
+
const ShaderRead = 0x0001;
|
|
42
|
+
const ShaderWrite = 0x0002;
|
|
43
|
+
const RenderTarget = 0x0004;
|
|
44
|
+
const PixelFormatView = 0x0010;
|
|
45
|
+
const ShaderAtomic = 0x0020;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// See <https://developer.apple.com/documentation/metal/mtltexturedescriptor>
|
|
50
|
+
pub enum MTLTextureDescriptor {}
|
|
51
|
+
|
|
52
|
+
foreign_obj_type! {
|
|
53
|
+
type CType = MTLTextureDescriptor;
|
|
54
|
+
pub struct TextureDescriptor;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
impl TextureDescriptor {
|
|
58
|
+
pub fn new() -> Self {
|
|
59
|
+
unsafe {
|
|
60
|
+
let class = class!(MTLTextureDescriptor);
|
|
61
|
+
msg_send![class, new]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
impl TextureDescriptorRef {
|
|
67
|
+
pub fn texture_type(&self) -> MTLTextureType {
|
|
68
|
+
unsafe { msg_send![self, textureType] }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
pub fn set_texture_type(&self, texture_type: MTLTextureType) {
|
|
72
|
+
unsafe { msg_send![self, setTextureType: texture_type] }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
pub fn pixel_format(&self) -> MTLPixelFormat {
|
|
76
|
+
unsafe { msg_send![self, pixelFormat] }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
pub fn set_pixel_format(&self, pixel_format: MTLPixelFormat) {
|
|
80
|
+
unsafe { msg_send![self, setPixelFormat: pixel_format] }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub fn width(&self) -> NSUInteger {
|
|
84
|
+
unsafe { msg_send![self, width] }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
pub fn set_width(&self, width: NSUInteger) {
|
|
88
|
+
unsafe { msg_send![self, setWidth: width] }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
pub fn height(&self) -> NSUInteger {
|
|
92
|
+
unsafe { msg_send![self, height] }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
pub fn set_height(&self, height: NSUInteger) {
|
|
96
|
+
unsafe { msg_send![self, setHeight: height] }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
pub fn depth(&self) -> NSUInteger {
|
|
100
|
+
unsafe { msg_send![self, depth] }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
pub fn set_depth(&self, depth: NSUInteger) {
|
|
104
|
+
unsafe { msg_send![self, setDepth: depth] }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pub fn mipmap_level_count(&self) -> NSUInteger {
|
|
108
|
+
unsafe { msg_send![self, mipmapLevelCount] }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
pub fn set_mipmap_level_count(&self, count: NSUInteger) {
|
|
112
|
+
unsafe { msg_send![self, setMipmapLevelCount: count] }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
pub fn set_mipmap_level_count_for_size(&self, size: MTLSize) {
|
|
116
|
+
let MTLSize {
|
|
117
|
+
width,
|
|
118
|
+
height,
|
|
119
|
+
depth,
|
|
120
|
+
} = size;
|
|
121
|
+
let count = (width.max(height).max(depth) as f64).log2().ceil() as u64;
|
|
122
|
+
self.set_mipmap_level_count(count);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
pub fn sample_count(&self) -> NSUInteger {
|
|
126
|
+
unsafe { msg_send![self, sampleCount] }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
pub fn set_sample_count(&self, count: NSUInteger) {
|
|
130
|
+
unsafe { msg_send![self, setSampleCount: count] }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
pub fn array_length(&self) -> NSUInteger {
|
|
134
|
+
unsafe { msg_send![self, arrayLength] }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
pub fn set_array_length(&self, length: NSUInteger) {
|
|
138
|
+
unsafe { msg_send![self, setArrayLength: length] }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
pub fn resource_options(&self) -> MTLResourceOptions {
|
|
142
|
+
unsafe { msg_send![self, resourceOptions] }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pub fn set_resource_options(&self, options: MTLResourceOptions) {
|
|
146
|
+
unsafe { msg_send![self, setResourceOptions: options] }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
pub fn cpu_cache_mode(&self) -> MTLCPUCacheMode {
|
|
150
|
+
unsafe { msg_send![self, cpuCacheMode] }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
pub fn set_cpu_cache_mode(&self, mode: MTLCPUCacheMode) {
|
|
154
|
+
unsafe { msg_send![self, setCpuCacheMode: mode] }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
pub fn storage_mode(&self) -> MTLStorageMode {
|
|
158
|
+
unsafe { msg_send![self, storageMode] }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
pub fn set_storage_mode(&self, mode: MTLStorageMode) {
|
|
162
|
+
unsafe { msg_send![self, setStorageMode: mode] }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
pub fn usage(&self) -> MTLTextureUsage {
|
|
166
|
+
unsafe { msg_send![self, usage] }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
pub fn set_usage(&self, usage: MTLTextureUsage) {
|
|
170
|
+
unsafe { msg_send![self, setUsage: usage] }
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
pub fn compression_type(&self) -> MTLTextureCompressionType {
|
|
174
|
+
unsafe { msg_send![self, compressionType] }
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
pub fn set_compression_type(&self, compression_type: MTLTextureCompressionType) {
|
|
178
|
+
unsafe { msg_send![self, setCompressionType: compression_type] }
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/// See <https://developer.apple.com/documentation/metal/mtltexture>
|
|
183
|
+
pub enum MTLTexture {}
|
|
184
|
+
|
|
185
|
+
foreign_obj_type! {
|
|
186
|
+
type CType = MTLTexture;
|
|
187
|
+
pub struct Texture;
|
|
188
|
+
type ParentType = Resource;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
impl TextureRef {
|
|
192
|
+
#[deprecated(since = "0.13.0")]
|
|
193
|
+
pub fn root_resource(&self) -> Option<&ResourceRef> {
|
|
194
|
+
unsafe { msg_send![self, rootResource] }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
pub fn parent_texture(&self) -> Option<&TextureRef> {
|
|
198
|
+
unsafe { msg_send![self, parentTexture] }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
pub fn parent_relative_level(&self) -> NSUInteger {
|
|
202
|
+
unsafe { msg_send![self, parentRelativeLevel] }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
pub fn parent_relative_slice(&self) -> NSUInteger {
|
|
206
|
+
unsafe { msg_send![self, parentRelativeSlice] }
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
pub fn buffer(&self) -> Option<&BufferRef> {
|
|
210
|
+
unsafe { msg_send![self, buffer] }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
pub fn buffer_offset(&self) -> NSUInteger {
|
|
214
|
+
unsafe { msg_send![self, bufferOffset] }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
pub fn buffer_stride(&self) -> NSUInteger {
|
|
218
|
+
unsafe { msg_send![self, bufferBytesPerRow] }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
pub fn texture_type(&self) -> MTLTextureType {
|
|
222
|
+
unsafe { msg_send![self, textureType] }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
pub fn pixel_format(&self) -> MTLPixelFormat {
|
|
226
|
+
unsafe { msg_send![self, pixelFormat] }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
pub fn width(&self) -> NSUInteger {
|
|
230
|
+
unsafe { msg_send![self, width] }
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
pub fn height(&self) -> NSUInteger {
|
|
234
|
+
unsafe { msg_send![self, height] }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
pub fn depth(&self) -> NSUInteger {
|
|
238
|
+
unsafe { msg_send![self, depth] }
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
pub fn mipmap_level_count(&self) -> NSUInteger {
|
|
242
|
+
unsafe { msg_send![self, mipmapLevelCount] }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
pub fn sample_count(&self) -> NSUInteger {
|
|
246
|
+
unsafe { msg_send![self, sampleCount] }
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
pub fn array_length(&self) -> NSUInteger {
|
|
250
|
+
unsafe { msg_send![self, arrayLength] }
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
pub fn usage(&self) -> MTLTextureUsage {
|
|
254
|
+
unsafe { msg_send![self, usage] }
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/// [framebufferOnly Apple Docs](https://developer.apple.com/documentation/metal/mtltexture/1515749-framebufferonly?language=objc)
|
|
258
|
+
pub fn framebuffer_only(&self) -> bool {
|
|
259
|
+
unsafe { msg_send_bool![self, isFramebufferOnly] }
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
pub fn get_bytes(
|
|
263
|
+
&self,
|
|
264
|
+
bytes: *mut std::ffi::c_void,
|
|
265
|
+
stride: NSUInteger,
|
|
266
|
+
region: MTLRegion,
|
|
267
|
+
mipmap_level: NSUInteger,
|
|
268
|
+
) {
|
|
269
|
+
unsafe {
|
|
270
|
+
msg_send![self, getBytes:bytes
|
|
271
|
+
bytesPerRow:stride
|
|
272
|
+
fromRegion:region
|
|
273
|
+
mipmapLevel:mipmap_level]
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
pub fn get_bytes_in_slice(
|
|
278
|
+
&self,
|
|
279
|
+
bytes: *mut std::ffi::c_void,
|
|
280
|
+
stride: NSUInteger,
|
|
281
|
+
image_stride: NSUInteger,
|
|
282
|
+
region: MTLRegion,
|
|
283
|
+
mipmap_level: NSUInteger,
|
|
284
|
+
slice: NSUInteger,
|
|
285
|
+
) {
|
|
286
|
+
unsafe {
|
|
287
|
+
msg_send![self, getBytes:bytes
|
|
288
|
+
bytesPerRow:stride
|
|
289
|
+
bytesPerImage:image_stride
|
|
290
|
+
fromRegion:region
|
|
291
|
+
mipmapLevel:mipmap_level
|
|
292
|
+
slice:slice]
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
pub fn replace_region(
|
|
297
|
+
&self,
|
|
298
|
+
region: MTLRegion,
|
|
299
|
+
mipmap_level: NSUInteger,
|
|
300
|
+
bytes: *const std::ffi::c_void,
|
|
301
|
+
stride: NSUInteger,
|
|
302
|
+
) {
|
|
303
|
+
unsafe {
|
|
304
|
+
msg_send![self, replaceRegion:region
|
|
305
|
+
mipmapLevel:mipmap_level
|
|
306
|
+
withBytes:bytes
|
|
307
|
+
bytesPerRow:stride]
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
pub fn replace_region_in_slice(
|
|
312
|
+
&self,
|
|
313
|
+
region: MTLRegion,
|
|
314
|
+
mipmap_level: NSUInteger,
|
|
315
|
+
slice: NSUInteger,
|
|
316
|
+
bytes: *const std::ffi::c_void,
|
|
317
|
+
stride: NSUInteger,
|
|
318
|
+
image_stride: NSUInteger,
|
|
319
|
+
) {
|
|
320
|
+
unsafe {
|
|
321
|
+
msg_send![self, replaceRegion:region
|
|
322
|
+
mipmapLevel:mipmap_level
|
|
323
|
+
slice:slice
|
|
324
|
+
withBytes:bytes
|
|
325
|
+
bytesPerRow:stride
|
|
326
|
+
bytesPerImage:image_stride]
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
pub fn new_texture_view(&self, pixel_format: MTLPixelFormat) -> Texture {
|
|
331
|
+
unsafe { msg_send![self, newTextureViewWithPixelFormat: pixel_format] }
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
pub fn new_texture_view_from_slice(
|
|
335
|
+
&self,
|
|
336
|
+
pixel_format: MTLPixelFormat,
|
|
337
|
+
texture_type: MTLTextureType,
|
|
338
|
+
mipmap_levels: crate::NSRange,
|
|
339
|
+
slices: crate::NSRange,
|
|
340
|
+
) -> Texture {
|
|
341
|
+
unsafe {
|
|
342
|
+
msg_send![self, newTextureViewWithPixelFormat:pixel_format
|
|
343
|
+
textureType:texture_type
|
|
344
|
+
levels:mipmap_levels
|
|
345
|
+
slices:slices]
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
pub fn gpu_resource_id(&self) -> MTLResourceID {
|
|
350
|
+
unsafe { msg_send![self, gpuResourceID] }
|
|
351
|
+
}
|
|
352
|
+
}
|