mtl_gpu/pass/
compute_sample_buffer.rs1use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::{Referencing, UInteger};
7use mtl_sys::{msg_send_0, msg_send_1, sel};
8
9#[repr(transparent)]
13pub struct ComputePassSampleBufferAttachmentDescriptor(pub(crate) NonNull<c_void>);
14
15impl ComputePassSampleBufferAttachmentDescriptor {
16 pub fn new() -> Option<Self> {
20 unsafe {
21 let class = mtl_sys::Class::get("MTLComputePassSampleBufferAttachmentDescriptor")?;
22 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
23 if ptr.is_null() {
24 return None;
25 }
26 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
27 Self::from_raw(ptr)
28 }
29 }
30
31 #[inline]
33 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
34 NonNull::new(ptr).map(Self)
35 }
36
37 #[inline]
39 pub fn as_raw(&self) -> *mut c_void {
40 self.0.as_ptr()
41 }
42
43 pub fn sample_buffer(&self) -> Option<crate::CounterSampleBuffer> {
47 unsafe {
48 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(sampleBuffer));
49 if ptr.is_null() {
50 return None;
51 }
52 msg_send_0::<*mut c_void>(ptr, sel!(retain));
53 crate::CounterSampleBuffer::from_raw(ptr)
54 }
55 }
56
57 pub fn set_sample_buffer(&self, sample_buffer: Option<&crate::CounterSampleBuffer>) {
61 unsafe {
62 let ptr = sample_buffer.map_or(std::ptr::null(), |s| s.as_ptr());
63 let _: () = msg_send_1(self.as_ptr(), sel!(setSampleBuffer:), ptr);
64 }
65 }
66
67 #[inline]
71 pub fn start_of_encoder_sample_index(&self) -> UInteger {
72 unsafe { msg_send_0(self.as_ptr(), sel!(startOfEncoderSampleIndex)) }
73 }
74
75 #[inline]
79 pub fn set_start_of_encoder_sample_index(&self, index: UInteger) {
80 unsafe {
81 let _: () = msg_send_1(self.as_ptr(), sel!(setStartOfEncoderSampleIndex:), index);
82 }
83 }
84
85 #[inline]
89 pub fn end_of_encoder_sample_index(&self) -> UInteger {
90 unsafe { msg_send_0(self.as_ptr(), sel!(endOfEncoderSampleIndex)) }
91 }
92
93 #[inline]
97 pub fn set_end_of_encoder_sample_index(&self, index: UInteger) {
98 unsafe {
99 let _: () = msg_send_1(self.as_ptr(), sel!(setEndOfEncoderSampleIndex:), index);
100 }
101 }
102}
103
104impl Clone for ComputePassSampleBufferAttachmentDescriptor {
105 fn clone(&self) -> Self {
106 unsafe {
107 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
108 }
109 Self(self.0)
110 }
111}
112
113impl Drop for ComputePassSampleBufferAttachmentDescriptor {
114 fn drop(&mut self) {
115 unsafe {
116 msg_send_0::<()>(self.as_ptr(), sel!(release));
117 }
118 }
119}
120
121impl Referencing for ComputePassSampleBufferAttachmentDescriptor {
122 #[inline]
123 fn as_ptr(&self) -> *const c_void {
124 self.0.as_ptr()
125 }
126}
127
128unsafe impl Send for ComputePassSampleBufferAttachmentDescriptor {}
129unsafe impl Sync for ComputePassSampleBufferAttachmentDescriptor {}
130
131impl std::fmt::Debug for ComputePassSampleBufferAttachmentDescriptor {
132 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
133 f.debug_struct("ComputePassSampleBufferAttachmentDescriptor")
134 .field(
135 "start_of_encoder_sample_index",
136 &self.start_of_encoder_sample_index(),
137 )
138 .field(
139 "end_of_encoder_sample_index",
140 &self.end_of_encoder_sample_index(),
141 )
142 .finish()
143 }
144}
145
146#[repr(transparent)]
150pub struct ComputePassSampleBufferAttachmentDescriptorArray(pub(crate) NonNull<c_void>);
151
152impl ComputePassSampleBufferAttachmentDescriptorArray {
153 pub fn new() -> Option<Self> {
157 unsafe {
158 let class =
159 mtl_sys::Class::get("MTLComputePassSampleBufferAttachmentDescriptorArray")?;
160 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
161 if ptr.is_null() {
162 return None;
163 }
164 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
165 Self::from_raw(ptr)
166 }
167 }
168
169 #[inline]
171 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
172 NonNull::new(ptr).map(Self)
173 }
174
175 #[inline]
177 pub fn as_raw(&self) -> *mut c_void {
178 self.0.as_ptr()
179 }
180
181 pub fn object(&self, index: UInteger) -> Option<ComputePassSampleBufferAttachmentDescriptor> {
185 unsafe {
186 let ptr: *mut c_void =
187 msg_send_1(self.as_ptr(), sel!(objectAtIndexedSubscript:), index);
188 if ptr.is_null() {
189 return None;
190 }
191 msg_send_0::<*mut c_void>(ptr, sel!(retain));
192 ComputePassSampleBufferAttachmentDescriptor::from_raw(ptr)
193 }
194 }
195
196 pub fn set_object(
200 &self,
201 attachment: Option<&ComputePassSampleBufferAttachmentDescriptor>,
202 index: UInteger,
203 ) {
204 unsafe {
205 let ptr = attachment.map_or(std::ptr::null(), |a| a.as_ptr());
206 let _: () = mtl_sys::msg_send_2(
207 self.as_ptr(),
208 sel!(setObject:atIndexedSubscript:),
209 ptr,
210 index,
211 );
212 }
213 }
214}
215
216impl Clone for ComputePassSampleBufferAttachmentDescriptorArray {
217 fn clone(&self) -> Self {
218 unsafe {
219 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
220 }
221 Self(self.0)
222 }
223}
224
225impl Drop for ComputePassSampleBufferAttachmentDescriptorArray {
226 fn drop(&mut self) {
227 unsafe {
228 msg_send_0::<()>(self.as_ptr(), sel!(release));
229 }
230 }
231}
232
233impl Referencing for ComputePassSampleBufferAttachmentDescriptorArray {
234 #[inline]
235 fn as_ptr(&self) -> *const c_void {
236 self.0.as_ptr()
237 }
238}
239
240unsafe impl Send for ComputePassSampleBufferAttachmentDescriptorArray {}
241unsafe impl Sync for ComputePassSampleBufferAttachmentDescriptorArray {}
242
243impl std::fmt::Debug for ComputePassSampleBufferAttachmentDescriptorArray {
244 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
245 f.debug_struct("ComputePassSampleBufferAttachmentDescriptorArray")
246 .finish()
247 }
248}