mtl_gpu/argument/
object_payload_binding.rs1use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::{Referencing, UInteger};
7use mtl_sys::{msg_send_0, sel};
8
9use crate::enums::{BindingAccess, BindingType};
10
11#[repr(transparent)]
15pub struct ObjectPayloadBinding(pub(crate) NonNull<c_void>);
16
17impl ObjectPayloadBinding {
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 #[inline]
38 pub fn access(&self) -> BindingAccess {
39 unsafe { msg_send_0(self.as_ptr(), sel!(access)) }
40 }
41
42 #[inline]
44 pub fn index(&self) -> UInteger {
45 unsafe { msg_send_0(self.as_ptr(), sel!(index)) }
46 }
47
48 #[inline]
50 pub fn is_argument(&self) -> bool {
51 unsafe { msg_send_0(self.as_ptr(), sel!(isArgument)) }
52 }
53
54 #[inline]
56 pub fn is_used(&self) -> bool {
57 unsafe { msg_send_0(self.as_ptr(), sel!(isUsed)) }
58 }
59
60 pub fn name(&self) -> Option<String> {
62 unsafe {
63 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(name));
64 if ptr.is_null() {
65 return None;
66 }
67 let utf8_ptr: *const std::ffi::c_char =
68 mtl_sys::msg_send_0(ptr as *const c_void, sel!(UTF8String));
69 if utf8_ptr.is_null() {
70 return None;
71 }
72 let c_str = std::ffi::CStr::from_ptr(utf8_ptr);
73 Some(c_str.to_string_lossy().into_owned())
74 }
75 }
76
77 #[inline]
79 pub fn binding_type(&self) -> BindingType {
80 unsafe { msg_send_0(self.as_ptr(), sel!(type)) }
81 }
82
83 #[inline]
89 pub fn object_payload_alignment(&self) -> UInteger {
90 unsafe { msg_send_0(self.as_ptr(), sel!(objectPayloadAlignment)) }
91 }
92
93 #[inline]
97 pub fn object_payload_data_size(&self) -> UInteger {
98 unsafe { msg_send_0(self.as_ptr(), sel!(objectPayloadDataSize)) }
99 }
100}
101
102impl Clone for ObjectPayloadBinding {
103 fn clone(&self) -> Self {
104 unsafe {
105 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
106 }
107 Self(self.0)
108 }
109}
110
111impl Drop for ObjectPayloadBinding {
112 fn drop(&mut self) {
113 unsafe {
114 msg_send_0::<()>(self.as_ptr(), sel!(release));
115 }
116 }
117}
118
119impl Referencing for ObjectPayloadBinding {
120 #[inline]
121 fn as_ptr(&self) -> *const c_void {
122 self.0.as_ptr()
123 }
124}
125
126unsafe impl Send for ObjectPayloadBinding {}
127unsafe impl Sync for ObjectPayloadBinding {}