metal-tools

1.1.1

eugenebokhan/metal-tools

What's New

Integral Image Kernel Release

2024-03-24T14:12:50Z

Full Changelog: 1.1.0...1.1.1

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: Tue Apr 23 2024 09:29:31 GMT-0900 (Hawaii-Aleutian Daylight Time)