build: make vulkan generation generic
This commit is contained in:
parent
472ebd5d7d
commit
fce250d233
5 changed files with 60 additions and 34 deletions
|
|
@ -1,32 +1,27 @@
|
|||
use {
|
||||
anyhow::{Context, anyhow, bail},
|
||||
compile_shaders_core::{BIN, ROOT, update_hash},
|
||||
compile_shaders_core::{TREES, Tree, update_hash},
|
||||
shaderc::{CompileOptions, ResolvedInclude},
|
||||
std::{fs::File, io::Write, path::Path},
|
||||
};
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
compile("fill.frag")?;
|
||||
compile("fill.vert")?;
|
||||
compile("tex.vert")?;
|
||||
compile("tex.frag")?;
|
||||
compile("out.vert")?;
|
||||
compile("out.frag")?;
|
||||
compile("legacy/fill.frag")?;
|
||||
compile("legacy/fill.vert")?;
|
||||
compile("legacy/tex.vert")?;
|
||||
compile("legacy/tex.frag")?;
|
||||
update_hash()?;
|
||||
for tree in TREES {
|
||||
for shader in tree.shaders {
|
||||
compile(tree, shader)?;
|
||||
}
|
||||
update_hash(tree)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile(name: &str) -> anyhow::Result<()> {
|
||||
fn compile(tree: &Tree, name: &str) -> anyhow::Result<()> {
|
||||
let out = format!("{name}.spv").replace("/", "_");
|
||||
compile_shader(name, &out).with_context(|| name.to_string())
|
||||
compile_shader(tree, name, &out).with_context(|| name.to_string())
|
||||
}
|
||||
|
||||
fn compile_shader(name: &str, out: &str) -> anyhow::Result<()> {
|
||||
let root = Path::new(ROOT).join(Path::new(name).parent().unwrap());
|
||||
fn compile_shader(tree: &Tree, name: &str, out: &str) -> anyhow::Result<()> {
|
||||
let root = Path::new(tree.root).join(Path::new(name).parent().unwrap());
|
||||
let read = |path: &str| std::fs::read_to_string(root.join(path));
|
||||
let mut options = CompileOptions::new()?;
|
||||
options.set_include_callback(|name, _, _, _| {
|
||||
|
|
@ -44,10 +39,10 @@ fn compile_shader(name: &str, out: &str) -> anyhow::Result<()> {
|
|||
"vert" => shaderc::ShaderKind::Vertex,
|
||||
n => bail!("Unknown shader stage {}", n),
|
||||
};
|
||||
let src = std::fs::read_to_string(format!("{}/{}", ROOT, name))?;
|
||||
let src = std::fs::read_to_string(format!("{}/{}", tree.root, name))?;
|
||||
let compiler = shaderc::Compiler::new()?;
|
||||
let binary = compiler.compile_into_spirv(&src, stage, name, "main", Some(&options))?;
|
||||
let mut file = File::create(Path::new(BIN).join(out))?;
|
||||
let mut file = File::create(Path::new(tree.bin).join(out))?;
|
||||
file.write_all(binary.as_binary_u8())?;
|
||||
file.flush()?;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
include!("../../../build/vulkan/hash.rs");
|
||||
|
||||
pub const BIN: &str = "src/gfx_apis/vulkan/shaders_bin";
|
||||
|
||||
pub fn update_hash() -> anyhow::Result<()> {
|
||||
std::fs::write(HASH, calculate_hash()?)?;
|
||||
pub fn update_hash(tree: &Tree) -> anyhow::Result<()> {
|
||||
std::fs::write(tree.hash, calculate_hash(tree)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
use compile_shaders_core::update_hash;
|
||||
use compile_shaders_core::{update_hash, TREES};
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
update_hash()
|
||||
for tree in TREES {
|
||||
update_hash(tree)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue