mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
add TODOs for handling undefined behavior
This commit is contained in:
@@ -2580,6 +2580,18 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
// TODO: handle undefined behavior of BinaryOperator::Modulo
|
||||
//
|
||||
// sint:
|
||||
// if right == 0 return 0
|
||||
// if left == min(type_of(left)) && right == -1 return 0
|
||||
// if sign(left) == -1 || sign(right) == -1 return result as defined by WGSL
|
||||
//
|
||||
// uint:
|
||||
// if right == 0 return 0
|
||||
//
|
||||
// float:
|
||||
// if right == 0 return ? see https://github.com/gpuweb/gpuweb/issues/2798
|
||||
BinaryOperation::Modulo => {
|
||||
write!(self.out, "(")?;
|
||||
|
||||
|
||||
@@ -1795,6 +1795,20 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
self.write_expr(module, left, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
|
||||
// TODO: handle undefined behavior of BinaryOperator::Modulo
|
||||
//
|
||||
// sint:
|
||||
// if right == 0 return 0
|
||||
// if left == min(type_of(left)) && right == -1 return 0
|
||||
// if sign(left) != sign(right) return result as defined by WGSL
|
||||
//
|
||||
// uint:
|
||||
// if right == 0 return 0
|
||||
//
|
||||
// float:
|
||||
// if right == 0 return ? see https://github.com/gpuweb/gpuweb/issues/2798
|
||||
|
||||
// While HLSL supports float operands with the % operator it is only
|
||||
// defined in cases where both sides are either positive or negative.
|
||||
Expression::Binary {
|
||||
|
||||
@@ -1482,6 +1482,20 @@ impl<W: Write> Writer<W> {
|
||||
.resolve_type(left)
|
||||
.scalar_kind()
|
||||
.ok_or(Error::UnsupportedBinaryOp(op))?;
|
||||
|
||||
// TODO: handle undefined behavior of BinaryOperator::Modulo
|
||||
//
|
||||
// sint:
|
||||
// if right == 0 return 0
|
||||
// if left == min(type_of(left)) && right == -1 return 0
|
||||
// if sign(left) == -1 || sign(right) == -1 return result as defined by WGSL
|
||||
//
|
||||
// uint:
|
||||
// if right == 0 return 0
|
||||
//
|
||||
// float:
|
||||
// if right == 0 return ? see https://github.com/gpuweb/gpuweb/issues/2798
|
||||
|
||||
if op == crate::BinaryOperator::Modulo && kind == crate::ScalarKind::Float {
|
||||
write!(self.out, "{}::fmod(", NAMESPACE)?;
|
||||
self.put_expression(left, context, true)?;
|
||||
|
||||
@@ -529,8 +529,15 @@ impl<'w> BlockContext<'w> {
|
||||
_ => unimplemented!(),
|
||||
},
|
||||
crate::BinaryOperator::Modulo => match left_ty_inner.scalar_kind() {
|
||||
// TODO: handle undefined behavior
|
||||
// if right == 0 return 0
|
||||
// if left == min(type_of(left)) && right == -1 return 0
|
||||
Some(crate::ScalarKind::Sint) => spirv::Op::SRem,
|
||||
// TODO: handle undefined behavior
|
||||
// if right == 0 return 0
|
||||
Some(crate::ScalarKind::Uint) => spirv::Op::UMod,
|
||||
// TODO: handle undefined behavior
|
||||
// if right == 0 return ? see https://github.com/gpuweb/gpuweb/issues/2798
|
||||
Some(crate::ScalarKind::Float) => spirv::Op::FRem,
|
||||
_ => unimplemented!(),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user