From cc10d790df6596c21a9e01ed6dadb680d7fe19e5 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Fri, 20 Jul 2018 13:09:45 -0400 Subject: Move fragCoord workaround declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures that all extension directives occur before any non-preprocessor tokens, as required by the spec (ยง 3.4). This was found by Qualcomm, and originally submitted as https://github.com/google/skia/pull/21 Bug: b/111525079 Change-Id: I24357e4d3654e76c2dfbc067aca3088948dfa5a8 Reviewed-on: https://skia-review.googlesource.com/142697 Reviewed-by: Brian Salomon Commit-Queue: Brian Osman --- src/sksl/SkSLGLSLCodeGenerator.cpp | 40 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'src/sksl') diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp index 5f6fedcdb5..76e76c3271 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.cpp +++ b/src/sksl/SkSLGLSLCodeGenerator.cpp @@ -1264,25 +1264,6 @@ void GLSLCodeGenerator::writeHeader() { this->writeExtension((Extension&) e); } } - if (!fProgram.fSettings.fCaps->canUseFragCoord()) { - Layout layout; - switch (fProgram.fKind) { - case Program::kVertex_Kind: { - Modifiers modifiers(layout, Modifiers::kOut_Flag | Modifiers::kHighp_Flag); - this->writeModifiers(modifiers, true); - this->write("vec4 sk_FragCoord_Workaround;\n"); - break; - } - case Program::kFragment_Kind: { - Modifiers modifiers(layout, Modifiers::kIn_Flag | Modifiers::kHighp_Flag); - this->writeModifiers(modifiers, true); - this->write("vec4 sk_FragCoord_Workaround;\n"); - break; - } - default: - break; - } - } } void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) { @@ -1359,6 +1340,27 @@ bool GLSLCodeGenerator::generateCode() { fOut = rawOut; write_stringstream(fHeader, *rawOut); + + if (!fProgram.fSettings.fCaps->canUseFragCoord()) { + Layout layout; + switch (fProgram.fKind) { + case Program::kVertex_Kind: { + Modifiers modifiers(layout, Modifiers::kOut_Flag | Modifiers::kHighp_Flag); + this->writeModifiers(modifiers, true); + this->write("vec4 sk_FragCoord_Workaround;\n"); + break; + } + case Program::kFragment_Kind: { + Modifiers modifiers(layout, Modifiers::kIn_Flag | Modifiers::kHighp_Flag); + this->writeModifiers(modifiers, true); + this->write("vec4 sk_FragCoord_Workaround;\n"); + break; + } + default: + break; + } + } + if (this->usesPrecisionModifiers()) { this->writeLine("precision mediump float;"); } -- cgit v1.2.3