Debian Codegraph @

third_party/rust/metal/src/commandbuffer.rs

raw
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 block::Block;
11
12 /// See <https://developer.apple.com/documentation/metal/mtlcommandbufferstatus>
13 #[repr(u32)]
14 #[allow(non_camel_case_types)]
15 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
16 pub enum MTLCommandBufferStatus {
17 NotEnqueued = 0,
18 Enqueued = 1,
19 Committed = 2,
20 Scheduled = 3,
21 Completed = 4,
22 Error = 5,
23 }
24
25 /// See <https://developer.apple.com/documentation/metal/mtlcommandbuffererror>
26 #[repr(u32)]
27 #[allow(non_camel_case_types)]
28 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
29 pub 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 /// See <https://developer.apple.com/documentation/metal/mtldispatchtype>
43 #[repr(u32)]
44 #[allow(non_camel_case_types)]
45 #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
46 pub enum MTLDispatchType {
47 Serial = 0,
48 Concurrent = 1,
49 }
50
51 type CommandBufferHandler<'a> = Block<(&'a CommandBufferRef,), ()>;
52
53 /// See <https://developer.apple.com/documentation/metal/mtlcommandbuffer>.
54 pub enum MTLCommandBuffer {}
55
56 foreign_obj_type! {
57 type CType = MTLCommandBuffer;
58 pub struct CommandBuffer;
59 }
60
61 impl 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 {
109 unsafe { msg_send![self, blitCommandEncoder] }
110 }
111
112 pub fn blit_command_encoder_with_descriptor(
113 &self,
114 descriptor: &BlitPassDescriptorRef,
115 ) -> &BlitCommandEncoderRef {
116 unsafe { msg_send![self, blitCommandEncoderWithDescriptor: descriptor] }
117 }
118
119 pub fn new_compute_command_encoder(&self) -> &ComputeCommandEncoderRef {
120 unsafe { msg_send![self, computeCommandEncoder] }
121 }
122
123 pub fn compute_command_encoder_with_dispatch_type(
124 &self,
125 ty: MTLDispatchType,
126 ) -> &ComputeCommandEncoderRef {
127 unsafe { msg_send![self, computeCommandEncoderWithDispatchType: ty] }
128 }
129
130 pub fn compute_command_encoder_with_descriptor(
131 &self,
132 descriptor: &ComputePassDescriptorRef,
133 ) -> &ComputeCommandEncoderRef {
134 unsafe { msg_send![self, computeCommandEncoderWithDescriptor: descriptor] }
135 }
136
137 pub fn new_render_command_encoder(
138 &self,
139 descriptor: &RenderPassDescriptorRef,
140 ) -> &RenderCommandEncoderRef {
141 unsafe { msg_send![self, renderCommandEncoderWithDescriptor: descriptor] }
142 }
143
144 pub fn new_parallel_render_command_encoder(
145 &self,
146 descriptor: &RenderPassDescriptorRef,
147 ) -> &ParallelRenderCommandEncoderRef {
148 unsafe { msg_send![self, parallelRenderCommandEncoderWithDescriptor: descriptor] }
149 }
150
151 pub fn new_acceleration_structure_command_encoder(
152 &self,
153 ) -> &AccelerationStructureCommandEncoderRef {
154 unsafe { msg_send![self, accelerationStructureCommandEncoder] }
155 }
156
157 pub fn acceleration_structure_command_encoder_with_descriptor(
158 &self,
159 descriptor: &AccelerationStructurePassDescriptorRef,
160 ) -> &AccelerationStructureCommandEncoderRef {
161 unsafe { msg_send![self, accelerationStructureCommandEncoderWithDescriptor: descriptor] }
162 }
163
164 pub fn encode_signal_event(&self, event: &EventRef, new_value: u64) {
165 unsafe {
166 msg_send![self,
167 encodeSignalEvent: event
168 value: new_value
169 ]
170 }
171 }
172
173 pub fn encode_wait_for_event(&self, event: &EventRef, value: u64) {
174 unsafe {
175 msg_send![self,
176 encodeWaitForEvent: event
177 value: value
178 ]
179 }
180 }
181
182 pub fn push_debug_group(&self, name: &str) {
183 unsafe {
184 let nslabel = crate::nsstring_from_str(name);
185 msg_send![self, pushDebugGroup: nslabel]
186 }
187 }
188
189 pub fn pop_debug_group(&self) {
190 unsafe { msg_send![self, popDebugGroup] }
191 }
192 }