MetalDevice

Struct MetalDevice 

Source
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

Source

pub fn system_default() -> Option<Self>

Get the system default Metal device

Returns None if no Metal device is available.

Source

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.

Source

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.

Source

pub fn name(&self) -> String

Get the name of this device

Source

pub fn create_command_queue(&self) -> Option<MetalCommandQueue>

Create a command queue for this device

Source

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.

Source

pub fn create_buffer( &self, length: usize, options: ResourceOptions, ) -> Option<MetalBuffer>

Create a buffer

Source

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);
}
Source

pub fn create_render_pipeline_state( &self, descriptor: &MetalRenderPipelineDescriptor, ) -> Option<MetalRenderPipelineState>

Create a render pipeline state from a descriptor

Source

pub fn as_ptr(&self) -> *mut c_void

Get the raw pointer to the underlying MTLDevice

Trait Implementations§

Source§

impl Debug for MetalDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MetalDevice

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for MetalDevice

Source§

impl Sync for MetalDevice

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.