apple-mps 0.2.1

Safe Rust bindings for Apple's MetalPerformanceShaders framework on macOS, backed by a Swift bridge
Documentation
  • Coverage
  • 18.98%
    138 out of 727 items documented1 out of 564 items with examples
  • Size
  • Source code size: 340.29 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 15.47 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 42s 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.1 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, NDArrayIdentity, and NDArrayMatrixMultiplication
  • State:
    • State, StateResourceList, StateTextureInfo
    • state_batch_increment_read_count, state_batch_resource_size, state_batch_synchronize
  • Ray tracing / denoising:
    • PolygonAccelerationStructure, RayIntersector, and SVGF
  • Neural / optimizer / RNN:
    • NNImageNode, NNGraph
    • CnnNeuronReluNode, CnnPoolingMaxNode, CnnSoftMaxNode, CnnUpsamplingNearestNode
    • CnnConvolutionDescriptor, CnnConvolution, CnnConvolutionWeightsAndBiasesState
    • NNOptimizerDescriptor, NNOptimizer, NNOptimizerStochasticGradientDescent, NNOptimizerRmsProp, NNOptimizerAdam
    • RnnDescriptor, RnnSingleGateDescriptor, GruDescriptor, LstmDescriptor, RnnImageInferenceLayer, RnnRecurrentImageState
  • Shared constants for MPSKernelOptions, MPSImageEdgeMode, MPSImageFeatureChannelFormat, MPSDataType, MPSDataLayout, plus convolution / optimizer / RNN / state 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
cargo run --example 06_ndarray_matrix_multiplication
cargo run --example 07_optimizer_and_state
cargo run --example 08_cnn_convolution
cargo run --example 09_rnn_image_inference