Add unit test for inlining trivial arguments.
Change-Id: I71cefc1ffacd671ede810d9133dfce75cb9f42b4
Bug: skia:10786
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/320958
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni
index eacd6ee..7aaaee3 100644
--- a/gn/sksl_tests.gni
+++ b/gn/sksl_tests.gni
@@ -260,6 +260,7 @@
"$_tests/sksl/inliner/SwizzleCanBeInlinedDirectly.sksl",
"$_tests/sksl/inliner/TernaryResultsCannotBeInlined.sksl",
"$_tests/sksl/inliner/TernaryTestCanBeInlined.sksl",
+ "$_tests/sksl/inliner/TrivialArgumentsInlineDirectly.sksl",
"$_tests/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.sksl",
"$_tests/sksl/inliner/WhileTestCannotBeInlined.sksl",
]
diff --git a/tests/sksl/inliner/TrivialArgumentsInlineDirectly.sksl b/tests/sksl/inliner/TrivialArgumentsInlineDirectly.sksl
new file mode 100644
index 0000000..7b210dd
--- /dev/null
+++ b/tests/sksl/inliner/TrivialArgumentsInlineDirectly.sksl
@@ -0,0 +1,62 @@
+in half val;
+uniform int ui;
+uniform half4 uh4;
+
+struct S {
+ half4 ah4[1];
+ half ah[1];
+ half4 h4;
+ half h;
+};
+
+void funcb(bool b, out half4 outColor) {
+ outColor = b ? outColor.xxxx : outColor.yyyy;
+}
+
+void func1(half h, out half4 outColor) {
+ outColor = h.xxxx;
+}
+
+void func2(half2 h2, out half4 outColor) {
+ outColor = h2.xyxy;
+}
+
+void func3(half3 h3, out half4 outColor) {
+ outColor = h3.xyzx;
+}
+
+void func4(half4 h4, out half4 outColor) {
+ outColor = h4;
+}
+
+void main() {
+ S s;
+ s.ah4[0] = half4(val);
+ s.ah[0] = val;
+ s.h4 = half4(val);
+ s.h = val;
+
+ S as[1];
+ as[0].ah4[0] = half4(val);
+
+ // These expressions are considered "trivial" and will be cloned directly into the inlined
+ // function without a temporary variable.
+ funcb(sk_Caps.floatIs32Bits, sk_FragColor);
+ func1(+s.h, 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);
+ func4(s.ah4[0].xxxy, sk_FragColor);
+ func4(uh4, sk_FragColor);
+
+ // These expressions are considered "non-trivial" and will be placed in a temporary variable
+ // when inlining occurs.
+ funcb(!sk_Caps.floatIs32Bits, sk_FragColor);
+ func1(-s.h, sk_FragColor);
+ func2(s.ah4[ui].yw, sk_FragColor);
+ func3(s.h4.yyy + s.h4.zzz, sk_FragColor);
+ func3(s.h.xxx, sk_FragColor);
+ func4(half4(s.h), sk_FragColor);
+ func4(s.h4.y001, sk_FragColor);
+}
diff --git a/tests/sksl/inliner/golden/TrivialArgumentsInlineDirectly.glsl b/tests/sksl/inliner/golden/TrivialArgumentsInlineDirectly.glsl
new file mode 100644
index 0000000..9e8b2cc
--- /dev/null
+++ b/tests/sksl/inliner/golden/TrivialArgumentsInlineDirectly.glsl
@@ -0,0 +1,101 @@
+
+out vec4 sk_FragColor;
+in float val;
+uniform int ui;
+uniform vec4 uh4;
+void main() {
+ struct S {
+ vec4[1] ah4;
+ float[1] ah;
+ vec4 h4;
+ float h;
+ } s;
+ s.ah4[0] = vec4(val);
+ s.ah[0] = val;
+ s.h4 = vec4(val);
+ s.h = val;
+ S as[1];
+ as[0].ah4[0] = vec4(val);
+ {
+ sk_FragColor = sk_FragColor.xxxx;
+ }
+
+
+ {
+ sk_FragColor = vec4(s.h);
+ }
+
+
+ {
+ sk_FragColor = s.ah4[0].ywyw;
+ }
+
+
+ {
+ sk_FragColor = as[0].ah4[0].xyxy;
+ }
+
+
+ {
+ sk_FragColor = s.h4.zzzz;
+ }
+
+
+ {
+ sk_FragColor = uh4.xyzx;
+ }
+
+
+ {
+ sk_FragColor = s.ah4[0].xxxy;
+ }
+
+
+ {
+ sk_FragColor = uh4;
+ }
+
+
+ bool _1_b = !true;
+ {
+ sk_FragColor = _1_b ? sk_FragColor.xxxx : sk_FragColor.yyyy;
+ }
+
+
+ float _2_h = -s.h;
+ {
+ sk_FragColor = vec4(_2_h);
+ }
+
+
+ vec2 _3_h2 = s.ah4[ui].yw;
+ {
+ sk_FragColor = _3_h2.xyxy;
+ }
+
+
+ vec3 _4_h3 = s.h4.yyy + s.h4.zzz;
+ {
+ sk_FragColor = _4_h3.xyzx;
+ }
+
+
+ vec3 _5_h3 = vec3(s.h);
+ {
+ sk_FragColor = _5_h3.xyzx;
+ }
+
+
+ vec4 _6_h4 = vec4(s.h);
+ {
+ sk_FragColor = _6_h4;
+ }
+
+
+ vec4 _7_h4 = vec3(s.h4.y, 0.0, 1.0).xyyz;
+ {
+ sk_FragColor = _7_h4;
+ }
+
+
+}