10 unstable releases (3 breaking)

0.6.2 Dec 14, 2024
0.6.1 Oct 15, 2024
0.5.3 Sep 30, 2024
0.3.3 Jul 29, 2024
0.1.0 Sep 24, 2022

#49 in Programming languages

Download history 228/week @ 2024-10-07 469/week @ 2024-10-14 683/week @ 2024-10-21 598/week @ 2024-10-28 721/week @ 2024-11-04 996/week @ 2024-11-11 941/week @ 2024-11-18 592/week @ 2024-11-25 586/week @ 2024-12-02 581/week @ 2024-12-09 602/week @ 2024-12-16 330/week @ 2024-12-23 562/week @ 2024-12-30 926/week @ 2025-01-06 966/week @ 2025-01-13 603/week @ 2025-01-20

3,108 downloads per month
Used in 19 crates (3 directly)

MIT/Apache

7.5MB
147K SLoC

C++ 82K SLoC // 0.1% comments GLSL 56K SLoC // 0.0% comments Happy 4.5K SLoC Rust 2.5K SLoC // 0.0% comments Bitbake 360 SLoC Shell 297 SLoC // 0.6% comments Python 289 SLoC // 0.3% comments JavaScript 141 SLoC Forge Config 101 SLoC // 0.8% comments HLSL 44 SLoC // 0.0% comments Templ 22 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