Rust bindings for the shaderc library.
This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.
The shaderc_combined
library (libshaderc_combined.a
on Unix-like systems)
is required for proper linking. You can compile it by checking out the shaderc
project and follow the instructions there. Then place libshaderc_combined.a
at a path that is scanned by the linker (e.g., the deps
directory within the
target
directory).
First add to your Cargo.toml
:
toml
[dependencies]
rspirv = "0.1"
Then add to your crate root:
rust
extern crate shaderc;
Compile a shader into SPIR-V binary module and assembly text:
```rust use shaderc;
let source = "#version 310 es\n void EP() {}";
let mut compiler = shaderc::Compiler::new().unwrap(); let mut options = shaderc::CompileOptions::new().unwrap(); options.addmacrodefinition("EP", Some("main")); let binaryresult = compiler.compileinto_spirv( source, shaderc::ShaderKind::Vertex, "shader.glsl", "main", Some(&options)).unwrap();
asserteq!(Some(&0x07230203), binaryresult.as_binary().first());
let textresult = compiler.compileintospirvassembly( source, shaderc::ShaderKind::Vertex, "shader.glsl", "main", Some(&options)).unwrap();
assert!(textresult.astext().starts_with("; SPIR-V\n")); ```
This project is licensed under the Apache 2 license. Please see CONTRIBUTING before contributing.
This project is initialized and mainly developed by Lei Zhang (@antiagainst).