C# bindings for Apple's Metal graphics API, auto-generated from metal-cpp headers.
dotnet add package Metal.NETRequirements: .NET 10+, macOS 15+
using Metal.NET;
MTLDevice device = MTLDevice.CreateSystemDefaultDevice();
using MTLCommandQueue queue = device.NewCommandQueue();
using MTLLibrary library = device.NewDefaultLibrary();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
var desc = new MTLTextureDescriptor();
// Owned
using MTLLibrary library = device.NewDefaultLibrary();
// Borrowed
MTLDevice device = commandQueue.Device;Metal.NET.slnx
├── Metal.NET/
│ ├── Common/
│ │ ├── NativeObject.cs
│ │ ├── ObjectiveC.cs ← Auto-generated P/Invoke to libobjc (objc_msgSend)
│ │ ├── Selector.cs
│ │ └── Bool8.cs
│ ├── CoreGraphics/
│ │ └── CGColorSpace.cs
│ ├── Foundation/
│ │ ├── NSObject.cs
│ │ ├── NSString.cs
│ │ ├── NSError.cs
│ │ ├── NSArray.cs
│ │ ├── NSURL.cs
│ │ ├── NSDictionary.cs
│ │ ├── NSNumber.cs
│ │ ├── NSData.cs
│ │ ├── NSBundle.cs
│ │ ├── NSAutoreleasePool.cs
│ │ └── NSEnums.cs ← Auto-generated
│ ├── GCD/
│ │ ├── DispatchObject.cs
│ │ ├── DispatchData.cs
│ │ └── DispatchQueue.cs
│ ├── Metal/ ← Auto-generated (231 files)
│ ├── MetalFX/ ← Auto-generated (18 files)
│ └── QuartzCore/ ← Auto-generated (2 files)
│
└── Metal.NET.Generator/
├── Program.cs
├── Generator.cs
├── CppParser.cs
├── CSharpEmitter.cs
├── TypeMapper.cs
├── GeneratorContext.cs
├── Models.cs
└── metal-cpp/
-
Download the latest metal-cpp archive.
-
Replace the contents of
Metal.NET.Generator/metal-cpp/. -
Run the generator:
dotnet run --project Metal.NET.Generator
-
Build and verify:
dotnet build Metal.NET
This library was built with AI assistance. It has undergone preliminary testing to verify basic usability, but has not been exhaustively validated in production scenarios. If you plan to use it in a real project, please ensure it meets your requirements through thorough testing.
This project is licensed under the MIT License.
"Metal" is a trademark of Apple Inc. This project is not affiliated with or endorsed by Apple Inc.