74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
use std::{fs::File, io::Write, path::Path, process::Command, str::from_utf8};
|
|
|
|
const VK_INCLUDE: &str = "/usr/include/vulkan";
|
|
const VK_HEADER: &[&str] = &[
|
|
"vulkan_core.h",
|
|
"vulkan_xcb.h",
|
|
"vulkan_xlib.h",
|
|
"vulkan_wayland.h",
|
|
];
|
|
const FN_PREFIX: &str = "PFN_";
|
|
|
|
const SHADER: &[&str] = &[
|
|
"src/overlay/elements/radar/single_color.vert",
|
|
"src/overlay/elements/radar/single_color.frag",
|
|
"src/overlay/elements/pedals/history.vert",
|
|
"src/overlay/elements/pedals/history.frag",
|
|
"src/overlay/elements/leaderboard/generator.frag",
|
|
"src/overlay/elements/leaderboard/generator.vert",
|
|
];
|
|
|
|
fn query_vulkan_function_typedefs() {
|
|
let mut fns = Vec::new();
|
|
|
|
for header in VK_HEADER {
|
|
Command::new("ctags")
|
|
.arg("--help")
|
|
.output()
|
|
.expect("Failed to execute ctags. Maybe you need to install it first?");
|
|
|
|
let output = Command::new("ctags")
|
|
.arg("-x")
|
|
.arg("--c-types=t")
|
|
.arg(format!("{}/{}", VK_INCLUDE, header))
|
|
.output()
|
|
.expect(&format!("failed to open file {}/{}", VK_INCLUDE, header));
|
|
|
|
let output_splits = from_utf8(&output.stdout).unwrap().split_whitespace();
|
|
|
|
for split in output_splits {
|
|
if split.starts_with(FN_PREFIX) {
|
|
fns.push(split.trim_start_matches(FN_PREFIX).to_string())
|
|
}
|
|
}
|
|
}
|
|
|
|
let path = Path::new("vk_functions");
|
|
let mut file = File::create(path).unwrap();
|
|
|
|
for func in fns {
|
|
file.write_all(format!("{}\n", func).as_bytes()).unwrap();
|
|
}
|
|
}
|
|
|
|
fn compile_shader() {
|
|
Command::new("glslangValidator")
|
|
.arg("--help")
|
|
.output()
|
|
.expect("Failed to execute glslangValidator. Maybe you need to install it first?");
|
|
|
|
for shader in SHADER {
|
|
Command::new("glslangValidator")
|
|
.arg("-V")
|
|
.arg(shader)
|
|
.arg("-o")
|
|
.arg(&format!("{}.spv", shader))
|
|
.output()
|
|
.expect(&format!("Failed to compile {}", shader));
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
query_vulkan_function_typedefs();
|
|
compile_shader();
|
|
}
|