-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
57 lines (52 loc) · 1.9 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::process::Command;
use anyhow::bail;
use glob::glob;
pub fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=shaders");
for entry in glob("./shaders/*").expect("Failed to read glob pattern") {
let entry = entry?;
if let Some(ext) = entry.extension() {
let output = match ext.to_str() {
Some("cu") => Command::new("nvcc")
.args([
"-O3",
"--ptx",
"-lineinfo",
"-o",
&format!("{}.ptx", entry.to_string_lossy()),
entry.to_str().unwrap(),
])
.output()?,
Some("hlsl") => Command::new("dxc")
.args([
"-T",
"cs_6_5",
"-spirv",
"-fspv-target-env=vulkan1.3",
"-Zi",
"-Fo",
&format!("{}.spirv", entry.to_string_lossy()),
entry.to_str().unwrap(),
])
.output()?,
Some("spirv") | Some("ptx") | Some("cubin") => continue,
_ => Command::new("glslc")
.args([
entry.to_str().unwrap(),
"--target-env=vulkan1.3",
"-g",
"-o",
&format!("{}.spirv", entry.to_string_lossy()),
"-O",
])
.output()?,
};
eprintln!("{}", String::from_utf8(output.stdout)?);
eprintln!("{}", String::from_utf8(output.stderr)?);
if !output.status.success() {
bail!("Failed to run shader compiler");
}
}
}
Ok(())
}