From 05d5a13fea6246648de7e41358ed338d53c85ea2 Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Fri, 15 Sep 2017 11:42:17 -0400 Subject: Revert "Revert "Switched highp float to highfloat and mediump float to half."" This reverts commit 1d816b92bb7cf2258007f3f74ffd143b89f25d01. Bug: skia: Change-Id: I388b5e5e9bf619db48297a80c9a80c039f26c9f1 Reviewed-on: https://skia-review.googlesource.com/46464 Reviewed-by: Brian Salomon Commit-Queue: Ethan Nicholas --- tests/SkSLGLSLTest.cpp | 421 ++++++++++++++++++++++++------------------------- 1 file changed, 210 insertions(+), 211 deletions(-) (limited to 'tests/SkSLGLSLTest.cpp') diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index a7f6740442..851c0e8a34 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -51,7 +51,7 @@ static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& cap DEF_TEST(SkSLHelloWorld, r) { test(r, - "void main() { sk_FragColor = float4(0.75); }", + "void main() { sk_FragColor = highfloat4(0.75); }", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -63,7 +63,7 @@ DEF_TEST(SkSLHelloWorld, r) { DEF_TEST(SkSLControl, r) { test(r, "void main() {" - "if (sqrt(2) > 5) { sk_FragColor = float4(0.75); } else { discard; }" + "if (sqrt(2) > 5) { sk_FragColor = highfloat4(0.75); } else { discard; }" "int i = 0;" "while (i < 10) { sk_FragColor *= 0.5; i++; }" "do { sk_FragColor += 0.01; } while (sk_FragColor.x < 0.75);" @@ -98,9 +98,9 @@ DEF_TEST(SkSLControl, r) { DEF_TEST(SkSLFunctions, r) { test(r, - "float foo(float v[2]) { return v[0] * v[1]; }" - "void bar(inout float x) { float y[2], z; y[0] = x; y[1] = x * 2; z = foo(y); x = z; }" - "void main() { float x = 10; bar(x); sk_FragColor = float4(x); }", + "highfloat foo(highfloat v[2]) { return v[0] * v[1]; }" + "void bar(inout highfloat x) { highfloat y[2], z; y[0] = x; y[1] = x * 2; z = foo(y); x = z; }" + "void main() { highfloat x = 10; bar(x); sk_FragColor = highfloat4(x); }", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -124,7 +124,7 @@ DEF_TEST(SkSLFunctions, r) { DEF_TEST(SkSLOperators, r) { test(r, "void main() {" - "float x = 1, y = 2;" + "highfloat x = 1, y = 2;" "int z = 3;" "x = x - x + y * z * x * (y - z);" "y = x / y / z;" @@ -142,8 +142,8 @@ DEF_TEST(SkSLOperators, r) { "z >>= 2;" "z <<= 4;" "z %= 5;" - "x = (float2(sqrt(1)) , 6);" - "z = (float2(sqrt(1)) , 6);" + "x = (highfloat2(sqrt(1)) , 6);" + "z = (highfloat2(sqrt(1)) , 6);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -175,12 +175,12 @@ DEF_TEST(SkSLOperators, r) { DEF_TEST(SkSLMatrices, r) { test(r, "void main() {" - "float2x4 x = float2x4(1);" - "float3x2 y = float3x2(1, 0, 0, 1, float2(2, 2));" - "float3x4 z = x * y;" - "float3 v1 = float3x3(1) * float3(2);" - "float3 v2 = float3(2) * float3x3(1);" - "sk_FragColor = float4(z[0].x, v1 + v2);" + "highfloat2x4 x = highfloat2x4(1);" + "highfloat3x2 y = highfloat3x2(1, 0, 0, 1, highfloat2(2, 2));" + "highfloat3x4 z = x * y;" + "highfloat3 v1 = highfloat3x3(1) * highfloat3(2);" + "highfloat3 v2 = highfloat3(2) * highfloat3x3(1);" + "sk_FragColor = highfloat4(z[0].x, v1 + v2);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -196,13 +196,13 @@ DEF_TEST(SkSLMatrices, r) { DEF_TEST(SkSLInterfaceBlock, r) { test(r, "uniform testBlock {" - "float x;" - "float y[2];" - "layout(binding=12) float3x2 z;" + "half x;" + "half y[2];" + "layout(binding=12) half3x2 z;" "bool w;" "};" "void main() {" - " sk_FragColor = float4(x, y[0], y[1], 0);" + " sk_FragColor = half4(x, y[0], y[1], 0);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -218,10 +218,10 @@ DEF_TEST(SkSLInterfaceBlock, r) { "}\n"); test(r, "uniform testBlock {" - "float x;" + "highfloat x;" "} test;" "void main() {" - " sk_FragColor = float4(test.x);" + " sk_FragColor = half4(test.x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -234,10 +234,10 @@ DEF_TEST(SkSLInterfaceBlock, r) { "}\n"); test(r, "uniform testBlock {" - "float x;" + "highfloat x;" "} test[2];" "void main() {" - " sk_FragColor = float4(test[1].x);" + " sk_FragColor = half4(test[1].x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -258,8 +258,8 @@ DEF_TEST(SkSLStructs, r) { "} a1, a2;" "A a3;" "struct B {" - "float x;" - "float y[2];" + "highfloat x;" + "highfloat y[2];" "layout(binding=1) A z;" "};" "B b1, b2, b3;" @@ -284,7 +284,7 @@ DEF_TEST(SkSLStructs, r) { DEF_TEST(SkSLVersion, r) { test(r, - "in float test; void main() { sk_FragColor = float4(0.75); }", + "in highfloat test; void main() { sk_FragColor = highfloat4(0.75); }", *SkSL::ShaderCapsFactory::Version450Core(), "#version 450 core\n" "out vec4 sk_FragColor;\n" @@ -293,7 +293,7 @@ DEF_TEST(SkSLVersion, r) { " sk_FragColor = vec4(0.75);\n" "}\n"); test(r, - "in float test; void main() { sk_FragColor = float4(0.75); }", + "in highfloat test; void main() { sk_FragColor = highfloat4(0.75); }", *SkSL::ShaderCapsFactory::Version110(), "#version 110\n" "varying float test;\n" @@ -304,8 +304,8 @@ DEF_TEST(SkSLVersion, r) { DEF_TEST(SkSLUsesPrecisionModifiers, r) { test(r, - "void main() { float x = 0.75; highp float y = 1; x++; y++;" - "sk_FragColor.rg = float2(x, y); }", + "void main() { half x = 0.75; highfloat y = 1; x++; y++;" + "sk_FragColor.rg = half2(x, y); }", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -317,15 +317,14 @@ DEF_TEST(SkSLUsesPrecisionModifiers, r) { " sk_FragColor.xy = vec2(x, y);\n" "}\n"); test(r, - "void main() { float x = 0.75; half y = 1; x++; y++;" - "sk_FragColor.rg = float2(x, y); }", + "void main() { half x = 0.75; highfloat y = 1; x++; y++;" + "sk_FragColor.rg = half2(x, y); }", *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), "#version 400\n" - "precision highp float;\n" "out mediump vec4 sk_FragColor;\n" "void main() {\n" - " float x = 0.75;\n" - " mediump float y = 1.0;\n" + " mediump float x = 0.75;\n" + " highp float y = 1.0;\n" " x++;\n" " y++;\n" " sk_FragColor.xy = vec2(x, y);\n" @@ -335,7 +334,7 @@ DEF_TEST(SkSLUsesPrecisionModifiers, r) { DEF_TEST(SkSLMinAbs, r) { test(r, "void main() {" - "float x = -5;" + "highfloat x = -5;" "sk_FragColor.r = min(abs(x), 6);" "}", *SkSL::ShaderCapsFactory::Default(), @@ -347,7 +346,7 @@ DEF_TEST(SkSLMinAbs, r) { test(r, "void main() {" - "float x = -5.0;" + "highfloat x = -5.0;" "sk_FragColor.r = min(abs(x), 6.0);" "}", *SkSL::ShaderCapsFactory::CannotUseMinAndAbsTogether(), @@ -364,7 +363,7 @@ DEF_TEST(SkSLMinAbs, r) { DEF_TEST(SkSLFractNegative, r) { static constexpr char input[] = "void main() {" - "float x = -42.0;" + "highfloat x = -42.0;" "sk_FragColor.r = fract(x);" "}"; static constexpr char output_default[] = @@ -386,7 +385,7 @@ DEF_TEST(SkSLFractNegative, r) { DEF_TEST(SkSLNegatedAtan, r) { test(r, - "void main() { float2 x = float2(sqrt(2)); sk_FragColor.r = atan(x.x, -x.y); }", + "void main() { highfloat2 x = highfloat2(sqrt(2)); sk_FragColor.r = atan(x.x, -x.y); }", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -395,7 +394,7 @@ DEF_TEST(SkSLNegatedAtan, r) { " sk_FragColor.x = atan(x.x, -x.y);\n" "}\n"); test(r, - "void main() { float2 x = float2(sqrt(2)); sk_FragColor.r = atan(x.x, -x.y); }", + "void main() { highfloat2 x = highfloat2(sqrt(2)); sk_FragColor.r = atan(x.x, -x.y); }", *SkSL::ShaderCapsFactory::MustForceNegatedAtanParamToFloat(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -466,13 +465,13 @@ DEF_TEST(SkSLHex, r) { DEF_TEST(SkSLVectorConstructors, r) { test(r, - "float2 v1 = float2(1);" - "float2 v2 = float2(1, 2);" - "float2 v3 = float2(float2(1));" - "float3 v4 = float3(float2(1), 1.0);" + "highfloat2 v1 = highfloat2(1);" + "highfloat2 v2 = highfloat2(1, 2);" + "highfloat2 v3 = highfloat2(highfloat2(1));" + "highfloat3 v4 = highfloat3(highfloat2(1), 1.0);" "int2 v5 = int2(1);" - "int2 v6 = int2(float2(1, 2));" - "float2 v7 = float2(int2(1, 2));", + "int2 v6 = int2(highfloat2(1, 2));" + "highfloat2 v7 = highfloat2(int2(1, 2));", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -487,9 +486,9 @@ DEF_TEST(SkSLVectorConstructors, r) { DEF_TEST(SkSLArrayConstructors, r) { test(r, - "float test1[] = float[](1, 2, 3, 4);" - "float2 test2[] = float2[](float2(1, 2), float2(3, 4));" - "float4x4 test3[] = float4x4[]();", + "highfloat test1[] = highfloat[](1, 2, 3, 4);" + "highfloat2 test2[] = highfloat2[](highfloat2(1, 2), highfloat2(3, 4));" + "highfloat4x4 test3[] = highfloat4x4[]();", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -511,7 +510,6 @@ DEF_TEST(SkSLDerivatives, r) { "void main() { sk_FragColor.r = 1; }", *SkSL::ShaderCapsFactory::ShaderDerivativeExtensionString(), "#version 400\n" - "precision highp float;\n" "out mediump vec4 sk_FragColor;\n" "void main() {\n" " sk_FragColor.x = 1.0;\n" @@ -521,7 +519,6 @@ DEF_TEST(SkSLDerivatives, r) { *SkSL::ShaderCapsFactory::ShaderDerivativeExtensionString(), "#version 400\n" "#extension GL_OES_standard_derivatives : require\n" - "precision highp float;\n" "out mediump vec4 sk_FragColor;\n" "void main() {\n" " sk_FragColor.x = dFdx(1.0);\n" @@ -717,55 +714,55 @@ DEF_TEST(SkSLBoolFolding, r) { DEF_TEST(SkSLVecFolding, r) { test(r, "void main() {" - "sk_FragColor.r = float4(0.5, 1, 1, 1).x;" - "sk_FragColor = float4(float2(1), float2(2, 3)) + float4(5, 6, 7, 8);" - "sk_FragColor = float4(8, float3(10)) - float4(1);" - "sk_FragColor = float4(2) * float4(1, 2, 3, 4);" - "sk_FragColor = float4(12) / float4(1, 2, 3, 4);" - "sk_FragColor.r = (float4(12) / float4(1, 2, 3, 4)).y;" - "sk_FragColor.x = float4(1) == float4(1) ? 1.0 : -1.0;" - "sk_FragColor.x = float4(1) == float4(2) ? 2.0 : -2.0;" - "sk_FragColor.x = float2(1) == float2(1, 1) ? 3.0 : -3.0;" - "sk_FragColor.x = float2(1, 1) == float2(1, 1) ? 4.0 : -4.0;" - "sk_FragColor.x = float2(1) == float2(1, 0) ? 5.0 : -5.0;" - "sk_FragColor.x = float4(1) == float4(float2(1), float2(1)) ? 6.0 : -6.0;" - "sk_FragColor.x = float4(float3(1), 1) == float4(float2(1), float2(1)) ? 7.0 : -7.0;" - "sk_FragColor.x = float4(float3(1), 1) == float4(float2(1), 1, 0) ? 8.0 : -8.0;" - "sk_FragColor.x = float2(1) != float2(1, 0) ? 9.0 : -9.0;" - "sk_FragColor.x = float4(1) != float4(float2(1), float2(1)) ? 10.0 : -10.0;" - "sk_FragColor = float4(sqrt(1)) * float4(1);" - "sk_FragColor = float4(1) * float4(sqrt(2));" - "sk_FragColor = float4(0) * float4(sqrt(3));" - "sk_FragColor = float4(sqrt(4)) * float4(0);" - "sk_FragColor = float4(0) / float4(sqrt(5));" - "sk_FragColor = float4(0) + float4(sqrt(6));" - "sk_FragColor = float4(sqrt(7)) + float4(0);" - "sk_FragColor = float4(sqrt(8)) - float4(0);" - "sk_FragColor = float4(0) + sqrt(9);" - "sk_FragColor = float4(0) * sqrt(10);" - "sk_FragColor = float4(0) / sqrt(11);" - "sk_FragColor = float4(1) * sqrt(12);" - "sk_FragColor = 0 + float4(sqrt(13));" - "sk_FragColor = 0 * float4(sqrt(14));" - "sk_FragColor = 0 / float4(sqrt(15));" - "sk_FragColor = 1 * float4(sqrt(16));" - "sk_FragColor = float4(sqrt(17)) + 0;" - "sk_FragColor = float4(sqrt(18)) * 0;" - "sk_FragColor = float4(sqrt(19)) * 1;" - "sk_FragColor = float4(sqrt(19.5)) - 0;" - "sk_FragColor = sqrt(20) * float4(1);" - "sk_FragColor = sqrt(21) + float4(0);" - "sk_FragColor = sqrt(22) - float4(0);" - "sk_FragColor = sqrt(23) / float4(1);" - "sk_FragColor = float4(sqrt(24)) / 1;" - "sk_FragColor += float4(1);" - "sk_FragColor += float4(0);" - "sk_FragColor -= float4(1);" - "sk_FragColor -= float4(0);" - "sk_FragColor *= float4(1);" - "sk_FragColor *= float4(2);" - "sk_FragColor /= float4(1);" - "sk_FragColor /= float4(2);" + "sk_FragColor.r = highfloat4(0.5, 1, 1, 1).x;" + "sk_FragColor = highfloat4(highfloat2(1), highfloat2(2, 3)) + highfloat4(5, 6, 7, 8);" + "sk_FragColor = highfloat4(8, highfloat3(10)) - highfloat4(1);" + "sk_FragColor = highfloat4(2) * highfloat4(1, 2, 3, 4);" + "sk_FragColor = highfloat4(12) / highfloat4(1, 2, 3, 4);" + "sk_FragColor.r = (highfloat4(12) / highfloat4(1, 2, 3, 4)).y;" + "sk_FragColor.x = highfloat4(1) == highfloat4(1) ? 1.0 : -1.0;" + "sk_FragColor.x = highfloat4(1) == highfloat4(2) ? 2.0 : -2.0;" + "sk_FragColor.x = highfloat2(1) == highfloat2(1, 1) ? 3.0 : -3.0;" + "sk_FragColor.x = highfloat2(1, 1) == highfloat2(1, 1) ? 4.0 : -4.0;" + "sk_FragColor.x = highfloat2(1) == highfloat2(1, 0) ? 5.0 : -5.0;" + "sk_FragColor.x = highfloat4(1) == highfloat4(highfloat2(1), highfloat2(1)) ? 6.0 : -6.0;" + "sk_FragColor.x = highfloat4(highfloat3(1), 1) == highfloat4(highfloat2(1), highfloat2(1)) ? 7.0 : -7.0;" + "sk_FragColor.x = highfloat4(highfloat3(1), 1) == highfloat4(highfloat2(1), 1, 0) ? 8.0 : -8.0;" + "sk_FragColor.x = highfloat2(1) != highfloat2(1, 0) ? 9.0 : -9.0;" + "sk_FragColor.x = highfloat4(1) != highfloat4(highfloat2(1), highfloat2(1)) ? 10.0 : -10.0;" + "sk_FragColor = highfloat4(sqrt(1)) * highfloat4(1);" + "sk_FragColor = highfloat4(1) * highfloat4(sqrt(2));" + "sk_FragColor = highfloat4(0) * highfloat4(sqrt(3));" + "sk_FragColor = highfloat4(sqrt(4)) * highfloat4(0);" + "sk_FragColor = highfloat4(0) / highfloat4(sqrt(5));" + "sk_FragColor = highfloat4(0) + highfloat4(sqrt(6));" + "sk_FragColor = highfloat4(sqrt(7)) + highfloat4(0);" + "sk_FragColor = highfloat4(sqrt(8)) - highfloat4(0);" + "sk_FragColor = highfloat4(0) + sqrt(9);" + "sk_FragColor = highfloat4(0) * sqrt(10);" + "sk_FragColor = highfloat4(0) / sqrt(11);" + "sk_FragColor = highfloat4(1) * sqrt(12);" + "sk_FragColor = 0 + highfloat4(sqrt(13));" + "sk_FragColor = 0 * highfloat4(sqrt(14));" + "sk_FragColor = 0 / highfloat4(sqrt(15));" + "sk_FragColor = 1 * highfloat4(sqrt(16));" + "sk_FragColor = highfloat4(sqrt(17)) + 0;" + "sk_FragColor = highfloat4(sqrt(18)) * 0;" + "sk_FragColor = highfloat4(sqrt(19)) * 1;" + "sk_FragColor = highfloat4(sqrt(19.5)) - 0;" + "sk_FragColor = sqrt(20) * highfloat4(1);" + "sk_FragColor = sqrt(21) + highfloat4(0);" + "sk_FragColor = sqrt(22) - highfloat4(0);" + "sk_FragColor = sqrt(23) / highfloat4(1);" + "sk_FragColor = highfloat4(sqrt(24)) / 1;" + "sk_FragColor += highfloat4(1);" + "sk_FragColor += highfloat4(0);" + "sk_FragColor -= highfloat4(1);" + "sk_FragColor -= highfloat4(0);" + "sk_FragColor *= highfloat4(1);" + "sk_FragColor *= highfloat4(2);" + "sk_FragColor /= highfloat4(1);" + "sk_FragColor /= highfloat4(2);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -822,24 +819,24 @@ DEF_TEST(SkSLVecFolding, r) { DEF_TEST(SkSLMatFolding, r) { test(r, "void main() {" - "sk_FragColor.x = float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) == " - "float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 1 : -1;" - "sk_FragColor.x = float2x2(float2(1.0, 0.0), float2(1.0, 1.0)) == " - "float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 2 : -2;" - "sk_FragColor.x = float2x2(1) == float2x2(1) ? 3 : -3;" - "sk_FragColor.x = float2x2(1) == float2x2(0) ? 4 : -4;" - "sk_FragColor.x = float2x2(1) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 5 : -5;" - "sk_FragColor.x = float2x2(2) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ? 6 : -6;" - "sk_FragColor.x = float3x2(2) == float3x2(float2(2.0, 0.0), float2(0.0, 2.0), float2(0.0))" + "sk_FragColor.x = highfloat2x2(highfloat2(1.0, 0.0), highfloat2(0.0, 1.0)) == " + "highfloat2x2(highfloat2(1.0, 0.0), highfloat2(0.0, 1.0)) ? 1 : -1;" + "sk_FragColor.x = highfloat2x2(highfloat2(1.0, 0.0), highfloat2(1.0, 1.0)) == " + "highfloat2x2(highfloat2(1.0, 0.0), highfloat2(0.0, 1.0)) ? 2 : -2;" + "sk_FragColor.x = highfloat2x2(1) == highfloat2x2(1) ? 3 : -3;" + "sk_FragColor.x = highfloat2x2(1) == highfloat2x2(0) ? 4 : -4;" + "sk_FragColor.x = highfloat2x2(1) == highfloat2x2(highfloat2(1.0, 0.0), highfloat2(0.0, 1.0)) ? 5 : -5;" + "sk_FragColor.x = highfloat2x2(2) == highfloat2x2(highfloat2(1.0, 0.0), highfloat2(0.0, 1.0)) ? 6 : -6;" + "sk_FragColor.x = highfloat3x2(2) == highfloat3x2(highfloat2(2.0, 0.0), highfloat2(0.0, 2.0), highfloat2(0.0))" "? 7 : -7;" - "sk_FragColor.x = float2x2(1) != float2x2(1) ? 8 : -8;" - "sk_FragColor.x = float2x2(1) != float2x2(0) ? 9 : -9;" - "sk_FragColor.x = float3x3(float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), " - "float3(0.0, 0.0, 0.0)) == float3x3(float2x2(1.0)) ? 10 : -10;" - "sk_FragColor.x = float2x2(float3x3(1.0)) == float2x2(1.0) ? 11 : -11;" - "sk_FragColor.x = float2x2(float4(1.0, 0.0, 0.0, 1.0)) == float2x2(1.0) ? 12 : -12;" - "sk_FragColor.x = float2x2(1.0, 0.0, float2(0.0, 1.0)) == float2x2(1.0) ? 13 : -13;" - "sk_FragColor.x = float2x2(float2(1.0, 0.0), 0.0, 1.0) == float2x2(1.0) ? 14 : -14;" + "sk_FragColor.x = highfloat2x2(1) != highfloat2x2(1) ? 8 : -8;" + "sk_FragColor.x = highfloat2x2(1) != highfloat2x2(0) ? 9 : -9;" + "sk_FragColor.x = highfloat3x3(highfloat3(1.0, 0.0, 0.0), highfloat3(0.0, 1.0, 0.0), " + "highfloat3(0.0, 0.0, 0.0)) == highfloat3x3(highfloat2x2(1.0)) ? 10 : -10;" + "sk_FragColor.x = highfloat2x2(highfloat3x3(1.0)) == highfloat2x2(1.0) ? 11 : -11;" + "sk_FragColor.x = highfloat2x2(highfloat4(1.0, 0.0, 0.0, 1.0)) == highfloat2x2(1.0) ? 12 : -12;" + "sk_FragColor.x = highfloat2x2(1.0, 0.0, highfloat2(0.0, 1.0)) == highfloat2x2(1.0) ? 13 : -13;" + "sk_FragColor.x = highfloat2x2(highfloat2(1.0, 0.0), 0.0, 1.0) == highfloat2x2(1.0) ? 14 : -14;" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -891,7 +888,7 @@ DEF_TEST(SkSLCaps, r) { "if (sk_Caps.fbFetchSupport) y = 1;" "if (sk_Caps.dropsTileOnZeroDivide && sk_Caps.texelFetchSupport) z = 1;" "if (sk_Caps.dropsTileOnZeroDivide && sk_Caps.canUseAnyFunctionInShader) w = 1;" - "sk_FragColor = float4(x, y, z, w);" + "sk_FragColor = half4(x, y, z, w);" "}", *SkSL::ShaderCapsFactory::VariousCaps(), "#version 400\n" @@ -906,11 +903,11 @@ DEF_TEST(SkSLTexture, r) { "uniform sampler1D one;" "uniform sampler2D two;" "void main() {" - "float4 a = texture(one, 0);" - "float4 b = texture(two, float2(0));" - "float4 c = texture(one, float2(0));" - "float4 d = texture(two, float3(0));" - "sk_FragColor = float4(a.x, b.x, c.x, d.x);" + "highfloat4 a = texture(one, 0);" + "highfloat4 b = texture(two, highfloat2(0));" + "highfloat4 c = texture(one, highfloat2(0));" + "highfloat4 d = texture(two, highfloat3(0));" + "sk_FragColor = half4(a.x, b.x, c.x, d.x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -928,11 +925,11 @@ DEF_TEST(SkSLTexture, r) { "uniform sampler1D one;" "uniform sampler2D two;" "void main() {" - "float4 a = texture(one, 0);" - "float4 b = texture(two, float2(0));" - "float4 c = texture(one, float2(0));" - "float4 d = texture(two, float3(0));" - "sk_FragColor = float4(a.x, b.x, c.x, d.x);" + "highfloat4 a = texture(one, 0);" + "highfloat4 b = texture(two, highfloat2(0));" + "highfloat4 c = texture(one, highfloat2(0));" + "highfloat4 d = texture(two, highfloat3(0));" + "sk_FragColor = half4(a.x, b.x, c.x, d.x);" "}", *SkSL::ShaderCapsFactory::Version110(), "#version 110\n" @@ -1047,7 +1044,7 @@ DEF_TEST(SkSLClipDistance, r) { "}\n", SkSL::Program::kVertex_Kind); test(r, - "void main() { sk_FragColor = float4(sk_ClipDistance[0]); }", + "void main() { sk_FragColor = half4(sk_ClipDistance[0]); }", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -1058,9 +1055,9 @@ DEF_TEST(SkSLClipDistance, r) { DEF_TEST(SkSLArrayTypes, r) { test(r, - "void main() { float2 x[2] = float2[2](float2(1), float2(2));" - "float2[2] y = float2[2](float2(3), float2(4));" - "sk_FragColor = float4(x[0], y[1]); }", + "void main() { highfloat2 x[2] = highfloat2[2](highfloat2(1), highfloat2(2));" + "highfloat2[2] y = highfloat2[2](highfloat2(3), highfloat2(4));" + "sk_FragColor = highfloat4(x[0], y[1]); }", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -1076,9 +1073,9 @@ DEF_TEST(SkSLGeometry, r) { "layout(invocations = 2) in;" "layout(line_strip, max_vertices = 2) out;" "void main() {" - "gl_Position = sk_in[0].gl_Position + float4(-0.5, 0, 0, sk_InvocationID);" + "gl_Position = sk_in[0].gl_Position + highfloat4(-0.5, 0, 0, sk_InvocationID);" "EmitVertex();" - "gl_Position = sk_in[0].gl_Position + float4(0.5, 0, 0, sk_InvocationID);" + "gl_Position = sk_in[0].gl_Position + highfloat4(0.5, 0, 0, sk_InvocationID);" "EmitVertex();" "EndPrimitive();" "}", @@ -1101,7 +1098,7 @@ DEF_TEST(SkSLSwitch, r) { // basic "does a switch even work" test test(r, "void main() {" - " float x;" + " highfloat x;" " switch (int(sqrt(1))) {" " case 0:" " x = 0.0;" @@ -1112,7 +1109,7 @@ DEF_TEST(SkSLSwitch, r) { " default:" " x = 2.0;" " }" - " sk_FragColor = float4(x);" + " sk_FragColor = highfloat4(x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1134,7 +1131,7 @@ DEF_TEST(SkSLSwitch, r) { // dead code inside of switch test(r, "void main() {" - " float x;" + " highfloat x;" " switch (int(sqrt(2))) {" " case 0:" " x = 0.0;" @@ -1143,7 +1140,7 @@ DEF_TEST(SkSLSwitch, r) { " default:" " x = 2.0;" " }" - " sk_FragColor = float4(x);" + " sk_FragColor = half4(x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1162,14 +1159,14 @@ DEF_TEST(SkSLSwitch, r) { // non-static test w/ fallthrough test(r, "void main() {" - " float x = 0.0;" + " highfloat x = 0.0;" " switch (int(sqrt(3))) {" " case 0:" " x = 0.0;" " case 1:" " x = 1.0;" " }" - " sk_FragColor = float4(x);" + " sk_FragColor = half4(x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1187,14 +1184,14 @@ DEF_TEST(SkSLSwitch, r) { // static test w/ fallthrough test(r, "void main() {" - " float x = 0.0;" + " highfloat x = 0.0;" " switch (0) {" " case 0:" " x = 0.0;" " case 1:" " x = 1.0;" " }" - " sk_FragColor = float4(x);" + " sk_FragColor = half4(x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1205,14 +1202,14 @@ DEF_TEST(SkSLSwitch, r) { // static test w/ fallthrough, different entry point test(r, "void main() {" - " float x = 0.0;" + " highfloat x = 0.0;" " switch (1) {" " case 0:" " x = 0.0;" " case 1:" " x = 1.0;" " }" - " sk_FragColor = float4(x);" + " sk_FragColor = half4(x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1223,7 +1220,7 @@ DEF_TEST(SkSLSwitch, r) { // static test w/ break test(r, "void main() {" - " float x = 0.0;" + " highfloat x = 0.0;" " switch (0) {" " case 0:" " x = 0.0;" @@ -1231,7 +1228,7 @@ DEF_TEST(SkSLSwitch, r) { " case 1:" " x = 1.0;" " }" - " sk_FragColor = float4(x);" + " sk_FragColor = half4(x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1242,7 +1239,7 @@ DEF_TEST(SkSLSwitch, r) { // static test w/ static conditional break test(r, "void main() {" - " float x = 0.0;" + " highfloat x = 0.0;" " switch (0) {" " case 0:" " x = 0.0;" @@ -1250,7 +1247,7 @@ DEF_TEST(SkSLSwitch, r) { " case 1:" " x = 1.0;" " }" - " sk_FragColor = float4(x);" + " sk_FragColor = half4(x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1261,7 +1258,7 @@ DEF_TEST(SkSLSwitch, r) { // static test w/ non-static conditional break test(r, "void main() {" - " float x = 0.0;" + " highfloat x = 0.0;" " switch (0) {" " case 0:" " x = 0.0;" @@ -1269,7 +1266,7 @@ DEF_TEST(SkSLSwitch, r) { " case 1:" " x = 1.0;" " }" - " sk_FragColor = float4(x);" + " sk_FragColor = half4(x);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1291,7 +1288,7 @@ DEF_TEST(SkSLRectangleTexture, r) { test(r, "uniform sampler2D test;" "void main() {" - " sk_FragColor = texture(test, float2(0.5));" + " sk_FragColor = texture(test, highfloat2(0.5));" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1303,7 +1300,7 @@ DEF_TEST(SkSLRectangleTexture, r) { test(r, "uniform sampler2DRect test;" "void main() {" - " sk_FragColor = texture(test, float2(0.5));" + " sk_FragColor = texture(test, highfloat2(0.5));" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1315,7 +1312,7 @@ DEF_TEST(SkSLRectangleTexture, r) { test(r, "uniform sampler2DRect test;" "void main() {" - " sk_FragColor = texture(test, float3(0.5));" + " sk_FragColor = texture(test, highfloat3(0.5));" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1329,12 +1326,12 @@ DEF_TEST(SkSLRectangleTexture, r) { DEF_TEST(SkSLUnusedVars, r) { test(r, "void main() {" - "float a = 1, b = 2, c = 3;" - "float d = c;" - "float e = d;" + "highfloat a = 1, b = 2, c = 3;" + "highfloat d = c;" + "highfloat e = d;" "b++;" "d++;" - "sk_FragColor = float4(b, b, d, d);" + "sk_FragColor = highfloat4(b, b, d, d);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1351,11 +1348,11 @@ DEF_TEST(SkSLUnusedVars, r) { DEF_TEST(SkSLMultipleAssignments, r) { test(r, "void main() {" - "float x;" - "float y;" + "highfloat x;" + "highfloat y;" "int z;" "x = y = z = 1;" - "sk_FragColor = float4(z);" + "sk_FragColor = highfloat4(z);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1367,13 +1364,13 @@ DEF_TEST(SkSLMultipleAssignments, r) { DEF_TEST(SkSLComplexDelete, r) { test(r, - "uniform float4x4 colorXform;" + "uniform highfloat4x4 colorXform;" "uniform sampler2D sampler;" "void main() {" - "float4 tmpColor;" - "sk_FragColor = float4(1.0) * (tmpColor = texture(sampler, float2(1)) , " - "colorXform != float4x4(1.0) ? float4(clamp((float4x4(colorXform) * " - "float4(tmpColor.xyz, 1.0)).xyz, " + "highfloat4 tmpColor;" + "sk_FragColor = highfloat4(1.0) * (tmpColor = texture(sampler, highfloat2(1)) , " + "colorXform != highfloat4x4(1.0) ? highfloat4(clamp((highfloat4x4(colorXform) * " + "highfloat4(tmpColor.xyz, 1.0)).xyz, " "0.0, tmpColor.w), tmpColor.w) : tmpColor);" "}", *SkSL::ShaderCapsFactory::Default(), @@ -1392,8 +1389,8 @@ DEF_TEST(SkSLComplexDelete, r) { DEF_TEST(SkSLDependentInitializers, r) { test(r, "void main() {" - "float x = 0.5, y = x * 2;" - "sk_FragColor = float4(y);" + "highfloat x = 0.5, y = x * 2;" + "sk_FragColor = highfloat4(y);" "}", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" @@ -1427,11 +1424,11 @@ DEF_TEST(SkSLInvocations, r) { "layout(invocations = 2) in;" "layout(line_strip, max_vertices = 2) out;" "void test() {" - "gl_Position = sk_in[0].gl_Position + float4(0.5, 0, 0, sk_InvocationID);" + "gl_Position = sk_in[0].gl_Position + highfloat4(0.5, 0, 0, sk_InvocationID);" "EmitVertex();" "}" "void main() {" - "gl_Position = sk_in[0].gl_Position + float4(-0.5, 0, 0, sk_InvocationID);" + "gl_Position = sk_in[0].gl_Position + highfloat4(-0.5, 0, 0, sk_InvocationID);" "EmitVertex();" "}", *SkSL::ShaderCapsFactory::MustImplementGSInvocationsWithLoop(), @@ -1458,13 +1455,13 @@ DEF_TEST(SkSLInvocations, r) { DEF_TEST(SkSLTypePrecision, r) { test(r, - "float f = 1;" + "highfloat f = 1;" "half h = 2;" "double d = 3;" - "float2 f2 = float2(1, 2);" + "highfloat2 f2 = highfloat2(1, 2);" "half3 h3 = half3(1, 2, 3);" "double4 d4 = double4(1, 2, 3, 4);" - "float2x2 f22 = float2x2(1, 2, 3, 4);" + "highfloat2x2 f22 = highfloat2x2(1, 2, 3, 4);" "half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8);" "double4x2 d42 = double4x2(1, 2, 3, 4, 5, 6, 7, 8);", *SkSL::ShaderCapsFactory::Default(), @@ -1480,21 +1477,20 @@ DEF_TEST(SkSLTypePrecision, r) { "mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n" "dmat4x2 d42 = dmat4x2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n"); test(r, - "float f = 1;" + "highfloat f = 1;" "half h = 2;" - "float2 f2 = float2(1, 2);" + "highfloat2 f2 = highfloat2(1, 2);" "half3 h3 = half3(1, 2, 3);" - "float2x2 f22 = float2x2(1, 2, 3, 4);" + "highfloat2x2 f22 = highfloat2x2(1, 2, 3, 4);" "half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8);", *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), "#version 400\n" - "precision highp float;\n" "out mediump vec4 sk_FragColor;\n" - "float f = 1.0;\n" + "highp float f = 1.0;\n" "mediump float h = 2.0;\n" - "vec2 f2 = vec2(1.0, 2.0);\n" + "highp vec2 f2 = vec2(1.0, 2.0);\n" "mediump vec3 h3 = vec3(1.0, 2.0, 3.0);\n" - "mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n" + "highp mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n" "mediump mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n"); } @@ -1505,50 +1501,37 @@ DEF_TEST(SkSLNumberConversions, r) { "ushort us = ushort(sqrt(1));" "uint ui = uint(sqrt(1));" "half h = sqrt(1);" - "float f = sqrt(1);" - "double d = sqrt(1);" + "highfloat f = sqrt(1);" "short s2s = s;" "short i2s = i;" "short us2s = short(us);" "short ui2s = short(ui);" "short h2s = short(h);" "short f2s = short(f);" - "short d2fs = short(d);" "int s2i = s;" "int i2i = i;" "int us2i = int(us);" "int ui2i = int(ui);" "int h2i = int(h);" "int f2i = int(f);" - "int d2fi = int(d);" "ushort s2us = ushort(s);" "ushort i2us = ushort(i);" "ushort us2us = us;" "ushort ui2us = ui;" "ushort h2us = ushort(h);" "ushort f2us = ushort(f);" - "ushort d2fus = ushort(d);" "uint s2ui = uint(s);" "uint i2ui = uint(i);" "uint us2ui = us;" "uint ui2ui = ui;" "uint h2ui = uint(h);" "uint f2ui = uint(f);" - "uint d2fui = uint(d);" - "float s2f = s;" - "float i2f = i;" - "float us2f = us;" - "float ui2f = ui;" - "float h2f = h;" - "float f2f = f;" - "float d2f = d;" - "double s2d = s;" - "double i2d = i;" - "double us2d = us;" - "double ui2d = ui;" - "double h2d = h;" - "double f2d = f;" - "double d2d = d;", + "highfloat s2f = s;" + "highfloat i2f = i;" + "highfloat us2f = us;" + "highfloat ui2f = ui;" + "highfloat h2f = h;" + "highfloat f2f = f;", *SkSL::ShaderCapsFactory::Default(), "#version 400\n" "out vec4 sk_FragColor;\n" @@ -1558,49 +1541,65 @@ DEF_TEST(SkSLNumberConversions, r) { "uint ui = uint(sqrt(1.0));\n" "float h = sqrt(1.0);\n" "float f = sqrt(1.0);\n" - "double d = sqrt(1.0);\n" "int s2s = s;\n" "int i2s = i;\n" "int us2s = int(us);\n" "int ui2s = int(ui);\n" "int h2s = int(h);\n" "int f2s = int(f);\n" - "int d2fs = int(d);\n" "int s2i = s;\n" "int i2i = i;\n" "int us2i = int(us);\n" "int ui2i = int(ui);\n" "int h2i = int(h);\n" "int f2i = int(f);\n" - "int d2fi = int(d);\n" "uint s2us = uint(s);\n" "uint i2us = uint(i);\n" "uint us2us = us;\n" "uint ui2us = ui;\n" "uint h2us = uint(h);\n" "uint f2us = uint(f);\n" - "uint d2fus = uint(d);\n" "uint s2ui = uint(s);\n" "uint i2ui = uint(i);\n" "uint us2ui = us;\n" "uint ui2ui = ui;\n" "uint h2ui = uint(h);\n" "uint f2ui = uint(f);\n" - "uint d2fui = uint(d);\n" "float s2f = float(s);\n" "float i2f = float(i);\n" "float us2f = float(us);\n" "float ui2f = float(ui);\n" "float h2f = h;\n" - "float f2f = f;\n" - "float d2f = d;\n" - "double s2d = double(s);\n" - "double i2d = double(i);\n" - "double us2d = double(us);\n" - "double ui2d = double(ui);\n" - "double h2d = h;\n" - "double f2d = f;\n" - "double d2d = d;\n"); + "float f2f = f;\n"); +} + +DEF_TEST(SkSLForceHighPrecision, r) { + test(r, + "void main() { half x = sqrt(1); half4 y = half4(x); sk_FragColor = y; }", + *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), + "#version 400\n" + "out mediump vec4 sk_FragColor;\n" + "void main() {\n" + " mediump float x = sqrt(1.0);\n" + " mediump vec4 y = vec4(x);\n" + " sk_FragColor = y;\n" + "}\n"); + SkSL::Program::Settings settings; + settings.fForceHighPrecision = true; + sk_sp caps = SkSL::ShaderCapsFactory::UsesPrecisionModifiers(); + settings.fCaps = caps.get(); + SkSL::Program::Inputs inputs; + test(r, + "void main() { half x = sqrt(1); half4 y = half4(x); sk_FragColor = y; }", + settings, + "#version 400\n" + "out mediump vec4 sk_FragColor;\n" + "void main() {\n" + " highp float x = sqrt(1.0);\n" + " highp vec4 y = vec4(x);\n" + " sk_FragColor = y;\n" + "}\n", + &inputs); } #endif -- cgit v1.2.3