15 releases (7 breaking)

new 0.7.0+1062752 Dec 14, 2024
0.6.2+3454c36 Oct 26, 2024
0.6.1+46ef757 Sep 30, 2024
0.3.3 Jul 29, 2024
0.0.1 May 9, 2015

#397 in Programming languages

Download history 474/week @ 2024-08-24 673/week @ 2024-08-31 1116/week @ 2024-09-07 1464/week @ 2024-09-14 1772/week @ 2024-09-21 1539/week @ 2024-09-28 846/week @ 2024-10-05 323/week @ 2024-10-12 440/week @ 2024-10-19 1014/week @ 2024-10-26 753/week @ 2024-11-02 828/week @ 2024-11-09 1014/week @ 2024-11-16 640/week @ 2024-11-23 636/week @ 2024-11-30 691/week @ 2024-12-07

3,304 downloads per month
Used in 19 crates (via glslang)

MIT/Apache

7.5MB
145K SLoC

C++ 82K SLoC // 0.1% comments GLSL 56K SLoC // 0.0% comments Happy 4.5K SLoC Rust 783 SLoC Bitbake 361 SLoC Shell 298 SLoC // 0.6% comments Python 290 SLoC // 0.3% comments JavaScript 142 SLoC Forge Config 102 SLoC // 0.8% comments HLSL 45 SLoC // 0.1% comments Templ 23 SLoC // 0.6% 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