Skip to content

Commit 59b2a92

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Add new unit tests for SkSL.
These cover: - Properly configured out-params - Invalid/non-lvalue out-params, which currently cause an SkSL crash - Interactions between the inliner and variable swizzles Change-Id: I4874101236084f273e704d8717149b431d813883 Bug: skia:10753 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319036 Reviewed-by: Brian Osman <[email protected]> Commit-Queue: Brian Osman <[email protected]> Auto-Submit: John Stiles <[email protected]>
1 parent 2bded27 commit 59b2a92

File tree

7 files changed

+125
-0
lines changed

7 files changed

+125
-0
lines changed

gn/sksl_tests.gni

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ sksl_glsl_tests_sources = [
9595
"$_tests/sksl/errors/InterfaceBlockScope.sksl",
9696
"$_tests/sksl/errors/InterfaceBlockStorageModifiers.sksl",
9797
"$_tests/sksl/errors/InvalidAssignment.sksl",
98+
"$_tests/sksl/errors/InvalidOutParams.sksl",
9899
"$_tests/sksl/errors/InvalidUnary.sksl",
99100
"$_tests/sksl/errors/OpenArray.sksl",
100101
"$_tests/sksl/errors/ReturnDifferentType.sksl",
@@ -180,6 +181,7 @@ sksl_glsl_tests_sources = [
180181
"$_tests/sksl/glsl/NumberConversions.sksl",
181182
"$_tests/sksl/glsl/Offset.sksl",
182183
"$_tests/sksl/glsl/Operators.sksl",
184+
"$_tests/sksl/glsl/OutParams.sksl",
183185
"$_tests/sksl/glsl/RectangleTexture.sksl",
184186
"$_tests/sksl/glsl/ResizeMatrix.sksl",
185187
"$_tests/sksl/glsl/SampleMask.sksl",
@@ -247,6 +249,7 @@ sksl_glsl_tests_sources = [
247249
"$_tests/sksl/inliner/SwitchWithCastCanBeInlined.sksl",
248250
"$_tests/sksl/inliner/SwitchWithReturnInsideCannotBeInlined.sksl",
249251
"$_tests/sksl/inliner/SwitchWithoutReturnInsideCanBeInlined.sksl",
252+
"$_tests/sksl/inliner/SwizzleCanBeInlinedDirectly.sksl",
250253
"$_tests/sksl/inliner/TernaryResultsCannotBeInlined.sksl",
251254
"$_tests/sksl/inliner/TernaryTestCanBeInlined.sksl",
252255
"$_tests/sksl/inliner/WhileBodyMustBeInlinedIntoAScope.sksl",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void inc1(out float x) { x++; }
2+
void inc4(out float4 x) { x += half4(1); }
3+
4+
void test_a() { inc1(0); }
5+
void test_b() { inc4(float4(0)); }
6+
void test_c() { inc1(sqrt(1)); }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Compilation failed:
2+
3+

tests/sksl/glsl/OutParams.sksl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
void out_half (out half v) { v = 1; }
2+
void out_half2(out half2 v) { v = half2(2); }
3+
void out_half3(out half3 v) { v = half3(3); }
4+
void out_half4(out half4 v) { v = half4(4); }
5+
6+
void out_half2x2(out half2x2 v) { v = half2x2(2); }
7+
void out_half3x3(out half3x3 v) { v = half3x3(3); }
8+
void out_half4x4(out half4x4 v) { v = half4x4(4); }
9+
10+
void out_int (out int v) { v = 1; }
11+
void out_int2(out int2 v) { v = int2(2); }
12+
void out_int3(out int3 v) { v = int3(3); }
13+
void out_int4(out int4 v) { v = int4(4); }
14+
15+
void out_float (out float v) { v = 1; }
16+
void out_float2(out float2 v) { v = float2(2); }
17+
void out_float3(out float3 v) { v = float3(3); }
18+
void out_float4(out float4 v) { v = float4(4); }
19+
20+
void out_float2x2(out float2x2 v) { v = float2x2(2); }
21+
void out_float3x3(out float3x3 v) { v = float3x3(3); }
22+
void out_float4x4(out float4x4 v) { v = float4x4(4); }
23+
24+
void out_bool (out bool v) { v = true; }
25+
void out_bool2(out bool2 v) { v = bool2(false); }
26+
void out_bool3(out bool3 v) { v = bool3(true); }
27+
void out_bool4(out bool4 v) { v = bool4(false); }
28+
29+
void main() {
30+
half h; out_half (h);
31+
half2 h2; out_half2(h2);
32+
half3 h3; out_half3(h3);
33+
half4 h4; out_half4(h4);
34+
sk_FragColor = half4(h, h2.x, h3.x, h4.x);
35+
36+
half2x2 h2x2; out_half2x2(h2x2);
37+
half3x3 h3x3; out_half3x3(h3x3);
38+
half4x4 h4x4; out_half4x4(h4x4);
39+
sk_FragColor = half4(h2x2[0][0], h3x3[0][0], h4x4[0][0], 1);
40+
41+
int i; out_int (i);
42+
int2 i2; out_int2(i2);
43+
int3 i3; out_int3(i3);
44+
int4 i4; out_int4(i4);
45+
sk_FragColor = half4(i, i2.x, i3.x, i4.x);
46+
47+
float f; out_float (f);
48+
float2 f2; out_float2(f2);
49+
float3 f3; out_float3(f3);
50+
float4 f4; out_float4(f4);
51+
sk_FragColor = half4(half(f), half(f2.x), half(f3.x), half(f4.x));
52+
53+
float2x2 f2x2; out_float2x2(f2x2);
54+
float3x3 f3x3; out_float3x3(f3x3);
55+
float4x4 f4x4; out_float4x4(f4x4);
56+
sk_FragColor = half4(half(f2x2[0][0]), half(f3x3[0][0]), half(f4x4[0][0]), 1);
57+
58+
bool b; out_bool (b);
59+
bool2 b2; out_bool2(b2);
60+
bool3 b3; out_bool3(b3);
61+
bool4 b4; out_bool4(b4);
62+
sk_FragColor = half4(half(b), half(b2.x), half(b3.x), half(b4.x));
63+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
out vec4 sk_FragColor;
3+
void main() {
4+
sk_FragColor = vec4(1.0, 2.0, 3.0, 4.0);
5+
sk_FragColor = vec4(mat2(2.0)[0][0], mat3(3.0)[0][0], mat4(4.0)[0][0], 1.0);
6+
sk_FragColor = vec4(1.0, 2.0, 3.0, 4.0);
7+
sk_FragColor = vec4(1.0, 2.0, 3.0, 4.0);
8+
sk_FragColor = vec4(mat2(2.0)[0][0], mat3(3.0)[0][0], mat4(4.0)[0][0], 1.0);
9+
sk_FragColor = vec4(1.0, bvec2(false).x ? 1.0 : 0.0, bvec3(true).x ? 1.0 : 0.0, bvec4(false).x ? 1.0 : 0.0);
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
uniform half4 inColor;
2+
3+
half4 flip(half4 v) {
4+
return v.wzyx;
5+
}
6+
7+
void mutating_flip(out half4 v) {
8+
v = v.wzyx;
9+
}
10+
11+
void main() {
12+
half4 color = inColor;
13+
14+
sk_FragColor = color.xyzy.wzyx;
15+
sk_FragColor = flip(color.xyzy);
16+
17+
mutating_flip(color);
18+
sk_FragColor = color;
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
out vec4 sk_FragColor;
3+
uniform vec4 inColor;
4+
void main() {
5+
vec4 color = inColor;
6+
sk_FragColor = color.yzyx;
7+
vec4 _0_flip;
8+
vec4 _1_v = color.xyzy;
9+
{
10+
_0_flip = _1_v.wzyx;
11+
}
12+
13+
sk_FragColor = _0_flip;
14+
15+
{
16+
color = color.wzyx;
17+
}
18+
19+
20+
sk_FragColor = color;
21+
}

0 commit comments

Comments
 (0)