Runtime Effects: Support 'uniform shader' (vs. 'in shader')
The previous behavior leaked Skia-internal concepts into public SkSL.
Users coming from GLSL will expect that bindable/sampleable objects are
uniform (just like texture2D). This keeps the old support around (and
tested), but updates all of our examples to use 'uniform'.
Bug: skia:10679
Change-Id: I0c98162f5e21dad7014d9778ceb26143d2f6030e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332376
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index ed04972..4a815aa 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -62,16 +62,16 @@
test("",
"shader child;",
"must be global");
- test("in shader child; half4 helper(shader fp) { return sample(fp); }",
+ test("uniform shader child; half4 helper(shader fp) { return sample(fp); }",
"half4 color = helper(child);",
"parameter");
- test("in shader child; shader get_child() { return child; }",
+ test("uniform shader child; shader get_child() { return child; }",
"half4 color = sample(get_child());",
"return");
- test("in shader child;",
+ test("uniform shader child;",
"half4 color = sample(shader(child));",
"construct");
- test("in shader child1; in shader child2;",
+ test("uniform shader child1; uniform shader child2;",
"half4 color = sample(p.x > 10 ? child1 : child2);",
"expression");
@@ -232,7 +232,7 @@
//
// Sampling a null child should return the paint color
- effect.build("in shader child;",
+ effect.build("uniform shader child;",
"return sample(child);");
effect.child("child") = nullptr;
effect.test(0xFF00FFFF,
@@ -241,23 +241,29 @@
sk_sp<SkShader> rgbwShader = make_RGBW_shader();
// Sampling a simple child at our coordinates (implicitly)
- effect.build("in shader child;",
+ effect.build("uniform shader child;",
"return sample(child);");
effect.child("child") = rgbwShader;
effect.test(0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFFFFFF);
// Sampling with explicit coordinates (reflecting about the diagonal)
- effect.build("in shader child;",
+ effect.build("uniform shader child;",
"return sample(child, p.yx);");
effect.child("child") = rgbwShader;
effect.test(0xFF0000FF, 0xFFFF0000, 0xFF00FF00, 0xFFFFFFFF);
// Sampling with a matrix (again, reflecting about the diagonal)
- effect.build("in shader child;",
+ effect.build("uniform shader child;",
"return sample(child, float3x3(0, 1, 0, 1, 0, 0, 0, 0, 1));");
effect.child("child") = rgbwShader;
effect.test(0xFF0000FF, 0xFFFF0000, 0xFF00FF00, 0xFFFFFFFF);
+ // Legacy behavior - shaders can be declared 'in' rather than 'uniform'
+ effect.build("in shader child;",
+ "return sample(child);");
+ effect.child("child") = rgbwShader;
+ effect.test(0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFFFFFF);
+
//
// Helper functions
//