14 releases (6 breaking)

0.6.2+3454c36 Oct 26, 2024
0.5.2+fa9c3de Sep 26, 2024
0.3.3 Jul 29, 2024
0.3.2 Feb 9, 2024
0.0.1 May 9, 2015

#387 in Programming languages

Download history 1289/week @ 2024-07-29 458/week @ 2024-08-05 460/week @ 2024-08-12 1267/week @ 2024-08-19 429/week @ 2024-08-26 1157/week @ 2024-09-02 1107/week @ 2024-09-09 1206/week @ 2024-09-16 1784/week @ 2024-09-23 1932/week @ 2024-09-30 232/week @ 2024-10-07 359/week @ 2024-10-14 801/week @ 2024-10-21 658/week @ 2024-10-28 738/week @ 2024-11-04 1015/week @ 2024-11-11

3,252 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 4K SLoC Rust 782 SLoC Bitbake 361 SLoC Shell 298 SLoC // 0.6% comments Python 278 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