Migrate runtime effect sample tests to golden files
Much easier to maintain, especially with an upcoming change to the
sampling syntax.
Change-Id: I378811b7be0afcce5b7e68a942e7b46d96568155
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/441518
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni
index 09d3584..5c1e3c9 100644
--- a/gn/sksl_tests.gni
+++ b/gn/sksl_tests.gni
@@ -550,6 +550,7 @@
"/sksl/runtime_errors/IllegalRecursionComplex.rts",
"/sksl/runtime_errors/IllegalRecursionMutual.rts",
"/sksl/runtime_errors/IllegalRecursionSimple.rts",
+ "/sksl/runtime_errors/IllegalShaderSampling.rts",
"/sksl/runtime_errors/IllegalShaderUse.rts",
"/sksl/runtime_errors/IllegalStatements.rts",
"/sksl/runtime_errors/InvalidBlendMain.rtb",
diff --git a/resources/sksl/runtime_errors/IllegalShaderSampling.rts b/resources/sksl/runtime_errors/IllegalShaderSampling.rts
new file mode 100644
index 0000000..e98c082
--- /dev/null
+++ b/resources/sksl/runtime_errors/IllegalShaderSampling.rts
@@ -0,0 +1,23 @@
+// Expect 12 errors
+
+uniform shader s;
+uniform colorFilter f;
+uniform blender b;
+
+uniform float2 xy;
+uniform half4 color;
+
+half4 shader_xy_color() { return sample(s, xy, color); }
+half4 shader_color() { return sample(s, color); }
+half4 shader_color_xy() { return sample(s, color, xy); }
+half4 shader_empty() { return sample(s); }
+half4 shader_matrix() { return sample(s, float3x3(1)); }
+
+half4 filter_empty() { return sample(f); }
+half4 filter_xy() { return sample(f, xy); }
+half4 filter_xy_color() { return sample(f, xy, color); }
+
+half4 blender_empty() { return sample(b); }
+half4 blender_color() { return sample(b, color); }
+half4 blender_xy() { return sample(b, xy); }
+half4 blender_xy_color() { return sample(b, xy, color); }
\ No newline at end of file
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index 3bad295..312c476 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -121,43 +121,14 @@
// Sampling a child shader requires that we pass explicit coords
test_valid("uniform shader child;"
"half4 main(half4 c) { return sample(child, c.rg); }");
- // Trying to pass a color as well. (Works internally with FPs, but not in runtime effects).
- test_invalid("uniform shader child;"
- "half4 main(half4 c) { return sample(child, c.rg, c); }",
- "no match for sample(shader, half2, half4)");
- // Shader with just a color
- test_invalid("uniform shader child;"
- "half4 main(half4 c) { return sample(child, c); }",
- "no match for sample(shader, half4)");
- // Coords and color in a different order
- test_invalid("uniform shader child;"
- "half4 main(half4 c) { return sample(child, c, c.rg); }",
- "no match for sample(shader, half4, half2)");
-
- // Older variants that are no longer allowed
- test_invalid(
- "uniform shader child;"
- "half4 main(half4 c) { return sample(child); }",
- "no match for sample(shader)");
- test_invalid(
- "uniform shader child;"
- "half4 main(half4 c) { return sample(child, float3x3(1)); }",
- "no match for sample(shader, float3x3)");
-
- // Sampling a colorFilter requires a color. No other signatures are valid.
+ // Sampling a colorFilter requires a color
test_valid("uniform colorFilter child;"
"half4 main(half4 c) { return sample(child, c); }");
- test_invalid("uniform colorFilter child;"
- "half4 main(half4 c) { return sample(child); }",
- "sample(colorFilter)");
- test_invalid("uniform colorFilter child;"
- "half4 main(half4 c) { return sample(child, c.rg); }",
- "sample(colorFilter, half2)");
- test_invalid("uniform colorFilter child;"
- "half4 main(half4 c) { return sample(child, c.rg, c); }",
- "sample(colorFilter, half2, half4)");
+ // Sampling a blender requires two colors
+ test_valid("uniform blender child;"
+ "half4 main(half4 c) { return sample(child, c, c); }");
}
DEF_TEST(SkRuntimeEffectForBlender, r) {
@@ -206,41 +177,14 @@
// Sampling a child shader requires that we pass explicit coords
test_valid("uniform shader child;"
"half4 main(half4 s, half4 d) { return sample(child, s.rg); }");
- // Trying to pass a color as well. (Works internally with FPs, but not in runtime effects).
- test_invalid("uniform shader child;"
- "half4 main(half4 s, half4 d) { return sample(child, s.rg, d); }",
- "no match for sample(shader, half2, half4)");
- // Shader with just a color
- test_invalid("uniform shader child;"
- "half4 main(half4 s, half4 d) { return sample(child, s); }",
- "no match for sample(shader, half4)");
- // Coords and color in a different order
- test_invalid("uniform shader child;"
- "half4 main(half4 s, half4 d) { return sample(child, s, d.rg); }",
- "no match for sample(shader, half4, half2)");
-
- // Older variants that are no longer allowed
- test_invalid("uniform shader child;"
- "half4 main(half4 s, half4 d) { return sample(child); }",
- "no match for sample(shader)");
- test_invalid("uniform shader child;"
- "half4 main(half4 s, half4 d) { return sample(child, float3x3(1)); }",
- "no match for sample(shader, float3x3)");
-
- // Sampling a colorFilter requires a color. No other signatures are valid.
+ // Sampling a colorFilter requires a color
test_valid("uniform colorFilter child;"
"half4 main(half4 s, half4 d) { return sample(child, d); }");
- test_invalid("uniform colorFilter child;"
- "half4 main(half4 s, half4 d) { return sample(child); }",
- "sample(colorFilter)");
- test_invalid("uniform colorFilter child;"
- "half4 main(half4 s, half4 d) { return sample(child, d.rg); }",
- "sample(colorFilter, half2)");
- test_invalid("uniform colorFilter child;"
- "half4 main(half4 s, half4 d) { return sample(child, d.rg, s); }",
- "sample(colorFilter, half2, half4)");
+ // Sampling a blender requires two colors
+ test_valid("uniform blender child;"
+ "half4 main(half4 s, half4 d) { return sample(child, s, d); }");
}
DEF_TEST(SkRuntimeEffectForShader, r) {
@@ -296,43 +240,13 @@
test_valid("uniform shader child;"
"half4 main(float2 p) { return sample(child, p); }");
- // Trying to pass a color as well. (Works internally with FPs, but not in runtime effects).
- test_invalid("uniform shader child;"
- "half4 main(float2 p, half4 c) { return sample(child, p, c); }",
- "no match for sample(shader, float2, half4)");
-
- // Shader with just a color
- test_invalid("uniform shader child;"
- "half4 main(float2 p, half4 c) { return sample(child, c); }",
- "no match for sample(shader, half4)");
- // Coords and color in a different order
- test_invalid("uniform shader child;"
- "half4 main(float2 p, half4 c) { return sample(child, c, p); }",
- "no match for sample(shader, half4, float2)");
-
- // Older variants that are no longer allowed
- test_invalid(
- "uniform shader child;"
- "half4 main(float2 p) { return sample(child); }",
- "no match for sample(shader)");
- test_invalid(
- "uniform shader child;"
- "half4 main(float2 p) { return sample(child, float3x3(1)); }",
- "no match for sample(shader, float3x3)");
-
- // Sampling a colorFilter requires a color. No other signatures are valid.
+ // Sampling a colorFilter requires a color
test_valid("uniform colorFilter child;"
"half4 main(float2 p, half4 c) { return sample(child, c); }");
- test_invalid("uniform colorFilter child;"
- "half4 main(float2 p) { return sample(child); }",
- "sample(colorFilter)");
- test_invalid("uniform colorFilter child;"
- "half4 main(float2 p) { return sample(child, p); }",
- "sample(colorFilter, float2)");
- test_invalid("uniform colorFilter child;"
- "half4 main(float2 p, half4 c) { return sample(child, p, c); }",
- "sample(colorFilter, float2, half4)");
+ // Sampling a blender requires two colors
+ test_valid("uniform blender child;"
+ "half4 main(float2 p, half4 c) { return sample(child, c, c); }");
}
using PreTestFn = std::function<void(SkCanvas*, SkPaint*)>;
diff --git a/tests/sksl/runtime_errors/IllegalShaderSampling.skvm b/tests/sksl/runtime_errors/IllegalShaderSampling.skvm
new file mode 100644
index 0000000..bc6173a
--- /dev/null
+++ b/tests/sksl/runtime_errors/IllegalShaderSampling.skvm
@@ -0,0 +1,15 @@
+### Compilation failed:
+
+error: 10: no match for sample(shader, float2, half4)
+error: 11: no match for sample(shader, half4)
+error: 12: no match for sample(shader, half4, float2)
+error: 13: no match for sample(shader)
+error: 14: no match for sample(shader, float3x3)
+error: 16: no match for sample(colorFilter)
+error: 17: no match for sample(colorFilter, float2)
+error: 18: no match for sample(colorFilter, float2, half4)
+error: 20: no match for sample(blender)
+error: 21: no match for sample(blender, half4)
+error: 22: no match for sample(blender, float2)
+error: 23: no match for sample(blender, float2, half4)
+12 errors