From 6c2115ee91cf3dd2239c9844d5a27c8eea4665e8 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Wed, 2 Mar 2022 14:15:52 +0000 Subject: [PATCH] GLSL: fix boolean "not" operator on vectors. GLSL uses not() for vectors, and ! for scalars. Bug: tint:1444 Change-Id: I7fa9bdf0b546224737f9cda18428dea7051fe9e5 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82362 Kokoro: Kokoro Reviewed-by: Ben Clayton Commit-Queue: Stephen White --- src/tint/writer/glsl/generator_impl.cc | 6 +++++- ...FUnordTest_FUnordEqual_Vector.spvasm.expected.glsl | 11 +---------- ...FUnordGreaterThanEqual_Vector.spvasm.expected.glsl | 11 +---------- ...Test_FUnordGreaterThan_Vector.spvasm.expected.glsl | 11 +---------- ...st_FUnordLessThanEqual_Vector.spvasm.expected.glsl | 11 +---------- ...ordTest_FUnordLessThan_Vector.spvasm.expected.glsl | 11 +---------- ...ordTest_FUnordNotEqual_Vector.spvasm.expected.glsl | 11 +---------- ...LogicalTest_LogicalNot_Vector.spvasm.expected.glsl | 11 +---------- 8 files changed, 12 insertions(+), 71 deletions(-) diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 6bab9283c4..f0ffc53fce 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -2717,7 +2717,11 @@ bool GeneratorImpl::EmitUnaryOp(std::ostream& out, out << "~"; break; case ast::UnaryOp::kNot: - out << "!"; + if (TypeOf(expr)->UnwrapRef()->is_scalar()) { + out << "!"; + } else { + out << "not"; + } break; case ast::UnaryOp::kNegation: out << "-"; diff --git a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordEqual_Vector.spvasm.expected.glsl b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordEqual_Vector.spvasm.expected.glsl index 795babea3b..88263dff61 100644 --- a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordEqual_Vector.spvasm.expected.glsl +++ b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordEqual_Vector.spvasm.expected.glsl @@ -1,10 +1,8 @@ -SKIP: FAILED - #version 310 es precision mediump float; void main_1() { - bvec2 x_1 = !(notEqual(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); + bvec2 x_1 = not(notEqual(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); return; } @@ -16,10 +14,3 @@ void main() { tint_symbol(); return; } -Error parsing GLSL shader: -ERROR: 0:5: '!' : wrong operand type no operation '!' exists that takes an operand of type const 2-component vector of bool (or there is no acceptable conversion) -ERROR: 0:5: '' : compilation terminated -ERROR: 2 compilation errors. No code generated. - - - diff --git a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordGreaterThanEqual_Vector.spvasm.expected.glsl b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordGreaterThanEqual_Vector.spvasm.expected.glsl index c56133f048..52aee68b95 100644 --- a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordGreaterThanEqual_Vector.spvasm.expected.glsl +++ b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordGreaterThanEqual_Vector.spvasm.expected.glsl @@ -1,10 +1,8 @@ -SKIP: FAILED - #version 310 es precision mediump float; void main_1() { - bvec2 x_1 = !(lessThan(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); + bvec2 x_1 = not(lessThan(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); return; } @@ -16,10 +14,3 @@ void main() { tint_symbol(); return; } -Error parsing GLSL shader: -ERROR: 0:5: '!' : wrong operand type no operation '!' exists that takes an operand of type const 2-component vector of bool (or there is no acceptable conversion) -ERROR: 0:5: '' : compilation terminated -ERROR: 2 compilation errors. No code generated. - - - diff --git a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordGreaterThan_Vector.spvasm.expected.glsl b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordGreaterThan_Vector.spvasm.expected.glsl index f78d5be4ed..f9b125cded 100644 --- a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordGreaterThan_Vector.spvasm.expected.glsl +++ b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordGreaterThan_Vector.spvasm.expected.glsl @@ -1,10 +1,8 @@ -SKIP: FAILED - #version 310 es precision mediump float; void main_1() { - bvec2 x_1 = !(lessThanEqual(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); + bvec2 x_1 = not(lessThanEqual(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); return; } @@ -16,10 +14,3 @@ void main() { tint_symbol(); return; } -Error parsing GLSL shader: -ERROR: 0:5: '!' : wrong operand type no operation '!' exists that takes an operand of type const 2-component vector of bool (or there is no acceptable conversion) -ERROR: 0:5: '' : compilation terminated -ERROR: 2 compilation errors. No code generated. - - - diff --git a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordLessThanEqual_Vector.spvasm.expected.glsl b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordLessThanEqual_Vector.spvasm.expected.glsl index cf5d8324cf..12919de40b 100644 --- a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordLessThanEqual_Vector.spvasm.expected.glsl +++ b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordLessThanEqual_Vector.spvasm.expected.glsl @@ -1,10 +1,8 @@ -SKIP: FAILED - #version 310 es precision mediump float; void main_1() { - bvec2 x_1 = !(greaterThan(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); + bvec2 x_1 = not(greaterThan(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); return; } @@ -16,10 +14,3 @@ void main() { tint_symbol(); return; } -Error parsing GLSL shader: -ERROR: 0:5: '!' : wrong operand type no operation '!' exists that takes an operand of type const 2-component vector of bool (or there is no acceptable conversion) -ERROR: 0:5: '' : compilation terminated -ERROR: 2 compilation errors. No code generated. - - - diff --git a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordLessThan_Vector.spvasm.expected.glsl b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordLessThan_Vector.spvasm.expected.glsl index 8674bdd982..065f4b73a8 100644 --- a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordLessThan_Vector.spvasm.expected.glsl +++ b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordLessThan_Vector.spvasm.expected.glsl @@ -1,10 +1,8 @@ -SKIP: FAILED - #version 310 es precision mediump float; void main_1() { - bvec2 x_1 = !(greaterThanEqual(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); + bvec2 x_1 = not(greaterThanEqual(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); return; } @@ -16,10 +14,3 @@ void main() { tint_symbol(); return; } -Error parsing GLSL shader: -ERROR: 0:5: '!' : wrong operand type no operation '!' exists that takes an operand of type const 2-component vector of bool (or there is no acceptable conversion) -ERROR: 0:5: '' : compilation terminated -ERROR: 2 compilation errors. No code generated. - - - diff --git a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordNotEqual_Vector.spvasm.expected.glsl b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordNotEqual_Vector.spvasm.expected.glsl index b4351707ae..fdf860bfea 100644 --- a/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordNotEqual_Vector.spvasm.expected.glsl +++ b/test/tint/unittest/reader/spirv/SpvFUnordTest_FUnordNotEqual_Vector.spvasm.expected.glsl @@ -1,10 +1,8 @@ -SKIP: FAILED - #version 310 es precision mediump float; void main_1() { - bvec2 x_1 = !(equal(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); + bvec2 x_1 = not(equal(vec2(50.0f, 60.0f), vec2(60.0f, 50.0f))); return; } @@ -16,10 +14,3 @@ void main() { tint_symbol(); return; } -Error parsing GLSL shader: -ERROR: 0:5: '!' : wrong operand type no operation '!' exists that takes an operand of type const 2-component vector of bool (or there is no acceptable conversion) -ERROR: 0:5: '' : compilation terminated -ERROR: 2 compilation errors. No code generated. - - - diff --git a/test/tint/unittest/reader/spirv/SpvUnaryLogicalTest_LogicalNot_Vector.spvasm.expected.glsl b/test/tint/unittest/reader/spirv/SpvUnaryLogicalTest_LogicalNot_Vector.spvasm.expected.glsl index 01e2b29a44..158f14c001 100644 --- a/test/tint/unittest/reader/spirv/SpvUnaryLogicalTest_LogicalNot_Vector.spvasm.expected.glsl +++ b/test/tint/unittest/reader/spirv/SpvUnaryLogicalTest_LogicalNot_Vector.spvasm.expected.glsl @@ -1,10 +1,8 @@ -SKIP: FAILED - #version 310 es precision mediump float; void main_1() { - bvec2 x_1 = !(bvec2(true, false)); + bvec2 x_1 = not(bvec2(true, false)); return; } @@ -16,10 +14,3 @@ void main() { tint_symbol(); return; } -Error parsing GLSL shader: -ERROR: 0:5: '!' : wrong operand type no operation '!' exists that takes an operand of type const 2-component vector of bool (or there is no acceptable conversion) -ERROR: 0:5: '' : compilation terminated -ERROR: 2 compilation errors. No code generated. - - -