This crate provides an FFI layer and idiomatic rust wrappers for the new DirectXShaderCompiler library.
Add this to your Cargo.toml
:
[dependencies]
hassle-rs = "0.4.0"
Then acquire dxcompiler.dll
on Windows or libdxcompiler.so
on Linux directly from AppVeyor, or compile it from source according to the instructions in the DirectXShaderCompiler GitHub repository and make sure it's in the executable environment.
DxcValidator also requires dxil.dll
which can be grabbed from any recent Windows 10 SDK flight.
More info: https://www.wihlidal.com/blog/pipeline/2018-09-16-dxil-signing-post-compile/
let spirv = compile_hlsl(
"shader_filename.hlsl",
code,
"copyCs",
"cs_6_5",
&vec!["-spirv"],
&vec![
("MY_DEFINE", Some("Value")),
("OTHER_DEFINE", None)
],
);
let dxil = compile_hlsl("test.cs.hlsl", test_cs, "main", "cs_6_5", args, &[]).unwrap();
let result = validate_dxil(&dxil); // Only a Windows machine in Developer Mode can run non-validated DXIL
if let Some(err) = result.err() {
println!("validation failed: {}", err);
}
Currently macOS support is quite early, however, one can build a libdxcompiler.dynlib from source by building this commit: https://github.com/microsoft/DirectXShaderCompiler/pull/3062/commits/9527fe6346391ac9a31799d730c7744b482e2386 and following these steps: https://github.com/microsoft/DirectXShaderCompiler/blob/master/docs/DxcOnUnix.rst#building-dxc
Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)
- Graham Wihlidal
- Tiago Carvalho
- Marijn Suijten
- Tomasz Stachowiak
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be licensed as above, without any additional terms or conditions.
Contributions are always welcome; please look at the issue tracker to see what known improvements are documented.