#glsl #spirv #wgsl #inline #graphics #hlsl #spir-v

macro inline-spirv

Compile GLSL/HLSL/WGSL and inline SPIR-V right inside your crate

5 releases

0.1.5 Oct 21, 2022
0.1.4 Jun 22, 2021
0.1.2 Nov 18, 2020
0.1.1 Aug 19, 2020
0.1.0 Aug 18, 2020

#362 in Graphics APIs

Download history 28/week @ 2022-10-13 55/week @ 2022-10-20 48/week @ 2022-10-27 51/week @ 2022-11-03 46/week @ 2022-11-10 40/week @ 2022-11-17 10/week @ 2022-11-24 27/week @ 2022-12-01 60/week @ 2022-12-08 29/week @ 2022-12-15 34/week @ 2022-12-22 27/week @ 2022-12-29 23/week @ 2023-01-05 30/week @ 2023-01-12 61/week @ 2023-01-19 44/week @ 2023-01-26

162 downloads per month
Used in 2 crates

MIT/Apache

26KB
432 lines

Inline SPIR-V

Crate Documentation

inline-spirv ease the way you write shaders. Although as game developers, we usually compile a permutation of shader stages for different objects and materials at runtime for the best flexibility; sometimes we do want to try out some new ideas and start up dirty. This crate helps you compile GLSL/HLSL shader in your Rust code, or in external files, into SPIR-V; and embed them right inside the binary, so you are freed from all the compilation hassle.

How to Use

To inline shader source:

use inline_spirv::include_spirv;

let spv: &'static [u32] = inline_spirv!(r#"
    #version 450 core
    void main() { gl_Position = vec4(0, 0, 0, 1); }
"#, vert);

To include a external shader source file:

use inline_spirv::include_spirv;

let spv: &'static [u32] = include_spirv!("assets/vert.hlsl", vert, hlsl, entry="Main");

For the full list of options please refer to the documentation.

Tips

The macro can be verbose especially you have a bunch of #includes, so please be aware of that you can alias and define a more customized macro for yourself:

use inline_spirv::include_spirv as include_spirv_raw;

macro_rules! include_spirv {
    ($path:expr, $stage:ident) => {
        include_spirv_raw!(
            $path,
            $stage, hlsl,
            entry="my_entry_pt",
            D VERBOSE_DEFINITION,
            D ANOTHER_VERBOSE_DEFINITION="verbose definition substitution",
            I "long/path/to/include/directory",
        )
    }
}

// ...
let vert: &[u32] = include_spirv!("examples/demo/assets/demo.hlsl", vert);

License

This project is licensed under either of

at your option.

Dependencies

~0.2–5.5MB
~120K SLoC