Add int-vector folding tests to VectorFolding.

This test is meant to demonstrate that constant folding for int and
float vectors is not on equal footing. Float vectors currently generate
better-optimized output.

Change-Id: Ib4822c7b594e9bc4eb4fb9cfe6ab46f7f76268d6
Bug: skia:10908
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332423
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2020-11-05 11:59:10 -05:00 committed by Skia Commit-Bot
parent a2d6b31f66
commit 107e862eb6
3 changed files with 257 additions and 92 deletions

View File

@ -1,10 +1,10 @@
void main() {
void test_half() {
sk_FragColor.r = half4(0.5, 1, 1, 1).x;
sk_FragColor = half4(half2(1), half2(2, 3)) + half4(5, 6, 7, 8);
sk_FragColor = half4(8, half3(10)) - half4(1);
sk_FragColor = half4(2) * half4(1, 2, 3, 4);
sk_FragColor = half4(12) / half4(1, 2, 3, 4);
sk_FragColor.r = (half4(12) / half4(1, 2, 3, 4)).y;
sk_FragColor.x = (half4(12) / half4(1, 2, 3, 4)).y;
sk_FragColor.x = half4(1) == half4(1) ? 1.0 : -1.0;
sk_FragColor.x = half4(1) == half4(2) ? 2.0 : -2.0;
sk_FragColor.x = half2(1) == half2(1, 1) ? 3.0 : -3.0;
@ -49,3 +49,62 @@ void main() {
sk_FragColor /= half4(1);
sk_FragColor /= half4(2);
}
void test_int() {
int4 result;
result.r = int4(2, 3, 3, 3).x;
result = int4(int2(1), int2(2, 3)) + int4(5, 6, 7, 8);
result = int4(8, int3(10)) - int4(1);
result = int4(2) * int4(1, 2, 3, 4);
result = int4(12) / int4(1, 2, 3, 4);
sk_FragColor.x = (int4(12) / int4(1, 2, 3, 4)).y;
sk_FragColor.x = int4(1) == int4(1) ? 1.0 : -1.0;
sk_FragColor.x = int4(1) == int4(2) ? 2.0 : -2.0;
sk_FragColor.x = int2(1) == int2(1, 1) ? 3.0 : -3.0;
sk_FragColor.x = int2(1, 1) == int2(1, 1) ? 4.0 : -4.0;
sk_FragColor.x = int2(1) == int2(1, 0) ? 5.0 : -5.0;
sk_FragColor.x = int4(1) == int4(int2(1), int2(1)) ? 6.0 : -6.0;
sk_FragColor.x = int4(int3(1), 1) == int4(int2(1), int2(1)) ? 7.0 : -7.0;
sk_FragColor.x = int4(int3(1), 1) == int4(int2(1), 1, 0) ? 8.0 : -8.0;
sk_FragColor.x = int2(1) != int2(1, 0) ? 9.0 : -9.0;
sk_FragColor.x = int4(1) != int4(int2(1), int2(1)) ? 10.0 : -10.0;
result = int4(int(sqrt(1))) * int4(1);
result = int4(1) * int4(int(sqrt(2)));
result = int4(0) * int4(int(sqrt(3)));
result = int4(int(sqrt(4))) * int4(0);
result = int4(0) / int4(int(sqrt(5)));
result = int4(0) + int4(int(sqrt(6)));
result = int4(int(sqrt(7))) + int4(0);
result = int4(int(sqrt(8))) - int4(0);
result = int4(0) + int(int(sqrt(9)));
result = int4(0) * int(sqrt(10));
result = int4(0) / int(sqrt(11));
result = int4(1) * int(sqrt(12));
result = 0 + int4(int(sqrt(13)));
result = 0 * int4(int(sqrt(14)));
result = 0 / int4(int(sqrt(15)));
result = 1 * int4(int(sqrt(16)));
result = int4(int(sqrt(17))) + 0;
result = int4(int(sqrt(18))) * 0;
result = int4(int(sqrt(19))) * 1;
result = int4(int(sqrt(19.5))) - 0;
result = int(int(sqrt(20))) * int4(1);
result = int(int(sqrt(21))) + int4(0);
result = int(int(sqrt(22))) - int4(0);
result = int(int(sqrt(23))) / int4(1);
result = int4(int(sqrt(24))) / 1;
result += int4(1);
result += int4(0);
result -= int4(1);
result -= int4(0);
result *= int4(1);
result *= int4(2);
result /= int4(1);
result /= int4(2);
sk_FragColor = int4(result);
}
void main() {
test_half();
test_int();
}

View File

@ -1,49 +1,102 @@
out vec4 sk_FragColor;
void main() {
sk_FragColor.x = 0.5;
sk_FragColor = vec4(6.0, 7.0, 9.0, 11.0);
sk_FragColor = vec4(7.0, 9.0, 9.0, 9.0);
sk_FragColor = vec4(2.0, 4.0, 6.0, 8.0);
sk_FragColor = vec4(12.0, 6.0, 4.0, 3.0);
sk_FragColor.x = 6.0;
sk_FragColor.x = 1.0;
sk_FragColor.x = -2.0;
sk_FragColor.x = 3.0;
sk_FragColor.x = 4.0;
sk_FragColor.x = -5.0;
sk_FragColor.x = 6.0;
sk_FragColor.x = 7.0;
sk_FragColor.x = -8.0;
sk_FragColor.x = 9.0;
sk_FragColor.x = -10.0;
sk_FragColor = vec4(sqrt(1.0));
sk_FragColor = vec4(sqrt(2.0));
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(sqrt(6.0));
sk_FragColor = vec4(sqrt(7.0));
sk_FragColor = vec4(sqrt(8.0));
sk_FragColor = vec4(sqrt(9.0));
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(sqrt(12.0));
sk_FragColor = vec4(sqrt(13.0));
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(sqrt(16.0));
sk_FragColor = vec4(sqrt(17.0));
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(sqrt(19.0));
sk_FragColor = vec4(sqrt(19.5));
sk_FragColor = vec4(sqrt(20.0));
sk_FragColor = vec4(sqrt(21.0));
sk_FragColor = vec4(sqrt(22.0));
sk_FragColor = vec4(sqrt(23.0));
sk_FragColor = vec4(sqrt(24.0));
sk_FragColor += vec4(1.0);
sk_FragColor -= vec4(1.0);
sk_FragColor *= vec4(2.0);
sk_FragColor /= vec4(2.0);
{
sk_FragColor.x = 0.5;
sk_FragColor = vec4(6.0, 7.0, 9.0, 11.0);
sk_FragColor = vec4(7.0, 9.0, 9.0, 9.0);
sk_FragColor = vec4(2.0, 4.0, 6.0, 8.0);
sk_FragColor = vec4(12.0, 6.0, 4.0, 3.0);
sk_FragColor.x = 6.0;
sk_FragColor.x = 1.0;
sk_FragColor.x = -2.0;
sk_FragColor.x = 3.0;
sk_FragColor.x = 4.0;
sk_FragColor.x = -5.0;
sk_FragColor.x = 6.0;
sk_FragColor.x = 7.0;
sk_FragColor.x = -8.0;
sk_FragColor.x = 9.0;
sk_FragColor.x = -10.0;
sk_FragColor = vec4(sqrt(1.0));
sk_FragColor = vec4(sqrt(2.0));
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(sqrt(6.0));
sk_FragColor = vec4(sqrt(7.0));
sk_FragColor = vec4(sqrt(8.0));
sk_FragColor = vec4(sqrt(9.0));
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(sqrt(12.0));
sk_FragColor = vec4(sqrt(13.0));
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(sqrt(16.0));
sk_FragColor = vec4(sqrt(17.0));
sk_FragColor = vec4(0.0);
sk_FragColor = vec4(sqrt(19.0));
sk_FragColor = vec4(sqrt(19.5));
sk_FragColor = vec4(sqrt(20.0));
sk_FragColor = vec4(sqrt(21.0));
sk_FragColor = vec4(sqrt(22.0));
sk_FragColor = vec4(sqrt(23.0));
sk_FragColor = vec4(sqrt(24.0));
sk_FragColor += vec4(1.0);
sk_FragColor -= vec4(1.0);
sk_FragColor *= vec4(2.0);
sk_FragColor /= vec4(2.0);
}
{
ivec4 _0_result;
_0_result.x = 2;
_0_result = ivec4(ivec2(1), ivec2(2, 3)) + ivec4(5, 6, 7, 8);
_0_result = ivec4(8, ivec3(10)) - ivec4(1);
_0_result = ivec4(2) * ivec4(1, 2, 3, 4);
_0_result = ivec4(12) / ivec4(1, 2, 3, 4);
sk_FragColor.x = float((ivec4(12) / ivec4(1, 2, 3, 4)).y);
sk_FragColor.x = ivec4(1) == ivec4(1) ? 1.0 : -1.0;
sk_FragColor.x = ivec4(1) == ivec4(2) ? 2.0 : -2.0;
sk_FragColor.x = ivec2(1) == ivec2(1, 1) ? 3.0 : -3.0;
sk_FragColor.x = ivec2(1, 1) == ivec2(1, 1) ? 4.0 : -4.0;
sk_FragColor.x = ivec2(1) == ivec2(1, 0) ? 5.0 : -5.0;
sk_FragColor.x = ivec4(1) == ivec4(ivec2(1), ivec2(1)) ? 6.0 : -6.0;
sk_FragColor.x = ivec4(ivec3(1), 1) == ivec4(ivec2(1), ivec2(1)) ? 7.0 : -7.0;
sk_FragColor.x = ivec4(ivec3(1), 1) == ivec4(ivec2(1), 1, 0) ? 8.0 : -8.0;
sk_FragColor.x = ivec2(1) != ivec2(1, 0) ? 9.0 : -9.0;
sk_FragColor.x = ivec4(1) != ivec4(ivec2(1), ivec2(1)) ? 10.0 : -10.0;
_0_result = ivec4(int(sqrt(1.0)));
_0_result = ivec4(int(sqrt(2.0)));
_0_result = ivec4(0);
_0_result = ivec4(0);
_0_result = ivec4(0);
_0_result = ivec4(int(sqrt(6.0)));
_0_result = ivec4(int(sqrt(7.0)));
_0_result = ivec4(int(sqrt(8.0)));
_0_result = ivec4(int(sqrt(9.0)));
_0_result = ivec4(0);
_0_result = ivec4(0);
_0_result = ivec4(int(sqrt(12.0)));
_0_result = ivec4(int(sqrt(13.0)));
_0_result = ivec4(0);
_0_result = ivec4(0);
_0_result = ivec4(int(sqrt(16.0)));
_0_result = ivec4(int(sqrt(17.0)));
_0_result = ivec4(0);
_0_result = ivec4(int(sqrt(19.0)));
_0_result = ivec4(int(sqrt(19.5)));
_0_result = ivec4(int(sqrt(20.0)));
_0_result = ivec4(int(sqrt(21.0)));
_0_result = ivec4(int(sqrt(22.0)));
_0_result = ivec4(int(sqrt(23.0)));
_0_result = ivec4(int(sqrt(24.0)));
_0_result += ivec4(1);
_0_result -= ivec4(1);
_0_result *= ivec4(2);
_0_result /= ivec4(2);
sk_FragColor = vec4(_0_result);
}
}

View File

@ -9,50 +9,103 @@ struct Outputs {
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _outputStruct;
thread Outputs* _out = &_outputStruct;
_out->sk_FragColor.x = 0.5;
_out->sk_FragColor = float4(6.0, 7.0, 9.0, 11.0);
_out->sk_FragColor = float4(7.0, 9.0, 9.0, 9.0);
_out->sk_FragColor = float4(2.0, 4.0, 6.0, 8.0);
_out->sk_FragColor = float4(12.0, 6.0, 4.0, 3.0);
_out->sk_FragColor.x = 6.0;
_out->sk_FragColor.x = 1.0;
_out->sk_FragColor.x = -2.0;
_out->sk_FragColor.x = 3.0;
_out->sk_FragColor.x = 4.0;
_out->sk_FragColor.x = -5.0;
_out->sk_FragColor.x = 6.0;
_out->sk_FragColor.x = 7.0;
_out->sk_FragColor.x = -8.0;
_out->sk_FragColor.x = 9.0;
_out->sk_FragColor.x = -10.0;
_out->sk_FragColor = float4(sqrt(1.0));
_out->sk_FragColor = float4(sqrt(2.0));
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(sqrt(6.0));
_out->sk_FragColor = float4(sqrt(7.0));
_out->sk_FragColor = float4(sqrt(8.0));
_out->sk_FragColor = float4(sqrt(9.0));
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(sqrt(12.0));
_out->sk_FragColor = float4(sqrt(13.0));
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(sqrt(16.0));
_out->sk_FragColor = float4(sqrt(17.0));
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(sqrt(19.0));
_out->sk_FragColor = float4(sqrt(19.5));
_out->sk_FragColor = float4(sqrt(20.0));
_out->sk_FragColor = float4(sqrt(21.0));
_out->sk_FragColor = float4(sqrt(22.0));
_out->sk_FragColor = float4(sqrt(23.0));
_out->sk_FragColor = float4(sqrt(24.0));
_out->sk_FragColor += float4(1.0);
_out->sk_FragColor -= float4(1.0);
_out->sk_FragColor *= float4(2.0);
_out->sk_FragColor /= float4(2.0);
{
_out->sk_FragColor.x = 0.5;
_out->sk_FragColor = float4(6.0, 7.0, 9.0, 11.0);
_out->sk_FragColor = float4(7.0, 9.0, 9.0, 9.0);
_out->sk_FragColor = float4(2.0, 4.0, 6.0, 8.0);
_out->sk_FragColor = float4(12.0, 6.0, 4.0, 3.0);
_out->sk_FragColor.x = 6.0;
_out->sk_FragColor.x = 1.0;
_out->sk_FragColor.x = -2.0;
_out->sk_FragColor.x = 3.0;
_out->sk_FragColor.x = 4.0;
_out->sk_FragColor.x = -5.0;
_out->sk_FragColor.x = 6.0;
_out->sk_FragColor.x = 7.0;
_out->sk_FragColor.x = -8.0;
_out->sk_FragColor.x = 9.0;
_out->sk_FragColor.x = -10.0;
_out->sk_FragColor = float4(sqrt(1.0));
_out->sk_FragColor = float4(sqrt(2.0));
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(sqrt(6.0));
_out->sk_FragColor = float4(sqrt(7.0));
_out->sk_FragColor = float4(sqrt(8.0));
_out->sk_FragColor = float4(sqrt(9.0));
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(sqrt(12.0));
_out->sk_FragColor = float4(sqrt(13.0));
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(sqrt(16.0));
_out->sk_FragColor = float4(sqrt(17.0));
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(sqrt(19.0));
_out->sk_FragColor = float4(sqrt(19.5));
_out->sk_FragColor = float4(sqrt(20.0));
_out->sk_FragColor = float4(sqrt(21.0));
_out->sk_FragColor = float4(sqrt(22.0));
_out->sk_FragColor = float4(sqrt(23.0));
_out->sk_FragColor = float4(sqrt(24.0));
_out->sk_FragColor += float4(1.0);
_out->sk_FragColor -= float4(1.0);
_out->sk_FragColor *= float4(2.0);
_out->sk_FragColor /= float4(2.0);
}
{
int4 _0_result;
_0_result.x = 2;
_0_result = int4(int2(1), int2(2, 3)) + int4(5, 6, 7, 8);
_0_result = int4(8, int3(10)) - int4(1);
_0_result = int4(2) * int4(1, 2, 3, 4);
_0_result = int4(12) / int4(1, 2, 3, 4);
_out->sk_FragColor.x = float((int4(12) / int4(1, 2, 3, 4)).y);
_out->sk_FragColor.x = all(int4(1) == int4(1)) ? 1.0 : -1.0;
_out->sk_FragColor.x = all(int4(1) == int4(2)) ? 2.0 : -2.0;
_out->sk_FragColor.x = all(int2(1) == int2(1, 1)) ? 3.0 : -3.0;
_out->sk_FragColor.x = all(int2(1, 1) == int2(1, 1)) ? 4.0 : -4.0;
_out->sk_FragColor.x = all(int2(1) == int2(1, 0)) ? 5.0 : -5.0;
_out->sk_FragColor.x = all(int4(1) == int4(int2(1), int2(1))) ? 6.0 : -6.0;
_out->sk_FragColor.x = all(int4(int3(1), 1) == int4(int2(1), int2(1))) ? 7.0 : -7.0;
_out->sk_FragColor.x = all(int4(int3(1), 1) == int4(int2(1), 1, 0)) ? 8.0 : -8.0;
_out->sk_FragColor.x = any(int2(1) != int2(1, 0)) ? 9.0 : -9.0;
_out->sk_FragColor.x = any(int4(1) != int4(int2(1), int2(1))) ? 10.0 : -10.0;
_0_result = int4(int(sqrt(1.0)));
_0_result = int4(int(sqrt(2.0)));
_0_result = int4(0);
_0_result = int4(0);
_0_result = int4(0);
_0_result = int4(int(sqrt(6.0)));
_0_result = int4(int(sqrt(7.0)));
_0_result = int4(int(sqrt(8.0)));
_0_result = int4(int(sqrt(9.0)));
_0_result = int4(0);
_0_result = int4(0);
_0_result = int4(int(sqrt(12.0)));
_0_result = int4(int(sqrt(13.0)));
_0_result = int4(0);
_0_result = int4(0);
_0_result = int4(int(sqrt(16.0)));
_0_result = int4(int(sqrt(17.0)));
_0_result = int4(0);
_0_result = int4(int(sqrt(19.0)));
_0_result = int4(int(sqrt(19.5)));
_0_result = int4(int(sqrt(20.0)));
_0_result = int4(int(sqrt(21.0)));
_0_result = int4(int(sqrt(22.0)));
_0_result = int4(int(sqrt(23.0)));
_0_result = int4(int(sqrt(24.0)));
_0_result += int4(1);
_0_result -= int4(1);
_0_result *= int4(2);
_0_result /= int4(2);
_out->sk_FragColor = float4(_0_result);
}
return *_out;
}