metal-tools

1.2.0

A Swift framework that simplifies working with Apple's Metal API.
computer-graphics-tools/metal-tools

What's New

MetalTools

Description

MetalTools provides a convenient, Swifty way of working with Metal. This library is heavily used in computer vision startups ZERO10 and Prisma.

Usage

Dispatch command buffers in both sync/async manner

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
    }
}

Easily create textures from CGImage

let texture = try context.texture(
    from: cgImage,
    usage: [.shaderRead, .shaderWrite]
)

Load a compute pipeline state for a function that sits in a framework

let library = context.shaderLibrary(for: Foo.self)
let computePipelineState = try lib.computePipelineState(function: "brightness")

Allocate buffer by value type

let buffer = context.buffer(
    for: InstanceUniforms.self,
    count: 99,
    options: .storageModeShared
)

Serialize and deserialize MTLTexture

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)

Setup blending mode in render passes

let renderPipelineDescriptor = MTLRenderPipelineDescriptor()
renderPipelineDescriptor.colorAttachments[0].setup(blending: .alpha)

Other things

License

MetalTools is licensed under MIT license.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

Last updated: Thu Dec 05 2024 20:28:29 GMT-1000 (Hawaii-Aleutian Standard Time)