3 releases

0.3.2 Feb 16, 2024
0.3.1 Feb 8, 2024
0.2.4 Feb 8, 2024
0.1.1 Feb 7, 2024
0.1.0 Sep 24, 2022

#67 in Programming languages

Download history 891/week @ 2024-02-05 1656/week @ 2024-02-12 746/week @ 2024-02-19 557/week @ 2024-02-26 669/week @ 2024-03-04 93/week @ 2024-03-11 107/week @ 2024-03-18

1,460 downloads per month
Used in 12 crates (via librashader-reflect)

MIT/Apache

7.5MB
146K SLoC

C++ 81K SLoC // 0.1% comments GLSL 55K SLoC // 0.0% comments Happy 4K SLoC Rust 3.5K SLoC // 0.0% comments Bitbake 360 SLoC Shell 295 SLoC // 0.6% comments Python 277 SLoC // 0.3% comments JavaScript 141 SLoC Forge Config 101 SLoC // 0.8% comments HLSL 44 SLoC // 0.0% comments

glslang-rs

Safe Rust bindings to glslang

Latest Version Docs License

Usage

[dependencies]
glslang = "0.3"

Example

Compiling a shader

    use rspirv::binary::Disassemble;
    use glslang::*;

    #[test]
    pub fn test_compile() {
        // Acquire the compiler instance
        let compiler = Compiler::acquire().unwrap();
        let source = ShaderSource::try_from(String::from(
r#"
#version 450

layout(location = 0) out vec4 color;
layout(binding = 1) uniform sampler2D tex;

void main() {
    color = texture(tex, vec2(0.0));
}
"#,
        ))
        .expect("source");

        let limits = ResourceLimits::default();
        let input = ShaderInput::new(
            &source,
            &limits,
            ShaderStage::Fragment,
            &CompilerOptions::default(),
            None,
        );
        let shader = Shader::new(&compiler, input).expect("shader init");

        let mut program = Program::new(&compiler);

        program.add_shader(shader);
        program.link().expect("link error");

        let code = program.compile(ShaderStage::Fragment).expect("shader");
       
        // Use rspirv to disassemble
        let mut loader = rspirv::dr::Loader::new();
        rspirv::binary::parse_words(&code, &mut loader).unwrap();
        let module = loader.module();

        println!("{}", module.disassemble())
    }

Dependencies