]> git.tdb.fi Git - libs/gl.git/commitdiff
Additional rules for bit shift operators
authorMikko Rasa <tdb@tdb.fi>
Sun, 7 Mar 2021 09:36:17 +0000 (11:36 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 7 Mar 2021 09:36:17 +0000 (11:36 +0200)
source/glsl/generate.cpp
tests/glsl/binary_operators.glsl
tests/glsl/invalid_expressions.glsl

index f29d65f58bfeeaf4fe837fa2222226473c6d3c66..1e57ed649041cacdfaa58b56fa0a56dee5642dc9 100644 (file)
@@ -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=='/')
        {
index 8e2520c83c7b9458584b6d92f1da51c0d2264ad2..a99b4446f9e2a22efcd9a8615e10f88a9d955b97 100644 (file)
@@ -14,6 +14,10 @@ void main()
        j = j<<(i%5);
        b = b || i!=j;
 
+       ivec2 iv;
+       i = i<<j;
+       iv = iv>>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<<j;
+       iv = iv>>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;
 }
index 996b0d355fecc09b2ce14d51f134672e12fa035f..2e67b76e01db0675ffc0a0d68ecce9a41109cb96 100644 (file)
@@ -12,6 +12,8 @@ void main()
        vec3 v;
        m*m;
        v*m;
+       ivec3 iv;
+       i<<iv;
 }
 
 /* Expected error:
@@ -24,4 +26,5 @@ void main()
 <test>:10: No matching operator '/' found for 'int' and 'float'
 <test>:13: No matching operator '*' found for 'mat3x2' and 'mat3x2'
 <test>:14: No matching operator '*' found for 'vec3' and 'mat3x2'
+<test>:16: No matching operator '<<' found for 'int' and 'ivec3'
 */