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
use std::ops::DerefMut;
use crate::{arc, define_mtl, define_obj_type, define_opts, mtl, ns, objc};
define_opts!(
/// Describes how a resource will be used by a shader through an argument buffer
#[doc(alias = "MTLResourceUsage")]
pub ResUsage(usize)
);
impl ResUsage {
/// An option that enables reading from the resource.
pub const READ: Self = Self(1 << 0);
/// An option that enables writing to the resource.
pub const WRITE: Self = Self(1 << 1);
/*
/// An option that enables sampling from the resource.
// #[deprecated(since = "0.1.0", note = "use mtl::ResourceUsage::READ instead")]
// pub const SAMPLE: Self = Self(1 << 2);
*/
}
define_opts!(
/// Describes the types of resources that the a barrier operates on
#[doc(alias = "MTLBarrierScope")]
pub BarrierScope(usize)
);
impl BarrierScope {
/// The barrier affects any buffer objects.
pub const BUFFERS: Self = Self(1 << 0);
/// The barrier affects textures.
pub const TEXTURES: Self = Self(1 << 1);
/// The barrier affects any render targets.
pub const RENDER_TARGETS: Self = Self(1 << 2);
}
define_opts!(
#[doc(alias = "MTLStages")]
pub Stages(usize)
);
impl Stages {
/// Represents all vertex shader stage work in a render pass.
pub const VERTEX: Self = Self(1 << 0);
/// Represents all fragment shader stage work in a render pass.
pub const FRAGMENT: Self = Self(1 << 1);
/// Represents all tile shading stage work in a render pass.
pub const TILE: Self = Self(1 << 2);
/// Represents all object shader stage work in a render pass.
pub const OBJ: Self = Self(1 << 3);
/// Represents all mesh shader stage work work in a render pass.
pub const MESH: Self = Self(1 << 4);
/// Represents all sparse and placement sparse resource mapping updates.
pub const RES_STATE: Self = Self(1 << 26);
/// Represents all compute dispatches in a compute pass.
pub const DISPATCH: Self = Self(1 << 27);
/// Represents all blit operations in a pass.
pub const BLIT: Self = Self(1 << 28);
/// Represents all acceleration structure operations.
pub const ACCELERATION_STRUCTURE: Self = Self(1 << 29);
/// Represents all machine learning network dispatch operations.
pub const ML: Self = Self(1 << 30);
/// Convenience mask representing all stages of GPU work.
pub const ALL: Self = Self(usize::MAX);
}
define_obj_type!(
/// An encoder that writes GPU commands into a command buffer.
#[doc(alias = "MTLCommandEncoder")]
pub CmdEncoder(ns::Id)
);
impl CmdEncoder {
define_mtl!(set_label, push_debug_group, pop_debug_group);
#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;
#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
/// Declares that all command generation from the encoder is completed.
///
/// After endEncoding is called, the command encoder has no further use.
/// You cannot encode any other commands with this encoder.
///
/// # Safety
///
/// Use `end()` function instead
#[objc::msg_send(endEncoding)]
pub unsafe fn end_encoding(&mut self);
#[objc::msg_send(insertDebugSignpost:)]
pub fn insert_debug_signpost(&mut self, signpost: &ns::String);
}
impl<T> arc::R<T>
where
T: objc::Obj + DerefMut<Target = CmdEncoder>,
{
pub fn end(mut self) {
unsafe { self.end_encoding() }
}
}
#[cfg(test)]
mod tests {
use crate::mtl;
#[test]
fn basics() {
let device = mtl::Device::sys_default().unwrap();
let queue = device.new_cmd_queue().unwrap();
let buf = queue.new_cmd_buf().unwrap();
let enc = buf.new_blit_cmd_enc().unwrap();
enc.end();
}
}