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/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