Add quad -> MSL testing

This commit is contained in:
Dzmitry Malyshau 2020-03-15 12:00:50 -04:00 committed by Dzmitry Malyshau
parent 4a72abb142
commit c467693253
2 changed files with 22 additions and 5 deletions

View File

@ -321,7 +321,7 @@ impl<W: Write> Writer<W> {
module: &'a crate::Module,
) -> Result<MaybeOwned<'a, crate::TypeInner>, Error> {
let expression = &expressions[expr_handle];
log::trace!("expression {:?}", expression);
log::trace!("expression {:?} = {:?}", expr_handle, expression);
match *expression {
crate::Expression::AccessIndex { base, index } => {
match *self.put_expression(base, expressions, module)?.borrow() {
@ -434,6 +434,7 @@ impl<W: Write> Writer<W> {
let ty_right = self.put_expression(right, expressions, module)?;
write!(self.out, ")")?;
Ok(match (ty_left.borrow(), ty_right.borrow()) {
(&crate::TypeInner::Scalar { .. }, &crate::TypeInner::Vector { size, kind, width }) |
(&crate::TypeInner::Vector { size, kind, width }, &crate::TypeInner::Scalar { .. }) =>
MaybeOwned::Owned(crate::TypeInner::Vector { size, kind, width }),
other => panic!("Unable to infer Mul for {:?}", other),

View File

@ -1,15 +1,31 @@
fn convert_wgsl(name: &str) {
fn load_wgsl(name: &str) -> naga::Module {
let path = format!("{}/test-data/{}.wgsl", env!("CARGO_MANIFEST_DIR"), name);
let input = std::fs::read_to_string(path).unwrap();
let _module = naga::front::wgsl::parse_str(&input).unwrap();
naga::front::wgsl::parse_str(&input).unwrap()
}
#[test]
fn convert_quad() {
convert_wgsl("quad");
let module = load_wgsl("quad");
{
use naga::back::msl;
let mut binding_map = msl::BindingMap::default();
binding_map.insert(
msl::BindSource { set: 0, binding: 0 },
msl::BindTarget { buffer: None, texture: Some(1), sampler: None },
);
binding_map.insert(
msl::BindSource { set: 0, binding: 1 },
msl::BindTarget { buffer: None, texture: None, sampler: Some(1) },
);
let options = msl::Options {
binding_map: &binding_map,
};
msl::write_string(&module, options).unwrap();
}
}
#[test]
fn convert_boids() {
convert_wgsl("boids");
let _module = load_wgsl("boids");
}