Run SkSL inliner tests as part of dm.

Previously, these tests were never actually executed, only read during
code review. They are now properly tested for correctness whenever dm
is run. Non-ES2 compliant statements (do/while/switch) are unfortunately
excluded here, as they are not compatible with Runtime Effects yet.

Change-Id: I965c782baad6f8dd3961a400ae791fb2c1f844d3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/389296
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-03-25 17:04:36 -04:00 committed by Skia Commit-Bot
parent 70cd59880d
commit 0c9d888748
65 changed files with 529 additions and 415 deletions

View File

@ -1,10 +1,14 @@
inline half4 adjust(half4 v) {
return v + half4(0.125);
uniform half4 colorGreen, colorRed;
inline half4 get() {
half4 x = colorGreen;
return x;
}
void main() {
sk_FragColor = half4(0);
half4 main() {
half4 result = colorRed;
do
sk_FragColor = adjust(sk_FragColor);
while (sk_FragColor.x < 0.5);
result = get();
while (result != colorGreen);
return result;
}

View File

@ -1,10 +1,13 @@
inline bool shouldLoop(half4 v) {
return v.x < 0.5;
uniform half4 colorGreen, colorRed;
inline bool shouldLoop(half4 value) {
return value != colorGreen;
}
void main() {
sk_FragColor = half4(0);
half4 main() {
half4 result = colorRed;
do {
sk_FragColor += half4(0.125);
} while (shouldLoop(sk_FragColor));
result = colorGreen;
} while (shouldLoop(result));
return result;
}

View File

@ -1,7 +1,9 @@
uniform half4 colorGreen, colorRed;
half4 helper();
void main() {
sk_FragColor = helper();
half4 main() {
return helper();
}
enum class E {
@ -13,9 +15,9 @@ enum class E {
half4 helper() {
E temp = E::kGray;
switch (temp) {
case E::kBlack: return half4(0, 0, 0, 1);
case E::kGray: return half4(0.5, 0.5, 0.5, 1);
case E::kWhite: return half4(1);
default: return half4(1, 0, 0, 1);
case E::kBlack: return colorRed;
case E::kGray: return colorGreen;
case E::kWhite: return colorRed;
default: return colorRed;
}
}

View File

@ -1,9 +1,14 @@
inline half4 adjust(half4 v) {
return v + half4(0.125);
uniform half4 colorGreen;
inline half4 multiply(half4 x, half y) {
half4 value = x * y;
return value;
}
void main() {
sk_FragColor = half4(0);
half4 main() {
half4 result;
for (int x=0; x<4; ++x)
sk_FragColor = adjust(sk_FragColor);
result = multiply(colorGreen, 1);
return result;
}

View File

@ -1,3 +1,5 @@
uniform half4 colorGreen;
inline half4 initLoopVar() {
return half4(0.0625);
}
@ -10,9 +12,10 @@ inline half4 grow(half4 v) {
return v + half4(0.125);
}
void main() {
half4 main() {
for (sk_FragColor = initLoopVar();
shouldLoop(sk_FragColor);
sk_FragColor = grow(sk_FragColor)) {
}
return colorGreen;
}

View File

@ -1,12 +1,12 @@
uniform int value;
uniform half4 colorGreen, colorRed;
inline half4 loopy(int v) {
for (int x=0; x<5; ++x) {
if (x == v) return half4(0.5);
inline half4 loopy() {
for (int x=0; x<=4; ++x) {
return colorGreen;
}
return half4(1.0);
return colorRed;
}
void main() {
sk_FragColor = loopy(value);
half4 main() {
return loopy();
}

View File

@ -1,13 +1,13 @@
uniform int value;
uniform half4 colorGreen;
inline half4 loopy(int v) {
half4 result = half4(1.0);
for (int x=0; x<5; ++x) {
if (x == v) result = half4(0.5);
inline half4 loopy() {
half4 result;
for (int x=0; x<4; ++x) {
result[x] = colorGreen[x];
}
return result;
}
void main() {
sk_FragColor = loopy(value);
half4 main() {
return loopy();
}

View File

@ -1,12 +1,13 @@
uniform half4 color;
uniform half4 colorGreen, colorRed;
inline half4 ifBody() {
return color + half4(0.125);
half4 x = colorGreen;
return x;
}
void main() {
half4 c = color;
if (c.x >= 0.5)
half4 main() {
half4 c = colorRed;
if (colorGreen.g == 1)
c = ifBody();
sk_FragColor = c;
return c;
}

View File

@ -1,14 +1,15 @@
uniform half4 color;
uniform half4 colorGreen, colorRed;
inline half4 elseBody() {
return color + half4(0.125);
half4 x = colorGreen;
return x;
}
void main() {
half4 c = color;
if (c.x >= 0.5)
half4 main() {
half4 c = colorRed;
if (colorGreen.g == 0)
;
else
c = elseBody();
sk_FragColor = c;
return c;
}

View File

@ -1,33 +1,31 @@
// An if-else statement at the end of a function, with a return as the last statement on all
// paths, are not actually "early" returns. The inliner is able to recognize this pattern.
uniform half4 color;
uniform half4 colorGreen, colorRed;
inline half4 branchy(half4 c) {
c *= 0.5;
if (c.x > 0)
return c.xxxx;
else if (c.y > 0)
return c.yyyy;
else if (c.z > 0)
return c.zzzz;
inline half branchy() {
if (colorGreen.g == 0)
return 0;
else if (colorRed.r == 0)
return 0;
else if (colorGreen == colorRed)
return 0;
else
return c.wwww;
return 1;
}
inline half4 branchyAndBlocky(half4 c) {{{
if (c.x > 0) {
half4 d = c * 0.5;
return d.xxxx;
} else {{{
if (c.x < 0) {
return c.wwww;
} else {
return c.yyyy;
}
inline half branchyAndBlocky() {
if (colorGreen.g == 0) {{{
return 0;
}}} else if (colorRed.r == 0) {{
return 0;
}} else { if (colorGreen == colorRed)
return 0;
else {{
return 1;
}}}
}}}
void main() {
sk_FragColor = branchy(color) * branchyAndBlocky(color);
}
half4 main() {
return bool(branchy() * branchyAndBlocky()) ? colorGreen : colorRed;
}

View File

@ -1,12 +1,13 @@
uniform half4 color;
uniform half4 colorGreen, colorRed;
inline bool ifTest(half4 v) {
return color.x >= 0.5;
inline bool ifTest(half4 color) {
bool result = bool(color.g);
return result;
}
void main() {
if (ifTest(color))
sk_FragColor = half4(1.0);
half4 main() {
if (ifTest(colorGreen))
return colorGreen;
else
sk_FragColor = half4(0.5);
return colorRed;
}

View File

@ -1,9 +1,9 @@
uniform half4 color;
uniform half4 colorGreen, colorRed;
half4 branchy(half4 c) {
if (c.z == c.w) return c.yyyy; else return c.zzzz;
if (colorGreen == colorRed) return colorRed; else return colorGreen;
}
void main() {
sk_FragColor = branchy(color);
half4 main() {
return branchy(colorGreen);
}

View File

@ -1,11 +1,14 @@
uniform half4 colorGreen;
inline int tooBig(int x) {
++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x;
++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x;
return x;
}
void main() {
half4 main() {
int y = 0;
y = tooBig(y);
y = tooBig(y);
return colorGreen;
}

View File

@ -1,10 +1,13 @@
uniform half4 colorGreen;
void tooBig(inout int x) {
++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x;
++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x;
}
void main() {
half4 main() {
int x = 0;
tooBig(x);
tooBig(x);
return colorGreen;
}

View File

@ -1,10 +1,12 @@
uniform half4 colorGreen;
// We don't inline functions with out parameters. (skia:11326)
inline void outParameter(inout half x) {
x *= 2;
inline void outParameter(inout half4 x) {
x *= x;
}
void main() {
half x = 1;
outParameter(x);
sk_FragColor.x = x;
half4 main() {
half4 c = colorGreen;
outParameter(c);
return c;
}

View File

@ -1,8 +1,12 @@
uniform half4 colorGreen;
inline half parameterWrite(half x) {
x *= 2;
x *= x;
return x;
}
void main() {
sk_FragColor.x = parameterWrite(1);
half4 main() {
half4 c = colorGreen;
c.g = parameterWrite(c.g);
return c;
}

View File

@ -1,19 +1,17 @@
uniform half val;
inline half BigX(half x) {
++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x;
--x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x;
x = 123;
x = 1;
return x;
}
inline half BigY(half x) {
++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x; ++x;
--x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x; --x;
x = 456;
x = 0;
return x;
}
void main() {
sk_FragColor = BigX(BigY(val)).xxxx;
half4 main() {
return BigX(BigY(12345)).0x0x;
}

View File

@ -1,9 +1,13 @@
inline half basic(half x) {
return x * 2;
inline half square(half x) {
return x * x;
}
void main() {
sk_FragColor.x = basic(1);
half y = 2;
sk_FragColor.y = basic(y);
half4 main() {
half one = 1;
half4 result = half4(123);
result.r = square(0);
result.b = square(result.r);
result.g = square(1);
result.a = square(one);
return result;
}

View File

@ -1,4 +1,4 @@
uniform half4 color;
uniform half4 colorGreen;
half4 blocky(half4 c) {
{
@ -6,6 +6,6 @@ half4 blocky(half4 c) {
}
}
void main() {
sk_FragColor = blocky(color);
half4 main() {
return blocky(colorGreen);
}

View File

@ -1,14 +1,12 @@
in half2 x;
inline half2 InlineB(half2 tmp)
{
half2 reusedName = tmp + half2(3, 4);
half2 reusedName = tmp - 1;
return reusedName;
}
inline half2 InlineA()
{
half2 reusedName = x + half2(1, 2);
half2 reusedName = half2(1, 2);
return InlineB(reusedName);
}

View File

@ -1,17 +1,17 @@
/*#pragma settings Default*/
uniform half4 color;
uniform half4 colorGreen, colorRed;
inline half4 MakeTempVar(half4 c) {
{
half4 d = c * 0.75;
half4 d = colorGreen;
c = d;
}
{
return c.xxxx;
return c;
}
}
void main() {
sk_FragColor = MakeTempVar(color);
half4 main() {
return MakeTempVar(colorRed);
}

View File

@ -1,15 +1,15 @@
/*#pragma settings Default*/
uniform half4 color;
uniform half4 colorWhite, colorGreen, colorRed;
inline half4 MakeTempVar(half4 c) {
if (c.x < c.y) {
return c.xxxx;
if (c.rg == c.ba) {
return colorGreen;
} else {
return c.yyyy;
return colorRed;
}
}
void main() {
sk_FragColor = MakeTempVar(color);
half4 main() {
return MakeTempVar(colorWhite);
}

View File

@ -1,14 +1,14 @@
/*#pragma settings Default*/
uniform half4 color;
uniform half4 colorWhite;
inline half4 MakeTempVar(half4 c) {
{
half4 d = c * 0.75;
return d.xxxx;
half4 d = c;
return d.0g0a;
}
}
void main() {
sk_FragColor = MakeTempVar(color);
half4 main() {
return MakeTempVar(colorWhite);
}

View File

@ -1,7 +1,7 @@
uniform half4 color;
uniform half4 colorGreen;
noinline half singleuse() {
return 1.25;
noinline half4 multiplyByAlpha(half4 x) {
return x * x.aaaa;
}
noinline half add(half a, half b) {
@ -17,9 +17,11 @@ noinline half fma(half a, half b, half c) {
return add(mul(a, b), c);
}
void main() {
half4 main() {
// Functions used multiple times:
sk_FragColor = fma(color.x, color.y, color.z).xxxx;
half4 result = fma(colorGreen.a, colorGreen.g, colorGreen.r).0x0x;
// Functions used only once:
sk_FragColor *= singleuse();
result = multiplyByAlpha(result);
return result;
}

View File

@ -1,19 +1,20 @@
uniform half4 color;
uniform half4 colorWhite;
inline bool testA(half4 v) {
return v.x <= 0.5;
return bool(v.r);
}
inline bool testB(half4 v) {
return v.x > 0.5;
return bool(v.g);
}
void main() {
sk_FragColor = half4(0);
if (testA(color) && testB(color)) {
sk_FragColor = half4(0.5);
half4 main() {
half4 result = half4(0);
if (testA(colorWhite) && testB(colorWhite)) {
result.g = 1;
}
if (testB(color) || testA(color)) {
sk_FragColor = half4(1.0);
if (testB(colorWhite) || testA(colorWhite)) {
result.a = 1;
}
return result;
}

View File

@ -1,9 +1,3 @@
half4 helper();
void main() {
sk_FragColor = helper();
}
struct Color {
half red;
half green;
@ -13,9 +7,13 @@ struct Color {
half4 helper() {
Color c;
c.red = 0.25;
c.green = 0.5;
c.blue = 0.75;
c.red = 0.0;
c.green = 1.0;
c.blue = 0.0;
c.alpha = 1.0;
return half4(c.red, c.green, c.blue, c.alpha);
}
half4 main() {
return helper();
}

View File

@ -1,14 +1,9 @@
uniform half4 inColor;
uniform half4 colorRed;
half4 flip(half4 v) {
return v.wzyx;
half4 switchRedAndGreen(half4 v) {
return v.grba;
}
void main() {
half4 color = inColor;
sk_FragColor = color.xyzy.wzyx;
sk_FragColor = flip(color.xyzy);
sk_FragColor = color;
half4 main() {
return switchRedAndGreen(switchRedAndGreen(switchRedAndGreen(colorRed)));
}

View File

@ -1,17 +1,13 @@
uniform half4 color;
half count = 0;
uniform half4 colorGreen, colorRed;
inline half4 trueSide(half4 v) {
count += 1;
return half4(sin(v.x), sin(v.y), sin(v.z), sin(v.w));
return v.r1ba;
}
inline half4 falseSide(half4 v) {
count += 1;
return half4(cos(v.y), cos(v.z), cos(v.w), cos(v.z));
return v.r0ba;
}
void main() {
sk_FragColor = (color.x <= 0.5) ? trueSide(color) : falseSide(color);
sk_FragColor *= count;
half4 main() {
return bool(colorGreen.g) ? trueSide(colorGreen) : falseSide(colorRed);
}

View File

@ -1,9 +1,9 @@
uniform half4 color;
uniform half4 colorGreen, colorRed;
inline bool test(half4 v) {
return v.x <= 0.5;
return bool(v.g);
}
void main() {
sk_FragColor = test(color) ? half4(0.5) : half4(1.0);
half4 main() {
return test(colorGreen) ? colorGreen : colorRed;
}

View File

@ -1,7 +1,5 @@
in half val;
uniform int ui;
uniform half4 uh4;
uniform bool b;
uniform half4 colorGreen;
uniform half unknownInput;
struct S {
half4 ah4[1];
@ -10,56 +8,62 @@ struct S {
half h;
};
// Each helper function needs to reference the variable multiple times, because if it's only read
// from once, it is inlined directly whether or not it is trivial.
half4 funcb(bool b) {
return b ? sk_FragColor.xxxx : sk_FragColor.yyyy;
return half4(b, b, b, !b);
}
half4 func1(half h) {
return h.xxxx;
return h.xxxx * h.xxxx;
}
half4 func2(half2 h2) {
return h2.xyxy;
return h2.xyxy * h2.yxyx;
}
half4 func3(half3 h3) {
return h3.xyzx;
return h3.xyzx * h3.xyzx;
}
half4 func4(half4 h4) {
return h4;
return h4 * h4;
}
void main() {
half4 main() {
S s;
s.ah4[0] = half4(val);
s.ah[0] = val;
s.h4 = half4(val);
s.h = val;
s.ah4[0] = half4(unknownInput);
s.ah[0] = unknownInput;
s.h4 = half4(unknownInput);
s.h = unknownInput;
S as[1];
as[0].ah4[0] = half4(val);
as[0].ah4[0] = half4(unknownInput);
bool b = bool(unknownInput);
int i = int(unknownInput);
// These expressions are considered "trivial" and will be cloned directly into the inlined
// function without a temporary variable.
sk_FragColor = funcb(sk_Caps.floatIs32Bits);
sk_FragColor = func1(+s.h);
sk_FragColor = funcb(b);
sk_FragColor = func2(s.ah4[0].yw);
sk_FragColor = func2(as[0].ah4[0].xy);
sk_FragColor = func3(s.h4.zzz);
sk_FragColor = func3(uh4.xyz);
sk_FragColor = func3(s.h.xxx);
sk_FragColor = func4(half4(s.h));
sk_FragColor = func4(s.ah4[0].xxxy);
sk_FragColor = func4(uh4);
half4 var;
var = func1(+s.h);
var = funcb(b);
var = func2(s.ah4[0].yw);
var = func2(as[0].ah4[0].xy);
var = func3(s.h4.zzz);
var = func3(colorGreen.xyz);
var = func3(s.h.xxx);
var = func4(half4(s.h));
var = func4(s.ah4[0].xxxy);
var = func4(colorGreen);
// These expressions are considered "non-trivial" and will be placed in a temporary variable
// when inlining occurs.
sk_FragColor = funcb(!sk_Caps.floatIs32Bits);
sk_FragColor = func1(-s.h);
sk_FragColor = funcb(!b);
sk_FragColor = func2(s.ah4[ui].yw);
sk_FragColor = func3(s.h4.yyy + s.h4.zzz);
sk_FragColor = func4(s.h4.y001);
var = func1(-s.h);
var = funcb(!b);
// var = func2(as[i].h4.yw); // indexing by non-constant expressions disallowed in ES2
var = func3(s.h4.yyy + s.h4.zzz);
var = func4(s.h4.y001);
return colorGreen;
}

View File

@ -1,9 +1,14 @@
inline half4 adjust(half4 v) {
return v + half4(0.125);
uniform half4 colorGreen, colorRed;
inline half4 green() {
half4 x = colorGreen;
return x;
}
void main() {
sk_FragColor = half4(0);
while (sk_FragColor.x < 0.5)
sk_FragColor = adjust(sk_FragColor);
half4 main() {
half4 result = colorRed;
while (result != colorGreen)
result = green();
return result;
}

View File

@ -1,10 +1,13 @@
uniform half4 colorGreen, colorRed;
inline bool shouldLoop(half4 v) {
return v.x < 0.5;
return v != colorGreen;
}
void main() {
sk_FragColor = half4(0);
while (shouldLoop(sk_FragColor)) {
sk_FragColor += half4(0.125);
half4 main() {
half4 result = colorRed;
while (shouldLoop(result)) {
result = colorGreen;
}
return result;
}

View File

@ -135,9 +135,40 @@ SKSL_TEST(SkSLShortCircuitBoolFolding, "folding/ShortCircuitBoolFolding.
SKSL_TEST(SkSLVectorScalarFolding, "folding/VectorScalarFolding.sksl")
SKSL_TEST(SkSLVectorVectorFolding, "folding/VectorVectorFolding.sksl")
SKSL_TEST(SkSLForBodyMustBeInlinedIntoAScope, "inliner/ForBodyMustBeInlinedIntoAScope.sksl")
SKSL_TEST(SkSLForWithoutReturnInsideCanBeInlined, "inliner/ForWithoutReturnInsideCanBeInlined.sksl")
SKSL_TEST(SkSLForWithReturnInsideCannotBeInlined, "inliner/ForWithReturnInsideCannotBeInlined.sksl")
SKSL_TEST(SkSLIfBodyMustBeInlinedIntoAScope, "inliner/IfBodyMustBeInlinedIntoAScope.sksl")
SKSL_TEST(SkSLIfElseBodyMustBeInlinedIntoAScope, "inliner/IfElseBodyMustBeInlinedIntoAScope.sksl")
SKSL_TEST(SkSLIfElseChainWithReturnsCanBeInlined, "inliner/IfElseChainWithReturnsCanBeInlined.sksl")
SKSL_TEST(SkSLIfTestCanBeInlined, "inliner/IfTestCanBeInlined.sksl")
SKSL_TEST(SkSLIfWithReturnsCanBeInlined, "inliner/IfWithReturnsCanBeInlined.sksl")
SKSL_TEST(SkSLInlineKeywordOverridesThreshold, "inliner/InlineKeywordOverridesThreshold.sksl")
SKSL_TEST(SkSLInlinerAvoidsVariableNameOverlap, "inliner/InlinerAvoidsVariableNameOverlap.sksl")
SKSL_TEST(SkSLInlinerElidesTempVarForReturnsInsideBlock,
"inliner/InlinerElidesTempVarForReturnsInsideBlock.sksl")
SKSL_TEST(SkSLInlinerUsesTempVarForMultipleReturns,
"inliner/InlinerUsesTempVarForMultipleReturns.sksl")
SKSL_TEST(SkSLInlinerUsesTempVarForReturnsInsideBlockWithVar,
"inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.sksl")
SKSL_TEST(SkSLInlineThreshold, "inliner/InlineThreshold.sksl")
SKSL_TEST(SkSLInlineWithInoutArgument, "inliner/InlineWithInoutArgument.sksl")
SKSL_TEST(SkSLInlineWithModifiedArgument, "inliner/InlineWithModifiedArgument.sksl")
SKSL_TEST(SkSLInlineWithNestedBigCalls, "inliner/InlineWithNestedBigCalls.sksl")
SKSL_TEST(SkSLInlineWithUnmodifiedArgument, "inliner/InlineWithUnmodifiedArgument.sksl")
SKSL_TEST(SkSLInlineWithUnnecessaryBlocks, "inliner/InlineWithUnnecessaryBlocks.sksl")
SKSL_TEST(SkSLNoInline, "inliner/NoInline.sksl")
SKSL_TEST(SkSLShortCircuitEvaluationsCannotInlineRightHandSide,
"inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.sksl")
SKSL_TEST(SkSLStructsCanBeInlinedSafely, "inliner/StructsCanBeInlinedSafely.sksl")
SKSL_TEST(SkSLSwizzleCanBeInlinedDirectly, "inliner/SwizzleCanBeInlinedDirectly.sksl")
SKSL_TEST(SkSLTernaryResultsCannotBeInlined, "inliner/TernaryResultsCannotBeInlined.sksl")
SKSL_TEST(SkSLTernaryTestCanBeInlined, "inliner/TernaryTestCanBeInlined.sksl")
SKSL_TEST(SkSLTrivialArgumentsInlineDirectly, "inliner/TrivialArgumentsInlineDirectly.sksl")
// TODO(skia:11052): SPIR-V does not yet honor `out` param semantics correctly
SKSL_TEST_CPU(SkSLInlinerHonorsGLSLOutParamSemantics,
"inliner/InlinerHonorsGLSLOutParamSemantics.sksl")
"inliner/InlinerHonorsGLSLOutParamSemantics.sksl")
SKSL_TEST(SkSLIntrinsicAbsFloat, "intrinsics/AbsFloat.sksl")
SKSL_TEST(SkSLIntrinsicCeil, "intrinsics/Ceil.sksl")
@ -207,6 +238,15 @@ TODO(skia:11209): enable these tests when Runtime Effects have support for ES3
SKSL_TEST(SkSLIntFoldingES3, "folding/IntFoldingES3.sksl")
SKSL_TEST(SkSLMatrixFoldingES3, "folding/MatrixFoldingES3.sksl")
SKSL_TEST(SkSLDoWhileBodyMustBeInlinedIntoAScope, "inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl")
SKSL_TEST(SkSLDoWhileTestCannotBeInlined, "inliner/DoWhileTestCannotBeInlined.sksl")
SKSL_TEST(SkSLEnumsCanBeInlinedSafely, "inliner/EnumsCanBeInlinedSafely.sksl")
SKSL_TEST(SkSLForInitializerExpressionsCanBeInlined,
"inliner/ForInitializerExpressionsCanBeInlined.sksl")
SKSL_TEST(SkSLStaticSwitch, "inliner/StaticSwitch.sksl")
SKSL_TEST(SkSLWhileBodyMustBeInlinedIntoAScope, "inliner/WhileBodyMustBeInlinedIntoAScope.sksl")
SKSL_TEST(SkSLWhileTestCannotBeInlined, "inliner/WhileTestCannotBeInlined.sksl")
SKSL_TEST(SkSLIntrinsicAbsInt, "intrinsics/AbsInt.sksl")
SKSL_TEST(SkSLIntrinsicClampInt, "intrinsics/ClampInt.sksl")
SKSL_TEST(SkSLIntrinsicMaxInt, "intrinsics/MaxInt.sksl")

View File

@ -1,8 +1,12 @@
out vec4 sk_FragColor;
void main() {
sk_FragColor = vec4(0.0);
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 result = colorRed;
do {
sk_FragColor = sk_FragColor + vec4(0.125);
} while (sk_FragColor.x < 0.5);
vec4 _0_x = colorGreen;
result = _0_x;
} while (result != colorGreen);
return result;
}

View File

@ -1,11 +1,14 @@
out vec4 sk_FragColor;
bool shouldLoop_bh4(vec4 v) {
return v.x < 0.5;
uniform vec4 colorGreen;
uniform vec4 colorRed;
bool shouldLoop_bh4(vec4 value) {
return value != colorGreen;
}
void main() {
sk_FragColor = vec4(0.0);
vec4 main() {
vec4 result = colorRed;
do {
sk_FragColor += vec4(0.125);
} while (shouldLoop_bh4(sk_FragColor));
result = colorGreen;
} while (shouldLoop_bh4(result));
return result;
}

View File

@ -1,19 +1,21 @@
out vec4 sk_FragColor;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 helper_h4();
void main() {
sk_FragColor = helper_h4();
vec4 main() {
return helper_h4();
}
vec4 helper_h4() {
int temp = 1;
switch (temp) {
case 0:
return vec4(0.0, 0.0, 0.0, 1.0);
return colorRed;
case 1:
return vec4(0.5, 0.5, 0.5, 1.0);
return colorGreen;
case 2:
return vec4(1.0);
return colorRed;
default:
return vec4(1.0, 0.0, 0.0, 1.0);
return colorRed;
}
}

View File

@ -1,8 +1,11 @@
out vec4 sk_FragColor;
void main() {
sk_FragColor = vec4(0.0);
uniform vec4 colorGreen;
vec4 main() {
vec4 result;
for (int x = 0;x < 4; ++x) {
sk_FragColor = sk_FragColor + vec4(0.125);
vec4 _0_value = colorGreen;
result = _0_value;
}
return result;
}

View File

@ -1,12 +1,14 @@
out vec4 sk_FragColor;
uniform vec4 colorGreen;
bool shouldLoop_bh4(vec4 v) {
return v.x < 0.5;
}
vec4 grow_h4h4(vec4 v) {
return v + vec4(0.125);
}
void main() {
vec4 main() {
for (sk_FragColor = vec4(0.0625);shouldLoop_bh4(sk_FragColor); sk_FragColor = grow_h4h4(sk_FragColor)) {
}
return colorGreen;
}

View File

@ -1,12 +1,13 @@
out vec4 sk_FragColor;
uniform int value;
vec4 loopy_h4i(int v) {
for (int x = 0;x < 5; ++x) {
if (x == v) return vec4(0.5);
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 loopy_h4() {
for (int x = 0;x <= 4; ++x) {
return colorGreen;
}
return vec4(1.0);
return colorRed;
}
void main() {
sk_FragColor = loopy_h4i(value);
vec4 main() {
return loopy_h4();
}

View File

@ -1,10 +1,10 @@
out vec4 sk_FragColor;
uniform int value;
void main() {
vec4 _0_result = vec4(1.0);
for (int _1_x = 0;_1_x < 5; ++_1_x) {
if (_1_x == value) _0_result = vec4(0.5);
uniform vec4 colorGreen;
vec4 main() {
vec4 _0_result;
for (int _1_x = 0;_1_x < 4; ++_1_x) {
_0_result[_1_x] = colorGreen[_1_x];
}
sk_FragColor = _0_result;
return _0_result;
}

View File

@ -1,10 +1,12 @@
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
vec4 c = color;
if (c.x >= 0.5) {
c = color + vec4(0.125);
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 c = colorRed;
if (colorGreen.y == 1.0) {
vec4 _0_x = colorGreen;
c = _0_x;
}
sk_FragColor = c;
return c;
}

View File

@ -1,10 +1,12 @@
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
vec4 c = color;
if (c.x >= 0.5) ; else {
c = color + vec4(0.125);
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 c = colorRed;
if (colorGreen.y == 0.0) ; else {
vec4 _0_x = colorGreen;
c = _0_x;
}
sk_FragColor = c;
return c;
}

View File

@ -1,29 +1,27 @@
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
vec4 _0_branchy;
vec4 _1_c = color;
_1_c *= 0.5;
if (_1_c.x > 0.0) _0_branchy = _1_c.xxxx; else if (_1_c.y > 0.0) _0_branchy = _1_c.yyyy; else if (_1_c.z > 0.0) _0_branchy = _1_c.zzzz; else _0_branchy = _1_c.wwww;
vec4 _2_branchyAndBlocky;
{
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
float _0_branchy;
if (colorGreen.y == 0.0) _0_branchy = 0.0; else if (colorRed.x == 0.0) _0_branchy = 0.0; else if (colorGreen == colorRed) _0_branchy = 0.0; else _0_branchy = 1.0;
float _1_branchyAndBlocky;
if (colorGreen.y == 0.0) {
{
if (color.x > 0.0) {
vec4 _3_d = color * 0.5;
_2_branchyAndBlocky = _3_d.xxxx;
} else {
{
{
if (color.x < 0.0) {
_2_branchyAndBlocky = color.wwww;
} else {
_2_branchyAndBlocky = color.yyyy;
}
}
}
{
_1_branchyAndBlocky = 0.0;
}
}
} else if (colorRed.x == 0.0) {
{
_1_branchyAndBlocky = 0.0;
}
} else {
if (colorGreen == colorRed) _1_branchyAndBlocky = 0.0; else {
{
_1_branchyAndBlocky = 1.0;
}
}
}
sk_FragColor = _0_branchy * _2_branchyAndBlocky;
return bool(_0_branchy * _1_branchyAndBlocky) ? colorGreen : colorRed;
}

View File

@ -1,6 +1,8 @@
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
if (color.x >= 0.5) sk_FragColor = vec4(1.0); else sk_FragColor = vec4(0.5);
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
bool _0_result = bool(colorGreen.y);
if (_0_result) return colorGreen; else return colorRed;
}

View File

@ -1,8 +1,9 @@
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 _0_branchy;
if (color.z == color.w) _0_branchy = color.yyyy; else _0_branchy = color.zzzz;
sk_FragColor = _0_branchy;
if (colorGreen == colorRed) _0_branchy = colorRed; else _0_branchy = colorGreen;
return _0_branchy;
}

View File

@ -1,5 +1,7 @@
void main() {
out vec4 sk_FragColor;
uniform vec4 colorGreen;
vec4 main() {
int y = 0;
int _0_x = y;
++_0_x;
@ -73,4 +75,5 @@ void main() {
++_1_x;
++_1_x;
y = _1_x;
return colorGreen;
}

View File

@ -1,4 +1,6 @@
out vec4 sk_FragColor;
uniform vec4 colorGreen;
void tooBig_vi(inout int x) {
++x;
++x;
@ -35,8 +37,9 @@ void tooBig_vi(inout int x) {
++x;
++x;
}
void main() {
vec4 main() {
int x = 0;
tooBig_vi(x);
tooBig_vi(x);
return colorGreen;
}

View File

@ -1,10 +1,11 @@
out vec4 sk_FragColor;
void outParameter_vh(inout float x) {
x *= 2.0;
uniform vec4 colorGreen;
void outParameter_vh4(inout vec4 x) {
x *= x;
}
void main() {
float x = 1.0;
outParameter_vh(x);
sk_FragColor.x = x;
vec4 main() {
vec4 c = colorGreen;
outParameter_vh4(c);
return c;
}

View File

@ -1,7 +1,10 @@
out vec4 sk_FragColor;
void main() {
float _0_x = 1.0;
_0_x *= 2.0;
sk_FragColor.x = _0_x;
uniform vec4 colorGreen;
vec4 main() {
vec4 c = colorGreen;
float _0_x = c.y;
_0_x *= _0_x;
c.y = _0_x;
return c;
}

View File

@ -1,8 +1,7 @@
out vec4 sk_FragColor;
uniform float val;
void main() {
float _0_x = val;
vec4 main() {
float _0_x = 12345.0;
++_0_x;
++_0_x;
++_0_x;
@ -37,7 +36,7 @@ void main() {
--_0_x;
--_0_x;
--_0_x;
_0_x = 456.0;
_0_x = 0.0;
float _1_x = _0_x;
++_1_x;
++_1_x;
@ -73,6 +72,6 @@ void main() {
--_1_x;
--_1_x;
--_1_x;
_1_x = 123.0;
sk_FragColor = vec4(_1_x);
_1_x = 1.0;
return vec3(vec2(_1_x), 0.0).zxzy;
}

View File

@ -1,7 +1,11 @@
out vec4 sk_FragColor;
void main() {
sk_FragColor.x = 2.0;
float y = 2.0;
sk_FragColor.y = y * 2.0;
vec4 main() {
float one = 1.0;
vec4 result = vec4(123.0);
result.x = 0.0;
result.z = result.x * result.x;
result.y = 1.0;
result.w = one * one;
return result;
}

View File

@ -1,6 +1,6 @@
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
sk_FragColor = color;
uniform vec4 colorGreen;
vec4 main() {
return colorGreen;
}

View File

@ -1,8 +1,7 @@
out vec4 sk_FragColor;
in vec2 x;
vec4 main() {
vec2 _1_reusedName = x + vec2(1.0, 2.0);
vec2 _2_reusedName = _1_reusedName + vec2(3.0, 4.0);
vec2 _1_reusedName = vec2(1.0, 2.0);
vec2 _2_reusedName = _1_reusedName - 1.0;
return _2_reusedName.xyxy;
}

View File

@ -1,11 +1,12 @@
#version 400
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
vec4 _0_c = color;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 _0_c = colorRed;
{
vec4 _1_d = _0_c * 0.75;
vec4 _1_d = colorGreen;
_0_c = _1_d;
}
sk_FragColor = _0_c.xxxx;
return _0_c;
}

View File

@ -1,12 +1,14 @@
#version 400
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
uniform vec4 colorWhite;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 _0_MakeTempVar;
if (color.x < color.y) {
_0_MakeTempVar = color.xxxx;
if (colorWhite.xy == colorWhite.zw) {
_0_MakeTempVar = colorGreen;
} else {
_0_MakeTempVar = color.yyyy;
_0_MakeTempVar = colorRed;
}
sk_FragColor = _0_MakeTempVar;
return _0_MakeTempVar;
}

View File

@ -1,11 +1,11 @@
#version 400
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
uniform vec4 colorWhite;
vec4 main() {
vec4 _0_MakeTempVar;
{
vec4 _1_d = color * 0.75;
_0_MakeTempVar = _1_d.xxxx;
vec4 _1_d = colorWhite;
_0_MakeTempVar = vec4(0.0, _1_d.y, 0.0, _1_d.w);
}
sk_FragColor = _0_MakeTempVar;
return _0_MakeTempVar;
}

View File

@ -1,8 +1,8 @@
out vec4 sk_FragColor;
uniform vec4 color;
float singleuse_h() {
return 1.25;
uniform vec4 colorGreen;
vec4 multiplyByAlpha_h4h4(vec4 x) {
return x * x.wwww;
}
float add_hhh(float a, float b) {
float c = a + b;
@ -14,7 +14,8 @@ float mul_hhh(float a, float b) {
float fma_hhhh(float a, float b, float c) {
return add_hhh(mul_hhh(a, b), c);
}
void main() {
sk_FragColor = vec4(fma_hhhh(color.x, color.y, color.z));
sk_FragColor *= singleuse_h();
vec4 main() {
vec4 result = vec3(vec2(fma_hhhh(colorGreen.w, colorGreen.y, colorGreen.x)), 0.0).zxzy;
result = multiplyByAlpha_h4h4(result);
return result;
}

View File

@ -1,18 +1,19 @@
out vec4 sk_FragColor;
uniform vec4 color;
uniform vec4 colorWhite;
bool testA_bh4(vec4 v) {
return v.x <= 0.5;
return bool(v.x);
}
bool testB_bh4(vec4 v) {
return v.x > 0.5;
return bool(v.y);
}
void main() {
sk_FragColor = vec4(0.0);
if (color.x <= 0.5 && testB_bh4(color)) {
sk_FragColor = vec4(0.5);
vec4 main() {
vec4 result = vec4(0.0);
if (bool(colorWhite.x) && testB_bh4(colorWhite)) {
result.y = 1.0;
}
if (color.x > 0.5 || testA_bh4(color)) {
sk_FragColor = vec4(1.0);
if (bool(colorWhite.y) || testA_bh4(colorWhite)) {
result.w = 1.0;
}
return result;
}

View File

@ -1,17 +1,16 @@
out vec4 sk_FragColor;
vec4 helper_h4();
struct Color {
float red;
float green;
float blue;
float alpha;
};
void main() {
vec4 main() {
Color _0_c;
_0_c.red = 0.25;
_0_c.green = 0.5;
_0_c.blue = 0.75;
_0_c.red = 0.0;
_0_c.green = 1.0;
_0_c.blue = 0.0;
_0_c.alpha = 1.0;
sk_FragColor = vec4(_0_c.red, _0_c.green, _0_c.blue, _0_c.alpha);
return vec4(_0_c.red, _0_c.green, _0_c.blue, _0_c.alpha);
}

View File

@ -1,9 +1,6 @@
out vec4 sk_FragColor;
uniform vec4 inColor;
void main() {
vec4 color = inColor;
sk_FragColor = color.yzyx;
sk_FragColor = color.yzyx;
sk_FragColor = color;
uniform vec4 colorRed;
vec4 main() {
return colorRed.yxzw;
}

View File

@ -1,16 +1,13 @@
out vec4 sk_FragColor;
uniform vec4 color;
float count = 0.0;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 trueSide_h4h4(vec4 v) {
count += 1.0;
return vec4(sin(v.x), sin(v.y), sin(v.z), sin(v.w));
return vec4(v.x, 1.0, v.zw);
}
vec4 falseSide_h4h4(vec4 v) {
count += 1.0;
return vec4(cos(v.y), cos(v.z), cos(v.w), cos(v.z));
return vec4(v.x, 0.0, v.zw);
}
void main() {
sk_FragColor = color.x <= 0.5 ? trueSide_h4h4(color) : falseSide_h4h4(color);
sk_FragColor *= count;
vec4 main() {
return bool(colorGreen.y) ? trueSide_h4h4(colorGreen) : falseSide_h4h4(colorRed);
}

View File

@ -1,6 +1,7 @@
out vec4 sk_FragColor;
uniform vec4 color;
void main() {
sk_FragColor = color.x <= 0.5 ? vec4(0.5) : vec4(1.0);
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
return bool(colorGreen.y) ? colorGreen : colorRed;
}

View File

@ -1,38 +1,40 @@
out vec4 sk_FragColor;
in float val;
uniform int ui;
uniform vec4 uh4;
uniform bool b;
uniform vec4 colorGreen;
uniform float unknownInput;
struct S {
vec4 ah4[1];
float ah[1];
vec4 h4;
float h;
};
void main() {
vec4 main() {
S s;
s.ah4[0] = vec4(val);
s.ah[0] = val;
s.h4 = vec4(val);
s.h = val;
s.ah4[0] = vec4(unknownInput);
s.ah[0] = unknownInput;
s.h4 = vec4(unknownInput);
s.h = unknownInput;
S as[1];
as[0].ah4[0] = vec4(val);
sk_FragColor = sk_FragColor.xxxx;
sk_FragColor = vec4(s.h);
sk_FragColor = b ? sk_FragColor.xxxx : sk_FragColor.yyyy;
sk_FragColor = s.ah4[0].ywyw;
sk_FragColor = as[0].ah4[0].xyxy;
sk_FragColor = s.h4.zzzz;
sk_FragColor = uh4.xyzx;
sk_FragColor = vec4(s.h);
sk_FragColor = vec4(s.h);
sk_FragColor = s.ah4[0].xxxy;
sk_FragColor = uh4;
sk_FragColor = sk_FragColor.yyyy;
sk_FragColor = vec4(-s.h);
sk_FragColor = !b ? sk_FragColor.xxxx : sk_FragColor.yyyy;
sk_FragColor = s.ah4[ui].ywyw;
sk_FragColor = (s.h4.yyy + s.h4.zzz).xyzx;
sk_FragColor = vec4(s.h4.y, 0.0, 0.0, 1.0);
as[0].ah4[0] = vec4(unknownInput);
bool b = bool(unknownInput);
vec4 var;
var = vec4(s.h) * vec4(s.h);
var = vec4(float(b), float(b), float(b), float(!b));
var = s.ah4[0].ywyw * s.ah4[0].wywy;
var = as[0].ah4[0].xyxy * as[0].ah4[0].yxyx;
var = s.h4.zzzz * s.h4.zzzz;
var = colorGreen.xyzx * colorGreen.xyzx;
var = vec4(s.h) * vec4(s.h);
var = vec4(s.h) * vec4(s.h);
var = s.ah4[0].xxxy * s.ah4[0].xxxy;
var = colorGreen * colorGreen;
float _0_h = -s.h;
var = vec4(_0_h) * vec4(_0_h);
bool _1_b = !b;
var = vec4(float(_1_b), float(_1_b), float(_1_b), float(!_1_b));
vec3 _2_h3 = s.h4.yyy + s.h4.zzz;
var = _2_h3.xyzx * _2_h3.xyzx;
vec4 _3_h4 = vec4(s.h4.y, 0.0, 0.0, 1.0);
var = _3_h4 * _3_h4;
return colorGreen;
}

View File

@ -1,8 +1,12 @@
out vec4 sk_FragColor;
void main() {
sk_FragColor = vec4(0.0);
while (sk_FragColor.x < 0.5) {
sk_FragColor = sk_FragColor + vec4(0.125);
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 result = colorRed;
while (result != colorGreen) {
vec4 _0_x = colorGreen;
result = _0_x;
}
return result;
}

View File

@ -1,11 +1,14 @@
out vec4 sk_FragColor;
uniform vec4 colorGreen;
uniform vec4 colorRed;
bool shouldLoop_bh4(vec4 v) {
return v.x < 0.5;
return v != colorGreen;
}
void main() {
sk_FragColor = vec4(0.0);
while (shouldLoop_bh4(sk_FragColor)) {
sk_FragColor += vec4(0.125);
vec4 main() {
vec4 result = colorRed;
while (shouldLoop_bh4(result)) {
result = colorGreen;
}
return result;
}