From 4414f0245005c8cfcd02b51ea394d612cc5776c4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 7 Mar 2021 11:36:17 +0200 Subject: [PATCH] Additional rules for bit shift operators --- source/glsl/generate.cpp | 10 ++++++++-- tests/glsl/binary_operators.glsl | 11 +++++++++-- tests/glsl/invalid_expressions.glsl | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index f29d65f5..1e57ed64 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -657,11 +657,17 @@ void ExpressionResolver::visit(BinaryExpression &binary, bool assign) } else if((oper=='<' || oper=='>') && oper2==oper) { - // Shifts only apply to integers. - if(basic_left->kind!=BasicTypeDeclaration::INT || basic_right->kind!=BasicTypeDeclaration::INT) + // Shifts apply to integer scalars and vectors, with some restrictions. + if(elem_left->kind!=BasicTypeDeclaration::INT || elem_right->kind!=BasicTypeDeclaration::INT) + return; + unsigned left_size = (basic_left->kind==BasicTypeDeclaration::INT ? 1 : basic_left->kind==BasicTypeDeclaration::VECTOR ? basic_left->size : 0); + unsigned right_size = (basic_right->kind==BasicTypeDeclaration::INT ? 1 : basic_right->kind==BasicTypeDeclaration::VECTOR ? basic_right->size : 0); + if(!left_size || (left_size==1 && right_size!=1) || (left_size>1 && right_size!=1 && right_size!=left_size)) return; type = basic_left; + // Don't perform conversion even if the operands are of different sizes. + compat = SAME_TYPE; } else if(oper=='+' || oper=='-' || oper=='*' || oper=='/') { diff --git a/tests/glsl/binary_operators.glsl b/tests/glsl/binary_operators.glsl index 8e2520c8..a99b4446 100644 --- a/tests/glsl/binary_operators.glsl +++ b/tests/glsl/binary_operators.glsl @@ -14,6 +14,10 @@ void main() j = j<<(i%5); b = b || i!=j; + ivec2 iv; + i = i<>i; + mat4x2 m1; mat2x4 m2; mat4 m3 = m2*m1*5; @@ -21,7 +25,7 @@ void main() vec4 v2; v2 = m3*v1; vec2 v3; - v3 = v1*m2+v2.xy; + v3 = v1*m2+v2.xy+iv; if(b) ++v3; @@ -41,11 +45,14 @@ void main() i = i|1; j = j<<(i%5); b = b||i!=j; + ivec2 iv; + i = i<>i; mat4x2 m1; mat2x4 m2; vec4 v1 = vec4(1.0); vec2 v3; - v3 = v1*m2+(m2*m1*float(5)*v1).xy; + v3 = v1*m2+(m2*m1*float(5)*v1).xy+vec2(iv); if(b) ++v3; } diff --git a/tests/glsl/invalid_expressions.glsl b/tests/glsl/invalid_expressions.glsl index 996b0d35..2e67b76e 100644 --- a/tests/glsl/invalid_expressions.glsl +++ b/tests/glsl/invalid_expressions.glsl @@ -12,6 +12,8 @@ void main() vec3 v; m*m; v*m; + ivec3 iv; + i<:10: No matching operator '/' found for 'int' and 'float' :13: No matching operator '*' found for 'mat3x2' and 'mat3x2' :14: No matching operator '*' found for 'vec3' and 'mat3x2' +:16: No matching operator '<<' found for 'int' and 'ivec3' */ -- 2.45.2