skia2/resources/sksl/inliner/TrivialArgumentsInlineDirectly.sksl
John Stiles 0c9d888748 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>
2021-03-25 22:58:54 +00:00

70 lines
1.6 KiB
Plaintext

uniform half4 colorGreen;
uniform half unknownInput;
struct S {
half4 ah4[1];
half ah[1];
half4 h4;
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 half4(b, b, b, !b);
}
half4 func1(half h) {
return h.xxxx * h.xxxx;
}
half4 func2(half2 h2) {
return h2.xyxy * h2.yxyx;
}
half4 func3(half3 h3) {
return h3.xyzx * h3.xyzx;
}
half4 func4(half4 h4) {
return h4 * h4;
}
half4 main() {
S s;
s.ah4[0] = half4(unknownInput);
s.ah[0] = unknownInput;
s.h4 = half4(unknownInput);
s.h = unknownInput;
S as[1];
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.
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.
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;
}