-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
NOTE 2025-11-24: WGSL was fixed by #7339, so this issue now only applies to GLSL.
NOTE 2024-04-16: description edited, so much of the following discussion may look irrelevant
The WGSL specification says that a && b only evaluates b if a is true, but Naga generally will always evaluate both.
The following input:
fn h() -> bool {
return f() || g();
}produces the following output WGSL:
fn h() -> bool {
let _e0 = f();
let _e1 = g();
return (_e0 || _e1);
}The call to g is hoisted out to a statement and made unconditional, which is incorrect.
This means that even though most backends turn Naga IR's BinaryOperator::LogicalAnd and BinaryOperator::LogicalOr into short-circuiting operations in the target language, it doesn't help because the front end has already hoisted the right-hand side, which ought to be conditional, out into its own unconditional statement.