Initial commit
This commit is contained in:
@@ -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