Add unit test for return statements wrapped in a block.

The inlining output for these statements is optimized in a followup CL.

Change-Id: I3a9a0fdca27e6a0ce80fe80b8869b1be677a8443
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313207
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-08-25 17:15:56 -04:00 committed by Skia Commit-Bot
parent 3c02c934af
commit c37d551167

View File

@ -1212,6 +1212,40 @@ do {
});
}
DEF_TEST(SkSLFPUnnecessaryBlocksAffectEarlyReturnDetection, r) {
test(r,
*SkSL::ShaderCapsFactory::Default(),
R"__SkSL__(
uniform half4 color;
half4 blocky(half4 c) {
{
return c;
}
}
void main() {
sk_OutColor = blocky(color);
}
)__SkSL__",
/*expectedH=*/{},
/*expectedCPP=*/{
R"__Cpp__(fragBuilder->codeAppendf(
R"SkSL(half4 _inlineResulthalf4blockyhalf40;
half4 _inlineArghalf4blockyhalf41_0 = %s;
do {
{
{
_inlineResulthalf4blockyhalf40 = _inlineArghalf4blockyhalf41_0;
break;
}
}
} while (false);
%s = _inlineResulthalf4blockyhalf40;
)SkSL"
, args.fUniformHandler->getUniformCStr(colorVar), args.fOutputColor);
)__Cpp__"});
}
DEF_TEST(SkSLFPGrSLTypesAreSupported, r) {
// We thwart the optimizer by wrapping our return statement in a loop, which prevents inlining.
test(r,