From 0c9d888748f739e08931540e491a142890070cc3 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Thu, 25 Mar 2021 17:04:36 -0400 Subject: [PATCH] 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 Commit-Queue: Ethan Nicholas Reviewed-by: Ethan Nicholas --- .../DoWhileBodyMustBeInlinedIntoAScope.sksl | 16 +++-- .../inliner/DoWhileTestCannotBeInlined.sksl | 15 ++-- .../sksl/inliner/EnumsCanBeInlinedSafely.sksl | 14 ++-- .../ForBodyMustBeInlinedIntoAScope.sksl | 15 ++-- ...ForInitializerExpressionsCanBeInlined.sksl | 5 +- .../ForWithReturnInsideCannotBeInlined.sksl | 14 ++-- .../ForWithoutReturnInsideCanBeInlined.sksl | 14 ++-- .../IfBodyMustBeInlinedIntoAScope.sksl | 13 ++-- .../IfElseBodyMustBeInlinedIntoAScope.sksl | 13 ++-- .../IfElseChainWithReturnsCanBeInlined.sksl | 46 ++++++------- .../sksl/inliner/IfTestCanBeInlined.sksl | 15 ++-- .../inliner/IfWithReturnsCanBeInlined.sksl | 8 +-- .../InlineKeywordOverridesThreshold.sksl | 5 +- resources/sksl/inliner/InlineThreshold.sksl | 5 +- .../sksl/inliner/InlineWithInoutArgument.sksl | 14 ++-- .../inliner/InlineWithModifiedArgument.sksl | 10 ++- .../inliner/InlineWithNestedBigCalls.sksl | 10 ++- .../inliner/InlineWithUnmodifiedArgument.sksl | 16 +++-- .../inliner/InlineWithUnnecessaryBlocks.sksl | 6 +- .../InlinerAvoidsVariableNameOverlap.sksl | 6 +- ...nerElidesTempVarForReturnsInsideBlock.sksl | 10 +-- .../InlinerUsesTempVarForMultipleReturns.sksl | 12 ++-- ...esTempVarForReturnsInsideBlockWithVar.sksl | 10 +-- resources/sksl/inliner/NoInline.sksl | 14 ++-- ...tEvaluationsCannotInlineRightHandSide.sksl | 19 +++--- .../inliner/StructsCanBeInlinedSafely.sksl | 16 ++--- .../inliner/SwizzleCanBeInlinedDirectly.sksl | 15 ++-- .../TernaryResultsCannotBeInlined.sksl | 14 ++-- .../sksl/inliner/TernaryTestCanBeInlined.sksl | 8 +-- .../TrivialArgumentsInlineDirectly.sksl | 68 ++++++++++--------- .../WhileBodyMustBeInlinedIntoAScope.sksl | 17 +++-- .../inliner/WhileTestCannotBeInlined.sksl | 13 ++-- tests/SkSLTest.cpp | 42 +++++++++++- .../DoWhileBodyMustBeInlinedIntoAScope.glsl | 12 ++-- .../inliner/DoWhileTestCannotBeInlined.glsl | 15 ++-- .../sksl/inliner/EnumsCanBeInlinedSafely.glsl | 14 ++-- .../ForBodyMustBeInlinedIntoAScope.glsl | 9 ++- ...ForInitializerExpressionsCanBeInlined.glsl | 4 +- .../ForWithReturnInsideCannotBeInlined.glsl | 15 ++-- .../ForWithoutReturnInsideCanBeInlined.glsl | 12 ++-- .../IfBodyMustBeInlinedIntoAScope.glsl | 14 ++-- .../IfElseBodyMustBeInlinedIntoAScope.glsl | 14 ++-- .../IfElseChainWithReturnsCanBeInlined.glsl | 42 ++++++------ tests/sksl/inliner/IfTestCanBeInlined.glsl | 8 ++- .../inliner/IfWithReturnsCanBeInlined.glsl | 9 +-- .../InlineKeywordOverridesThreshold.glsl | 5 +- tests/sksl/inliner/InlineThreshold.glsl | 5 +- .../sksl/inliner/InlineWithInoutArgument.glsl | 13 ++-- .../inliner/InlineWithModifiedArgument.glsl | 11 +-- .../inliner/InlineWithNestedBigCalls.glsl | 11 ++- .../inliner/InlineWithUnmodifiedArgument.glsl | 12 ++-- .../inliner/InlineWithUnnecessaryBlocks.glsl | 6 +- .../InlinerAvoidsVariableNameOverlap.glsl | 5 +- ...nerElidesTempVarForReturnsInsideBlock.glsl | 11 +-- .../InlinerUsesTempVarForMultipleReturns.glsl | 14 ++-- ...esTempVarForReturnsInsideBlockWithVar.glsl | 10 +-- tests/sksl/inliner/NoInline.glsl | 13 ++-- ...tEvaluationsCannotInlineRightHandSide.glsl | 19 +++--- .../inliner/StructsCanBeInlinedSafely.glsl | 11 ++- .../inliner/SwizzleCanBeInlinedDirectly.glsl | 9 +-- .../TernaryResultsCannotBeInlined.glsl | 15 ++-- .../sksl/inliner/TernaryTestCanBeInlined.glsl | 7 +- .../TrivialArgumentsInlineDirectly.glsl | 56 +++++++-------- .../WhileBodyMustBeInlinedIntoAScope.glsl | 12 ++-- .../inliner/WhileTestCannotBeInlined.glsl | 13 ++-- 65 files changed, 529 insertions(+), 415 deletions(-) diff --git a/resources/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl b/resources/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl index 57fafc516a..2e09fd7698 100644 --- a/resources/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl +++ b/resources/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl @@ -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; } diff --git a/resources/sksl/inliner/DoWhileTestCannotBeInlined.sksl b/resources/sksl/inliner/DoWhileTestCannotBeInlined.sksl index 1697053dea..be2885815c 100644 --- a/resources/sksl/inliner/DoWhileTestCannotBeInlined.sksl +++ b/resources/sksl/inliner/DoWhileTestCannotBeInlined.sksl @@ -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; } diff --git a/resources/sksl/inliner/EnumsCanBeInlinedSafely.sksl b/resources/sksl/inliner/EnumsCanBeInlinedSafely.sksl index b53c82eef4..252740ad71 100644 --- a/resources/sksl/inliner/EnumsCanBeInlinedSafely.sksl +++ b/resources/sksl/inliner/EnumsCanBeInlinedSafely.sksl @@ -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; } } diff --git a/resources/sksl/inliner/ForBodyMustBeInlinedIntoAScope.sksl b/resources/sksl/inliner/ForBodyMustBeInlinedIntoAScope.sksl index 2fc8e2633e..bd9b678415 100644 --- a/resources/sksl/inliner/ForBodyMustBeInlinedIntoAScope.sksl +++ b/resources/sksl/inliner/ForBodyMustBeInlinedIntoAScope.sksl @@ -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; } diff --git a/resources/sksl/inliner/ForInitializerExpressionsCanBeInlined.sksl b/resources/sksl/inliner/ForInitializerExpressionsCanBeInlined.sksl index d793be1336..afece2ca34 100644 --- a/resources/sksl/inliner/ForInitializerExpressionsCanBeInlined.sksl +++ b/resources/sksl/inliner/ForInitializerExpressionsCanBeInlined.sksl @@ -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; } diff --git a/resources/sksl/inliner/ForWithReturnInsideCannotBeInlined.sksl b/resources/sksl/inliner/ForWithReturnInsideCannotBeInlined.sksl index 39998dcbeb..c36acb794f 100644 --- a/resources/sksl/inliner/ForWithReturnInsideCannotBeInlined.sksl +++ b/resources/sksl/inliner/ForWithReturnInsideCannotBeInlined.sksl @@ -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(); } diff --git a/resources/sksl/inliner/ForWithoutReturnInsideCanBeInlined.sksl b/resources/sksl/inliner/ForWithoutReturnInsideCanBeInlined.sksl index 178d1e1167..e6efadeaa7 100644 --- a/resources/sksl/inliner/ForWithoutReturnInsideCanBeInlined.sksl +++ b/resources/sksl/inliner/ForWithoutReturnInsideCanBeInlined.sksl @@ -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(); } diff --git a/resources/sksl/inliner/IfBodyMustBeInlinedIntoAScope.sksl b/resources/sksl/inliner/IfBodyMustBeInlinedIntoAScope.sksl index fd18de61a8..36d8522a88 100644 --- a/resources/sksl/inliner/IfBodyMustBeInlinedIntoAScope.sksl +++ b/resources/sksl/inliner/IfBodyMustBeInlinedIntoAScope.sksl @@ -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; } diff --git a/resources/sksl/inliner/IfElseBodyMustBeInlinedIntoAScope.sksl b/resources/sksl/inliner/IfElseBodyMustBeInlinedIntoAScope.sksl index d6bb0ed718..7b14319cb2 100644 --- a/resources/sksl/inliner/IfElseBodyMustBeInlinedIntoAScope.sksl +++ b/resources/sksl/inliner/IfElseBodyMustBeInlinedIntoAScope.sksl @@ -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; } diff --git a/resources/sksl/inliner/IfElseChainWithReturnsCanBeInlined.sksl b/resources/sksl/inliner/IfElseChainWithReturnsCanBeInlined.sksl index 50cc320d26..977969bb3e 100644 --- a/resources/sksl/inliner/IfElseChainWithReturnsCanBeInlined.sksl +++ b/resources/sksl/inliner/IfElseChainWithReturnsCanBeInlined.sksl @@ -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; } diff --git a/resources/sksl/inliner/IfTestCanBeInlined.sksl b/resources/sksl/inliner/IfTestCanBeInlined.sksl index ac3e0db804..15f10fa96c 100644 --- a/resources/sksl/inliner/IfTestCanBeInlined.sksl +++ b/resources/sksl/inliner/IfTestCanBeInlined.sksl @@ -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; } diff --git a/resources/sksl/inliner/IfWithReturnsCanBeInlined.sksl b/resources/sksl/inliner/IfWithReturnsCanBeInlined.sksl index fc53428218..a8839f5678 100644 --- a/resources/sksl/inliner/IfWithReturnsCanBeInlined.sksl +++ b/resources/sksl/inliner/IfWithReturnsCanBeInlined.sksl @@ -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); } diff --git a/resources/sksl/inliner/InlineKeywordOverridesThreshold.sksl b/resources/sksl/inliner/InlineKeywordOverridesThreshold.sksl index bfb3916af3..12fcba9fe7 100644 --- a/resources/sksl/inliner/InlineKeywordOverridesThreshold.sksl +++ b/resources/sksl/inliner/InlineKeywordOverridesThreshold.sksl @@ -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; } diff --git a/resources/sksl/inliner/InlineThreshold.sksl b/resources/sksl/inliner/InlineThreshold.sksl index bfca1f0cf8..8e5fda0304 100644 --- a/resources/sksl/inliner/InlineThreshold.sksl +++ b/resources/sksl/inliner/InlineThreshold.sksl @@ -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; } diff --git a/resources/sksl/inliner/InlineWithInoutArgument.sksl b/resources/sksl/inliner/InlineWithInoutArgument.sksl index 4b1052852c..b26fb57080 100644 --- a/resources/sksl/inliner/InlineWithInoutArgument.sksl +++ b/resources/sksl/inliner/InlineWithInoutArgument.sksl @@ -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; } diff --git a/resources/sksl/inliner/InlineWithModifiedArgument.sksl b/resources/sksl/inliner/InlineWithModifiedArgument.sksl index 4574475d0b..5d841f96c6 100644 --- a/resources/sksl/inliner/InlineWithModifiedArgument.sksl +++ b/resources/sksl/inliner/InlineWithModifiedArgument.sksl @@ -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; } diff --git a/resources/sksl/inliner/InlineWithNestedBigCalls.sksl b/resources/sksl/inliner/InlineWithNestedBigCalls.sksl index 877c7b9427..c9d96c5936 100644 --- a/resources/sksl/inliner/InlineWithNestedBigCalls.sksl +++ b/resources/sksl/inliner/InlineWithNestedBigCalls.sksl @@ -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; } diff --git a/resources/sksl/inliner/InlineWithUnmodifiedArgument.sksl b/resources/sksl/inliner/InlineWithUnmodifiedArgument.sksl index ad6f596ff5..6bab818bcd 100644 --- a/resources/sksl/inliner/InlineWithUnmodifiedArgument.sksl +++ b/resources/sksl/inliner/InlineWithUnmodifiedArgument.sksl @@ -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; } diff --git a/resources/sksl/inliner/InlineWithUnnecessaryBlocks.sksl b/resources/sksl/inliner/InlineWithUnnecessaryBlocks.sksl index 77d9d37687..87bd1ea21a 100644 --- a/resources/sksl/inliner/InlineWithUnnecessaryBlocks.sksl +++ b/resources/sksl/inliner/InlineWithUnnecessaryBlocks.sksl @@ -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); } diff --git a/resources/sksl/inliner/InlinerAvoidsVariableNameOverlap.sksl b/resources/sksl/inliner/InlinerAvoidsVariableNameOverlap.sksl index cf8c8f50e1..48c52e1cfb 100644 --- a/resources/sksl/inliner/InlinerAvoidsVariableNameOverlap.sksl +++ b/resources/sksl/inliner/InlinerAvoidsVariableNameOverlap.sksl @@ -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); } diff --git a/resources/sksl/inliner/InlinerElidesTempVarForReturnsInsideBlock.sksl b/resources/sksl/inliner/InlinerElidesTempVarForReturnsInsideBlock.sksl index e7e0ee24f7..45ce07b45f 100644 --- a/resources/sksl/inliner/InlinerElidesTempVarForReturnsInsideBlock.sksl +++ b/resources/sksl/inliner/InlinerElidesTempVarForReturnsInsideBlock.sksl @@ -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); } diff --git a/resources/sksl/inliner/InlinerUsesTempVarForMultipleReturns.sksl b/resources/sksl/inliner/InlinerUsesTempVarForMultipleReturns.sksl index 3ae7c39bf5..b25b6a8f15 100644 --- a/resources/sksl/inliner/InlinerUsesTempVarForMultipleReturns.sksl +++ b/resources/sksl/inliner/InlinerUsesTempVarForMultipleReturns.sksl @@ -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); } diff --git a/resources/sksl/inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.sksl b/resources/sksl/inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.sksl index 64f3c3e368..e66c6e729a 100644 --- a/resources/sksl/inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.sksl +++ b/resources/sksl/inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.sksl @@ -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); } diff --git a/resources/sksl/inliner/NoInline.sksl b/resources/sksl/inliner/NoInline.sksl index 510c62a30f..cee916b892 100644 --- a/resources/sksl/inliner/NoInline.sksl +++ b/resources/sksl/inliner/NoInline.sksl @@ -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; } diff --git a/resources/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.sksl b/resources/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.sksl index fef0d619e6..0ea6102f18 100644 --- a/resources/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.sksl +++ b/resources/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.sksl @@ -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; } diff --git a/resources/sksl/inliner/StructsCanBeInlinedSafely.sksl b/resources/sksl/inliner/StructsCanBeInlinedSafely.sksl index a550ebfaba..491e79a56b 100644 --- a/resources/sksl/inliner/StructsCanBeInlinedSafely.sksl +++ b/resources/sksl/inliner/StructsCanBeInlinedSafely.sksl @@ -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(); +} diff --git a/resources/sksl/inliner/SwizzleCanBeInlinedDirectly.sksl b/resources/sksl/inliner/SwizzleCanBeInlinedDirectly.sksl index e156a48c85..1ead572edc 100644 --- a/resources/sksl/inliner/SwizzleCanBeInlinedDirectly.sksl +++ b/resources/sksl/inliner/SwizzleCanBeInlinedDirectly.sksl @@ -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))); } diff --git a/resources/sksl/inliner/TernaryResultsCannotBeInlined.sksl b/resources/sksl/inliner/TernaryResultsCannotBeInlined.sksl index b961ae1284..f46811628b 100644 --- a/resources/sksl/inliner/TernaryResultsCannotBeInlined.sksl +++ b/resources/sksl/inliner/TernaryResultsCannotBeInlined.sksl @@ -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); } diff --git a/resources/sksl/inliner/TernaryTestCanBeInlined.sksl b/resources/sksl/inliner/TernaryTestCanBeInlined.sksl index 25523eb90c..b323a8e590 100644 --- a/resources/sksl/inliner/TernaryTestCanBeInlined.sksl +++ b/resources/sksl/inliner/TernaryTestCanBeInlined.sksl @@ -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; } diff --git a/resources/sksl/inliner/TrivialArgumentsInlineDirectly.sksl b/resources/sksl/inliner/TrivialArgumentsInlineDirectly.sksl index 4619ec0aea..2a0e7374fc 100644 --- a/resources/sksl/inliner/TrivialArgumentsInlineDirectly.sksl +++ b/resources/sksl/inliner/TrivialArgumentsInlineDirectly.sksl @@ -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; } diff --git a/resources/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.sksl b/resources/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.sksl index 9adaf4a5ad..19e46deab6 100644 --- a/resources/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.sksl +++ b/resources/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.sksl @@ -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; } diff --git a/resources/sksl/inliner/WhileTestCannotBeInlined.sksl b/resources/sksl/inliner/WhileTestCannotBeInlined.sksl index 2f734e7c4c..9f6e57a4ec 100644 --- a/resources/sksl/inliner/WhileTestCannotBeInlined.sksl +++ b/resources/sksl/inliner/WhileTestCannotBeInlined.sksl @@ -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; } diff --git a/tests/SkSLTest.cpp b/tests/SkSLTest.cpp index 6177144b3f..584bb2dc72 100644 --- a/tests/SkSLTest.cpp +++ b/tests/SkSLTest.cpp @@ -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") diff --git a/tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.glsl b/tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.glsl index 7d314e19bc..d586189a9f 100644 --- a/tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.glsl +++ b/tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.glsl @@ -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; } diff --git a/tests/sksl/inliner/DoWhileTestCannotBeInlined.glsl b/tests/sksl/inliner/DoWhileTestCannotBeInlined.glsl index b3e2f90a02..0d0ec899f3 100644 --- a/tests/sksl/inliner/DoWhileTestCannotBeInlined.glsl +++ b/tests/sksl/inliner/DoWhileTestCannotBeInlined.glsl @@ -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; } diff --git a/tests/sksl/inliner/EnumsCanBeInlinedSafely.glsl b/tests/sksl/inliner/EnumsCanBeInlinedSafely.glsl index e34efeab19..d7581d6e58 100644 --- a/tests/sksl/inliner/EnumsCanBeInlinedSafely.glsl +++ b/tests/sksl/inliner/EnumsCanBeInlinedSafely.glsl @@ -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; } } diff --git a/tests/sksl/inliner/ForBodyMustBeInlinedIntoAScope.glsl b/tests/sksl/inliner/ForBodyMustBeInlinedIntoAScope.glsl index 4e1ac2db84..91e558585a 100644 --- a/tests/sksl/inliner/ForBodyMustBeInlinedIntoAScope.glsl +++ b/tests/sksl/inliner/ForBodyMustBeInlinedIntoAScope.glsl @@ -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; } diff --git a/tests/sksl/inliner/ForInitializerExpressionsCanBeInlined.glsl b/tests/sksl/inliner/ForInitializerExpressionsCanBeInlined.glsl index 4e0bb499ba..29c2e35d98 100644 --- a/tests/sksl/inliner/ForInitializerExpressionsCanBeInlined.glsl +++ b/tests/sksl/inliner/ForInitializerExpressionsCanBeInlined.glsl @@ -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; } diff --git a/tests/sksl/inliner/ForWithReturnInsideCannotBeInlined.glsl b/tests/sksl/inliner/ForWithReturnInsideCannotBeInlined.glsl index 50b191188c..993f6e9673 100644 --- a/tests/sksl/inliner/ForWithReturnInsideCannotBeInlined.glsl +++ b/tests/sksl/inliner/ForWithReturnInsideCannotBeInlined.glsl @@ -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(); } diff --git a/tests/sksl/inliner/ForWithoutReturnInsideCanBeInlined.glsl b/tests/sksl/inliner/ForWithoutReturnInsideCanBeInlined.glsl index c0c972e320..43f91704dc 100644 --- a/tests/sksl/inliner/ForWithoutReturnInsideCanBeInlined.glsl +++ b/tests/sksl/inliner/ForWithoutReturnInsideCanBeInlined.glsl @@ -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; } diff --git a/tests/sksl/inliner/IfBodyMustBeInlinedIntoAScope.glsl b/tests/sksl/inliner/IfBodyMustBeInlinedIntoAScope.glsl index 14f6735465..f83972329f 100644 --- a/tests/sksl/inliner/IfBodyMustBeInlinedIntoAScope.glsl +++ b/tests/sksl/inliner/IfBodyMustBeInlinedIntoAScope.glsl @@ -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; } diff --git a/tests/sksl/inliner/IfElseBodyMustBeInlinedIntoAScope.glsl b/tests/sksl/inliner/IfElseBodyMustBeInlinedIntoAScope.glsl index 7c111aa81f..6a53909bc0 100644 --- a/tests/sksl/inliner/IfElseBodyMustBeInlinedIntoAScope.glsl +++ b/tests/sksl/inliner/IfElseBodyMustBeInlinedIntoAScope.glsl @@ -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; } diff --git a/tests/sksl/inliner/IfElseChainWithReturnsCanBeInlined.glsl b/tests/sksl/inliner/IfElseChainWithReturnsCanBeInlined.glsl index f87dadf8a2..b14049fbe5 100644 --- a/tests/sksl/inliner/IfElseChainWithReturnsCanBeInlined.glsl +++ b/tests/sksl/inliner/IfElseChainWithReturnsCanBeInlined.glsl @@ -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; } diff --git a/tests/sksl/inliner/IfTestCanBeInlined.glsl b/tests/sksl/inliner/IfTestCanBeInlined.glsl index 72d28bff09..a5f0dfd170 100644 --- a/tests/sksl/inliner/IfTestCanBeInlined.glsl +++ b/tests/sksl/inliner/IfTestCanBeInlined.glsl @@ -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; } diff --git a/tests/sksl/inliner/IfWithReturnsCanBeInlined.glsl b/tests/sksl/inliner/IfWithReturnsCanBeInlined.glsl index c2d8b1ee6d..85389d2a32 100644 --- a/tests/sksl/inliner/IfWithReturnsCanBeInlined.glsl +++ b/tests/sksl/inliner/IfWithReturnsCanBeInlined.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlineKeywordOverridesThreshold.glsl b/tests/sksl/inliner/InlineKeywordOverridesThreshold.glsl index f129c4646d..52334cab1f 100644 --- a/tests/sksl/inliner/InlineKeywordOverridesThreshold.glsl +++ b/tests/sksl/inliner/InlineKeywordOverridesThreshold.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlineThreshold.glsl b/tests/sksl/inliner/InlineThreshold.glsl index baa9607c53..685253c4a6 100644 --- a/tests/sksl/inliner/InlineThreshold.glsl +++ b/tests/sksl/inliner/InlineThreshold.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlineWithInoutArgument.glsl b/tests/sksl/inliner/InlineWithInoutArgument.glsl index bbe8f0b6ce..1989cf815f 100644 --- a/tests/sksl/inliner/InlineWithInoutArgument.glsl +++ b/tests/sksl/inliner/InlineWithInoutArgument.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlineWithModifiedArgument.glsl b/tests/sksl/inliner/InlineWithModifiedArgument.glsl index c15f9dbd0c..e5224f8b2b 100644 --- a/tests/sksl/inliner/InlineWithModifiedArgument.glsl +++ b/tests/sksl/inliner/InlineWithModifiedArgument.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlineWithNestedBigCalls.glsl b/tests/sksl/inliner/InlineWithNestedBigCalls.glsl index b7e1cef46e..e7b33e2f76 100644 --- a/tests/sksl/inliner/InlineWithNestedBigCalls.glsl +++ b/tests/sksl/inliner/InlineWithNestedBigCalls.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlineWithUnmodifiedArgument.glsl b/tests/sksl/inliner/InlineWithUnmodifiedArgument.glsl index 6df700f3d7..f5ff2deef3 100644 --- a/tests/sksl/inliner/InlineWithUnmodifiedArgument.glsl +++ b/tests/sksl/inliner/InlineWithUnmodifiedArgument.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlineWithUnnecessaryBlocks.glsl b/tests/sksl/inliner/InlineWithUnnecessaryBlocks.glsl index c3b9813b27..97458bf20d 100644 --- a/tests/sksl/inliner/InlineWithUnnecessaryBlocks.glsl +++ b/tests/sksl/inliner/InlineWithUnnecessaryBlocks.glsl @@ -1,6 +1,6 @@ out vec4 sk_FragColor; -uniform vec4 color; -void main() { - sk_FragColor = color; +uniform vec4 colorGreen; +vec4 main() { + return colorGreen; } diff --git a/tests/sksl/inliner/InlinerAvoidsVariableNameOverlap.glsl b/tests/sksl/inliner/InlinerAvoidsVariableNameOverlap.glsl index b8dbc8337e..85bb2b30ee 100644 --- a/tests/sksl/inliner/InlinerAvoidsVariableNameOverlap.glsl +++ b/tests/sksl/inliner/InlinerAvoidsVariableNameOverlap.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlinerElidesTempVarForReturnsInsideBlock.glsl b/tests/sksl/inliner/InlinerElidesTempVarForReturnsInsideBlock.glsl index 5e5e959ffd..4c324d3ea8 100644 --- a/tests/sksl/inliner/InlinerElidesTempVarForReturnsInsideBlock.glsl +++ b/tests/sksl/inliner/InlinerElidesTempVarForReturnsInsideBlock.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlinerUsesTempVarForMultipleReturns.glsl b/tests/sksl/inliner/InlinerUsesTempVarForMultipleReturns.glsl index 976716dc6e..b689c7e714 100644 --- a/tests/sksl/inliner/InlinerUsesTempVarForMultipleReturns.glsl +++ b/tests/sksl/inliner/InlinerUsesTempVarForMultipleReturns.glsl @@ -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; } diff --git a/tests/sksl/inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.glsl b/tests/sksl/inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.glsl index 45c6951197..758b471a68 100644 --- a/tests/sksl/inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.glsl +++ b/tests/sksl/inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.glsl @@ -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; } diff --git a/tests/sksl/inliner/NoInline.glsl b/tests/sksl/inliner/NoInline.glsl index d634159c4a..bab3c52e75 100644 --- a/tests/sksl/inliner/NoInline.glsl +++ b/tests/sksl/inliner/NoInline.glsl @@ -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; } diff --git a/tests/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.glsl b/tests/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.glsl index 343d4ba2bb..b0de449a02 100644 --- a/tests/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.glsl +++ b/tests/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.glsl @@ -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; } diff --git a/tests/sksl/inliner/StructsCanBeInlinedSafely.glsl b/tests/sksl/inliner/StructsCanBeInlinedSafely.glsl index 6b7c0e974b..3d4fcfdc12 100644 --- a/tests/sksl/inliner/StructsCanBeInlinedSafely.glsl +++ b/tests/sksl/inliner/StructsCanBeInlinedSafely.glsl @@ -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); } diff --git a/tests/sksl/inliner/SwizzleCanBeInlinedDirectly.glsl b/tests/sksl/inliner/SwizzleCanBeInlinedDirectly.glsl index 6f19893c72..bb136e08f8 100644 --- a/tests/sksl/inliner/SwizzleCanBeInlinedDirectly.glsl +++ b/tests/sksl/inliner/SwizzleCanBeInlinedDirectly.glsl @@ -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; } diff --git a/tests/sksl/inliner/TernaryResultsCannotBeInlined.glsl b/tests/sksl/inliner/TernaryResultsCannotBeInlined.glsl index dd39a9eb6b..5a0b0f238f 100644 --- a/tests/sksl/inliner/TernaryResultsCannotBeInlined.glsl +++ b/tests/sksl/inliner/TernaryResultsCannotBeInlined.glsl @@ -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); } diff --git a/tests/sksl/inliner/TernaryTestCanBeInlined.glsl b/tests/sksl/inliner/TernaryTestCanBeInlined.glsl index 1b3f0f3ca6..6d6cf6e534 100644 --- a/tests/sksl/inliner/TernaryTestCanBeInlined.glsl +++ b/tests/sksl/inliner/TernaryTestCanBeInlined.glsl @@ -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; } diff --git a/tests/sksl/inliner/TrivialArgumentsInlineDirectly.glsl b/tests/sksl/inliner/TrivialArgumentsInlineDirectly.glsl index 31889464e7..0e65ea662f 100644 --- a/tests/sksl/inliner/TrivialArgumentsInlineDirectly.glsl +++ b/tests/sksl/inliner/TrivialArgumentsInlineDirectly.glsl @@ -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; } diff --git a/tests/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.glsl b/tests/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.glsl index dbebdc046b..de59f070c9 100644 --- a/tests/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.glsl +++ b/tests/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.glsl @@ -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; } diff --git a/tests/sksl/inliner/WhileTestCannotBeInlined.glsl b/tests/sksl/inliner/WhileTestCannotBeInlined.glsl index a9f8910ddf..2b2617adde 100644 --- a/tests/sksl/inliner/WhileTestCannotBeInlined.glsl +++ b/tests/sksl/inliner/WhileTestCannotBeInlined.glsl @@ -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; }