Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 9eb3a1d

Browse files
jimblandyteoxoy
authored andcommitted
[wgsl-out] Generate correct code for bit complement on integers.
Remove incorrect special case for `UnaryOperator::Not` on vectors.
1 parent 1b485ea commit 9eb3a1d

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/back/wgsl/writer.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1600,13 +1600,10 @@ impl<W: Write> Writer<W> {
16001600
let unary = match op {
16011601
crate::UnaryOperator::Negate => "-",
16021602
crate::UnaryOperator::Not => {
1603-
match *func_ctx.resolve_type(expr, &module.types) {
1604-
TypeInner::Scalar {
1605-
kind: crate::ScalarKind::Bool,
1606-
..
1607-
}
1608-
| TypeInner::Vector { .. } => "!",
1609-
_ => "~",
1603+
match func_ctx.resolve_type(expr, &module.types).scalar_kind() {
1604+
Some(crate::ScalarKind::Sint) | Some(crate::ScalarKind::Uint) => "~",
1605+
Some(crate::ScalarKind::Bool) => "!",
1606+
_ => return Err(Error::Custom("validation failure".to_string())),
16101607
}
16111608
}
16121609
};

tests/out/wgsl/operators.wgsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ fn arithmetic() {
128128
fn bit() {
129129
let flip0_ = ~(1);
130130
let flip1_ = ~(1u);
131-
let flip2_ = !(vec2(1));
132-
let flip3_ = !(vec3(1u));
131+
let flip2_ = ~(vec2(1));
132+
let flip3_ = ~(vec3(1u));
133133
let or0_ = (2 | 1);
134134
let or1_ = (2u | 1u);
135135
let or2_ = (vec2(2) | vec2(1));

0 commit comments

Comments
 (0)