mtl_gpu/pass/
blit_pass.rs1use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::Referencing;
7use mtl_sys::{msg_send_0, sel};
8
9use super::BlitPassSampleBufferAttachmentDescriptorArray;
10
11#[repr(transparent)]
15pub struct BlitPassDescriptor(NonNull<c_void>);
16
17impl BlitPassDescriptor {
18 #[inline]
24 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
25 NonNull::new(ptr).map(Self)
26 }
27
28 #[inline]
30 pub fn as_raw(&self) -> *mut c_void {
31 self.0.as_ptr()
32 }
33
34 pub fn new() -> Option<Self> {
38 unsafe {
39 let class = mtl_sys::class!(MTLBlitPassDescriptor);
40 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(blitPassDescriptor));
41 if ptr.is_null() {
42 return None;
43 }
44 let _: *mut c_void = msg_send_0(ptr, sel!(retain));
45 Self::from_raw(ptr)
46 }
47 }
48
49 pub fn sample_buffer_attachments(
53 &self,
54 ) -> Option<BlitPassSampleBufferAttachmentDescriptorArray> {
55 unsafe {
56 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(sampleBufferAttachments));
57 BlitPassSampleBufferAttachmentDescriptorArray::from_raw(ptr)
58 }
59 }
60}
61
62impl Default for BlitPassDescriptor {
63 fn default() -> Self {
64 Self::new().expect("failed to create BlitPassDescriptor")
65 }
66}
67
68impl Clone for BlitPassDescriptor {
69 fn clone(&self) -> Self {
70 unsafe {
71 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
72 }
73 Self(self.0)
74 }
75}
76
77impl Drop for BlitPassDescriptor {
78 fn drop(&mut self) {
79 unsafe {
80 msg_send_0::<()>(self.as_ptr(), sel!(release));
81 }
82 }
83}
84
85impl Referencing for BlitPassDescriptor {
86 #[inline]
87 fn as_ptr(&self) -> *const c_void {
88 self.0.as_ptr()
89 }
90}
91
92unsafe impl Send for BlitPassDescriptor {}
93unsafe impl Sync for BlitPassDescriptor {}
94
95impl std::fmt::Debug for BlitPassDescriptor {
96 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97 f.debug_struct("BlitPassDescriptor").finish()
98 }
99}