MetalTools provides a convenient, Swifty way of working with Metal. This library is heavily used in computer vision startups ZERO10 and Prisma.
See how you can group encodings with Swift closures.
self.context.scheduleAndWait { buffer in
buffer.compute { encoder in
// compute command encoding logic
}
buffer.blit { encoder in
// blit command encoding logic
}
}
let texture = try context.texture(
from: cgImage,
usage: [.shaderRead, .shaderWrite]
)
let library = context.shaderLibrary(for: Foo.self)
let computePipelineState = try lib.computePipelineState(function: "brightness")
let buffer = context.buffer(
for: InstanceUniforms.self,
count: 99,
options: .storageModeShared
)
let encoder = JSONEncoder()
let data = try encoder.encode(texture.codable())
let decoder = JSONDecoder()
let decodableTexture = try decoder.decode(MTLTextureCodableBox.self, from: data)
let decodedTexture = try decodableTexture.texture(device: self.context.device)
let renderPipelineDescriptor = MTLRenderPipelineDescriptor()
renderPipelineDescriptor.colorAttachments[0].setup(blending: .alpha)
- Create multi-sample render target pairs
- Create textures
- Create depth buffers
- Create depth/stencil states
- Lots of ready-to-use compute kernels
- A couple of simple geometry renderers
- etc.
MetalTools is licensed under MIT license.