#![allow(clippy::unwrap_used)]
use dxil_reader::module::Module;
use dxil_reader::reflection;
fn module(name: &str) -> Module {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures")
.join(name);
let bytes = std::fs::read(path).unwrap();
let chunks = dxil_reader::parts(&bytes).unwrap();
dxil_reader::module(&chunks, b"DXIL").unwrap().unwrap()
}
#[test]
fn the_shader_flags_are_the_entry_properties_tag_0() {
assert_eq!(
reflection::shader_flags(&module("precise.cs.dxil")).unwrap(),
Some(16)
);
assert_eq!(
reflection::shader_flags(&module("precise.vs.dxil")).unwrap(),
None
);
assert_eq!(reflection::shader_flags(&module("usage.ps.dxil")).unwrap(), None);
}
#[test]
fn a_signature_element_states_the_components_the_program_uses() {
let m = module("usage.ps.dxil");
let [inputs, outputs, patch] = reflection::usage_masks(&m).unwrap();
assert_eq!(inputs, [Some(0b0011), Some(0b0001), Some(0b1000)]);
assert_eq!(outputs, [Some(0b1111)]);
assert!(patch.is_empty());
let (elements, _) = reflection::elements(&m).unwrap();
assert_eq!(elements.len(), inputs.len());
let [inputs, ..] = reflection::usage_masks(&module("usage2.ps.dxil")).unwrap();
assert_eq!(inputs, [Some(0b010), Some(0b001), Some(0b010)]);
let [inputs, outputs, patch] = reflection::usage_masks(&module("precise.cs.dxil")).unwrap();
assert!(inputs.is_empty() && outputs.is_empty() && patch.is_empty());
}