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 device will NOT
be released when this wrapper is dropped - use from_ptr_retained if
you want the wrapper to own the device.
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
§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