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

Commit ae049ed

Browse files
committed
glsl-in: Add not vector relational builtin
1 parent 191d71c commit ae049ed

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/front/glsl/builtins.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::{
99
use crate::{
1010
BinaryOperator, Block, Constant, DerivativeAxis, Expression, Handle, ImageClass,
1111
ImageDimension as Dim, ImageQuery, MathFunction, Module, RelationalFunction, SampleLevel,
12-
ScalarKind as Sk, Span, Type, TypeInner, VectorSize,
12+
ScalarKind as Sk, Span, Type, TypeInner, UnaryOperator, VectorSize,
1313
};
1414

1515
impl crate::ScalarKind {
@@ -825,7 +825,7 @@ fn inject_standard_builtins(
825825
.push(module.add_builtin(args, MacroCall::MathFunction(fun)))
826826
}
827827
}
828-
"all" | "any" => {
828+
"all" | "any" | "not" => {
829829
// bits layout
830830
// bit 0 trough 1 - dims
831831
for bits in 0..0b11 {
@@ -841,11 +841,12 @@ fn inject_standard_builtins(
841841
width: crate::BOOL_WIDTH,
842842
}];
843843

844-
let fun = MacroCall::Relational(match name {
845-
"all" => RelationalFunction::All,
846-
"any" => RelationalFunction::Any,
844+
let fun = match name {
845+
"all" => MacroCall::Relational(RelationalFunction::All),
846+
"any" => MacroCall::Relational(RelationalFunction::Any),
847+
"not" => MacroCall::Unary(UnaryOperator::Not),
847848
_ => unreachable!(),
848-
});
849+
};
849850

850851
declaration.overloads.push(module.add_builtin(args, fun))
851852
}
@@ -1653,6 +1654,7 @@ pub enum MacroCall {
16531654
BitfieldExtract,
16541655
BitfieldInsert,
16551656
Relational(RelationalFunction),
1657+
Unary(UnaryOperator),
16561658
Binary(BinaryOperator),
16571659
Mod(Option<VectorSize>),
16581660
Splatted(MathFunction, Option<VectorSize>, usize),
@@ -2020,6 +2022,11 @@ impl MacroCall {
20202022
Span::default(),
20212023
body,
20222024
),
2025+
MacroCall::Unary(op) => ctx.add_expression(
2026+
Expression::Unary { op, expr: args[0] },
2027+
Span::default(),
2028+
body,
2029+
),
20232030
MacroCall::Binary(op) => ctx.add_expression(
20242031
Expression::Binary {
20252032
op,

tests/in/glsl/vector-functions.vert

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void btest(bvec4 a, bvec4 b) {
4141
bvec4 d = notEqual(a, b);
4242
bool e = any(a);
4343
bool f = all(a);
44+
bvec4 g = not(a);
4445
}
4546

4647
void main() {}

tests/out/wgsl/vector-functions-vert.wgsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ fn btest(a_8: vec4<bool>, b_8: vec4<bool>) {
185185
var d_4: vec4<bool>;
186186
var e_4: bool;
187187
var f_4: bool;
188+
var g_4: vec4<bool>;
188189

189190
a_9 = a_8;
190191
b_9 = b_8;
@@ -204,6 +205,9 @@ fn btest(a_8: vec4<bool>, b_8: vec4<bool>) {
204205
_ = a_9;
205206
let _e21 = a_9;
206207
f_4 = all(_e21);
208+
_ = a_9;
209+
let _e25 = a_9;
210+
g_4 = !(_e25);
207211
return;
208212
}
209213

0 commit comments

Comments
 (0)