Flip the arguments to sample() when passing both coords and a color
A subset of these signatures will be available to public SkSL, and structured in a way that really pushes the coords as the primary argument (and color as an optional one). In any case, I find this ordering more natural. Change-Id: I7b3bc962c5b305b9eeed1ae11ae1dc2ce7269364 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396021 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
4bbb29070c
commit
debcbbf6a8
@ -366,8 +366,8 @@ DSLExpression Sample(DSLExpression target, DSLExpression x, PositionInfo pos = P
|
||||
|
||||
/**
|
||||
* Implements the following functions:
|
||||
* half4 sample(fragmentProcessor fp, half4 input, float3x3 transform);
|
||||
* half4 sample(fragmentProcessor fp, half4 input, float2 coords);
|
||||
* half4 sample(fragmentProcessor fp, float3x3 transform, half4 input);
|
||||
* half4 sample(fragmentProcessor fp, float2 coords, half4 input);
|
||||
*/
|
||||
DSLExpression Sample(DSLExpression childProcessor, DSLExpression x, DSLExpression y,
|
||||
PositionInfo pos = PositionInfo());
|
||||
|
@ -385,36 +385,40 @@ void CPPCodeGenerator::writeFunctionCall(const FunctionCall& c) {
|
||||
// sksl variables defined in earlier sksl code.
|
||||
this->newExtraEmitCodeBlock();
|
||||
|
||||
// inputColor is an optional argument that always appears last
|
||||
String inputColor;
|
||||
if (arguments.size() > 1 && arguments[1]->type().name() == "half4") {
|
||||
if (arguments.back()->type().name() == "half4") {
|
||||
// Use the invokeChild() variant that accepts an input color, so convert the 2nd
|
||||
// argument's expression into C++ code that produces sksl stored in an SkString.
|
||||
String inputColorName = this->getSampleVarName("_input", sampleCounter);
|
||||
addExtraEmitCodeLine(convertSKSLExpressionToCPP(*arguments[1], inputColorName));
|
||||
addExtraEmitCodeLine(convertSKSLExpressionToCPP(*arguments.back(), inputColorName));
|
||||
|
||||
// invokeChild() needs a char* and a pre-pended comma
|
||||
inputColor = ", " + inputColorName + ".c_str()";
|
||||
}
|
||||
|
||||
// coords can be float2, float3x3, or not there at all. They appear right after the fp.
|
||||
String inputCoord;
|
||||
String invokeFunction = "invokeChild";
|
||||
if (arguments.back()->type().name() == "float2") {
|
||||
// Invoking child with explicit coordinates at this call site
|
||||
inputCoord = this->getSampleVarName("_coords", sampleCounter);
|
||||
addExtraEmitCodeLine(convertSKSLExpressionToCPP(*arguments.back(), inputCoord));
|
||||
inputCoord.append(".c_str()");
|
||||
} else if (arguments.back()->type().name() == "float3x3") {
|
||||
// Invoking child with a matrix, sampling relative to the input coords.
|
||||
invokeFunction = "invokeChildWithMatrix";
|
||||
SampleUsage usage = Analysis::GetSampleUsage(fProgram, child);
|
||||
|
||||
if (!usage.hasUniformMatrix()) {
|
||||
inputCoord = this->getSampleVarName("_matrix", sampleCounter);
|
||||
addExtraEmitCodeLine(convertSKSLExpressionToCPP(*arguments.back(), inputCoord));
|
||||
if (arguments.size() > 1) {
|
||||
if (arguments[1]->type().name() == "float2") {
|
||||
// Invoking child with explicit coordinates at this call site
|
||||
inputCoord = this->getSampleVarName("_coords", sampleCounter);
|
||||
addExtraEmitCodeLine(convertSKSLExpressionToCPP(*arguments[1], inputCoord));
|
||||
inputCoord.append(".c_str()");
|
||||
} else if (arguments[1]->type().name() == "float3x3") {
|
||||
// Invoking child with a matrix, sampling relative to the input coords.
|
||||
invokeFunction = "invokeChildWithMatrix";
|
||||
SampleUsage usage = Analysis::GetSampleUsage(fProgram, child);
|
||||
|
||||
if (!usage.hasUniformMatrix()) {
|
||||
inputCoord = this->getSampleVarName("_matrix", sampleCounter);
|
||||
addExtraEmitCodeLine(convertSKSLExpressionToCPP(*arguments[1], inputCoord));
|
||||
inputCoord.append(".c_str()");
|
||||
}
|
||||
// else pass in the empty string to rely on invokeChildWithMatrix's automatic
|
||||
// uniform resolution
|
||||
}
|
||||
// else pass in the empty string to rely on invokeChildWithMatrix's automatic uniform
|
||||
// resolution
|
||||
}
|
||||
if (!inputCoord.empty()) {
|
||||
inputCoord = ", " + inputCoord;
|
||||
|
@ -98,11 +98,11 @@ static uint8_t SKSL_INCLUDE_sksl_fp[] = {18,1,
|
||||
16,135,0,
|
||||
47,12,0,3,
|
||||
53,29,0,
|
||||
16,196,0,
|
||||
47,8,0,3,
|
||||
53,30,0,
|
||||
16,163,0,
|
||||
47,16,0,3,
|
||||
53,30,0,
|
||||
16,196,0,
|
||||
47,8,0,3,
|
||||
52,31,0,5,
|
||||
47,13,0,
|
||||
47,18,0,
|
||||
@ -116,11 +116,11 @@ static uint8_t SKSL_INCLUDE_sksl_fp[] = {18,1,
|
||||
16,135,0,
|
||||
47,12,0,3,
|
||||
53,34,0,
|
||||
16,196,0,
|
||||
47,8,0,3,
|
||||
53,35,0,
|
||||
16,182,0,
|
||||
47,21,0,3,
|
||||
53,35,0,
|
||||
16,196,0,
|
||||
47,8,0,3,
|
||||
52,36,0,6,
|
||||
47,13,0,
|
||||
47,18,0,
|
||||
|
@ -15,6 +15,7 @@ layout(builtin=9999) half4 gl_SecondaryFragColorEXT;
|
||||
half4 sample(fragmentProcessor fp);
|
||||
half4 sample(fragmentProcessor fp, float3x3 transform);
|
||||
half4 sample(fragmentProcessor fp, float2 coords);
|
||||
|
||||
half4 sample(fragmentProcessor fp, half4 input);
|
||||
half4 sample(fragmentProcessor fp, half4 input, float3x3 transform);
|
||||
half4 sample(fragmentProcessor fp, half4 input, float2 coords);
|
||||
half4 sample(fragmentProcessor fp, float3x3 transform, half4 input);
|
||||
half4 sample(fragmentProcessor fp, float2 coords, half4 input);
|
||||
|
@ -1500,9 +1500,9 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLSample, r, ctxInfo) {
|
||||
EXPECT_EQUAL(Sample(child, Float2(0, 0)), "sample(child, float2(0.0, 0.0))");
|
||||
EXPECT_EQUAL(Sample(child, Float3x3(1.0)), "sample(child, float3x3(1.0))");
|
||||
EXPECT_EQUAL(Sample(child, Half4(1)), "sample(child, half4(1.0))");
|
||||
EXPECT_EQUAL(Sample(child, Half4(1), Float2(0)), "sample(child, half4(1.0), float2(0.0))");
|
||||
EXPECT_EQUAL(Sample(child, Half4(1), Float3x3(1.0)),
|
||||
"sample(child, half4(1.0), float3x3(1.0))");
|
||||
EXPECT_EQUAL(Sample(child, Float2(0), Half4(1)), "sample(child, float2(0.0), half4(1.0))");
|
||||
EXPECT_EQUAL(Sample(child, Float3x3(1.0), Half4(1)),
|
||||
"sample(child, float3x3(1.0), half4(1.0))");
|
||||
|
||||
{
|
||||
ExpectError error(r, "error: no match for sample(fragmentProcessor, bool)\n");
|
||||
|
Loading…
Reference in New Issue
Block a user