Swiftpack.co - MaximV88/Aluminum as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by MaximV88.
MaximV88/Aluminum v1.0.3
Metal encoding utility based on reflection.
⭐️ 13
🕓 3 years ago
iOS macOS
.package(url: "https://github.com/MaximV88/Aluminum.git", from: "v1.0.3")

Aluminum

Aluminum is a Metal encoding utility that greatly simplifies workflow. It promotes usage of string paths and names to ease development, hides indexing logic and provides descriptive errors.

Features

  • ☑ String paths.
  • ☑ Eliminate attribute usage.
  • ☑ Descriptive assertions.
  • ☑ Simple API with Swift's overload abilities.
  • ☑ Encode values or structs without needing a bridging header.
  • ☑ Reusable encoder groups that are encoded once (no overhead on reuse).

Code example 1

In order to bind a metal argument such as:

struct ArgumentBufferWithSamplerArray {
    metal::array<sampler, 10> s;
    texture2d<int, access::sample> tex;
};

kernel void my_function(device ArgumentBufferWithSamplerArray * argument_buffer)
{
  ...
}

All it needs is the following snippet:

let encoder = controller.makeEncoder(for: "argument_buffer", with: computeCommandEncoder)
encoder.setArgumentBuffer(buffer)

encoder.encode(samplerArray, to: "s") // visual form 
encoder.encode(texture, to: [.argument("tex")]) // path form

Code example 2

Its possible to cache bindings of a function to a group and apply it on a command encoder as many times as needed.

For example, a metal function with 2 arguments:

kernel void test_argument_pointer(device uint * argument_1, device uint * argument_2)
{
    ...
}

Has the following snippet:

let group = controller.makeEncoderGroup()

let arg1Encoder = group.makeEncoder(for: "argument_1")
arg1Encoder.encode(buffer1)

let arg2Encoder = group.makeEncoder(for: "argument_2")
arg2Encoder.encode(buffer2)

computeCommandEncoder.apply(group)

Installation

Swift Package Manager

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/MaximV88/Aluminum.git", .upToNextMajor(from: "1.0.0"))

Documentations

Checkout the WIKI PAGES (Usage Guide) for documentations.

For more up-to-date ones, please see the header-doc. (use alt+click in Xcode)

GitHub

link
Stars: 13
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Release v1.0.3
3 years ago

Bug fix (due to typo) for encoding an array of textures without using the index parameter.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics