apple-mps 0.1.0

Safe Rust bindings for Apple's MetalPerformanceShaders framework on macOS, backed by a Swift bridge
Documentation
  • Coverage
  • 45.52%
    122 out of 268 items documented1 out of 187 items with examples
  • Size
  • Source code size: 107.43 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 5.48 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 56s 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.1 surface

  • 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 for histogram-to-MTLBuffer workloads
  • ImageAdd plus ImageScaleAndAdd convenience semantics backed by MPSImageAdd
  • MatrixDescriptor, VectorDescriptor, MatrixMultiplicationDescriptor, Matrix, Vector, and MatrixMultiplication
  • Shared constants for MPSKernelOptions, MPSImageEdgeMode, MPSImageFeatureChannelFormat, MPSDataType, and MPSDataLayout

Smoke examples

cargo run --example 01_blur_image
cargo run --example 02_matrix_multiply