1use super::*;
9
10use block::Block;
11
12#[repr(u32)]
14#[allow(non_camel_case_types)]
15#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
16pub enum MTLCommandBufferStatus {
17 NotEnqueued = 0,
18 Enqueued = 1,
19 Committed = 2,
20 Scheduled = 3,
21 Completed = 4,
22 Error = 5,
23}
24
25#[repr(u32)]
27#[allow(non_camel_case_types)]
28#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
29pub enum MTLCommandBufferError {
30 None = 0,
31 Internal = 1,
32 Timeout = 2,
33 PageFault = 3,
34 Blacklisted = 4,
35 NotPermitted = 7,
36 OutOfMemory = 8,
37 InvalidResource = 9,
38 Memoryless = 10,
39 DeviceRemoved = 11,
40}
41
42#[repr(u32)]
44#[allow(non_camel_case_types)]
45#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
46pub enum MTLDispatchType {
47 Serial = 0,
48 Concurrent = 1,
49}
50
51type CommandBufferHandler<'a> = Block<(&'a CommandBufferRef,), ()>;
52
53pub enum MTLCommandBuffer {}
55
56foreign_obj_type! {
57 type CType = MTLCommandBuffer;
58 pub struct CommandBuffer;
59}
60
61impl CommandBufferRef {
62 pub fn label(&self) -> &str {
63 unsafe {
64 let label = msg_send![self, label];
65 crate::nsstring_as_str(label)
66 }
67 }
68
69 pub fn set_label(&self, label: &str) {
70 unsafe {
71 let nslabel = crate::nsstring_from_str(label);
72 let () = msg_send![self, setLabel: nslabel];
73 }
74 }
75
76 pub fn enqueue(&self) {
77 unsafe { msg_send![self, enqueue] }
78 }
79
80 pub fn commit(&self) {
81 unsafe { msg_send![self, commit] }
82 }
83
84 pub fn status(&self) -> MTLCommandBufferStatus {
85 unsafe { msg_send![self, status] }
86 }
87
88 pub fn present_drawable(&self, drawable: &DrawableRef) {
89 unsafe { msg_send![self, presentDrawable: drawable] }
90 }
91
92 pub fn wait_until_completed(&self) {
93 unsafe { msg_send![self, waitUntilCompleted] }
94 }
95
96 pub fn wait_until_scheduled(&self) {
97 unsafe { msg_send![self, waitUntilScheduled] }
98 }
99
100 pub fn add_completed_handler(&self, block: &CommandBufferHandler) {
101 unsafe { msg_send![self, addCompletedHandler: block] }
102 }
103
104 pub fn add_scheduled_handler(&self, block: &CommandBufferHandler) {
105 unsafe { msg_send![self, addScheduledHandler: block] }
106 }
107
108 pub fn new_blit_command_encoder(&self) -> &BlitCommandEncoderRef {
114 unsafe { msg_send![self, blitCommandEncoder] }
115 }
116
117 pub fn blit_command_encoder_with_descriptor(
118 &self,
119 descriptor: &BlitPassDescriptorRef,
120 ) -> &BlitCommandEncoderRef {
121 unsafe { msg_send![self, blitCommandEncoderWithDescriptor: descriptor] }
122 }
123
124 pub fn new_compute_command_encoder(&self) -> &ComputeCommandEncoderRef {
130 unsafe { msg_send![self, computeCommandEncoder] }
131 }
132
133 pub fn compute_command_encoder_with_dispatch_type(
134 &self,
135 ty: MTLDispatchType,
136 ) -> &ComputeCommandEncoderRef {
137 unsafe { msg_send![self, computeCommandEncoderWithDispatchType: ty] }
138 }
139
140 pub fn compute_command_encoder_with_descriptor(
141 &self,
142 descriptor: &ComputePassDescriptorRef,
143 ) -> &ComputeCommandEncoderRef {
144 unsafe { msg_send![self, computeCommandEncoderWithDescriptor: descriptor] }
145 }
146
147 pub fn new_render_command_encoder(
153 &self,
154 descriptor: &RenderPassDescriptorRef,
155 ) -> &RenderCommandEncoderRef {
156 unsafe { msg_send![self, renderCommandEncoderWithDescriptor: descriptor] }
157 }
158
159 pub fn new_parallel_render_command_encoder(
165 &self,
166 descriptor: &RenderPassDescriptorRef,
167 ) -> &ParallelRenderCommandEncoderRef {
168 unsafe { msg_send![self, parallelRenderCommandEncoderWithDescriptor: descriptor] }
169 }
170
171 pub fn new_acceleration_structure_command_encoder(
177 &self,
178 ) -> &AccelerationStructureCommandEncoderRef {
179 unsafe { msg_send![self, accelerationStructureCommandEncoder] }
180 }
181
182 pub fn acceleration_structure_command_encoder_with_descriptor(
188 &self,
189 descriptor: &AccelerationStructurePassDescriptorRef,
190 ) -> &AccelerationStructureCommandEncoderRef {
191 unsafe { msg_send![self, accelerationStructureCommandEncoderWithDescriptor: descriptor] }
192 }
193
194 pub fn encode_signal_event(&self, event: &EventRef, new_value: u64) {
195 unsafe {
196 msg_send![self,
197 encodeSignalEvent: event
198 value: new_value
199 ]
200 }
201 }
202
203 pub fn encode_wait_for_event(&self, event: &EventRef, value: u64) {
204 unsafe {
205 msg_send![self,
206 encodeWaitForEvent: event
207 value: value
208 ]
209 }
210 }
211
212 pub fn push_debug_group(&self, name: &str) {
213 unsafe {
214 let nslabel = crate::nsstring_from_str(name);
215 msg_send![self, pushDebugGroup: nslabel]
216 }
217 }
218
219 pub fn pop_debug_group(&self) {
220 unsafe { msg_send![self, popDebugGroup] }
221 }
222}