3 releases (breaking)

0.2.0-beta… Sep 26, 2024
0.1.0+irconverter-1.1 Jul 16, 2024
0.0.0-alpha.1 May 1, 2024

#184 in Programming languages

Download history 36/week @ 2024-06-24 41/week @ 2024-07-01 47/week @ 2024-07-08 121/week @ 2024-07-15 9/week @ 2024-07-22 20/week @ 2024-07-29 2/week @ 2024-08-05 8/week @ 2024-08-19 18/week @ 2024-08-26 48/week @ 2024-09-02 22/week @ 2024-09-09 50/week @ 2024-09-16 191/week @ 2024-09-23 114/week @ 2024-09-30 13/week @ 2024-10-07

368 downloads per month

Apache-2.0

140KB
3K SLoC

🤘 Saxaboom

Actions Status Latest version Documentation Apache Contributor Covenant

Banner

saxaboom is a small helper library around Metal shader converter to create metal shader libraries from DXIL files (HLSL source code). See also saxaboom-runtime which provides the runtime structures and interop with the metal crate needed to make use of the resulting metallib shaders.

Usage

Add this to your Cargo.toml:

[dependencies]
saxaboom = "0.2.0-beta.1"

Example to compile DXIL to metallib:

use saxaboom::{ffi, MetalIrConverter};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load the library
    let metal_irconverter = MetalIrConverter::new("libmetalirconverter.dylib").unwrap();
    // Create an instance of IRCompiler
    let mut compiler = metal_irconverter.create_compiler();
    // Create an object containing DXIL bytes, replace &[0u8] with your DXIL data
    let dxil = metal_irconverter.create_object_from_dxil(&[0u8]);

    // See `IRCompiler` docs for possible state that can be set on the compiler before compiling
    // DXIL source, such as a global root signatures and various raytracing parameters.

    // Compile the `dxil` data blob with entrypoint `main` into mtllib
    let mtllib = compiler.alloc_compile_and_link(c"main", &dxil)?;

    let reflection = mtllib.reflection();
    let mtl_binary = mtllib
        .metal_lib_binary()
        .expect("Compiled object should contain a `metallib`");
    let bytecode = mtl_binary.byte_code();

    Ok(())
}

For using the loaded metallib shaders at runtime most effectively, consult saxaboom-runtime.

Dependencies

~0.4–5MB
~18K SLoC