Skip to content

Commit

Permalink
[wgsl-out] Generate correct code for bit complement on integers.
Browse files Browse the repository at this point in the history
Remove incorrect special case for `UnaryOperator::Not` on vectors.
  • Loading branch information
jimblandy authored and teoxoy committed Oct 12, 2023
1 parent 1b485ea commit 9eb3a1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,13 +1600,10 @@ impl<W: Write> Writer<W> {
let unary = match op {
crate::UnaryOperator::Negate => "-",
crate::UnaryOperator::Not => {
match *func_ctx.resolve_type(expr, &module.types) {
TypeInner::Scalar {
kind: crate::ScalarKind::Bool,
..
}
| TypeInner::Vector { .. } => "!",
_ => "~",
match func_ctx.resolve_type(expr, &module.types).scalar_kind() {
Some(crate::ScalarKind::Sint) | Some(crate::ScalarKind::Uint) => "~",
Some(crate::ScalarKind::Bool) => "!",
_ => return Err(Error::Custom("validation failure".to_string())),
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions tests/out/wgsl/operators.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ fn arithmetic() {
fn bit() {
let flip0_ = ~(1);
let flip1_ = ~(1u);
let flip2_ = !(vec2(1));
let flip3_ = !(vec3(1u));
let flip2_ = ~(vec2(1));
let flip3_ = ~(vec3(1u));
let or0_ = (2 | 1);
let or1_ = (2u | 1u);
let or2_ = (vec2(2) | vec2(1));
Expand Down

0 comments on commit 9eb3a1d

Please sign in to comment.