2023-10-01 11:10:49 +11:00
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2023-10-04 10:11:39 +11:00
|
|
|
#[cfg(feature = "vulkan-renderer")]
|
2023-10-01 11:10:49 +11:00
|
|
|
{
|
2023-10-07 10:10:24 +11:00
|
|
|
let host_triple = std::env::var("HOST").unwrap();
|
|
|
|
let target_triple = std::env::var("TARGET").unwrap();
|
|
|
|
|
|
|
|
if host_triple != target_triple {
|
|
|
|
// cross compile
|
|
|
|
if !host_triple.contains("windows") && target_triple.contains("x86_64-pc-windows") {
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-link-search={}",
|
|
|
|
std::env::var("VULKAN_SDK_WIN")
|
|
|
|
.expect("Could not find windows vulkan sdk path")
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-link-search={}",
|
|
|
|
std::env::var("SHADERC_WIN").expect("Could not find windows shaderc path")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-03 12:51:27 +11:00
|
|
|
const SHADER_SRC_DIR: &str = "src/renderer/vulkan/shaders";
|
|
|
|
const SHADER_OUT_DIR: &str = "shaders";
|
|
|
|
|
2023-10-01 11:10:49 +11:00
|
|
|
println!("cargo:rerun-if-changed={}", SHADER_SRC_DIR);
|
|
|
|
std::fs::create_dir_all(SHADER_OUT_DIR)?;
|
|
|
|
|
|
|
|
for shader in std::fs::read_dir(SHADER_SRC_DIR)?.filter_map(|v| v.ok()) {
|
|
|
|
if shader.file_type()?.is_file() {
|
|
|
|
let in_path = shader.path();
|
|
|
|
if in_path
|
|
|
|
.extension()
|
|
|
|
.is_some_and(|e| e.to_string_lossy() == "wgsl")
|
|
|
|
{
|
|
|
|
let out_path = format!(
|
|
|
|
"{}/{}.spv",
|
|
|
|
SHADER_OUT_DIR,
|
|
|
|
in_path.file_stem().unwrap().to_string_lossy()
|
|
|
|
);
|
|
|
|
let module = naga::front::wgsl::parse_str(&std::fs::read_to_string(in_path)?)?;
|
|
|
|
|
|
|
|
let info = naga::valid::Validator::new(Default::default(), Default::default())
|
|
|
|
.validate(&module)?;
|
|
|
|
|
|
|
|
let spv =
|
|
|
|
naga::back::spv::write_vec(&module, &info, &Default::default(), None)?;
|
|
|
|
|
|
|
|
let compiled =
|
|
|
|
spv.iter()
|
|
|
|
.fold(Vec::with_capacity(spv.len() * 4), |mut v, w| {
|
|
|
|
v.extend_from_slice(&w.to_le_bytes());
|
|
|
|
v
|
|
|
|
});
|
|
|
|
|
|
|
|
std::fs::write(out_path, compiled.as_slice())?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|