mtl_gpu/pass/
render_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)]
15pub struct RenderPassSampleBufferAttachmentDescriptor(pub(crate) NonNull<c_void>);
16
17impl RenderPassSampleBufferAttachmentDescriptor {
18 pub fn new() -> Option<Self> {
22 unsafe {
23 let class = mtl_sys::Class::get("MTLRenderPassSampleBufferAttachmentDescriptor")?;
24 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
25 if ptr.is_null() {
26 return None;
27 }
28 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
29 Self::from_raw(ptr)
30 }
31 }
32
33 #[inline]
35 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
36 NonNull::new(ptr).map(Self)
37 }
38
39 #[inline]
41 pub fn as_raw(&self) -> *mut c_void {
42 self.0.as_ptr()
43 }
44
45 pub fn sample_buffer(&self) -> Option<crate::CounterSampleBuffer> {
49 unsafe {
50 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(sampleBuffer));
51 if ptr.is_null() {
52 return None;
53 }
54 msg_send_0::<*mut c_void>(ptr, sel!(retain));
55 crate::CounterSampleBuffer::from_raw(ptr)
56 }
57 }
58
59 pub fn set_sample_buffer(&self, sample_buffer: Option<&crate::CounterSampleBuffer>) {
63 unsafe {
64 let ptr = sample_buffer.map_or(std::ptr::null(), |s| s.as_ptr());
65 let _: () = msg_send_1(self.as_ptr(), sel!(setSampleBuffer:), ptr);
66 }
67 }
68
69 #[inline]
73 pub fn start_of_vertex_sample_index(&self) -> UInteger {
74 unsafe { msg_send_0(self.as_ptr(), sel!(startOfVertexSampleIndex)) }
75 }
76
77 #[inline]
81 pub fn set_start_of_vertex_sample_index(&self, index: UInteger) {
82 unsafe {
83 let _: () = msg_send_1(self.as_ptr(), sel!(setStartOfVertexSampleIndex:), index);
84 }
85 }
86
87 #[inline]
91 pub fn end_of_vertex_sample_index(&self) -> UInteger {
92 unsafe { msg_send_0(self.as_ptr(), sel!(endOfVertexSampleIndex)) }
93 }
94
95 #[inline]
99 pub fn set_end_of_vertex_sample_index(&self, index: UInteger) {
100 unsafe {
101 let _: () = msg_send_1(self.as_ptr(), sel!(setEndOfVertexSampleIndex:), index);
102 }
103 }
104
105 #[inline]
109 pub fn start_of_fragment_sample_index(&self) -> UInteger {
110 unsafe { msg_send_0(self.as_ptr(), sel!(startOfFragmentSampleIndex)) }
111 }
112
113 #[inline]
117 pub fn set_start_of_fragment_sample_index(&self, index: UInteger) {
118 unsafe {
119 let _: () = msg_send_1(self.as_ptr(), sel!(setStartOfFragmentSampleIndex:), index);
120 }
121 }
122
123 #[inline]
127 pub fn end_of_fragment_sample_index(&self) -> UInteger {
128 unsafe { msg_send_0(self.as_ptr(), sel!(endOfFragmentSampleIndex)) }
129 }
130
131 #[inline]
135 pub fn set_end_of_fragment_sample_index(&self, index: UInteger) {
136 unsafe {
137 let _: () = msg_send_1(self.as_ptr(), sel!(setEndOfFragmentSampleIndex:), index);
138 }
139 }
140}
141
142impl Clone for RenderPassSampleBufferAttachmentDescriptor {
143 fn clone(&self) -> Self {
144 unsafe {
145 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
146 }
147 Self(self.0)
148 }
149}
150
151impl Drop for RenderPassSampleBufferAttachmentDescriptor {
152 fn drop(&mut self) {
153 unsafe {
154 msg_send_0::<()>(self.as_ptr(), sel!(release));
155 }
156 }
157}
158
159impl Referencing for RenderPassSampleBufferAttachmentDescriptor {
160 #[inline]
161 fn as_ptr(&self) -> *const c_void {
162 self.0.as_ptr()
163 }
164}
165
166unsafe impl Send for RenderPassSampleBufferAttachmentDescriptor {}
167unsafe impl Sync for RenderPassSampleBufferAttachmentDescriptor {}
168
169impl std::fmt::Debug for RenderPassSampleBufferAttachmentDescriptor {
170 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
171 f.debug_struct("RenderPassSampleBufferAttachmentDescriptor")
172 .field(
173 "start_of_vertex_sample_index",
174 &self.start_of_vertex_sample_index(),
175 )
176 .field(
177 "end_of_vertex_sample_index",
178 &self.end_of_vertex_sample_index(),
179 )
180 .field(
181 "start_of_fragment_sample_index",
182 &self.start_of_fragment_sample_index(),
183 )
184 .field(
185 "end_of_fragment_sample_index",
186 &self.end_of_fragment_sample_index(),
187 )
188 .finish()
189 }
190}
191
192#[repr(transparent)]
196pub struct RenderPassSampleBufferAttachmentDescriptorArray(pub(crate) NonNull<c_void>);
197
198impl RenderPassSampleBufferAttachmentDescriptorArray {
199 pub fn new() -> Option<Self> {
203 unsafe {
204 let class =
205 mtl_sys::Class::get("MTLRenderPassSampleBufferAttachmentDescriptorArray")?;
206 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
207 if ptr.is_null() {
208 return None;
209 }
210 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
211 Self::from_raw(ptr)
212 }
213 }
214
215 #[inline]
217 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
218 NonNull::new(ptr).map(Self)
219 }
220
221 #[inline]
223 pub fn as_raw(&self) -> *mut c_void {
224 self.0.as_ptr()
225 }
226
227 pub fn object(&self, index: UInteger) -> Option<RenderPassSampleBufferAttachmentDescriptor> {
231 unsafe {
232 let ptr: *mut c_void =
233 msg_send_1(self.as_ptr(), sel!(objectAtIndexedSubscript:), index);
234 if ptr.is_null() {
235 return None;
236 }
237 msg_send_0::<*mut c_void>(ptr, sel!(retain));
238 RenderPassSampleBufferAttachmentDescriptor::from_raw(ptr)
239 }
240 }
241
242 pub fn set_object(
246 &self,
247 attachment: Option<&RenderPassSampleBufferAttachmentDescriptor>,
248 index: UInteger,
249 ) {
250 unsafe {
251 let ptr = attachment.map_or(std::ptr::null(), |a| a.as_ptr());
252 let _: () = mtl_sys::msg_send_2(
253 self.as_ptr(),
254 sel!(setObject:atIndexedSubscript:),
255 ptr,
256 index,
257 );
258 }
259 }
260}
261
262impl Clone for RenderPassSampleBufferAttachmentDescriptorArray {
263 fn clone(&self) -> Self {
264 unsafe {
265 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
266 }
267 Self(self.0)
268 }
269}
270
271impl Drop for RenderPassSampleBufferAttachmentDescriptorArray {
272 fn drop(&mut self) {
273 unsafe {
274 msg_send_0::<()>(self.as_ptr(), sel!(release));
275 }
276 }
277}
278
279impl Referencing for RenderPassSampleBufferAttachmentDescriptorArray {
280 #[inline]
281 fn as_ptr(&self) -> *const c_void {
282 self.0.as_ptr()
283 }
284}
285
286unsafe impl Send for RenderPassSampleBufferAttachmentDescriptorArray {}
287unsafe impl Sync for RenderPassSampleBufferAttachmentDescriptorArray {}
288
289impl std::fmt::Debug for RenderPassSampleBufferAttachmentDescriptorArray {
290 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
291 f.debug_struct("RenderPassSampleBufferAttachmentDescriptorArray")
292 .finish()
293 }
294}