diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2016-12-12 15:33:30 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-12-13 14:28:53 +0000 |
commit | 941e7e2c9567ab1d8a3b2d1b0e3db71ee5eb75c9 (patch) | |
tree | 7f0ad6c5b2c3772d2c83be545fe04c53044746bd /tests | |
parent | 3dc73f3596d93a89f71b0c7e96d5d63dafeaf378 (diff) |
re-land of added sk_FragCoord support to skslc
BUG=skia:
Change-Id: Ifac1aa39839058787ad1794200c3dbb93c147a69
Reviewed-on: https://skia-review.googlesource.com/5850
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/SkSLErrorTest.cpp | 21 | ||||
-rw-r--r-- | tests/SkSLGLSLTest.cpp | 88 |
2 files changed, 98 insertions, 11 deletions
diff --git a/tests/SkSLErrorTest.cpp b/tests/SkSLErrorTest.cpp index c653072dd1..e872977eeb 100644 --- a/tests/SkSLErrorTest.cpp +++ b/tests/SkSLErrorTest.cpp @@ -14,21 +14,34 @@ static void test_failure(skiatest::Reporter* r, const char* src, const char* error) { SkSL::Compiler compiler; SkDynamicMemoryWStream out; - bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, SkString(src), out); + SkSL::Program::Settings settings; + sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); + settings.fCaps = caps.get(); + std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind, + SkString(src), settings); + if (program) { + SkString ignored; + compiler.toSPIRV(*program, &ignored); + } SkString skError(error); if (compiler.errorText() != skError) { SkDebugf("SKSL ERROR:\n source: %s\n expected: %s received: %s", src, error, compiler.errorText().c_str()); } - REPORTER_ASSERT(r, !result); REPORTER_ASSERT(r, compiler.errorText() == skError); } static void test_success(skiatest::Reporter* r, const char* src) { SkSL::Compiler compiler; SkDynamicMemoryWStream out; - bool result = compiler.toSPIRV(SkSL::Program::kFragment_Kind, SkString(src), out); - REPORTER_ASSERT(r, result); + SkSL::Program::Settings settings; + sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); + settings.fCaps = caps.get(); + std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind, + SkString(src), settings); + REPORTER_ASSERT(r, program); + SkString ignored; + REPORTER_ASSERT(r, compiler.toSPIRV(*program, &ignored)); } DEF_TEST(SkSLUndefinedSymbol, r) { diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index ceb7cb7229..12ac4d1101 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -11,25 +11,37 @@ #if SK_SUPPORT_GPU -static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& caps, - const char* expected) { +static void test(skiatest::Reporter* r, const char* src, const SkSL::Program::Settings& settings, + const char* expected, SkSL::Program::Inputs* inputs) { SkSL::Compiler compiler; SkString output; - bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind, SkString(src), caps, &output); - if (!result) { + std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind, + SkString(src), + settings); + if (!program) { SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str()); } - REPORTER_ASSERT(r, result); - if (result) { + REPORTER_ASSERT(r, program); + *inputs = program->fInputs; + REPORTER_ASSERT(r, compiler.toGLSL(*program, &output)); + if (program) { SkString skExpected(expected); if (output != skExpected) { - SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src, + SkDebugf("GLSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src, expected, output.c_str()); } REPORTER_ASSERT(r, output == skExpected); } } +static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& caps, + const char* expected) { + SkSL::Program::Settings settings; + settings.fCaps = ∩︀ + SkSL::Program::Inputs inputs; + test(r, src, settings, expected, &inputs); +} + DEF_TEST(SkSLHelloWorld, r) { test(r, "void main() { sk_FragColor = vec4(0.75); }", @@ -603,4 +615,66 @@ DEF_TEST(SkSLOffset, r) { " int z;\n" "} test;\n"); } + +DEF_TEST(SkSLFragCoord, r) { + SkSL::Program::Settings settings; + settings.fFlipY = true; + sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::FragCoordsOld(); + settings.fCaps = caps.get(); + SkSL::Program::Inputs inputs; + test(r, + "void main() { sk_FragColor.xy = sk_FragCoord.xy; }", + settings, + "#version 110\n" + "#extension GL_ARB_fragment_coord_conventions : require\n" + "layout(origin_upper_left) in vec4 gl_FragCoord;\n" + "void main() {\n" + " gl_FragColor.xy = gl_FragCoord.xy;\n" + "}\n", + &inputs); + REPORTER_ASSERT(r, !inputs.fRTHeight); + + caps = SkSL::ShaderCapsFactory::FragCoordsNew(); + settings.fCaps = caps.get(); + test(r, + "void main() { sk_FragColor.xy = sk_FragCoord.xy; }", + settings, + "#version 400\n" + "layout(origin_upper_left) in vec4 gl_FragCoord;\n" + "out vec4 sk_FragColor;\n" + "void main() {\n" + " sk_FragColor.xy = gl_FragCoord.xy;\n" + "}\n", + &inputs); + REPORTER_ASSERT(r, !inputs.fRTHeight); + + caps = SkSL::ShaderCapsFactory::Default(); + settings.fCaps = caps.get(); + test(r, + "void main() { sk_FragColor.xy = sk_FragCoord.xy; }", + settings, + "#version 400\n" + "uniform float u_skRTHeight;\n" + "out vec4 sk_FragColor;\n" + "void main() {\n" + " vec2 _sktmpCoord = gl_FragCoord.xy;\n" + " vec4 sk_FragCoord = vec4(_sktmpCoord.x, u_skRTHeight - _sktmpCoord.y, 1.0, 1.0);\n" + " sk_FragColor.xy = sk_FragCoord.xy;\n" + "}\n", + &inputs); + REPORTER_ASSERT(r, inputs.fRTHeight); + + settings.fFlipY = false; + test(r, + "void main() { sk_FragColor.xy = sk_FragCoord.xy; }", + settings, + "#version 400\n" + "out vec4 sk_FragColor;\n" + "void main() {\n" + " sk_FragColor.xy = gl_FragCoord.xy;\n" + "}\n", + &inputs); + REPORTER_ASSERT(r, !inputs.fRTHeight); +} + #endif |