#glsl-shader #glsl #spir-v #shader #vulkan #hotload #file-extension

hotglsl

一个简单的crate,用于将GLSL着色器作为SPIR-V热加载

2个不稳定版本

0.2.0 2024年1月17日
0.1.0 2020年3月21日

#640 in 图形API

26每月下载量

MIT/Apache

14KB
236 代码行

hotglsl 构建状态 Crates.io Crates.io docs.rs

一个简单的crate,用于将GLSL着色器作为SPIR-V热加载。

fn main() {
    let shader_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("examples")
        .join("shaders");
    let watch = hotglsl::watch(&shader_dir).unwrap();
    println!("Edit the shaders in `examples/shaders/`!");
    loop {
        watch.await_event().unwrap();

        // On some OSes, a whole bunch of events will occur at once. Wait for
        // this to happen to avoid compiling our shader(s) twice unnecessarily.
        std::thread::sleep(std::time::Duration::from_millis(10));

        // Compile each shader that has been touched and produce the result.
        for (path, result) in watch.compile_touched().unwrap() {
            println!("Tried compiling {:?}:", path);
            match result {
                Ok(_spirv_bytes) => println!("  Success!"),
                Err(e) => println!("  Woopsie!\n{}", e),
            }
        }
    }
}

允许监视一个或多个文件和/或目录路径以查找GLSL着色器文件更改。

查看支持的GLSL扩展的常量GLSL_EXTENSIONS。一个hotglsl::Watch将忽略所有不涉及具有这些扩展之一的文件的事件。

使用notify crate进行文件系统事件,并使用glsl-to-spirv crate进行GLSL到SPIR-V编译。

依赖项

~5–16MB
~181K SLoC