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.7.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);
}
One can build libdxcompiler.dynlib
from source with this commit for clang
or the entire PR for GCC
, by following the DXC Unix build guide. These patches have been merged to DXC and are available since release-1.6.2012
.
Linux shares the same requirements as macOS support when compiling from source but DXC provides prebuilt libraries for every commit on AppVeyor. These are linked from individual commits on GitHub too.
Furthermore semantics around BSTR
(only used in intellisense
) have changed since hassle-rs 0.5.1 and require libdxcompiler.so
compiled from at least this commit, also included in release-1.6.2012
. Intellisense
on hassle-rs 0.5.0
and below is not compatible with these newer libraries.
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.