mtl_gpu/pipeline/
reflection.rs1use std::ffi::c_void;
6use std::ptr::NonNull;
7
8use mtl_foundation::Referencing;
9use mtl_sys::{msg_send_0, sel};
10
11pub struct ComputePipelineReflection(pub(crate) NonNull<c_void>);
12
13impl ComputePipelineReflection {
14 pub fn new() -> Option<Self> {
18 unsafe {
19 let class = mtl_sys::Class::get("MTLComputePipelineReflection")?;
20 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
21 if ptr.is_null() {
22 return None;
23 }
24 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
25 Self::from_raw(ptr)
26 }
27 }
28
29 #[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 arguments_raw(&self) -> *mut c_void {
55 unsafe { msg_send_0(self.as_ptr(), sel!(arguments)) }
56 }
57
58 pub fn bindings_raw(&self) -> *mut c_void {
64 unsafe { msg_send_0(self.as_ptr(), sel!(bindings)) }
65 }
66}
67
68impl Clone for ComputePipelineReflection {
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 ComputePipelineReflection {
78 fn drop(&mut self) {
79 unsafe {
80 msg_send_0::<()>(self.as_ptr(), sel!(release));
81 }
82 }
83}
84
85impl Referencing for ComputePipelineReflection {
86 #[inline]
87 fn as_ptr(&self) -> *const c_void {
88 self.0.as_ptr()
89 }
90}
91
92unsafe impl Send for ComputePipelineReflection {}
93unsafe impl Sync for ComputePipelineReflection {}
94
95impl std::fmt::Debug for ComputePipelineReflection {
96 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97 f.debug_struct("ComputePipelineReflection").finish()
98 }
99}
100
101#[repr(transparent)]
109pub struct RenderPipelineReflection(pub(crate) NonNull<c_void>);
110
111impl RenderPipelineReflection {
112 pub fn new() -> Option<Self> {
116 unsafe {
117 let class = mtl_sys::Class::get("MTLRenderPipelineReflection")?;
118 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
119 if ptr.is_null() {
120 return None;
121 }
122 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
123 Self::from_raw(ptr)
124 }
125 }
126
127 #[inline]
133 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
134 NonNull::new(ptr).map(Self)
135 }
136
137 #[inline]
139 pub fn as_raw(&self) -> *mut c_void {
140 self.0.as_ptr()
141 }
142
143 pub fn vertex_arguments_raw(&self) -> *mut c_void {
151 unsafe { msg_send_0(self.as_ptr(), sel!(vertexArguments)) }
152 }
153
154 pub fn fragment_arguments_raw(&self) -> *mut c_void {
158 unsafe { msg_send_0(self.as_ptr(), sel!(fragmentArguments)) }
159 }
160
161 pub fn tile_arguments_raw(&self) -> *mut c_void {
165 unsafe { msg_send_0(self.as_ptr(), sel!(tileArguments)) }
166 }
167
168 pub fn vertex_bindings_raw(&self) -> *mut c_void {
176 unsafe { msg_send_0(self.as_ptr(), sel!(vertexBindings)) }
177 }
178
179 pub fn fragment_bindings_raw(&self) -> *mut c_void {
183 unsafe { msg_send_0(self.as_ptr(), sel!(fragmentBindings)) }
184 }
185
186 pub fn tile_bindings_raw(&self) -> *mut c_void {
190 unsafe { msg_send_0(self.as_ptr(), sel!(tileBindings)) }
191 }
192
193 pub fn object_bindings_raw(&self) -> *mut c_void {
197 unsafe { msg_send_0(self.as_ptr(), sel!(objectBindings)) }
198 }
199
200 pub fn mesh_bindings_raw(&self) -> *mut c_void {
204 unsafe { msg_send_0(self.as_ptr(), sel!(meshBindings)) }
205 }
206}
207
208impl Clone for RenderPipelineReflection {
209 fn clone(&self) -> Self {
210 unsafe {
211 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
212 }
213 Self(self.0)
214 }
215}
216
217impl Drop for RenderPipelineReflection {
218 fn drop(&mut self) {
219 unsafe {
220 msg_send_0::<()>(self.as_ptr(), sel!(release));
221 }
222 }
223}
224
225impl Referencing for RenderPipelineReflection {
226 #[inline]
227 fn as_ptr(&self) -> *const c_void {
228 self.0.as_ptr()
229 }
230}
231
232unsafe impl Send for RenderPipelineReflection {}
233unsafe impl Sync for RenderPipelineReflection {}
234
235impl std::fmt::Debug for RenderPipelineReflection {
236 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
237 f.debug_struct("RenderPipelineReflection").finish()
238 }
239}