Skip to content

About

Metal differentiable rasterization for Apple Silicon

Resources

Stars

5 stars

Watchers

1 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

mtldiffrast

Metal implementation of differentiable rasterization primitives for Apple Silicon.

Based on Modular Primitives for High-Performance Differentiable Rendering (Laine et al. 2020).

Features

  • Rasterize: Triangle rasterization with differentiable barycentrics
  • Interpolate: Vertex attribute interpolation with screen-space derivatives
  • Texture: Texture sampling with mipmapping (nearest, linear, trilinear)
  • Antialias: Differentiable antialiasing for silhouette edges
  • Zero-copy: MPS and CPU tensors bind directly to Metal via unified memory

All operations support torch.autograd for end-to-end differentiable rendering.

API-compatible with nvdiffrast for drop-in use in existing pipelines.

Installation

Requires macOS 14+ on Apple Silicon, Xcode command line tools, and PyTorch >= 2.0.

pip install --no-build-isolation -e .
python setup.py build_ext --inplace

Usage

import mtldiffrast.torch as dr

ctx = dr.MtlRasterizeContext()
rast, rast_db = dr.rasterize(ctx, pos, tri, resolution=[512, 512])
out, _ = dr.interpolate(attr, rast, tri)
tex_out = dr.texture(tex, uv)
aa_out = dr.antialias(color, rast, pos, tri)

License

MIT License


Apple-Silicon follow-ups

Cross-repo follow-up work (deferred mtlgemm perf items, fp16/bf16 shader specializations, universal tiled sparse attention, etc.) is tracked in this repo's GitHub issues. Bug reports and PRs are welcome on any of the four mtl* repos — mtlbvh, mtlgemm, mtlmesh and mtldiffrast — and on trellis2-apple, which depends on all of them.

About

Metal differentiable rasterization for Apple Silicon

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages