Skip to content

Repository files navigation

LLAIR - Create and manipulate Apple Metal shading programs with the LLVM API.

The purpose of this library is to facilitate the generation of shading programs at runtime or the development of new shading program front ends, without using the Metal Shading Language itself as an intermediate representation.

LLAIR specifies a few classes that model the parts of the Metal intermediate representation that extend the LLVM IR itself. 'llair::Module' is such a class: it maintains a reference to a 'llvm::Module' as well as references to Metal-specific things (such as vertex, fragment, and compute functions).

The function 'llair::Tools::compileBuffer()' accepts a string containing source code in the Metal Shading Language and returns a new 'llair::Module'. The function 'llair::Tools::makeLibrary()' accepts a reference to a 'llair::Module' and returns a buffer that can be passed to the MTLDevice function 'newLibraryWithData'. Both functions are implemented by running some of the Metal command-line utilities distributed with Xcode (respectively, the 'metal' and 'metallib' utilities).

This project requires this fork of LLVM, which is itself based on another fork developed by Florian Ziesche; among other things, that project provides the capability to emit (and disassemble) valid '.metallib' files from the application itself, & without invoking air-lld as a child process. The variable 'LLVM_DIR' should be set to the location of the LLVM distribution's 'LLVMConfig.cmake' when running 'cmake'.

Building

Use the CMake presets to configure and build against a prebuilt LLVM:

cmake --preset macos
cmake --build --preset macos

Presets are also provided for macos-release, macos-xcode, ios, ios-sim, visionos, tvos, and tvos-sim. Each preset points LLVM_DIR at the matching platform's install under bourbon's build-deps-<platform>/ (built via deps/CMakePresets.json in the parent bourbon project). Building without presets still works — just set LLVM_DIR yourself before running cmake.

About

Library to manipulate Apple Metal Shading Language IR

Resources

Stars

63 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages