From 93061b53442ce303e9d3ef74c7eeddc034802c4f Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Tue, 1 Aug 2017 13:41:59 -0400 Subject: support for 'half' types in sksl, plus general numeric type improvements Bug: skia: Change-Id: Id285262fda8291847f11343d499b5df62ddb4b09 Reviewed-on: https://skia-review.googlesource.com/28980 Reviewed-by: Brian Salomon Commit-Queue: Ethan Nicholas --- tests/SkSLGLSLTest.cpp | 151 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 2 deletions(-) (limited to 'tests/SkSLGLSLTest.cpp') diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index de002c7e81..80727d9804 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -316,7 +316,7 @@ DEF_TEST(SkSLUsesPrecisionModifiers, r) { " sk_FragColor.xy = vec2(x, y);\n" "}\n"); test(r, - "void main() { float x = 0.75; highp float y = 1; x++; y++;" + "void main() { float x = 0.75; half y = 1; x++; y++;" "sk_FragColor.rg = float2(x, y); }", *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), "#version 400\n" @@ -324,7 +324,7 @@ DEF_TEST(SkSLUsesPrecisionModifiers, r) { "out mediump vec4 sk_FragColor;\n" "void main() {\n" " float x = 0.75;\n" - " highp float y = 1.0;\n" + " mediump float y = 1.0;\n" " x++;\n" " y++;\n" " sk_FragColor.xy = vec2(x, y);\n" @@ -1432,4 +1432,151 @@ DEF_TEST(SkSLInvocations, r) { SkSL::Program::kGeometry_Kind); } +DEF_TEST(SkSLTypePrecision, r) { + test(r, + "float f = 1;" + "half h = 2;" + "double d = 3;" + "float2 f2 = float2(1, 2);" + "half3 h3 = half3(1, 2, 3);" + "double4 d4 = double4(1, 2, 3, 4);" + "float2x2 f22 = float2x2(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(), + "#version 400\n" + "out vec4 sk_FragColor;\n" + "float f = 1.0;\n" + "float h = 2.0;\n" + "double d = 3.0;\n" + "vec2 f2 = vec2(1.0, 2.0);\n" + "vec3 h3 = vec3(1.0, 2.0, 3.0);\n" + "dvec4 d4 = dvec4(1.0, 2.0, 3.0, 4.0);\n" + "mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n" + "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;" + "half h = 2;" + "float2 f2 = float2(1, 2);" + "half3 h3 = half3(1, 2, 3);" + "float2x2 f22 = float2x2(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" + "mediump float h = 2.0;\n" + "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" + "mediump mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n"); +} + +DEF_TEST(SkSLNumberConversions, r) { + test(r, + "short s = short(sqrt(1));" + "int i = int(sqrt(1));" + "ushort us = ushort(sqrt(1));" + "uint ui = uint(sqrt(1));" + "half h = sqrt(1);" + "float f = sqrt(1);" + "double d = 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;", + *SkSL::ShaderCapsFactory::Default(), + "#version 400\n" + "out vec4 sk_FragColor;\n" + "int s = int(sqrt(1.0));\n" + "int i = int(sqrt(1.0));\n" + "uint us = uint(sqrt(1.0));\n" + "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"); +} + #endif -- cgit v1.2.3