pub struct MetalDevice { /* private fields */ }Expand description
A Metal device (GPU)
This is a wrapper around MTLDevice that provides safe access to Metal functionality.
Implementations§
Source§impl MetalDevice
impl MetalDevice
Sourcepub fn system_default() -> Option<Self>
pub fn system_default() -> Option<Self>
Get the system default Metal device
Returns None if no Metal device is available.
Sourcepub unsafe fn from_ptr(ptr: *mut c_void) -> Option<Self>
pub unsafe fn from_ptr(ptr: *mut c_void) -> Option<Self>
Create a MetalDevice from a raw MTLDevice pointer
This is useful when you already have a device from another source
(e.g., the metal crate) and want to use it for texture creation.
§Safety
The pointer must be a valid MTLDevice pointer. The wrapper borrows
the device: it will NOT be released when this wrapper is dropped. Use
Self::from_ptr_retained if you want the wrapper to hold its own
reference.
Sourcepub unsafe fn from_ptr_retained(ptr: *mut c_void) -> Option<Self>
pub unsafe fn from_ptr_retained(ptr: *mut c_void) -> Option<Self>
Create a MetalDevice from a raw MTLDevice pointer, retaining it
The wrapper takes its own +1 reference (via an Objective-C retain)
and releases it on drop, so the caller keeps ownership of their
reference.
§Safety
The pointer must be a valid MTLDevice pointer.
Sourcepub fn create_command_queue(&self) -> Option<MetalCommandQueue>
pub fn create_command_queue(&self) -> Option<MetalCommandQueue>
Create a command queue for this device
Sourcepub fn create_library_with_source(
&self,
source: &str,
) -> Result<MetalLibrary, String>
pub fn create_library_with_source( &self, source: &str, ) -> Result<MetalLibrary, String>
Create a shader library from source code
§Errors
Returns an error message if shader compilation fails.
Sourcepub fn create_buffer(
&self,
length: usize,
options: ResourceOptions,
) -> Option<MetalBuffer>
pub fn create_buffer( &self, length: usize, options: ResourceOptions, ) -> Option<MetalBuffer>
Create a buffer
Sourcepub fn create_buffer_with_data<T>(&self, data: &T) -> Option<MetalBuffer>
pub fn create_buffer_with_data<T>(&self, data: &T) -> Option<MetalBuffer>
Create a buffer and populate it with the given data
This is a convenience method that creates a buffer, copies the data, and returns the buffer. Useful for uniform buffers or vertex data.
§Example
use screencapturekit::metal::{MetalDevice, Uniforms};
fn example() {
let device = MetalDevice::system_default().expect("No Metal device");
let uniforms = Uniforms::new(1920.0, 1080.0, 1920.0, 1080.0);
let buffer = device.create_buffer_with_data(&uniforms);
}Sourcepub fn create_render_pipeline_state(
&self,
descriptor: &MetalRenderPipelineDescriptor,
) -> Option<MetalRenderPipelineState>
pub fn create_render_pipeline_state( &self, descriptor: &MetalRenderPipelineDescriptor, ) -> Option<MetalRenderPipelineState>
Create a render pipeline state from a descriptor
Sourcepub fn as_apple_metal(&self) -> ManuallyDropDevice
pub fn as_apple_metal(&self) -> ManuallyDropDevice
Wrap this device as an [apple_metal::ManuallyDropDevice] for
interop with the lightweight apple-metal crate. The returned
handle references the same MTLDevice instance and does not
release it on drop — keep this MetalDevice alive while the
borrowed handle is in use.
Useful when handing this device to other apple_metal APIs from
code that already holds an SCK MetalDevice.