Metal.NET
2.3.0
dotnet add package Metal.NET --version 2.3.0
NuGet\Install-Package Metal.NET -Version 2.3.0
<PackageReference Include="Metal.NET" Version="2.3.0" />
<PackageVersion Include="Metal.NET" Version="2.3.0" />
<PackageReference Include="Metal.NET" />
paket add Metal.NET --version 2.3.0
#r "nuget: Metal.NET, 2.3.0"
#:package Metal.NET@2.3.0
#addin nuget:?package=Metal.NET&version=2.3.0
#tool nuget:?package=Metal.NET&version=2.3.0
Metal.NET
Low-level C# bindings for Apple's Metal and MetalFX frameworks — auto-generated from the macOS SDK via Clang AST + Swift Symbol Graph extraction.
Features
- Comprehensive coverage — Metal, Metal 4 and MetalFX (252 generated files), plus hand-written wrappers for CoreFoundation, CoreAnimation, CoreGraphics, GCD and SIMD types.
- Clang AST + Swift Symbol Graph — bindings are extracted from SDK headers, not a hand-maintained IDL. Swift names provide human-readable method & parameter names where Clang only exposes selectors.
- Three ownership modes —
Borrowed,OwnedandManaged, with deterministicDispose()and an optional finalizer safety net. - ObjC block support —
NativeBlock<T>usesUnmanagedCallersOnlyfunction pointers for zero-overhead callbacks. - Native AOT & trimming ready — annotated with
IsAotCompatibleandIsTrimmable.
Installation
dotnet add package Metal.NET
Requirements: .NET 10+, macOS 15+
Quick Start
using Metal.NET;
// Obtain the default GPU device
MTLDevice device = MTLDevice.CreateSystemDefaultDevice();
// Create a command queue
using MTLCommandQueue queue = device.MakeCommandQueue();
// Load the default shader library
using MTLLibrary library = device.MakeDefaultLibrary();
// Look up a compute function and create a pipeline state
using MTLFunction kernel = library.MakeFunction("myKernel");
using MTLComputePipelineState pso = device.MakeComputePipelineState(kernel, out NSError error);
// Create a buffer
using MTLBuffer buffer = device.MakeBuffer(1024, MTLResourceOptions.StorageModeShared);
API Coverage
| Framework | Files | Highlights |
|---|---|---|
| Metal / Metal 4 | 233 | Devices, command queues & buffers, render / compute / blit encoders, pipeline states, acceleration structures, MTL4* APIs |
| MetalFX | 18 | Temporal & spatial scalers, frame interpolators |
Hand-written wrappers are included for CoreFoundation (NSObject, NSString, NSArray, …), CoreAnimation (CAMetalLayer, CAMetalDrawable), CoreGraphics (CGColorSpace, CGSize), GCD (DispatchQueue, DispatchData) and SIMD types.
Memory Management
| Ownership | Dispose() |
Finalizer | Typical Usage |
|---|---|---|---|
Borrowed |
— | — | Property getters, indexed subscript |
Owned |
✓ | — | Method return values, out NSError |
Managed |
✓ | ✓ | new via AllocInit |
// Managed – finalizer will release if not disposed
var desc = new MTLTextureDescriptor();
// Owned – caller is responsible for disposal
using MTLLibrary library = device.MakeDefaultLibrary();
// Borrowed – do not dispose
MTLDevice device = commandQueue.Device;
How It Works
┌──────────────────┐
macOS SDK │ Xcode / Clang │
└────────┬─────────┘
│
┌────────────┴────────────┐
▼ ▼
Clang AST (JSON) Swift Symbol Graphs
│ │
└────────────┬────────────┘
▼
parse_metal_ast.py (Python)
│
▼
metal-ast.json
│
▼
Metal.NET.Generator (C#)
│
▼
Generated bindings
A GitHub Actions workflow (extract-metal-api.yml) runs on a macOS runner to:
- Dump the Clang AST —
clang -Xclang -ast-dump=jsonproduces a complete JSON representation of every declaration in the Metal / MetalFX headers. - Extract Swift Symbol Graphs —
swift-symbolgraph-extractprovides the human-readable Swift names for methods and properties. - Merge into
metal-ast.json— A Python script merges both sources, applies Swift name propagation, resolves overload collisions, and outputs a compact JSON describing every enum, struct, protocol, class, property, method, free function and block typedef. - Generate C# bindings — The C# generator reads
metal-ast.jsonand emits idiomatic wrappers that call the Objective-C runtime directly viaobjc_msgSend.
Project Structure
Metal.NET.slnx
│
├─ Metal.NET/ Runtime library (NuGet package)
│ ├─ Interop/ Interop core (hand-written)
│ │ ├─ NativeObject.cs Base class for all ObjC wrappers
│ │ ├─ NativeBlock.cs ObjC block support (UnmanagedCallersOnly)
│ │ ├─ ObjectiveC.cs Auto-generated objc_msgSend overloads
│ │ ├─ Selector.cs Lazy selector handle
│ │ └─ Bool8.cs Boolean value type
│ ├─ CoreFoundation/ Hand-written NS* wrappers
│ ├─ CoreAnimation/ Hand-written CA* wrappers
│ ├─ CoreGraphics/ Hand-written CG* wrappers
│ ├─ Dispatch/ Hand-written Dispatch* wrappers
│ ├─ Simd/ Hand-written SIMD value types
│ ├─ Metal/ Auto-generated Metal & Metal 4 API
│ └─ MetalFX/ Auto-generated MetalFX API
│
├─ Metal.NET.Generator/ Code generator (not shipped)
│ ├─ AstJsonParser*.cs JSON → model (7 partial files)
│ ├─ CSharpEmitter*.cs Model → C# source (9 partial files)
│ ├─ TypeMapper.cs ObjC ↔ C# type mapping
│ ├─ Models.cs / AstModels.cs Data models
│ ├─ GeneratorContext.cs Shared state across stages
│ └─ metal-ast.json Extracted API snapshot (generated by CI)
│
└─ .github/
├─ workflows/extract-metal-api.yml CI: extract AST → commit metal-ast.json
└─ scripts/parse_metal_ast.py Clang AST + Swift Symbol Graph → JSON
Updating Bindings
- Run the Extract Metal API workflow to regenerate
metal-ast.jsonfrom the latest Xcode SDK. - Regenerate and verify locally:
dotnet run --project Metal.NET.Generator
dotnet build Metal.NET
License
Disclaimer
This library was built with AI assistance. It has undergone preliminary testing but has not been exhaustively validated in production scenarios. Please test thoroughly before production use.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Metal.NET:
| Package | Downloads |
|---|---|
|
Zenith.NET.Metal
Zenith.NET is a modern, cross-platform graphics and compute library for .NET. It provides a unified GPU programming interface supporting DirectX12, Metal, and Vulkan backends. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.3.0 | 152 | 3/31/2026 |
| 2.2.1 | 101 | 3/29/2026 |
| 2.2.0 | 90 | 3/20/2026 |
| 2.1.0 | 92 | 3/18/2026 |
| 2.0.1 | 89 | 3/17/2026 |
| 2.0.0 | 95 | 3/17/2026 |
| 1.4.2 | 99 | 3/13/2026 |
| 1.4.1 | 94 | 3/13/2026 |
| 1.4.0 | 102 | 3/11/2026 |
| 1.3.1 | 99 | 3/5/2026 |
| 1.3.0 | 90 | 3/5/2026 |
| 1.2.0 | 94 | 3/3/2026 |
| 1.1.0 | 94 | 2/25/2026 |
| 1.0.9 | 88 | 2/25/2026 |
| 1.0.8 | 89 | 2/25/2026 |
| 1.0.7 | 92 | 2/25/2026 |
| 1.0.6 | 92 | 2/25/2026 |
| 1.0.5 | 93 | 2/24/2026 |
| 1.0.4 | 91 | 2/24/2026 |
| 1.0.3 | 89 | 2/21/2026 |