Initial commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "enkou-shaders-tests"
|
||||
publish = false
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
rspirv.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
anyhow.workspace = true
|
||||
cargo-gpu-install.workspace = true
|
||||
@@ -0,0 +1,24 @@
|
||||
use cargo_gpu_install::install::Install;
|
||||
use cargo_gpu_install::spirv_builder::{ShaderPanicStrategy, SpirvMetadata};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn main() -> anyhow::Result<()> {
|
||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
||||
let crate_path = [manifest_dir, "..", "enkou-shaders"]
|
||||
.iter()
|
||||
.copied()
|
||||
.collect::<PathBuf>();
|
||||
|
||||
let install = Install::from_shader_crate(crate_path.clone())
|
||||
.within_build_script()
|
||||
.run()?;
|
||||
let mut builder = install.to_spirv_builder(crate_path, "spirv-unknown-vulkan1.3");
|
||||
builder.build_script.defaults = true;
|
||||
builder.shader_panic_strategy = ShaderPanicStrategy::SilentExit;
|
||||
builder.spirv_metadata = SpirvMetadata::Full;
|
||||
|
||||
let compile_result = builder.build()?;
|
||||
let spv_path = compile_result.module.unwrap_single();
|
||||
println!("cargo::rustc-env=SHADER_SPV_PATH={}", spv_path.display());
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use rspirv::binary::parse_bytes;
|
||||
use rspirv::dr::{Module, Operand};
|
||||
use rspirv::spirv::ExecutionModel;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
static SHADER_MODULE: OnceLock<Module> = OnceLock::new();
|
||||
|
||||
fn shader() -> &'static Module {
|
||||
SHADER_MODULE.get_or_init(|| {
|
||||
let shader_bytes = include_bytes!(env!("SHADER_SPV_PATH"));
|
||||
|
||||
let mut loader = rspirv::dr::Loader::new();
|
||||
parse_bytes(shader_bytes, &mut loader).expect("Unable to parse shader");
|
||||
|
||||
loader.module()
|
||||
})
|
||||
}
|
||||
|
||||
fn has_entry_point(execution_model: ExecutionModel, name: &str) -> bool {
|
||||
for ref entry_point in shader().entry_points.iter() {
|
||||
let operands: Vec<Operand> = entry_point
|
||||
.operands
|
||||
.iter()
|
||||
.filter(|op| match op {
|
||||
Operand::ExecutionModel(_) | Operand::LiteralString(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
.map(|op| op.clone())
|
||||
.collect();
|
||||
|
||||
assert_eq!(operands.len(), 2);
|
||||
match &operands[0] {
|
||||
Operand::ExecutionModel(actual) => {
|
||||
if execution_model != *actual {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
op => panic!("Unexpected operand; {}", op),
|
||||
}
|
||||
|
||||
match &operands[1] {
|
||||
Operand::LiteralString(actual) => {
|
||||
if name != actual {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
op => panic!("Unexpected operand; {}", op),
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn has_entry_main_fs() {
|
||||
assert!(has_entry_point(ExecutionModel::Fragment, "main_fs"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn has_entry_main_vs() {
|
||||
assert!(has_entry_point(ExecutionModel::Vertex, "main_vs"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user