Remove SkSL sample() intrinsic for Skia object types

Bug: skia:12302
Change-Id: Ifc107ca2cf13c1daa59521b93fe4ad1d3c215258
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/447297
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/resources/sksl/runtime_errors/IllegalShaderSampling.rts b/resources/sksl/runtime_errors/IllegalShaderSampling.rts
index 4d2195e..d36ba61 100644
--- a/resources/sksl/runtime_errors/IllegalShaderSampling.rts
+++ b/resources/sksl/runtime_errors/IllegalShaderSampling.rts
@@ -1,4 +1,4 @@
-// Expect 24 errors
+// Expect 12 errors
 
 uniform shader      s;
 uniform colorFilter f;
@@ -7,23 +7,6 @@
 uniform float2 xy;
 uniform half4  color;
 
-half4 sample_shader_xy_color() { return sample(s, xy, color); }
-half4 sample_shader_color()    { return sample(s, color); }
-half4 sample_shader_color_xy() { return sample(s, color, xy); }
-half4 sample_shader_empty()    { return sample(s); }
-half4 sample_shader_matrix()   { return sample(s, float3x3(1)); }
-
-half4 sample_colorFilter_empty()    { return sample(f); }
-half4 sample_colorFilter_xy()       { return sample(f, xy); }
-half4 sample_colorFilter_xy_color() { return sample(f, xy, color); }
-
-half4 sample_blender_empty()    { return sample(b); }
-half4 sample_blender_color()    { return sample(b, color); }
-half4 sample_blender_xy()       { return sample(b, xy); }
-half4 sample_blender_xy_color() { return sample(b, xy, color); }
-
-// Using .eval()
-
 half4 eval_shader_xy_color() { return s.eval(xy, color); }
 half4 eval_shader_color()    { return s.eval(color); }
 half4 eval_shader_color_xy() { return s.eval(color, xy); }
diff --git a/src/sksl/dsl/DSLCore.cpp b/src/sksl/dsl/DSLCore.cpp
index eb0a615..f7664cb 100644
--- a/src/sksl/dsl/DSLCore.cpp
+++ b/src/sksl/dsl/DSLCore.cpp
@@ -601,17 +601,12 @@
     return DSLExpression(DSLCore::Call("round", std::move(x)), pos);
 }
 
-DSLExpression Sample(DSLExpression target, PositionInfo pos) {
-    return DSLExpression(DSLCore::Call("sample", std::move(target)), pos);
-}
-
-
 DSLExpression Sample(DSLExpression target, DSLExpression x, PositionInfo pos) {
-    return DSLExpression(DSLCore::Call("sample", std::move(target), std::move(x)), pos);
+    return DSLExpression(DSLCore::Call("$eval", std::move(x), std::move(target)), pos);
 }
 
 DSLExpression Sample(DSLExpression target, DSLExpression x, DSLExpression y, PositionInfo pos) {
-    return DSLExpression(DSLCore::Call("sample", std::move(target), std::move(x), std::move(y)),
+    return DSLExpression(DSLCore::Call("$eval", std::move(x), std::move(y), std::move(target)),
                          pos);
 }
 
diff --git a/src/sksl/generated/sksl_public.dehydrated.sksl b/src/sksl/generated/sksl_public.dehydrated.sksl
index 77c0e71..268bec1 100644
--- a/src/sksl/generated/sksl_public.dehydrated.sksl
+++ b/src/sksl/generated/sksl_public.dehydrated.sksl
@@ -1,4 +1,4 @@
-static uint8_t SKSL_INCLUDE_sksl_public[] = {188,3,
+static uint8_t SKSL_INCLUDE_sksl_public[] = {181,3,
 7,100,101,103,114,101,101,115,
 8,36,103,101,110,84,121,112,101,
 7,114,97,100,105,97,110,115,
@@ -128,18 +128,17 @@
 4,100,70,100,121,
 5,99,111,108,111,114,
 8,117,110,112,114,101,109,117,108,
+6,99,111,111,114,100,115,
 1,115,
 6,115,104,97,100,101,114,
-6,99,111,111,114,100,115,
-6,115,97,109,112,108,101,
+5,36,101,118,97,108,
 1,102,
 11,99,111,108,111,114,70,105,108,116,101,114,
-1,98,
-7,98,108,101,110,100,101,114,
 3,115,114,99,
 3,100,115,116,
-5,36,101,118,97,108,
-48,118,2,
+1,98,
+7,98,108,101,110,100,101,114,
+48,106,2,
 52,1,0,
 17,2,0,
 49,2,0,10,0,3,
@@ -2252,79 +2251,42 @@
 46,128,2,
 52,129,2,
 17,129,3,
-49,130,2,131,3,3,
-52,131,2,
-17,138,3,
 46,92,1,3,
+52,130,2,
+17,136,3,
+49,131,2,138,3,3,
 29,132,2,
-17,145,3,2,129,2,131,2,
+17,145,3,2,129,2,130,2,
 46,3,2,
 52,133,2,
-17,152,3,
-49,134,2,154,3,3,
-52,135,2,
 17,114,3,
 46,3,2,3,
+52,134,2,
+17,151,3,
+49,135,2,153,3,3,
 51,136,2,2,
 46,132,2,
 29,137,2,
-17,145,3,2,133,2,135,2,
+17,145,3,2,133,2,134,2,
 46,3,2,
 46,137,2,
 52,138,2,
-17,166,3,
-49,139,2,168,3,3,
+17,165,3,
+46,3,2,3,
+52,139,2,
+17,169,3,
+46,3,2,3,
 52,140,2,
-17,176,3,
-46,3,2,3,
-52,141,2,
-17,180,3,
-46,3,2,3,
+17,173,3,
+49,141,2,175,3,3,
 51,142,2,3,
 46,132,2,
 46,137,2,
 29,143,2,
-17,145,3,3,138,2,140,2,141,2,
+17,145,3,3,138,2,139,2,140,2,
 46,3,2,
-46,143,2,
-52,144,2,
-17,138,3,
-46,92,1,3,
-52,145,2,
-17,129,3,
-46,130,2,3,
-29,146,2,
-17,184,3,2,144,2,145,2,
-46,3,2,
-52,147,2,
-17,114,3,
-46,3,2,3,
-52,148,2,
-17,152,3,
-46,134,2,3,
-51,149,2,2,
-46,146,2,
-29,150,2,
-17,184,3,2,147,2,148,2,
-46,3,2,
-46,150,2,
-52,151,2,
-17,176,3,
-46,3,2,3,
-52,152,2,
-17,180,3,
-46,3,2,3,
-52,153,2,
-17,166,3,
-46,139,2,3,
-51,154,2,3,
-46,146,2,
-46,150,2,
-29,155,2,
-17,184,3,3,151,2,152,2,153,2,
-46,3,2,
-46,155,2,73,0,
-116,2,
+46,143,2,72,0,
+104,2,
 118,0,
 33,0,
 71,0,
@@ -2382,7 +2344,6 @@
 140,1,
 22,1,
 27,1,
-104,2,
 207,0,
 123,0,
 13,0,
diff --git a/src/sksl/ir/SkSLFunctionCall.cpp b/src/sksl/ir/SkSLFunctionCall.cpp
index 19ee6f9..7b9d5b7 100644
--- a/src/sksl/ir/SkSLFunctionCall.cpp
+++ b/src/sksl/ir/SkSLFunctionCall.cpp
@@ -864,26 +864,12 @@
         }
     }
 
-    switch (function.intrinsicKind()) {
-        case k_sample_IntrinsicKind: {
-            if (arguments.size() >= 1 && arguments[0]->type().isEffectChild()) {
-                // Translate these intrinsic calls into a ChildCall, which simplifies handling in
-                // the generators and analysis code
-                const Variable& child = *arguments[0]->as<VariableReference>().variable();
-                std::rotate(arguments.begin(), arguments.begin() + 1, arguments.end());
-                arguments.pop_back();
-                return ChildCall::Make(context, offset, returnType, child, std::move(arguments));
-            }
-            break;
-        }
-        case k_eval_IntrinsicKind: {
-            // Similar, but this is a method call, so the argument ordering is different
-            const Variable& child = *arguments.back()->as<VariableReference>().variable();
-            arguments.pop_back();
-            return ChildCall::Make(context, offset, returnType, child, std::move(arguments));
-        }
-        default:
-            break;
+    if (function.intrinsicKind() == k_eval_IntrinsicKind) {
+        // This is a method call on an effect child. Translate it into a ChildCall, which simplifies
+        // handling in the generators and analysis code.
+        const Variable& child = *arguments.back()->as<VariableReference>().variable();
+        arguments.pop_back();
+        return ChildCall::Make(context, offset, returnType, child, std::move(arguments));
     }
 
     return Make(context, offset, returnType, function, std::move(arguments));
diff --git a/src/sksl/sksl_public.sksl b/src/sksl/sksl_public.sksl
index 3d9463e..ab7bdd7 100644
--- a/src/sksl/sksl_public.sksl
+++ b/src/sksl/sksl_public.sksl
@@ -227,10 +227,6 @@
 float4 unpremul(float4 color) { return float4(color.rgb / max(color.a, 0.0001), color.a); }
 
 // SkSL intrinsics that reflect Skia's C++ object model:
-half4 sample(shader s, float2 coords);
-half4 sample(colorFilter f, half4 color);
-half4 sample(blender b, half4 src, half4 dst);
-
 half4 $eval(float2 coords, shader s);
 half4 $eval(half4 color, colorFilter f);
 half4 $eval(half4 src, half4 dst, blender b);
diff --git a/tests/SkSLDSLTest.cpp b/tests/SkSLDSLTest.cpp
index 2250c2b..8298609 100644
--- a/tests/SkSLDSLTest.cpp
+++ b/tests/SkSLDSLTest.cpp
@@ -1954,7 +1954,7 @@
     EXPECT_EQUAL(Sample(shader, Float2(0, 0)), "child.eval(float2(0.0, 0.0))");
 
     {
-        ExpectError error(r, "no match for sample(shader, half4)");
+        ExpectError error(r, "no match for $eval(half4, shader)");
         Sample(shader, Half4(1)).release();
     }
 }
diff --git a/tests/sksl/runtime_errors/IllegalShaderSampling.skvm b/tests/sksl/runtime_errors/IllegalShaderSampling.skvm
index 9d08754..84e0d7d 100644
--- a/tests/sksl/runtime_errors/IllegalShaderSampling.skvm
+++ b/tests/sksl/runtime_errors/IllegalShaderSampling.skvm
@@ -1,27 +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)
-error: 27: no match for shader::eval(float2, half4)
-error: 28: no match for shader::eval(half4)
-error: 29: no match for shader::eval(half4, float2)
-error: 30: no match for shader::eval()
-error: 31: no match for shader::eval(float3x3)
-error: 33: no match for colorFilter::eval()
-error: 34: no match for colorFilter::eval(float2)
-error: 35: no match for colorFilter::eval(float2, half4)
-error: 37: no match for blender::eval()
-error: 38: no match for blender::eval(half4)
-error: 39: no match for blender::eval(float2)
-error: 40: no match for blender::eval(float2, half4)
-24 errors
+error: 10: no match for shader::eval(float2, half4)
+error: 11: no match for shader::eval(half4)
+error: 12: no match for shader::eval(half4, float2)
+error: 13: no match for shader::eval()
+error: 14: no match for shader::eval(float3x3)
+error: 16: no match for colorFilter::eval()
+error: 17: no match for colorFilter::eval(float2)
+error: 18: no match for colorFilter::eval(float2, half4)
+error: 20: no match for blender::eval()
+error: 21: no match for blender::eval(half4)
+error: 22: no match for blender::eval(float2)
+error: 23: no match for blender::eval(float2, half4)
+12 errors