Crates.io | inline-spirv |
lib.rs | inline-spirv |
version | 0.2.1 |
source | src |
created_at | 2020-08-18 12:46:25.334483 |
updated_at | 2024-03-27 15:56:09.80345 |
description | Compile GLSL/HLSL/WGSL and inline SPIR-V right inside your crate. |
homepage | https://github.com/PENGUINLIONG/inline-spirv-rs |
repository | https://github.com/PENGUINLIONG/inline-spirv-rs |
max_upload_size | |
id | 277845 |
size | 56,776 |
inline-spirv
ease the way you write shaders. Although as game developers, we usually compile a permutation of shader stages for different objects and materials at runtime for the best flexibility; sometimes we do want to try out some new ideas and start up dirty. This crate helps you compile GLSL/HLSL shader in your Rust code, or in external files, into SPIR-V; and embed them right inside the binary, so you are freed from all the compilation hassle.
To inline shader source:
use inline_spirv::include_spirv;
let spv: &'static [u32] = inline_spirv!(r#"
#version 450 core
void main() { gl_Position = vec4(0, 0, 0, 1); }
"#, vert);
To include a external shader source file:
use inline_spirv::include_spirv;
let spv: &'static [u32] = include_spirv!("assets/vert.hlsl", vert, hlsl, entry="Main");
To include a precompiled SPIR-V binary:
use inline_spirv::include_spirv;
let spv: &'static [u32] = include_spirv!("assets/vert.spv");
For the full list of options please refer to the documentation.
The macro can be verbose especially you have a bunch of #include
s, so please be aware of that you can alias and define a more customized macro for yourself:
use inline_spirv::include_spirv as include_spirv_raw;
macro_rules! include_spirv {
($path:expr, $stage:ident) => {
include_spirv_raw!(
$path,
$stage, hlsl,
entry="my_entry_pt",
D VERBOSE_DEFINITION,
D ANOTHER_VERBOSE_DEFINITION="verbose definition substitution",
I "long/path/to/include/directory",
)
}
}
// ...
let vert: &[u32] = include_spirv!("examples/demo/assets/demo.hlsl", vert);
This project is licensed under either of
at your option.