#spir-v #shader #compiler #glsl #hlsl #cache

spirv-compiler

为 shaderc 在 Rust 中的便利包装

2 个不稳定版本

0.2.0 2021年8月15日
0.1.0 2020年12月27日

#964图形API


用于 2 个库

Apache-2.0

20KB
495

spirv-compiler

用 Rust 编写的 shaderc 包装器,具有内置的包含支持等功能。

用法

此库使用 shaderc 作为其后端进行着色器编译。包含的包装编译器增加了在内存中和文件中缓存着色器编译的功能。包含支持也是内置的。

设置编译器

use spirv_compiler::*;
let mut compiler = CompilerBuilder::new()
    // Add include dirs
    .with_include_dir("my-include-dir")
    // Add macros
    .with_macro("MY_MACRO", Some("1"))
    // Set source language
    .with_source_language(SourceLanguage::GLSL)
    // Build compiler
    .build()
    // If shaderc fails to initialize, this returns None
    .unwrap();

// Compile from file
let result: Result<Vec<u32>, CompileError> = compiler
    .compile_from_file(
        "test-spirv/test-macro.vert",
        ShaderKind::Vertex,
        false // Set to true if shaders should be cached to filesystem
    );

// Compile from string
let result: Result<Vec<u32>, CompileError> = compiler
    .compile_from_string(
        "#version 450...",
        ShaderKind::Vertex,
        false // Set to true if shaders should be cached to filesystem
    );

依赖项

~28MB
~625K SLoC