Fix fragment processors and unit tests which mix ints and floats.
These need to change because type coercion in SkSL is about to become
more strict in a followup CL; we are disallowing expressions that mix
ints and floats without a cast.
Change-Id: Iff5e2820806b9419afdfcbf25d4a7f96f2eeeccb
Bug: skia:11164
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353416
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/gm/samplelocations.cpp b/gm/samplelocations.cpp
index 11e2b7a..7873513 100644
--- a/gm/samplelocations.cpp
+++ b/gm/samplelocations.cpp
@@ -153,10 +153,10 @@
// outset value to get too small.
v->codeAppendf("float outset = 1/32.0;");
v->codeAppendf("outset = (0 == (x + y) %% 2) ? -outset : +outset;");
- v->codeAppendf("float l = ileft/16.0 - outset;");
- v->codeAppendf("float r = iright/16.0 + outset;");
- v->codeAppendf("float t = itop/16.0 - outset;");
- v->codeAppendf("float b = ibot/16.0 + outset;");
+ v->codeAppendf("float l = float(ileft)/16.0 - outset;");
+ v->codeAppendf("float r = float(iright)/16.0 + outset;");
+ v->codeAppendf("float t = float(itop)/16.0 - outset;");
+ v->codeAppendf("float b = float(ibot)/16.0 + outset;");
v->codeAppendf("float2 vertexpos;");
v->codeAppendf("vertexpos.x = float(x) + ((0 == (sk_VertexID %% 2)) ? l : r);");
diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
index 2a69b58..d4cc5a4 100644
--- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp
+++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
@@ -181,8 +181,8 @@
const char* kernelBias = uniformHandler->getUniformCStr(fKernelBiasUni);
SkString kernelSample = this->invokeChild(1, args, "float2(float(i) + 0.5, 0.5)");
fragBuilder->codeAppendf("k = %s.w + %s;", kernelSample.c_str(), kernelBias);
- fragBuilder->codeAppendf("sourceOffset.y = floor(i / %d);", kernelWidth);
- fragBuilder->codeAppendf("sourceOffset.x = i - sourceOffset.y * %d;", kernelWidth);
+ fragBuilder->codeAppendf("sourceOffset.y = floor(half(i) / %d);", kernelWidth);
+ fragBuilder->codeAppendf("sourceOffset.x = half(i) - sourceOffset.y * %d;", kernelWidth);
} else {
fragBuilder->codeAppendf("sourceOffset = half2(%d, %d);", loc.x(), loc.y());
int offset = loc.y() * kernelWidth + loc.x();
diff --git a/src/gpu/tessellate/GrDrawAtlasPathOp.cpp b/src/gpu/tessellate/GrDrawAtlasPathOp.cpp
index 6a43279..dad050b 100644
--- a/src/gpu/tessellate/GrDrawAtlasPathOp.cpp
+++ b/src/gpu/tessellate/GrDrawAtlasPathOp.cpp
@@ -79,7 +79,7 @@
if (dev_xywh.w < 0) { // Negative height indicates that the path is transposed.
atlascoord = atlascoord.yx;
}
- atlascoord += atlas_xy;
+ atlascoord += float2(atlas_xy);
%s = atlascoord * %s;)",
atlasCoord.vsOut(), atlasAdjust);
diff --git a/src/gpu/tessellate/GrStencilPathShader.cpp b/src/gpu/tessellate/GrStencilPathShader.cpp
index c3569bc..0de7925 100644
--- a/src/gpu/tessellate/GrStencilPathShader.cpp
+++ b/src/gpu/tessellate/GrStencilPathShader.cpp
@@ -363,7 +363,7 @@
((sk_VertexID & 2) == 0) ? inputPoints_0_1.zw : inputPoints_2_3.xy;
} else {
// Evaluate the cubic at T = (sk_VertexID / 2^kMaxResolveLevel).
- float T = sk_VertexID * kInverseMaxVertexID;
+ float T = float(sk_VertexID) * kInverseMaxVertexID;
float4x3 P = unpack_rational_cubic(inputPoints_0_1.xy, inputPoints_0_1.zw,
inputPoints_2_3.xy, inputPoints_2_3.zw);
pos = eval_rational_cubic(P, T);
diff --git a/src/gpu/tessellate/GrStrokeTessellateShader.cpp b/src/gpu/tessellate/GrStrokeTessellateShader.cpp
index 7d2e880..f127b9f 100644
--- a/src/gpu/tessellate/GrStrokeTessellateShader.cpp
+++ b/src/gpu/tessellate/GrStrokeTessellateShader.cpp
@@ -623,7 +623,7 @@
float maxRotation0 = (1 + combinedEdgeID) * abs(radsPerSegment);
for (int exp = MAX_PARAMETRIC_SEGMENTS_LOG2 - 1; exp >= 0; --exp) {
// Test the parametric edge at lastParametricEdgeID + 2^exp.
- float testParametricID = lastParametricEdgeID + (1 << exp);
+ float testParametricID = lastParametricEdgeID + float(1 << exp);
if (testParametricID <= maxParametricEdgeID) {
float2 testTan = fma(float2(testParametricID), A, B_);
testTan = fma(float2(testParametricID), testTan, C_);
@@ -940,7 +940,8 @@
args.fVertBuilder->codeAppend(R"(
float numParametricSegments = ceil(sqrt(uParametricIntolerance * sqrt(m)));
- numParametricSegments = clamp(numParametricSegments, 1, 1 << MAX_PARAMETRIC_SEGMENTS_LOG2);
+ numParametricSegments = clamp(numParametricSegments,
+ 1, float(1 << MAX_PARAMETRIC_SEGMENTS_LOG2));
if (P[0] == P[1] && P[2] == P[3]) {
// This is how we describe lines, but Wang's formula does not return 1 in this case.
numParametricSegments = 1;
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 1589038..7f9b5fe 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -517,7 +517,7 @@
if (mp.fVertexPosition.isInitialized()) {
v->codeAppendf("float2 offset = %s;", mp.fVertexPosition.name());
} else {
- v->codeAppend ("float2 offset = float2(sk_VertexID / 2, sk_VertexID % 2);");
+ v->codeAppend("float2 offset = float2(sk_VertexID / 2, sk_VertexID % 2);");
}
v->codeAppendf("float2 vertex = %s + offset * %i;", mp.fInstanceLocation.name(),
kBoxSize);
diff --git a/tests/SkSLInterpreterTest.cpp b/tests/SkSLInterpreterTest.cpp
index 260cf25..0269e98 100644
--- a/tests/SkSLInterpreterTest.cpp
+++ b/tests/SkSLInterpreterTest.cpp
@@ -246,7 +246,7 @@
test(r, "void main(inout half4 color) { color += half4(1, 2, 3, 4); }", 4, 3, 2, 1, 5, 5, 5, 5);
test(r, "void main(inout half4 color) { half4 c = color; color += c; }", 0.25, 0.5, 0.75, 1,
0.5, 1, 1.5, 2);
- test(r, "void main(inout half4 color) { color.r = int(color.r) + int(color.g); }", 1, 3, 0, 0,
+ test(r, "void main(inout half4 color) { color.r = half(int(color.r) + int(color.g)); }", 1, 3, 0, 0,
4, 3, 0, 0);
}
@@ -258,7 +258,7 @@
0, 0, 0, 0);
test(r, "void main(inout half4 color) { color.x = -color.x; }", 4, 3, 2, 1, -4, 3, 2, 1);
test(r, "void main(inout half4 color) { color = -color; }", 4, 3, 2, 1, -4, -3, -2, -1);
- test(r, "void main(inout half4 color) { color.r = int(color.r) - int(color.g); }", 3, 1, 0, 0,
+ test(r, "void main(inout half4 color) { color.r = half(int(color.r) - int(color.g)); }", 3, 1, 0, 0,
2, 1, 0, 0);
}
@@ -269,7 +269,7 @@
20);
test(r, "void main(inout half4 color) { half4 c = color; color *= c; }", 4, 3, 2, 1,
16, 9, 4, 1);
- test(r, "void main(inout half4 color) { color.r = int(color.r) * int(color.g); }", 3, -2, 0, 0,
+ test(r, "void main(inout half4 color) { color.r = half(int(color.r) * int(color.g)); }", 3, -2, 0, 0,
-6, -2, 0, 0);
}
@@ -280,7 +280,7 @@
4, 3);
test(r, "void main(inout half4 color) { half4 c = color; color /= c; }", 4, 3, 2, 1,
1, 1, 1, 1);
- test(r, "void main(inout half4 color) { color.r = int(color.r) / int(color.g); }", 8, -2, 0, 0,
+ test(r, "void main(inout half4 color) { color.r = half(int(color.r) / int(color.g)); }", 8, -2, 0, 0,
-4, -2, 0, 0);
}
@@ -291,10 +291,10 @@
"color = half4(color.a); }", 1, 1, 0, 3, 1, 1, 0, 3);
test(r, "void main(inout half4 color) { if (color.r > color.g && color.g > color.b) "
"color = half4(color.a); }", 2, 1, 1, 3, 2, 1, 1, 3);
- test(r, "int global; bool update() { global = 123; return true; }"
+ test(r, "half global; bool update() { global = 123; return true; }"
"void main(inout half4 color) { global = 0; if (color.r > color.g && update()) "
"color = half4(color.a); color.a = global; }", 2, 1, 1, 3, 3, 3, 3, 123);
- test(r, "int global; bool update() { global = 123; return true; }"
+ test(r, "half global; bool update() { global = 123; return true; }"
"void main(inout half4 color) { global = 0; if (color.r > color.g && update()) "
"color = half4(color.a); color.a = global; }", 1, 1, 1, 3, 1, 1, 1, 0);
}
@@ -306,10 +306,10 @@
"color = half4(color.a); }", 1, 1, 0, 3, 3, 3, 3, 3);
test(r, "void main(inout half4 color) { if (color.r > color.g || color.g > color.b) "
"color = half4(color.a); }", 1, 1, 1, 3, 1, 1, 1, 3);
- test(r, "int global; bool update() { global = 123; return true; }"
+ test(r, "half global; bool update() { global = 123; return true; }"
"void main(inout half4 color) { global = 0; if (color.r > color.g || update()) "
"color = half4(color.a); color.a = global; }", 1, 1, 1, 3, 3, 3, 3, 123);
- test(r, "int global; bool update() { global = 123; return true; }"
+ test(r, "half global; bool update() { global = 123; return true; }"
"void main(inout half4 color) { global = 0; if (color.r > color.g || update()) "
"color = half4(color.a); color.a = global; }", 2, 1, 1, 3, 3, 3, 3, 0);
}
@@ -497,14 +497,14 @@
}
DEF_TEST(SkSLInterpreterFor, r) {
- test(r, "void main(inout half4 color) { for (int i = 1; i <= 10; ++i) color.r += i; }",
+ test(r, "void main(inout half4 color) { for (int i = 1; i <= 10; ++i) color.r += half(i); }",
0, 0, 0, 0,
55, 0, 0, 0);
test(r,
"void main(inout half4 color) {"
" for (int i = 1; i <= 10; ++i)"
" for (int j = 1; j <= 10; ++j)"
- " if (j >= i) { color.r += j; }"
+ " if (j >= i) { color.r += half(j); }"
"}",
0, 0, 0, 0,
385, 0, 0, 0);
@@ -514,7 +514,7 @@
" for (int j = 1; j < 20 ; ++j) {"
" if (i == j) continue;"
" if (j > 10) break;"
- " color.r += j;"
+ " color.r += half(j);"
" }"
"}",
0, 0, 0, 0,
@@ -530,13 +530,13 @@
test(r, "void main(inout half4 color) { color = color.abgr; }", 1, 2, 3, 4, 4, 3, 2, 1);
test(r, "void main(inout half4 color) { color.rgb = half4(5, 6, 7, 8).bbg; }", 1, 2, 3, 4, 7, 7,
6, 4);
- test(r, "void main(inout half4 color) { color.bgr = int3(5, 6, 7); }", 1, 2, 3, 4, 7, 6,
+ test(r, "void main(inout half4 color) { color.bgr = half3(5, 6, 7); }", 1, 2, 3, 4, 7, 6,
5, 4);
}
DEF_TEST(SkSLInterpreterGlobal, r) {
- test(r, "int x; void main(inout half4 color) { x = 10; color.b = x; }", 1, 2, 3, 4, 1, 2, 10,
- 4);
+ test(r, "int x; void main(inout half4 color) { x = 10; color.b = half(x); }", 1, 2, 3, 4, 1, 2,
+ 10, 4);
test(r, "float4 x; void main(inout float4 color) { x = color * 2; color = x; }",
1, 2, 3, 4, 2, 4, 6, 8);
test(r, "float4 x; void main(inout float4 color) { x = float4(5, 6, 7, 8); color = x.wzyx; }",
@@ -598,7 +598,7 @@
" for (int i = 0; i < 4; ++i) {\n"
" if (i >= mr.numRects) { break; }\n"
" mr.rects[i].r = gRects[i];\n"
- " float b = mr.rects[i].r.p1.y;\n"
+ " float b = float(mr.rects[i].r.p1.y);\n"
" mr.rects[i].color = float4(b, b, b, b);\n"
" }\n"
"}\n";