Systemcluster / hassle-rs

πŸ¦€ This crate provides an FFI layer and idiomatic rust wrappers for the new DirectXShaderCompiler library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🌀 hassle-rs

Actions Status Latest version Documentation Lines of code MIT Contributor Covenant

Banner

This crate provides an FFI layer and idiomatic rust wrappers for the new DirectXShaderCompiler library.

Usage

Add this to your Cargo.toml:

[dependencies]
hassle-rs = "0.9.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/

Compile HLSL into SPIR-V:

let spirv = compile_hlsl(
    "shader_filename.hlsl",
    code,
    "copyCs",
    "cs_6_5",
    &vec!["-spirv"],
    &vec![
        ("MY_DEFINE", Some("Value")),
        ("OTHER_DEFINE", None)
    ],
);

Compile HLSL into DXIL and validate it:

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);
}

macOS support

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 support

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.

License

Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)

Contributions

  • Graham Wihlidal
  • Tiago Carvalho
  • Marijn Suijten
  • Tomasz Stachowiak

Contribution

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.

About

πŸ¦€ This crate provides an FFI layer and idiomatic rust wrappers for the new DirectXShaderCompiler library.

License:MIT License


Languages

Language:Rust 100.0%