apple-mps 0.2.0

Safe Rust bindings for Apple's MetalPerformanceShaders framework on macOS, backed by a Swift bridge
Documentation
  • Coverage
  • 27.18%
    131 out of 482 items documented1 out of 350 items with examples
  • Size
  • Source code size: 213.73 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 11.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 48s Average build duration of successful builds.
  • all releases: 49s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • doom-fish/mps-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 1313

mps-rs

Safe Rust bindings for Apple's MetalPerformanceShaders framework on macOS.

The GitHub repository is mps-rs; the published crates.io package is apple-mps because the mps-rs package name is already taken.

Install

cargo add apple-mps apple-metal

Quick start

use apple_metal::MetalDevice;
use apple_mps::{feature_channel_format, Image, ImageDescriptor, ImageGaussianBlur};

let device = MetalDevice::system_default().expect("no Metal device");
let queue = device.new_command_queue().expect("queue");
let descriptor = ImageDescriptor::new(256, 256, 1, feature_channel_format::FLOAT32);
let src = Image::new(&device, descriptor).expect("source image");
let dst = Image::new(&device, descriptor).expect("destination image");
let blur = ImageGaussianBlur::new(&device, 2.0).expect("gaussian blur");
let command_buffer = queue.new_command_buffer().expect("command buffer");
blur.encode_image(&command_buffer, &src, &dst);

v0.2 surface

  • Core helpers:
    • supports_mtl_device, preferred_device, hint_temporary_memory_high_water_mark, set_heap_cache_duration
    • Predicate and MpsCommandBuffer
  • Images:
    • ImageDescriptor + Image for lazily allocated MPS images or texture-backed images
    • Float32 image read/write helpers plus raw byte transfer with MPSDataLayout
    • Unary image filters:
      • ImageGaussianBlur
      • ImageBox
      • ImageSobel
      • ImageMedian
      • ImageConvolution
      • ImageBilinearScale
      • ImageLanczosScale
      • ImageThresholdBinary
      • ImageStatisticsMinAndMax
      • ImageStatisticsMean
      • ImageReduceRowMin, ImageReduceRowMax, ImageReduceRowMean, ImageReduceRowSum
    • ImageHistogram, ImageAdd, and ImageScaleAndAdd
  • Matrix/vector:
    • MatrixDescriptor, VectorDescriptor, MatrixMultiplicationDescriptor, Matrix, Vector, and MatrixMultiplication
  • NDArray:
    • NDArrayDescriptor, NDArray, and NDArrayIdentity
  • Ray tracing / denoising:
    • PolygonAccelerationStructure, RayIntersector, and SVGF
  • Neural graph / descriptors:
    • NNImageNode, NNGraph
    • CnnNeuronReluNode, CnnPoolingMaxNode, CnnSoftMaxNode, CnnUpsamplingNearestNode
    • CnnConvolutionDescriptor, RnnSingleGateDescriptor
  • Shared constants for MPSKernelOptions, MPSImageEdgeMode, MPSImageFeatureChannelFormat, MPSDataType, MPSDataLayout, and new ray/RNN enums

See COVERAGE.md for the Wave-C audit and the implemented/partial matrix.

Validation

cargo test
cargo run --example 01_blur_image
cargo run --example 02_matrix_multiply
cargo run --example 03_ndarray_identity
cargo run --example 04_ray_intersection
cargo run --example 05_nn_graph_relu