hlsl-out: relational expressions

This commit is contained in:
Dzmitry Malyshau
2021-08-15 15:05:01 -04:00
committed by Dzmitry Malyshau
parent 5415d8c7c4
commit 0d829d6bb0

View File

@@ -1735,18 +1735,30 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
Expression::Derivative { axis, expr } => {
use crate::DerivativeAxis as Da;
write!(
self.out,
"{}(",
match axis {
Da::X => "ddx",
Da::Y => "ddy",
Da::Width => "fwidth",
}
)?;
let fun_str = match axis {
Da::X => "ddx",
Da::Y => "ddy",
Da::Width => "fwidth",
};
write!(self.out, "{}(", fun_str)?;
self.write_expr(module, expr, func_ctx)?;
write!(self.out, ")")?
}
Expression::Relational { fun, argument } => {
use crate::RelationalFunction as Rf;
let fun_str = match fun {
Rf::All => "all",
Rf::Any => "any",
Rf::IsNan => "isnan",
Rf::IsInf => "isinf",
Rf::IsFinite => "isfinite",
Rf::IsNormal => "isnormal",
};
write!(self.out, "{}(", fun_str)?;
self.write_expr(module, argument, func_ctx)?;
write!(self.out, ")")?
}
Expression::Splat { size, value } => {
// hlsl is not supported one value constructor
// if we write, for example, int4(0), dxc returns error:
@@ -1777,7 +1789,6 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
}
// Nothing to do here, since call expression already cached
Expression::CallResult(_) | Expression::AtomicResult { .. } => {}
_ => return Err(Error::Unimplemented(format!("write_expr {:?}", expression))),
}
if !closing_bracket.is_empty() {