Files
enkou/enkou-shaders-tests/src/lib.rs
T
bspeice 54ba76b380
CI / cargo fmt (push) Successful in 22s
CI / cargo test (push) Successful in 12m34s
CI / cargo test (GPU) (push) Successful in 12m51s
Implement camera colors
Still needs some unit tests, and to fix the gasket example
2026-07-03 14:07:45 -04:00

74 lines
2.0 KiB
Rust

#[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_chaos_game() {
assert!(has_entry_point(
ExecutionModel::GLCompute,
"main_chaos_game"
))
}
#[test]
pub fn has_entry_main_image_render() {
assert!(has_entry_point(
ExecutionModel::GLCompute,
"main_image_render"
))
}
}