mtl_gpu/pass/
blit_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 BlitPassSampleBufferAttachmentDescriptor(pub(crate) NonNull<c_void>);
14
15impl BlitPassSampleBufferAttachmentDescriptor {
16 pub fn new() -> Option<Self> {
20 unsafe {
21 let class = mtl_sys::Class::get("MTLBlitPassSampleBufferAttachmentDescriptor")?;
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 BlitPassSampleBufferAttachmentDescriptor {
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 BlitPassSampleBufferAttachmentDescriptor {
114 fn drop(&mut self) {
115 unsafe {
116 msg_send_0::<()>(self.as_ptr(), sel!(release));
117 }
118 }
119}
120
121impl Referencing for BlitPassSampleBufferAttachmentDescriptor {
122 #[inline]
123 fn as_ptr(&self) -> *const c_void {
124 self.0.as_ptr()
125 }
126}
127
128unsafe impl Send for BlitPassSampleBufferAttachmentDescriptor {}
129unsafe impl Sync for BlitPassSampleBufferAttachmentDescriptor {}
130
131impl std::fmt::Debug for BlitPassSampleBufferAttachmentDescriptor {
132 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
133 f.debug_struct("BlitPassSampleBufferAttachmentDescriptor")
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 BlitPassSampleBufferAttachmentDescriptorArray(pub(crate) NonNull<c_void>);
151
152impl BlitPassSampleBufferAttachmentDescriptorArray {
153 pub fn new() -> Option<Self> {
157 unsafe {
158 let class = mtl_sys::Class::get("MTLBlitPassSampleBufferAttachmentDescriptorArray")?;
159 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
160 if ptr.is_null() {
161 return None;
162 }
163 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
164 Self::from_raw(ptr)
165 }
166 }
167
168 #[inline]
170 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
171 NonNull::new(ptr).map(Self)
172 }
173
174 #[inline]
176 pub fn as_raw(&self) -> *mut c_void {
177 self.0.as_ptr()
178 }
179
180 pub fn object(&self, index: UInteger) -> Option<BlitPassSampleBufferAttachmentDescriptor> {
184 unsafe {
185 let ptr: *mut c_void =
186 msg_send_1(self.as_ptr(), sel!(objectAtIndexedSubscript:), index);
187 if ptr.is_null() {
188 return None;
189 }
190 msg_send_0::<*mut c_void>(ptr, sel!(retain));
191 BlitPassSampleBufferAttachmentDescriptor::from_raw(ptr)
192 }
193 }
194
195 pub fn set_object(
199 &self,
200 attachment: Option<&BlitPassSampleBufferAttachmentDescriptor>,
201 index: UInteger,
202 ) {
203 unsafe {
204 let ptr = attachment.map_or(std::ptr::null(), |a| a.as_ptr());
205 let _: () = mtl_sys::msg_send_2(
206 self.as_ptr(),
207 sel!(setObject:atIndexedSubscript:),
208 ptr,
209 index,
210 );
211 }
212 }
213}
214
215impl Clone for BlitPassSampleBufferAttachmentDescriptorArray {
216 fn clone(&self) -> Self {
217 unsafe {
218 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
219 }
220 Self(self.0)
221 }
222}
223
224impl Drop for BlitPassSampleBufferAttachmentDescriptorArray {
225 fn drop(&mut self) {
226 unsafe {
227 msg_send_0::<()>(self.as_ptr(), sel!(release));
228 }
229 }
230}
231
232impl Referencing for BlitPassSampleBufferAttachmentDescriptorArray {
233 #[inline]
234 fn as_ptr(&self) -> *const c_void {
235 self.0.as_ptr()
236 }
237}
238
239unsafe impl Send for BlitPassSampleBufferAttachmentDescriptorArray {}
240unsafe impl Sync for BlitPassSampleBufferAttachmentDescriptorArray {}
241
242impl std::fmt::Debug for BlitPassSampleBufferAttachmentDescriptorArray {
243 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
244 f.debug_struct("BlitPassSampleBufferAttachmentDescriptorArray")
245 .finish()
246 }
247}