mtl_gpu/mtl4/
linking_descriptor.rs1use std::ffi::c_void;
6use std::ptr::NonNull;
7
8use mtl_foundation::{Referencing, UInteger};
9use mtl_sys::{msg_send_0, msg_send_1, sel};
10
11#[repr(transparent)]
22pub struct StaticLinkingDescriptor(NonNull<c_void>);
23
24impl StaticLinkingDescriptor {
25 #[inline]
27 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
28 NonNull::new(ptr).map(Self)
29 }
30
31 #[inline]
33 pub fn as_raw(&self) -> *mut c_void {
34 self.0.as_ptr()
35 }
36
37 pub fn new() -> Option<Self> {
39 unsafe {
40 let class = mtl_sys::Class::get("MTL4StaticLinkingDescriptor")?;
41 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
42 if ptr.is_null() {
43 return None;
44 }
45 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
46 Self::from_raw(ptr)
47 }
48 }
49
50 pub fn function_descriptors_raw(&self) -> *mut c_void {
54 unsafe { msg_send_0(self.as_ptr(), sel!(functionDescriptors)) }
55 }
56
57 pub fn set_function_descriptors_raw(&self, descriptors: *const c_void) {
61 unsafe {
62 let _: () = msg_send_1(self.as_ptr(), sel!(setFunctionDescriptors:), descriptors);
63 }
64 }
65
66 pub fn groups_raw(&self) -> *mut c_void {
70 unsafe { msg_send_0(self.as_ptr(), sel!(groups)) }
71 }
72
73 pub fn set_groups_raw(&self, groups: *const c_void) {
77 unsafe {
78 let _: () = msg_send_1(self.as_ptr(), sel!(setGroups:), groups);
79 }
80 }
81
82 pub fn private_function_descriptors_raw(&self) -> *mut c_void {
86 unsafe { msg_send_0(self.as_ptr(), sel!(privateFunctionDescriptors)) }
87 }
88
89 pub fn set_private_function_descriptors_raw(&self, descriptors: *const c_void) {
93 unsafe {
94 let _: () = msg_send_1(
95 self.as_ptr(),
96 sel!(setPrivateFunctionDescriptors:),
97 descriptors,
98 );
99 }
100 }
101}
102
103impl Clone for StaticLinkingDescriptor {
104 fn clone(&self) -> Self {
105 unsafe {
106 mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
107 }
108 Self(self.0)
109 }
110}
111
112impl Drop for StaticLinkingDescriptor {
113 fn drop(&mut self) {
114 unsafe {
115 mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
116 }
117 }
118}
119
120impl Referencing for StaticLinkingDescriptor {
121 #[inline]
122 fn as_ptr(&self) -> *const c_void {
123 self.0.as_ptr()
124 }
125}
126
127unsafe impl Send for StaticLinkingDescriptor {}
128unsafe impl Sync for StaticLinkingDescriptor {}
129
130impl std::fmt::Debug for StaticLinkingDescriptor {
131 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
132 f.debug_struct("StaticLinkingDescriptor").finish()
133 }
134}
135
136#[repr(transparent)]
147pub struct PipelineStageDynamicLinkingDescriptor(NonNull<c_void>);
148
149impl PipelineStageDynamicLinkingDescriptor {
150 #[inline]
152 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
153 NonNull::new(ptr).map(Self)
154 }
155
156 #[inline]
158 pub fn as_raw(&self) -> *mut c_void {
159 self.0.as_ptr()
160 }
161
162 pub fn new() -> Option<Self> {
164 unsafe {
165 let class = mtl_sys::Class::get("MTL4PipelineStageDynamicLinkingDescriptor")?;
166 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
167 if ptr.is_null() {
168 return None;
169 }
170 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
171 Self::from_raw(ptr)
172 }
173 }
174
175 pub fn binary_linked_functions_raw(&self) -> *mut c_void {
179 unsafe { msg_send_0(self.as_ptr(), sel!(binaryLinkedFunctions)) }
180 }
181
182 pub fn set_binary_linked_functions_raw(&self, functions: *const c_void) {
186 unsafe {
187 let _: () = msg_send_1(self.as_ptr(), sel!(setBinaryLinkedFunctions:), functions);
188 }
189 }
190
191 pub fn max_call_stack_depth(&self) -> UInteger {
195 unsafe { msg_send_0(self.as_ptr(), sel!(maxCallStackDepth)) }
196 }
197
198 pub fn set_max_call_stack_depth(&self, depth: UInteger) {
202 unsafe {
203 let _: () = msg_send_1(self.as_ptr(), sel!(setMaxCallStackDepth:), depth);
204 }
205 }
206
207 pub fn preloaded_libraries_raw(&self) -> *mut c_void {
211 unsafe { msg_send_0(self.as_ptr(), sel!(preloadedLibraries)) }
212 }
213
214 pub fn set_preloaded_libraries_raw(&self, libraries: *const c_void) {
218 unsafe {
219 let _: () = msg_send_1(self.as_ptr(), sel!(setPreloadedLibraries:), libraries);
220 }
221 }
222}
223
224impl Clone for PipelineStageDynamicLinkingDescriptor {
225 fn clone(&self) -> Self {
226 unsafe {
227 mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
228 }
229 Self(self.0)
230 }
231}
232
233impl Drop for PipelineStageDynamicLinkingDescriptor {
234 fn drop(&mut self) {
235 unsafe {
236 mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
237 }
238 }
239}
240
241impl Referencing for PipelineStageDynamicLinkingDescriptor {
242 #[inline]
243 fn as_ptr(&self) -> *const c_void {
244 self.0.as_ptr()
245 }
246}
247
248unsafe impl Send for PipelineStageDynamicLinkingDescriptor {}
249unsafe impl Sync for PipelineStageDynamicLinkingDescriptor {}
250
251impl std::fmt::Debug for PipelineStageDynamicLinkingDescriptor {
252 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
253 f.debug_struct("PipelineStageDynamicLinkingDescriptor")
254 .field("max_call_stack_depth", &self.max_call_stack_depth())
255 .finish()
256 }
257}
258
259#[repr(transparent)]
270pub struct RenderPipelineDynamicLinkingDescriptor(NonNull<c_void>);
271
272impl RenderPipelineDynamicLinkingDescriptor {
273 #[inline]
275 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
276 NonNull::new(ptr).map(Self)
277 }
278
279 #[inline]
281 pub fn as_raw(&self) -> *mut c_void {
282 self.0.as_ptr()
283 }
284
285 pub fn new() -> Option<Self> {
287 unsafe {
288 let class = mtl_sys::Class::get("MTL4RenderPipelineDynamicLinkingDescriptor")?;
289 let ptr: *mut c_void = msg_send_0(class.as_ptr(), sel!(alloc));
290 if ptr.is_null() {
291 return None;
292 }
293 let ptr: *mut c_void = msg_send_0(ptr, sel!(init));
294 Self::from_raw(ptr)
295 }
296 }
297
298 pub fn fragment_linking_descriptor(&self) -> Option<PipelineStageDynamicLinkingDescriptor> {
302 unsafe {
303 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(fragmentLinkingDescriptor));
304 PipelineStageDynamicLinkingDescriptor::from_raw(ptr)
305 }
306 }
307
308 pub fn mesh_linking_descriptor(&self) -> Option<PipelineStageDynamicLinkingDescriptor> {
312 unsafe {
313 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(meshLinkingDescriptor));
314 PipelineStageDynamicLinkingDescriptor::from_raw(ptr)
315 }
316 }
317
318 pub fn object_linking_descriptor(&self) -> Option<PipelineStageDynamicLinkingDescriptor> {
322 unsafe {
323 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(objectLinkingDescriptor));
324 PipelineStageDynamicLinkingDescriptor::from_raw(ptr)
325 }
326 }
327
328 pub fn tile_linking_descriptor(&self) -> Option<PipelineStageDynamicLinkingDescriptor> {
332 unsafe {
333 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(tileLinkingDescriptor));
334 PipelineStageDynamicLinkingDescriptor::from_raw(ptr)
335 }
336 }
337
338 pub fn vertex_linking_descriptor(&self) -> Option<PipelineStageDynamicLinkingDescriptor> {
342 unsafe {
343 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(vertexLinkingDescriptor));
344 PipelineStageDynamicLinkingDescriptor::from_raw(ptr)
345 }
346 }
347}
348
349impl Clone for RenderPipelineDynamicLinkingDescriptor {
350 fn clone(&self) -> Self {
351 unsafe {
352 mtl_sys::msg_send_0::<*mut c_void>(self.as_ptr(), mtl_sys::sel!(retain));
353 }
354 Self(self.0)
355 }
356}
357
358impl Drop for RenderPipelineDynamicLinkingDescriptor {
359 fn drop(&mut self) {
360 unsafe {
361 mtl_sys::msg_send_0::<()>(self.as_ptr(), mtl_sys::sel!(release));
362 }
363 }
364}
365
366impl Referencing for RenderPipelineDynamicLinkingDescriptor {
367 #[inline]
368 fn as_ptr(&self) -> *const c_void {
369 self.0.as_ptr()
370 }
371}
372
373unsafe impl Send for RenderPipelineDynamicLinkingDescriptor {}
374unsafe impl Sync for RenderPipelineDynamicLinkingDescriptor {}
375
376impl std::fmt::Debug for RenderPipelineDynamicLinkingDescriptor {
377 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
378 f.debug_struct("RenderPipelineDynamicLinkingDescriptor")
379 .finish()
380 }
381}
382
383#[cfg(test)]
384mod tests {
385 use super::*;
386
387 #[test]
388 fn test_static_linking_descriptor_size() {
389 assert_eq!(
390 std::mem::size_of::<StaticLinkingDescriptor>(),
391 std::mem::size_of::<*mut c_void>()
392 );
393 }
394
395 #[test]
396 fn test_pipeline_stage_dynamic_linking_descriptor_size() {
397 assert_eq!(
398 std::mem::size_of::<PipelineStageDynamicLinkingDescriptor>(),
399 std::mem::size_of::<*mut c_void>()
400 );
401 }
402
403 #[test]
404 fn test_render_pipeline_dynamic_linking_descriptor_size() {
405 assert_eq!(
406 std::mem::size_of::<RenderPipelineDynamicLinkingDescriptor>(),
407 std::mem::size_of::<*mut c_void>()
408 );
409 }
410}