Metal.NET
2.0.0
See the version list below for details.
dotnet add package Metal.NET --version 2.0.0
NuGet\Install-Package Metal.NET -Version 2.0.0
<PackageReference Include="Metal.NET" Version="2.0.0" />
<PackageVersion Include="Metal.NET" Version="2.0.0" />
<PackageReference Include="Metal.NET" />
paket add Metal.NET --version 2.0.0
#r "nuget: Metal.NET, 2.0.0"
#:package Metal.NET@2.0.0
#addin nuget:?package=Metal.NET&version=2.0.0
#tool nuget:?package=Metal.NET&version=2.0.0
Metal.NET
C# bindings for Apple's Metal graphics API, auto-generated from the Objective-C headers via Clang AST extraction.
The generator parses metal-ast.json — an AST snapshot extracted directly from the macOS SDK using clang -ast-dump=json — and emits idiomatic C# wrappers that call into the Objective-C runtime via objc_msgSend.
Features
- Comprehensive API coverage — Metal, Metal 4, MetalFX, QuartzCore, Foundation, CoreGraphics and GCD bindings.
- Clang AST-based generation — bindings are extracted from the SDK headers, not from a hand-maintained IDL.
- Automatic memory management — three ownership modes (
Borrowed,Owned,Managed) with deterministic disposal and optional finalizer safety net. - Objective-C block support —
NativeBlockwrappers useUnmanagedCallersOnlyfunction pointers for zero-overhead callbacks. - Native AOT & trimming ready — the library is 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.NewCommandQueue();
// Load the default shader library
using MTLLibrary library = device.NewDefaultLibrary();
// Look up a compute function and create a pipeline state
using MTLFunction kernel = library.NewFunction("myKernel");
using MTLComputePipelineState pso = device.NewComputePipelineState(kernel);
// Create a buffer
using MTLBuffer buffer = device.NewBuffer(1024, MTLResourceOptions.StorageModeShared);
API Coverage
| Framework | Namespace | Contents |
|---|---|---|
| Metal | Metal.NET |
Devices, command queues & buffers, encoders, pipeline states, acceleration structures, Metal 4 APIs (MTL4*), and more. |
| MetalFX | Metal.NET |
Temporal / spatial scalers, frame interpolators. |
| QuartzCore | Metal.NET |
CAMetalLayer, CAMetalDrawable. |
| Foundation | Metal.NET |
Hand-written NSObject, NSString, NSArray, NSError, NSURL, NSData, etc. |
| CoreGraphics | Metal.NET |
CGColorSpace. |
| GCD | Metal.NET |
DispatchQueue, DispatchData, DispatchObject. |
Memory Management
Every NativeObject wrapper has a NativeObjectOwnership that controls its lifetime:
| Ownership | Dispose() releases |
Finalizer releases | Usage |
|---|---|---|---|
Borrowed |
✗ | ✗ | Property getters, objectAtIndex: |
Owned |
✓ | ✗ | Method return values, out NSError |
Managed |
✓ | ✓ | Objects created via parameterless constructor (AllocInit) |
// Managed – finalizer will release if not disposed
var desc = new MTLTextureDescriptor();
// Owned – caller is responsible for disposal
using MTLLibrary library = device.NewDefaultLibrary();
// Borrowed – do not dispose
MTLDevice device = commandQueue.Device;
Project Structure
Metal.NET.slnx
├── Metal.NET/ ← Runtime library (NuGet package)
│ ├── Common/ ← Hand-written interop core
│ │ ├── NativeObject.cs ← Base class for all ObjC wrappers
│ │ ├── NativeBlock.cs ← ObjC block wrappers (UnmanagedCallersOnly)
│ │ ├── ObjectiveC.cs ← Auto-generated objc_msgSend overloads
│ │ └── ...
│ ├── Foundation/ ← Hand-written NS* wrappers
│ ├── CoreGraphics/ ← Hand-written CG* wrappers
│ ├── GCD/ ← Hand-written Dispatch* wrappers
│ ├── Metal/ ← Auto-generated Metal & Metal 4 API
│ │ ├── MTLEnums.cs ← All Metal enumerations
│ │ ├── MTLStructs.cs ← All Metal structs
│ │ ├── MTLDelegates.cs ← Block handler classes
│ │ └── MTL*.cs / MTL4*.cs ← Protocol & class wrappers
│ ├── MetalFX/ ← Auto-generated MetalFX API
│ └── QuartzCore/ ← Auto-generated QuartzCore API
│
└── Metal.NET.Generator/ ← Code generator (not shipped)
├── AstJsonParser.cs ← Parses metal-ast.json
├── CSharpEmitter.cs ← Emits C# source files
├── TypeMapper.cs ← ObjC → C# type mapping
└── metal-ast.json ← Extracted API definitions (generated by CI)
Updating Bindings
- Run the Extract Metal API GitHub Action (
extract-metal-api.yml) to regeneratemetal-ast.jsonfrom the latest Xcode SDK. - Regenerate the C# bindings and verify:
dotnet run --project Metal.NET.Generator
dotnet build Metal.NET
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 |